Skip to content

Commit 8a09b51

Browse files
[3.13] gh-141536: Fix a crash when running test_capi *after* test_code in the same process (GH-141537) (GH-143625)
(cherry picked from commit b2827de) Co-authored-by: T. Wouters <thomas@python.org>
1 parent ab82246 commit 8a09b51

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
@@ -143,7 +143,7 @@
143143
check_impl_detail, requires_debug_ranges,
144144
gc_collect, Py_GIL_DISABLED,
145145
suppress_immortalization,
146-
skip_if_suppress_immortalization)
146+
skip_if_suppress_immortalization, late_deletion)
147147
from test.support.script_helper import assert_python_ok
148148
from test.support import threading_helper, import_helper
149149
from test.support.bytecode_helper import instructions_with_positions
@@ -844,6 +844,11 @@ def myfree(ptr):
844844

845845
FREE_FUNC = freefunc(myfree)
846846
FREE_INDEX = RequestCodeExtraIndex(FREE_FUNC)
847+
# Make sure myfree sticks around at least as long as the interpreter,
848+
# since we (currently) can't unregister the function and leaving a
849+
# dangling pointer will cause a crash on deallocation of code objects if
850+
# something else uses co_extras, like test_capi.test_misc.
851+
late_deletion(myfree)
847852

848853
class CoExtra(unittest.TestCase):
849854
def get_func(self):

0 commit comments

Comments
 (0)