Skip to content

Commit 60e0a08

Browse files
committed
Use test.support.late_deletion instead of a sys attribute to keep the
function alive.
1 parent 8b19275 commit 60e0a08

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

Lib/test/test_code.py

Lines changed: 3 additions & 5 deletions
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
@@ -1558,10 +1558,8 @@ def myfree(ptr):
15581558
# Make sure myfree sticks around at least as long as the interpreter,
15591559
# since we (currently) can't unregister the function and leaving a
15601560
# dangling pointer will cause a crash on deallocation of code objects if
1561-
# something else uses co_extras, like test_capi.test_misc. (Maybe this
1562-
# should use PyInterpreterState_GetDict, but that isn't easily exposed
1563-
# to Python code.)
1564-
setattr(sys, f'_test_code.{myfree!r}', myfree)
1561+
# something else uses co_extras, like test_capi.test_misc.
1562+
late_deletion(myfree)
15651563

15661564
class CoExtra(unittest.TestCase):
15671565
def get_func(self):

0 commit comments

Comments
 (0)