8000 gh-107080: Fix Py_TRACE_REFS Crashes Under Isolated Subinterpreters by ericsnowcurrently · Pull Request #107567 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-107080: Fix Py_TRACE_REFS Crashes Under Isolated Subinterpreters #107567

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

Merged
merged 6 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
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
Drop _Py_StealRefchain().
  • Loading branch information
ericsnowcurrently committed Aug 3, 2023
commit e21c558e8dd812e48b34a497a48e527e0272ac25
3 changes: 1 addition & 2 deletions Include/internal/pycore_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,7 @@ extern void _PyDebug_PrintTotalRefs(void);
#ifdef Py_TRACE_REFS
extern void _Py_AddToAllObjects(PyObject *op, int force);
extern void _Py_PrintReferences(PyInterpreterState *, FILE *);
extern void _Py_PrintReferenceAddresses(PyObject *, FILE *);
extern void _Py_StealRefchain(PyInterpreterState *, PyObject *);
extern void _Py_PrintReferenceAddresses(PyInterpreterState *, FILE *);
#endif


Expand Down
7 changes: 6 additions & 1 deletion Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -2299,10 +2299,15 @@ _Py_PrintReferences(PyInterpreterState *interp, FILE *fp)
/* Print the addresses of all live objects. Unlike _Py_PrintReferences, this
* doesn't make any calls to the Python C API, so is always safe to call.
*/
// XXX This function is not safe to use if the interpreter has been
// freed or is in an unhealthy state (e.g. late in finalization).
// The call in Py_FinalizeEx() is okay since the main interpreter
// is statically allocated.
void
_Py_PrintReferenceAddresses(PyObject *refchain, FILE *fp)
_Py_PrintReferenceAddresses(PyInterpreterState *interp, FILE *fp)
{
PyObject *op;
PyObject *refchain = REFCHAIN(interp);
fprintf(fp, "Remaining object addresses:\n");
for (op = refchain->_ob_next; op != refchain; op = op->_ob_next)
fprintf(fp, "%p [%zd] %s\n", (void *)op,
Expand Down
7 changes: 2 additions & 5 deletions Python/pylifecycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -1927,9 +1927,6 @@ Py_FinalizeEx(void)
if (dump_refs_fp != NULL) {
_Py_PrintReferences(tstate->interp, dump_refs_fp);
}

PyObject refchain = { 0 };
_Py_StealRefchain(tstate->interp, &refchain);
#endif /* Py_TRACE_REFS */

/* At this point there's almost no other Python code that will run,
Expand Down Expand Up @@ -1964,11 +1961,11 @@ Py_FinalizeEx(void)
*/

if (dump_refs) {
_Py_PrintReferenceAddresses(&refchain, stderr);
_Py_PrintReferenceAddresses(tstate->interp, stderr);
}

if (dump_refs_fp != NULL) {
_Py_PrintReferenceAddresses(&refchain, dump_refs_fp);
_Py_PrintReferenceAddresses(tstate->interp, dump_refs_fp);
fclose(dump_refs_fp);
}
#endif /* Py_TRACE_REFS */
Expand Down
0