Debian Codegraph @

rpython/rlib/rstackovf.py

raw symbols SCIP
1 import sys
2 from rpython.rlib.objectmodel import we_are_translated
3
4 # RPython raises StackOverflow instead of just RuntimeError when running
5 # out of C stack. We need some hacks to support "except StackOverflow:"
6 # in untranslated code too. This StackOverflow has a strange shape in
7 # order to be special-cased by the flow object space (it is replaced by
8 # the class StackOverflow).
9
10 class StackOverflow(RuntimeError):
11 """Out of C stack."""
12
13 # rename the variable, but the name of the class is still StackOverflow
14 _StackOverflow = StackOverflow
15
16 # replace StackOverflow with this, which works in untranslated code too
17 StackOverflow = ((RuntimeError, RuntimeError),)
18
19
20 def check_stack_overflow():
21 if we_are_translated():
22 return
23 # before translation, an "except StackOverflow" includes all RuntimeErrors,
24 # including NotImplementedError. Special-case them.
25 e, v, _ = sys.exc_info()
26 if e is not RuntimeError or 'recursion' not in str(v):
27 raise