File tree 1 file changed +22
-0
lines changed 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,28 @@ extern "C" {
14
14
#include "pycore_pystate.h" // _PyInterpreterState_GET()
15
15
#include "pycore_runtime.h" // _PyRuntime
16
16
17
+ #define _Py_IMMORTAL_REFCNT_LOOSE ((_Py_IMMORTAL_REFCNT >> 1) + 1)
18
+
19
+ // gh-121528, gh-118997: Similar to _Py_IsImmortal() but be more loose when
20
+ // comparing the reference count to stay compatible with C extensions built
21
+ // with the stable ABI 3.11 or older. Such extensions implement INCREF/DECREF
22
+ // as refcnt++ and refcnt-- without taking in account immortal objects. For
23
+ // example, the reference count of an immortal object can change from
24
+ // _Py_IMMORTAL_REFCNT to _Py_IMMORTAL_REFCNT+1 (INCREF) or
25
+ // _Py_IMMORTAL_REFCNT-1 (DECREF).
26
+ //
27
+ // This function should only be used in assertions. Otherwise, _Py_IsImmortal()
28
+ // must be used instead.
29
+ static inline int _Py_IsImmortalLoose (PyObject * op )
30
+ {
31
+ #if defined(Py_GIL_DISABLED )
32
+ return _Py_IsImmortal (op );
33
+ #else
34
+ return (op -> ob_refcnt >= _Py_IMMORTAL_REFCNT_LOOSE );
35
+ #endif
36
+ }
37
+ #define _Py_IsImmortalLoose (op ) _Py_IsImmortalLoose(_PyObject_CAST(op))
38
+
17
39
/* We need to maintain an internal copy of Py{Var}Object_HEAD_INIT to avoid
18
40
designated initializer conflicts in C++20. If we use the deinition in
19
41
object.h, we will be mixing designated and non-designated initializers in
You can’t perform that action at this time.
0 commit comments