diff options
author | Brett Cannon <bcannon@gmail.com> | 2007-09-07 04:18:30 +0000 |
---|---|---|
committer | Brett Cannon <bcannon@gmail.com> | 2007-09-07 04:18:30 +0000 |
commit | 1e534b5425d836cb58a73d24f0be791d67bf3503 (patch) | |
tree | 1f9fc8b8802c5ba236c026fc6cbe785d7f9bf20b /Lib/test | |
parent | 68a6da99e6dc127d817143f74e98d665117f99c2 (diff) | |
download | cpython-git-1e534b5425d836cb58a73d24f0be791d67bf3503.tar.gz |
Fix a crasher where Python code managed to infinitely recurse in C code without
ever going back out to Python code in PyObject_Call(). Required introducing a
static RuntimeError instance so that normalizing an exception there is no
reliance on a recursive call that would put the exception system over the
recursion check itself.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/crashers/infinite_rec_1.py | 11 | ||||
-rw-r--r-- | Lib/test/crashers/infinite_rec_2.py | 10 | ||||
-rw-r--r-- | Lib/test/crashers/infinite_rec_4.py | 7 | ||||
-rw-r--r-- | Lib/test/crashers/infinite_rec_5.py | 10 | ||||
-rw-r--r-- | Lib/test/test_descr.py | 18 |
5 files changed, 17 insertions, 39 deletions
diff --git a/Lib/test/crashers/infinite_rec_1.py b/Lib/test/crashers/infinite_rec_1.py deleted file mode 100644 index 573a509b5f..0000000000 --- a/Lib/test/crashers/infinite_rec_1.py +++ /dev/null @@ -1,11 +0,0 @@ - -# http://python.org/sf/1202533 - -import new, operator - -class A: - pass -A.__mul__ = new.instancemethod(operator.mul, None, A) - -if __name__ == '__main__': - A()*2 # segfault: infinite recursion in C diff --git a/Lib/test/crashers/infinite_rec_2.py b/Lib/test/crashers/infinite_rec_2.py deleted file mode 100644 index 5a14b33eaa..0000000000 --- a/Lib/test/crashers/infinite_rec_2.py +++ /dev/null @@ -1,10 +0,0 @@ - -# http://python.org/sf/1202533 - -class A(str): - __get__ = getattr - -if __name__ == '__main__': - a = A('a') - A.a = a - a.a # segfault: infinite recursion in C diff --git a/Lib/test/crashers/infinite_rec_4.py b/Lib/test/crashers/infinite_rec_4.py deleted file mode 100644 index 14f15208e7..0000000000 --- a/Lib/test/crashers/infinite_rec_4.py +++ /dev/null @@ -1,7 +0,0 @@ - -# http://python.org/sf/1202533 - -if __name__ == '__main__': - lst = [apply] - lst.append(lst) - apply(*lst) # segfault: infinite recursion in C diff --git a/Lib/test/crashers/infinite_rec_5.py b/Lib/test/crashers/infinite_rec_5.py deleted file mode 100644 index 18d2963233..0000000000 --- a/Lib/test/crashers/infinite_rec_5.py +++ /dev/null @@ -1,10 +0,0 @@ - -# http://python.org/sf/1267884 - -import types - -class C: - __str__ = types.InstanceType.__str__ - -if __name__ == '__main__': - str(C()) # segfault: infinite recursion in C diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py index 57cef44097..9a45cf1760 100644 --- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -4,6 +4,7 @@ from test.test_support import verify, vereq, verbose, TestFailed, TESTFN, get_or from copy import deepcopy import warnings import types +import new warnings.filterwarnings("ignore", r'complex divmod\(\), // and % are deprecated$', @@ -1981,6 +1982,10 @@ def specials(): unsafecmp(1, 1L) unsafecmp(1L, 1) +def recursions(): + if verbose: + print "Testing recursion checks ..." + class Letter(str): def __new__(cls, letter): if letter == 'EPS': @@ -1990,7 +1995,6 @@ def specials(): if not self: return 'EPS' return self - # sys.stdout needs to be the original to trigger the recursion bug import sys test_stdout = sys.stdout @@ -2004,6 +2008,17 @@ def specials(): raise TestFailed, "expected a RuntimeError for print recursion" sys.stdout = test_stdout + # Bug #1202533. + class A(object): + pass + A.__mul__ = new.instancemethod(lambda self, x: self * x, None, A) + try: + A()*2 + except RuntimeError: + pass + else: + raise TestFailed("expected a RuntimeError") + def weakrefs(): if verbose: print "Testing weak references..." import weakref @@ -4395,6 +4410,7 @@ def test_main(): overloading() methods() specials() + recursions() weakrefs() properties() supers() |