Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-113750: Fix object resurrection in free-threaded builds #113751

Merged
merged 1 commit into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Include/cpython/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

PyAPI_FUNC(void) _Py_NewReference(PyObject *op);
PyAPI_FUNC(void) _Py_NewReferenceNoTotal(PyObject *op);
PyAPI_FUNC(void) _Py_ResurrectReference(PyObject *op);

#ifdef Py_REF_DEBUG
/* These are useful as debugging aids when chasing down refleaks. */
Expand Down
4 changes: 1 addition & 3 deletions Modules/_testcapi/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,7 @@ slot_tp_del(PyObject *self)
* never happened.
*/
{
Py_ssize_t refcnt = Py_REFCNT(self);
_Py_NewReferenceNoTotal(self);
Py_SET_REFCNT(self, refcnt);
_Py_ResurrectReference(self);
}
assert(!PyType_IS_GC(Py_TYPE(self)) || PyObject_GC_IsTracked(self));
}
Expand Down
15 changes: 12 additions & 3 deletions Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down
Loading