Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Revert "Drop has_own_refchain() calls where not needed."
This reverts commit ffe2633.
  • Loading branch information
ericsnowcurrently committed Oct 21, 2024
commit fbc4e2dac0eb27adac50cee1c7fb60ab33fc0817
18 changes: 18 additions & 0 deletions Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,19 @@ refchain_fini(PyInterpreterState *interp)
bool
_PyRefchain_IsTraced(PyInterpreterState *interp, PyObject *obj)
{
if (!has_own_refchain(interp)) {
interp = _PyInterpreterState_Main();
}
return (_Py_hashtable_get(REFCHAIN(interp), obj) == REFCHAIN_VALUE);
}


static void
_PyRefchain_Trace(PyInterpreterState *interp, PyObject *obj)
{
if (!has_own_refchain(interp)) {
interp = _PyInterpreterState_Main();
}
if (_Py_hashtable_set(REFCHAIN(interp), obj, REFCHAIN_VALUE) < 0) {
// Use a fatal error because _Py_NewReference() cannot report
// the error to the caller.
Expand All @@ -233,6 +239,9 @@ _PyRefchain_Trace(PyInterpreterState *interp, PyObject *obj)
static void
_PyRefchain_Remove(PyInterpreterState *interp, PyObject *obj)
{
if (!has_own_refchain(interp)) {
interp = _PyInterpreterState_Main();
}
void *value = _Py_hashtable_steal(REFCHAIN(interp), obj);
#ifndef NDEBUG
assert(value == REFCHAIN_VALUE);
Expand Down Expand Up @@ -2578,6 +2587,9 @@ _Py_PrintReferences(PyInterpreterState *interp, FILE *fp)
interp = _PyInterpreterState_Main();
}
fprintf(fp, "Remaining objects:\n");
if (!has_own_refchain(interp)) {
interp = _PyInterpreterState_Main();
}
_Py_hashtable_foreach(REFCHAIN(interp), _Py_PrintReference, fp);
}

Expand Down Expand Up @@ -2606,6 +2618,9 @@ void
_Py_PrintReferenceAddresses(PyInterpreterState *interp, FILE *fp)
{
fprintf(fp, "Remaining object addresses:\n");
if (!has_own_refchain(interp)) {
interp = _PyInterpreterState_Main();
}
_Py_hashtable_foreach(REFCHAIN(interp), _Py_PrintReferenceAddress, fp);
}

Expand Down Expand Up @@ -2685,6 +2700,9 @@ _Py_GetObjects(PyObject *self, PyObject *args)
.limit = limit,
};
PyInterpreterState *interp = _PyInterpreterState_GET();
if (!has_own_refchain(interp)) {
interp = _PyInterpreterState_Main();
}
int res = _Py_hashtable_foreach(REFCHAIN(interp), _Py_GetObject, &data);
if (res == _PY_GETOBJECTS_ERROR) {
Py_DECREF(list);
Expand Down