summaryrefslogtreecommitdiffstats
path: root/Misc/find_recursionlimit.py
diff options
context:
space:
mode:
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>2008-09-11 21:03:37 (GMT)
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>2008-09-11 21:03:37 (GMT)
commitfb1a5eb101373c677ecd9daeb7579a2385e1f2bc (patch)
treec87609fea9e2680368f2e09484d8ba69e1b5d999 /Misc/find_recursionlimit.py
parent06974bb1cc3a3e94c58d6b496827a31630467586 (diff)
downloadcpython-fb1a5eb101373c677ecd9daeb7579a2385e1f2bc.zip
cpython-fb1a5eb101373c677ecd9daeb7579a2385e1f2bc.tar.gz
cpython-fb1a5eb101373c677ecd9daeb7579a2385e1f2bc.tar.bz2
#3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Reviewed by Martin von Loewis.
Diffstat (limited to 'Misc/find_recursionlimit.py')
-rw-r--r--Misc/find_recursionlimit.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/Misc/find_recursionlimit.py b/Misc/find_recursionlimit.py
index b7592ce..295e094 100644
--- a/Misc/find_recursionlimit.py
+++ b/Misc/find_recursionlimit.py
@@ -20,6 +20,7 @@ MemoryError.
"""
import sys
+import itertools
class RecursiveBlowup1:
def __init__(self):
@@ -59,6 +60,24 @@ def test_getitem():
def test_recurse():
return test_recurse()
+def test_cpickle(_cache={}):
+ import io
+ try:
+ import _pickle
+ except ImportError:
+ print("cannot import _pickle, skipped!")
+ return
+ 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 = [l]
+ _pickle.Pickler(io.BytesIO(), protocol=-1).dump(l)
+ _cache[n] = l
+
def check_limit(n, test_func_name):
sys.setrecursionlimit(n)
if test_func_name.startswith("test_"):
@@ -81,5 +100,6 @@ while 1:
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