Skip to content

Commit 3f7e71b

Browse files
committed
gh-117174: Fix reference leak and gdb tests
1 parent 1908115 commit 3f7e71b

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

Lib/test/libregrtest/refleak.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import warnings
44
from inspect import isabstract
55
from typing import Any
6+
import linecache
67

78
from test import support
89
from test.support import os_helper
@@ -73,6 +74,7 @@ def runtest_refleak(test_name, test_func,
7374
ps = copyreg.dispatch_table.copy()
7475
pic = sys.path_importer_cache.copy()
7576
zdc: dict[str, Any] | None
77+
linecache_data = linecache.cache.copy(), linecache._interactive_cache.copy()
7678
try:
7779
import zipimport
7880
except ImportError:
@@ -122,7 +124,7 @@ def get_pooled_int(value):
122124

123125
xml_filename = 'refleak-xml.tmp'
124126
result = None
125-
dash_R_cleanup(fs, ps, pic, zdc, abcs)
127+
dash_R_cleanup(fs, ps, pic, zdc, abcs, linecache_data)
126128

127129
for i in rep_range:
128130
support.gc_collect()
@@ -134,7 +136,7 @@ def get_pooled_int(value):
134136
refleak_helper._hunting_for_refleaks = current
135137

136138
save_support_xml(xml_filename)
137-
dash_R_cleanup(fs, ps, pic, zdc, abcs)
139+
dash_R_cleanup(fs, ps, pic, zdc, abcs, linecache_data)
138140
support.gc_collect()
139141

140142
# Read memory statistics immediately after the garbage collection.
@@ -223,7 +225,7 @@ def check_fd_deltas(deltas):
223225
return (failed, result)
224226

225227

226-
def dash_R_cleanup(fs, ps, pic, zdc, abcs):
228+
def dash_R_cleanup(fs, ps, pic, zdc, abcs, linecache_data):
227229
import copyreg
228230
import collections.abc
229231

@@ -233,6 +235,11 @@ def dash_R_cleanup(fs, ps, pic, zdc, abcs):
233235
copyreg.dispatch_table.update(ps)
234236
sys.path_importer_cache.clear()
235237
sys.path_importer_cache.update(pic)
238+
lcache, linteractive = linecache_data
239+
linecache._interactive_cache.clear()
240+
linecache._interactive_cache.update(linteractive)
241+
linecache.cache.clear()
242+
linecache.cache.update(lcache)
236243
try:
237244
import zipimport
238245
except ImportError:

Lib/test/test_gdb/test_pretty_print.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ def get_gdb_repr(self, source,
3838
# to (using its "wrap_here" function)
3939
m = re.search(
4040
# Match '#0 _typing_idfunc(module=..., x=...)'
41-
r'#0\s+_typing__idfunc\s+\(module\=.*,\s+x=\s*(.*?)?\)'
41+
r'#0\s+_typing__idfunc\s+\((?:module\=.*,\s+x=\s*(.*?)?)?\)'
4242
# Match ' at Python/bltinmodule.c'.
4343
# bpo-38239: typing_idfunc() is defined in Module/_typingmldule.c,
4444
# but accept any "Directory\file.c" to support Link Time
4545
# Optimization (LTO).
46-
r'\s+at\s+\S*[A-Za-z]+/[A-Za-z0-9_-]+\.c',
46+
r'\s+at\s+\S*[A-Za-z]+/[A-Za-z0-9_-]+\.[ch]',
4747
gdb_output, re.DOTALL)
4848
if not m:
4949
self.fail('Unexpected gdb output: %r\n%s' % (gdb_output, gdb_output))

0 commit comments

Comments
 (0)