https://github.com/python/cpython/commit/28f5e3de572e1f688b05126d395cf3aadd5ab8ad
commit: 28f5e3de572e1f688b05126d395cf3aadd5ab8ad
branch: main
author: Dino Viehland <[email protected]>
committer: DinoV <[email protected]>
date: 2025-02-13T09:01:43-08:00
summary:
gh-129984: Mark immortal objects as deferred (#129985)
Mark immortal objects as deferred
files:
M Include/internal/pycore_object.h
M Include/internal/pycore_stackref.h
M Objects/dictobject.c
M Objects/object.c
diff --git a/Include/internal/pycore_object.h b/Include/internal/pycore_object.h
index 49ddfd5b43b00c..ffd31bd4a27f49 100644
--- a/Include/internal/pycore_object.h
+++ b/Include/internal/pycore_object.h
@@ -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;
}
diff --git a/Include/internal/pycore_stackref.h
b/Include/internal/pycore_stackref.h
index 1ae62cc69bb364..92b10d21100a25 100644
--- a/Include/internal/pycore_stackref.h
+++ b/Include/internal/pycore_stackref.h
@@ -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 {
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index d979cd72b48e69..900d001d4dd56a 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -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;
}
diff --git a/Objects/object.c b/Objects/object.c
index 2dd50339c5800d..16aedac916bf34 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -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
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]