summaryrefslogtreecommitdiffstats
path: root/Lib/test/libregrtest
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2017-09-01 11:05:27 (GMT)
committerGitHub <noreply@github.com>2017-09-01 11:05:27 (GMT)
commit6c2feabc5dac2f3049b15134669e9ad5af573193 (patch)
tree641056b462afdc86801807caf7617acd17da13d4 /Lib/test/libregrtest
parent122e88a8354e3f75aeaf6211232dac88ac296d54 (diff)
downloadcpython-6c2feabc5dac2f3049b15134669e9ad5af573193.zip
cpython-6c2feabc5dac2f3049b15134669e9ad5af573193.tar.gz
cpython-6c2feabc5dac2f3049b15134669e9ad5af573193.tar.bz2
bpo-31217: Fix regrtest -R for small integer (#3260)
Use a pool of integer objects toprevent false alarm when checking for memory block leaks. Fill the pool with values in -1000..1000 which are the most common (reference, memory block, file descriptor) differences. Co-Authored-By: Antoine Pitrou <pitrou@free.fr>
Diffstat (limited to 'Lib/test/libregrtest')
-rw-r--r--Lib/test/libregrtest/refleak.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/Lib/test/libregrtest/refleak.py b/Lib/test/libregrtest/refleak.py
index efe5210..18d5bd0 100644
--- a/Lib/test/libregrtest/refleak.py
+++ b/Lib/test/libregrtest/refleak.py
@@ -38,6 +38,14 @@ def dash_R(the_module, test, indirect_test, huntrleaks):
for obj in abc.__subclasses__() + [abc]:
abcs[obj] = obj._abc_registry.copy()
+ # bpo-31217: Integer pool to get a single integer object for the same
+ # value. The pool is used to prevent false alarm when checking for memory
+ # block leaks. Fill the pool with values in -1000..1000 which are the most
+ # common (reference, memory block, file descriptor) differences.
+ int_pool = {value: value for value in range(-1000, 1000)}
+ def get_pooled_int(value):
+ return int_pool.setdefault(value, value)
+
nwarmup, ntracked, fname = huntrleaks
fname = os.path.join(support.SAVEDCWD, fname)
repcount = nwarmup + ntracked
@@ -56,9 +64,9 @@ def dash_R(the_module, test, indirect_test, huntrleaks):
abcs)
print('.', end='', file=sys.stderr, flush=True)
if i >= nwarmup:
- rc_deltas[i] = rc_after - rc_before
- alloc_deltas[i] = alloc_after - alloc_before
- fd_deltas[i] = fd_after - fd_before
+ rc_deltas[i] = get_pooled_int(rc_after - rc_before)
+ alloc_deltas[i] = get_pooled_int(alloc_after - alloc_before)
+ fd_deltas[i] = get_pooled_int(fd_after - fd_before)
alloc_before = alloc_after
rc_before = rc_after
fd_before = fd_after