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-127705: Add debug mode for _PyStackRefs inspired by HPy debug mode #128121

Merged
merged 10 commits into from
Dec 20, 2024

Conversation

markshannon
Copy link
Member

@markshannon markshannon commented Dec 20, 2024

This PR:

  • Adds a hashtable to track _PyStackRefs if Py_STACKREF_DEBUG is set.
  • Aborts and reports any double-close or leaks of stack refs
  • Fixes the leaks found in bytecodes.c by the above

When reporting leaks, both the origin of the _PyStackRef and the last call to PyStackRef_AsPyObjectBorrow are reported.

Only supports the default build for now. It shouldn't be too hard to support free-threading in the future.


Running on the full test suite passes all but these tests:

Expecting a _PyStackRef to look like a tagged pointer, not an index. Mostly segfaults

test.test_gdb.test_backtrace
test.test_gdb.test_misc
test.test_gdb.test_pretty_print
test_external_inspection

Calling a _PyStackRef... function without holding the GIL at shutdown.

test_faulthandler
test_regrtest

Actual leaks

test.test_multiprocessing_spawn.test_manager
test_repl
test_threading

Python/stackrefs.c Outdated Show resolved Hide resolved
Python/stackrefs.c Outdated Show resolved Hide resolved
Python/stackrefs.c Show resolved Hide resolved
Python/ceval.c Outdated Show resolved Hide resolved
Python/ceval.c Outdated Show resolved Hide resolved
@markshannon markshannon merged commit 128cc47 into python:main Dec 20, 2024
61 checks passed
srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this pull request Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants