mirror of
https://github.com/python/cpython.git
synced 2025-09-30 12:21:51 +00:00
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>
(cherry picked from commit 6c2feabc5d
)
This commit is contained in:
parent
60f3f1fb5c
commit
98c849a2f3
1 changed files with 11 additions and 3 deletions
|
@ -68,6 +68,14 @@ def dash_R(the_module, test, indirect_test, huntrleaks):
|
||||||
for obj in abc.__subclasses__() + [abc]:
|
for obj in abc.__subclasses__() + [abc]:
|
||||||
abcs[obj] = obj._abc_registry.copy()
|
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
|
nwarmup, ntracked, fname = huntrleaks
|
||||||
fname = os.path.join(support.SAVEDCWD, fname)
|
fname = os.path.join(support.SAVEDCWD, fname)
|
||||||
repcount = nwarmup + ntracked
|
repcount = nwarmup + ntracked
|
||||||
|
@ -86,9 +94,9 @@ def dash_R(the_module, test, indirect_test, huntrleaks):
|
||||||
abcs)
|
abcs)
|
||||||
print('.', end='', file=sys.stderr, flush=True)
|
print('.', end='', file=sys.stderr, flush=True)
|
||||||
if i >= nwarmup:
|
if i >= nwarmup:
|
||||||
rc_deltas[i] = rc_after - rc_before
|
rc_deltas[i] = get_pooled_int(rc_after - rc_before)
|
||||||
alloc_deltas[i] = alloc_after - alloc_before
|
alloc_deltas[i] = get_pooled_int(alloc_after - alloc_before)
|
||||||
fd_deltas[i] = fd_after - fd_before
|
fd_deltas[i] = get_pooled_int(fd_after - fd_before)
|
||||||
alloc_before = alloc_after
|
alloc_before = alloc_after
|
||||||
rc_before = rc_after
|
rc_before = rc_after
|
||||||
fd_before = fd_after
|
fd_before = fd_after
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue