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.
diff --git a/Lib/test/crashers/infinite_rec_1.py b/Lib/test/crashers/infinite_rec_1.py
deleted file mode 100644
index 573a509..0000000
--- 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 5a14b33..0000000
--- 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 14f1520..0000000
--- 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 18d2963..0000000
--- 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 57cef44..9a45cf1 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -4,6 +4,7 @@
from copy import deepcopy
import warnings
import types
+import new
warnings.filterwarnings("ignore",
r'complex divmod\(\), // and % are deprecated$',
@@ -1981,6 +1982,10 @@
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 @@
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 @@
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 @@
overloading()
methods()
specials()
+ recursions()
weakrefs()
properties()
supers()