diff options
author | Sam Gross <colesbury@gmail.com> | 2024-01-06 03:12:26 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-06 03:12:26 (GMT) |
commit | d0f0308a373298a8906ee5a7546275e1b2e906ea (patch) | |
tree | 2220f010051413aadc70662c9f76add31260228b /Objects/object.c | |
parent | 3375dfed400494ba5cc1b744d52f6fb8b7796059 (diff) | |
download | cpython-d0f0308a373298a8906ee5a7546275e1b2e906ea.zip cpython-d0f0308a373298a8906ee5a7546275e1b2e906ea.tar.gz cpython-d0f0308a373298a8906ee5a7546275e1b2e906ea.tar.bz2 |
gh-113750: Fix object resurrection in free-threaded builds (gh-113751)
gh-113750: Fix object resurrection on free-threaded builds
This avoids the undesired re-initializing of fields like `ob_gc_bits`,
`ob_mutex`, and `ob_tid` when an object is resurrected due to its
finalizer being called.
This change has no effect on the default (with GIL) build.
Diffstat (limited to 'Objects/object.c')
-rw-r--r-- | Objects/object.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/Objects/object.c b/Objects/object.c index d970a26..587c552 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -509,9 +509,7 @@ PyObject_CallFinalizerFromDealloc(PyObject *self) /* tp_finalize resurrected it! Make it look like the original Py_DECREF * never happened. */ - Py_ssize_t refcnt = Py_REFCNT(self); - _Py_NewReferenceNoTotal(self); - Py_SET_REFCNT(self, refcnt); + _Py_ResurrectReference(self); _PyObject_ASSERT(self, (!_PyType_IS_GC(Py_TYPE(self)) @@ -2389,6 +2387,17 @@ _Py_NewReferenceNoTotal(PyObject *op) new_reference(op); } +void +_Py_ResurrectReference(PyObject *op) +{ + if (_PyRuntime.tracemalloc.config.tracing) { + _PyTraceMalloc_NewReference(op); + } +#ifdef Py_TRACE_REFS + _Py_AddToAllObjects(op); +#endif +} + #ifdef Py_TRACE_REFS void |