Skip to content

Commit

Permalink
Use PyObject_GC_IsFinalized in Cython >= 3.9 (#5481)
Browse files Browse the repository at this point in the history
Co-authored-by: Thomas A Caswell <tcaswell@gmail.com>
  • Loading branch information
2 people authored and da-woods committed Jun 9, 2023
1 parent 54b92e3 commit 863e931
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Cython/Compiler/ModuleNode.py
Original file line number Diff line number Diff line change
Expand Up @@ -1463,10 +1463,10 @@ def generate_dealloc_function(self, scope, code):
# in Py3.4+, call tp_finalize() as early as possible
code.putln("#if CYTHON_USE_TP_FINALIZE")
if needs_gc:
finalised_check = '!_PyGC_FINALIZED(o)'
finalised_check = '!__Pyx_PyObject_GC_IsFinalized(o)'
else:
finalised_check = (
'(!PyType_IS_GC(Py_TYPE(o)) || !_PyGC_FINALIZED(o))')
'(!PyType_IS_GC(Py_TYPE(o)) || !__Pyx_PyObject_GC_IsFinalized(o))')
code.putln(
"if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE)"
" && Py_TYPE(o)->tp_finalize) && %s) {" % finalised_check)
Expand Down
6 changes: 6 additions & 0 deletions Cython/Utility/ModuleSetupCode.c
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,12 @@ class __Pyx_FakeReference {
#define __Pyx_DefaultClassType PyType_Type
#endif

#if PY_VERSION_HEX >= 0x030900F0 && !CYTHON_COMPILING_IN_PYPY
#define __Pyx_PyObject_GC_IsFinalized(o) PyObject_GC_IsFinalized(o)
#else
#define __Pyx_PyObject_GC_IsFinalized(o) _PyGC_FINALIZED(o)
#endif

#ifndef Py_TPFLAGS_CHECKTYPES
#define Py_TPFLAGS_CHECKTYPES 0
#endif
Expand Down

0 comments on commit 863e931

Please sign in to comment.