[pypy-svn] r73077 - in pypy/branch/stackovf/pypy: objspace/flow rlib rlib/test
arigo at codespeak.net
arigo at codespeak.net
Mon Mar 29 16:44:54 CEST 2010
Author: arigo
Date: Mon Mar 29 16:44:52 2010
New Revision: 73077
Added:
pypy/branch/stackovf/pypy/rlib/rstackovf.py (contents, props changed)
pypy/branch/stackovf/pypy/rlib/test/test_rstackovf.py (contents, props changed)
Modified:
pypy/branch/stackovf/pypy/objspace/flow/objspace.py
Log:
Add rstackovf.StackOverflow. Translating it is in-progress.
Modified: pypy/branch/stackovf/pypy/objspace/flow/objspace.py
==============================================================================
--- pypy/branch/stackovf/pypy/objspace/flow/objspace.py (original)
+++ pypy/branch/stackovf/pypy/objspace/flow/objspace.py Mon Mar 29 16:44:52 2010
@@ -8,6 +8,7 @@
from pypy.objspace.flow import flowcontext
from pypy.objspace.flow.operation import FunctionByName
from pypy.rlib.unroll import unrolling_iterable, _unroller
+from pypy.rlib import rstackovf
debug = 0
@@ -201,9 +202,13 @@
if not isinstance(check_class, tuple):
# the simple case
return ObjSpace.exception_match(self, w_exc_type, w_check_class)
+ # special case for StackOverflow (see rlib/rstackovf.py)
+ if check_class == rstackovf.StackOverflow:
+ w_real_class = self.wrap(rstackovf._StackOverflow)
+ return ObjSpace.exception_match(self, w_exc_type, w_real_class)
# checking a tuple of classes
for w_klass in self.fixedview(w_check_class):
- if ObjSpace.exception_match(self, w_exc_type, w_klass):
+ if self.exception_match(w_exc_type, w_klass):
return True
return False
Added: pypy/branch/stackovf/pypy/rlib/rstackovf.py
==============================================================================
--- (empty file)
+++ pypy/branch/stackovf/pypy/rlib/rstackovf.py Mon Mar 29 16:44:52 2010
@@ -0,0 +1,15 @@
+
+# RPython raises StackOverflow instead of just RuntimeError when running
+# out of C stack. We need some hacks to support "except StackOverflow:"
+# in untranslated code too. This StackOverflow has a strange shape in
+# order to be special-cased by the flow object space (it is replaced by
+# the class StackOverflow).
+
+class StackOverflow(RuntimeError):
+ """Out of C stack."""
+
+# rename the variable, but the name of the class is still StackOverflow
+_StackOverflow = StackOverflow
+
+# replace StackOverflow with this, which works in untranslated code too
+StackOverflow = ((RuntimeError, RuntimeError),)
Added: pypy/branch/stackovf/pypy/rlib/test/test_rstackovf.py
==============================================================================
--- (empty file)
+++ pypy/branch/stackovf/pypy/rlib/test/test_rstackovf.py Mon Mar 29 16:44:52 2010
@@ -0,0 +1,24 @@
+import sys
+from pypy.rlib import rstackovf
+
+def recurse(n):
+ if n > 0:
+ return recurse(n-1) + n
+ return 0
+
+def f(n):
+ try:
+ recurse(n)
+ except rstackovf.StackOverflow:
+ return 1
+ else:
+ return 0
+
+
+def test_direct():
+ assert f(sys.maxint) == 1
+
+def test_llinterp():
+ from pypy.rpython.test.test_llinterp import interpret
+ res = interpret(f, [sys.maxint])
+ assert res == 1
More information about the Pypy-commit
mailing list