This project has moved. For the latest updates, please go here.
2

Closed

StackOverflow in code that works in CPython 2.5

description

<Test>test_exceptions.py</Test>
 
The following code causes a StackOverflowException in 2.0b4 but not Python 2.5:
class Foo(object):
location = None
project_name = "Foo"

def version(self):
    raise ValueError("foo: ", self)

version = property(version)
 
def __repr__(self):
    if self.location:
        return "%s (%s)" % (self,self.location)
    else:
        return str(self)
 
def __str__(self):
    try: version = getattr(self,'version',None)
    except ValueError: version = None
    version = version or "[unknown version]"
    return "%s %s" % (self.project_name,version)
 
f = Foo()
print f.version
 
This is based on some code from setuptools.
 
CPython returns:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 5, in version
ValueError: ('foo: ', Foo [unknown version])
 
With recursion checking turned on, IronPython returns:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 5, in version
File "<stdin>", line 11, in repr
File "<stdin>", line 13, in str
RuntimeError: maximum recursion depth exceeded

comments

dinov wrote Aug 13, 2008 at 4:47 AM

It raises a RuntimeError if you pass the -X:MaxRecursion 1001 command line option. Recursion enforcement is set to sys.maxint which disables recursion enforcement.

wrote Aug 13, 2008 at 4:47 AM

wrote Aug 15, 2008 at 5:13 PM

sborde wrote Aug 29, 2008 at 12:08 PM

** Closed by sborde 8/15/2008 10:13 AM

CurtHagenlocher wrote Aug 29, 2008 at 12:08 PM

Even with maxrecursion set, IronPython returns a different answer than CPython does.

CurtHagenlocher wrote Aug 29, 2008 at 12:10 PM

(Edited to reflect the difference.)

wrote Aug 29, 2008 at 12:10 PM

wrote Sep 2, 2008 at 11:42 AM

dinov wrote Sep 10, 2008 at 11:14 PM

The problem is when converting to a CLR exception we convert all of the exception arguments into strings as well. That results in the SO or the recursion enforcement.

wrote Sep 10, 2008 at 11:14 PM

wrote Oct 13, 2008 at 6:09 PM

wrote Nov 12, 2008 at 6:09 PM

wrote Nov 12, 2008 at 6:09 PM

wrote Feb 22, 2013 at 1:15 AM

wrote May 16, 2013 at 12:06 PM