Skip to content

Commit 28f5e3d

Browse files
authored
gh-129984: Mark immortal objects as deferred (#129985)
Mark immortal objects as deferred
1 parent 0559339 commit 28f5e3d

File tree

4 files changed

+5
-3
lines changed

4 files changed

+5
-3
lines changed

Include/internal/pycore_object.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ PyAPI_FUNC(int) _PyObject_IsFreed(PyObject *);
7474
{ \
7575
.ob_ref_local = _Py_IMMORTAL_REFCNT_LOCAL, \
7676
.ob_flags = _Py_STATICALLY_ALLOCATED_FLAG, \
77+
.ob_gc_bits = _PyGC_BITS_DEFERRED, \
7778
.ob_type = (type) \
7879
}
7980
#else
@@ -612,7 +613,7 @@ _Py_TryIncrefCompare(PyObject **src, PyObject *op)
612613
static inline int
613614
_Py_TryIncrefCompareStackRef(PyObject **src, PyObject *op, _PyStackRef *out)
614615
{
615-
if (_Py_IsImmortal(op) || _PyObject_HasDeferredRefcount(op)) {
616+
if (_PyObject_HasDeferredRefcount(op)) {
616617
*out = (_PyStackRef){ .bits = (intptr_t)op | Py_TAG_DEFERRED };
617618
return 1;
618619
}

Include/internal/pycore_stackref.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ PyStackRef_FromPyObjectNew(PyObject *obj)
219219
// Make sure we don't take an already tagged value.
220220
assert(((uintptr_t)obj & Py_TAG_BITS) == 0);
221221
assert(obj != NULL);
222-
if (_Py_IsImmortal(obj) || _PyObject_HasDeferredRefcount(obj)) {
222+
if (_PyObject_HasDeferredRefcount(obj)) {
223223
return (_PyStackRef){ .bits = (uintptr_t)obj | Py_TAG_DEFERRED };
224224
}
225225
else {

Objects/dictobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1590,7 +1590,7 @@ _Py_dict_lookup_threadsafe_stackref(PyDictObject *mp, PyObject *key, Py_hash_t h
15901590
*value_addr = PyStackRef_NULL;
15911591
return DKIX_EMPTY;
15921592
}
1593-
if (_Py_IsImmortal(value) || _PyObject_HasDeferredRefcount(value)) {
1593+
if (_PyObject_HasDeferredRefcount(value)) {
15941594
*value_addr = (_PyStackRef){ .bits = (uintptr_t)value | Py_TAG_DEFERRED };
15951595
return ix;
15961596
}

Objects/object.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2538,6 +2538,7 @@ _Py_SetImmortalUntracked(PyObject *op)
25382538
op->ob_tid = _Py_UNOWNED_TID;
25392539
op->ob_ref_local = _Py_IMMORTAL_REFCNT_LOCAL;
25402540
op->ob_ref_shared = 0;
2541+
_Py_atomic_or_uint8(&op->ob_gc_bits, _PyGC_BITS_DEFERRED);
25412542
#else
25422543
op->ob_refcnt = _Py_IMMORTAL_INITIAL_REFCNT;
25432544
#endif

0 commit comments

Comments
 (0)