]> granicus.if.org Git - python/commitdiff
bpo-30675: Fix refleak hunting in regrtest (#2227)
authorVictor Stinner <victor.stinner@gmail.com>
Fri, 16 Jun 2017 10:14:09 +0000 (12:14 +0200)
committerGitHub <noreply@github.com>
Fri, 16 Jun 2017 10:14:09 +0000 (12:14 +0200)
regrtest now warms up caches: create explicitly all internal
singletons which are created on demand to prevent false positives
when checking for reference leaks.

Lib/test/regrtest.py

index 48779fc9c8779294969e63c25491bf350add349d..521ac137b6112cba84fc877d7dbda39b6e87cfc0 100755 (executable)
@@ -438,6 +438,8 @@ def main(tests=None, testdir=None, verbose=0, quiet=False,
 
     if slaveargs is not None:
         args, kwargs = json.loads(slaveargs)
+        if kwargs['huntrleaks']:
+            warm_caches()
         if testdir:
             kwargs['testdir'] = testdir
         try:
@@ -448,6 +450,9 @@ def main(tests=None, testdir=None, verbose=0, quiet=False,
         print json.dumps(result)
         sys.exit(0)
 
+    if huntrleaks:
+        warm_caches()
+
     good = []
     bad = []
     skipped = []
@@ -1418,6 +1423,18 @@ def clear_caches():
     # Collect cyclic trash.
     gc.collect()
 
+def warm_caches():
+    """Create explicitly internal singletons which are created on demand
+    to prevent false positive when hunting reference leaks."""
+    # char cache
+    for i in range(256):
+        chr(i)
+    # unicode cache
+    for i in range(256):
+        unichr(i)
+    # int cache
+    list(range(-5, 257))
+
 def findtestdir(path=None):
     return path or os.path.dirname(__file__) or os.curdir