diff options
author | Mark Shannon <mark@hotpy.org> | 2024-12-11 17:37:38 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-11 17:37:38 (GMT) |
commit | bc262de06b10a2d119c28bac75060bf00301697a (patch) | |
tree | ee2cd2b91e8c9d91aa3b2287b7c59db0097a10ec /Objects | |
parent | dd9da738ad1d420fabafaded3fe63912b2b17cfb (diff) | |
download | cpython-bc262de06b10a2d119c28bac75060bf00301697a.zip cpython-bc262de06b10a2d119c28bac75060bf00301697a.tar.gz cpython-bc262de06b10a2d119c28bac75060bf00301697a.tar.bz2 |
GH-125174: Mark objects as statically allocated. (#127797)
* Set a bit in the unused part of the refcount on 64 bit machines and the free-threaded build.
* Use the top of the refcount range on 32 bit machines
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/object.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/Objects/object.c b/Objects/object.c index 74f47fa..c64675b 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -2475,10 +2475,16 @@ new_reference(PyObject *op) { // Skip the immortal object check in Py_SET_REFCNT; always set refcnt to 1 #if !defined(Py_GIL_DISABLED) +#if SIZEOF_VOID_P > 4 + op->ob_refcnt_full = 1; + assert(op->ob_refcnt == 1); + assert(op->ob_flags == 0); +#else op->ob_refcnt = 1; +#endif #else op->ob_tid = _Py_ThreadId(); - op->_padding = 0; + op->ob_flags = 0; op->ob_mutex = (PyMutex){ 0 }; op->ob_gc_bits = 0; op->ob_ref_local = 1; @@ -2515,6 +2521,10 @@ _Py_SetImmortalUntracked(PyObject *op) || PyUnicode_CHECK_INTERNED(op) == SSTATE_INTERNED_IMMORTAL_STATIC); } #endif + // Check if already immortal to avoid degrading from static immortal to plain immortal + if (_Py_IsImmortal(op)) { + return; + } #ifdef Py_GIL_DISABLED op->ob_tid = _Py_UNOWNED_TID; op->ob_ref_local = _Py_IMMORTAL_REFCNT_LOCAL; |