]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-129984: Mark immortal objects as deferred (#129985)
authorDino Viehland <dinoviehland@meta.com>
Thu, 13 Feb 2025 17:01:43 +0000 (09:01 -0800)
committerGitHub <noreply@github.com>
Thu, 13 Feb 2025 17:01:43 +0000 (09:01 -0800)
Mark immortal objects as deferred

Include/internal/pycore_object.h
Include/internal/pycore_stackref.h
Objects/dictobject.c
Objects/object.c

index 49ddfd5b43b00cf9fad950cdf34a061b009a70e0..ffd31bd4a27f498582b04da89fab8b12ee077fe9 100644 (file)
@@ -74,6 +74,7 @@ PyAPI_FUNC(int) _PyObject_IsFreed(PyObject *);
     {                                               \
         .ob_ref_local = _Py_IMMORTAL_REFCNT_LOCAL,  \
         .ob_flags = _Py_STATICALLY_ALLOCATED_FLAG,  \
+        .ob_gc_bits = _PyGC_BITS_DEFERRED,          \
         .ob_type = (type)                           \
     }
 #else
@@ -612,7 +613,7 @@ _Py_TryIncrefCompare(PyObject **src, PyObject *op)
 static inline int
 _Py_TryIncrefCompareStackRef(PyObject **src, PyObject *op, _PyStackRef *out)
 {
-    if (_Py_IsImmortal(op) || _PyObject_HasDeferredRefcount(op)) {
+    if (_PyObject_HasDeferredRefcount(op)) {
         *out = (_PyStackRef){ .bits = (intptr_t)op | Py_TAG_DEFERRED };
         return 1;
     }
index 1ae62cc69bb36472e7812363440e5541abe48fd3..92b10d21100a2506028723a8886a96e9a1832f6f 100644 (file)
@@ -219,7 +219,7 @@ PyStackRef_FromPyObjectNew(PyObject *obj)
     // Make sure we don't take an already tagged value.
     assert(((uintptr_t)obj & Py_TAG_BITS) == 0);
     assert(obj != NULL);
-    if (_Py_IsImmortal(obj) || _PyObject_HasDeferredRefcount(obj)) {
+    if (_PyObject_HasDeferredRefcount(obj)) {
         return (_PyStackRef){ .bits = (uintptr_t)obj | Py_TAG_DEFERRED };
     }
     else {
index d979cd72b48e690f89ad7bb65cc391e16876a028..900d001d4dd56ab13633a17affd8536dd43978b8 100644 (file)
@@ -1590,7 +1590,7 @@ _Py_dict_lookup_threadsafe_stackref(PyDictObject *mp, PyObject *key, Py_hash_t h
                 *value_addr = PyStackRef_NULL;
                 return DKIX_EMPTY;
             }
-            if (_Py_IsImmortal(value) || _PyObject_HasDeferredRefcount(value)) {
+            if (_PyObject_HasDeferredRefcount(value)) {
                 *value_addr =  (_PyStackRef){ .bits = (uintptr_t)value | Py_TAG_DEFERRED };
                 return ix;
             }
index 2dd50339c5800db722d999acf367219fa1c95468..16aedac916bf346db0e6bb71d2dc44e953cf90d1 100644 (file)
@@ -2538,6 +2538,7 @@ _Py_SetImmortalUntracked(PyObject *op)
     op->ob_tid = _Py_UNOWNED_TID;
     op->ob_ref_local = _Py_IMMORTAL_REFCNT_LOCAL;
     op->ob_ref_shared = 0;
+    _Py_atomic_or_uint8(&op->ob_gc_bits, _PyGC_BITS_DEFERRED);
 #else
     op->ob_refcnt = _Py_IMMORTAL_INITIAL_REFCNT;
 #endif