Skip to content

Commit f739b43

Browse files
Yhg1smiss-islington
authored andcommitted
gh-141536: Fix a crash when running test_capi *after* test_code in the same process (GH-141537)
(cherry picked from commit b2827de) Co-authored-by: T. Wouters <thomas@python.org>
1 parent fcd9500 commit f739b43

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Lib/test/test_code.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@
210210
ctypes = None
211211
from test.support import (cpython_only,
212212
check_impl_detail, requires_debug_ranges,
213-
gc_collect, Py_GIL_DISABLED)
213+
gc_collect, Py_GIL_DISABLED, late_deletion)
214214
from test.support.script_helper import assert_python_ok
215215
from test.support import threading_helper, import_helper
216216
from test.support.bytecode_helper import instructions_with_positions
@@ -1555,6 +1555,11 @@ def myfree(ptr):
15551555

15561556
FREE_FUNC = freefunc(myfree)
15571557
FREE_INDEX = RequestCodeExtraIndex(FREE_FUNC)
1558+
# Make sure myfree sticks around at least as long as the interpreter,
1559+
# since we (currently) can't unregister the function and leaving a
1560+
# dangling pointer will cause a crash on deallocation of code objects if
1561+
# something else uses co_extras, like test_capi.test_misc.
1562+
late_deletion(myfree)
15581563

15591564
class CoExtra(unittest.TestCase):
15601565
def get_func(self):

0 commit comments

Comments
 (0)