diff options
Diffstat (limited to 'Tools/scripts/find_recursionlimit.py')
-rwxr-xr-x | Tools/scripts/find_recursionlimit.py | 55 |
1 files changed, 22 insertions, 33 deletions
diff --git a/Tools/scripts/find_recursionlimit.py b/Tools/scripts/find_recursionlimit.py index b2842a6..88e9bb5 100755 --- a/Tools/scripts/find_recursionlimit.py +++ b/Tools/scripts/find_recursionlimit.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python3 +#! /usr/bin/env python """Find the maximum recursion limit that prevents interpreter termination. This script finds the maximum safe recursion limit on a particular @@ -71,58 +71,47 @@ def test_recurse(): return test_recurse() def test_cpickle(_cache={}): - import io try: - import _pickle + import cPickle except ImportError: - print("cannot import _pickle, skipped!") + print "cannot import cPickle, skipped!" return - k, l = None, None + l = None for n in itertools.count(): try: l = _cache[n] continue # Already tried and it works, let's save some time except KeyError: for i in range(100): - l = [k, l] - k = {i: l} - _pickle.Pickler(io.BytesIO(), protocol=-1).dump(l) + l = [l] + cPickle.dumps(l, protocol=-1) _cache[n] = l -def test_compiler_recursion(): - # The compiler uses a scaling factor to support additional levels - # of recursion. This is a sanity check of that scaling to ensure - # it still raises RecursionError even at higher recursion limits - compile("()" * (10 * sys.getrecursionlimit()), "<single>", "single") - def check_limit(n, test_func_name): sys.setrecursionlimit(n) if test_func_name.startswith("test_"): - print(test_func_name[5:]) + print test_func_name[5:] else: - print(test_func_name) + print test_func_name test_func = globals()[test_func_name] try: test_func() # AttributeError can be raised because of the way e.g. PyDict_GetItem() # silences all exceptions and returns NULL, which is usually interpreted # as "missing attribute". - except (RecursionError, AttributeError): + except (RuntimeError, AttributeError): pass else: - print("Yikes!") - -if __name__ == '__main__': - - limit = 1000 - while 1: - check_limit(limit, "test_recurse") - check_limit(limit, "test_add") - check_limit(limit, "test_repr") - check_limit(limit, "test_init") - check_limit(limit, "test_getattr") - check_limit(limit, "test_getitem") - check_limit(limit, "test_cpickle") - check_limit(limit, "test_compiler_recursion") - print("Limit of %d is fine" % limit) - limit = limit + 100 + print "Yikes!" + +limit = 1000 +while 1: + check_limit(limit, "test_recurse") + check_limit(limit, "test_add") + check_limit(limit, "test_repr") + check_limit(limit, "test_init") + check_limit(limit, "test_getattr") + check_limit(limit, "test_getitem") + check_limit(limit, "test_cpickle") + print "Limit of %d is fine" % limit + limit = limit + 100 |