Author: Armin Rigo <[email protected]>
Branch: rpython-error-to-systemerror
Changeset: r88171:04a9363395d5
Date: 2016-11-07 14:51 +0100
http://bitbucket.org/pypy/pypy/changeset/04a9363395d5/

Log:    Move the logic to pyframe. Should avoid the ContinueRunningNormally
        exception seen with the JIT

diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -3,7 +3,7 @@
 from rpython.rlib.cache import Cache
 from rpython.tool.uid import HUGEVAL_BYTES
 from rpython.rlib import jit, types
-from rpython.rlib.debug import make_sure_not_resized, debug_print_traceback
+from rpython.rlib.debug import make_sure_not_resized
 from rpython.rlib.objectmodel import (we_are_translated, newlist_hint,
      compute_unique_id, specialize)
 from rpython.rlib.signature import signature
@@ -1836,30 +1836,6 @@
         finally:
             self.sys.track_resources = flag
 
-    def _convert_unexpected_exception_extra(self, e):
-        "NOT_RPYTHON"
-        if e.__class__.__name__ in (
-            'Skipped',     # list of exception class names that are ok
-            ):             # to get during ==untranslated tests== only
-            raise
-        # include the RPython-level traceback
-        exc = sys.exc_info()
-        import traceback, cStringIO
-        f = cStringIO.StringIO()
-        print >> f, "\nTraceback (interpreter-level):"
-        traceback.print_tb(exc[2], file=f)
-        return f.getvalue()
-
-    def _convert_unexpected_exception(self, e):
-        if we_are_translated():
-            debug_print_traceback()
-            extra = '; internal traceback was dumped to stderr'
-        else:
-            extra = self._convert_unexpected_exception_extra(e)
-        raise OperationError(self.w_SystemError, self.wrap(
-            "unexpected internal exception (please report a bug): %r%s" %
-            (e, extra)))
-
 
 class AppExecCache(SpaceCache):
     def build(cache, source):
diff --git a/pypy/interpreter/gateway.py b/pypy/interpreter/gateway.py
--- a/pypy/interpreter/gateway.py
+++ b/pypy/interpreter/gateway.py
@@ -712,8 +712,6 @@
             if not we_are_translated():
                 raise
             raise e
-        except OperationError:
-            raise
         except KeyboardInterrupt:
             raise OperationError(space.w_KeyboardInterrupt, space.w_None)
         except MemoryError:
@@ -724,8 +722,6 @@
                         "maximum recursion depth exceeded")
         except RuntimeError:   # not on top of py.py
             raise OperationError(space.w_RuntimeError, space.w_None)
-        except Exception as e:      # general fall-back
-            raise space._convert_unexpected_exception(e)
 
 # (verbose) performance hack below
 
diff --git a/pypy/interpreter/pyframe.py b/pypy/interpreter/pyframe.py
--- a/pypy/interpreter/pyframe.py
+++ b/pypy/interpreter/pyframe.py
@@ -1,6 +1,7 @@
 """ PyFrame class implementation with the interpreter main loop.
 """
 
+import sys
 from rpython.rlib import jit
 from rpython.rlib.debug import make_sure_not_resized, check_nonneg
 from rpython.rlib.jit import hint
@@ -276,8 +277,13 @@
                     next_instr = r_uint(self.last_instr + 1)
                     if next_instr != 0:
                         self.pushvalue(w_inputvalue)
-                w_exitvalue = self.dispatch(self.pycode, next_instr,
-                                            executioncontext)
+                try:
+                    w_exitvalue = self.dispatch(self.pycode, next_instr,
+                                                executioncontext)
+                except OperationError:
+                    raise
+                except Exception as e:      # general fall-back
+                    raise self._convert_unexpected_exception(e)
             finally:
                 executioncontext.return_trace(self, w_exitvalue)
             # it used to say self.last_exception = None
@@ -883,6 +889,34 @@
             frame = frame.f_backref()
         return None
 
+    def _convert_unexpected_exception_extra(self, e):
+        "NOT_RPYTHON"
+        if e.__class__.__name__ in (
+            'Skipped',     # list of exception class names that are ok
+            ):             # to get during ==untranslated tests== only
+            raise
+        # include the RPython-level traceback
+        exc = sys.exc_info()
+        import traceback, cStringIO
+        f = cStringIO.StringIO()
+        print >> f, "\nTraceback (interpreter-level):"
+        traceback.print_tb(exc[2], file=f)
+        return f.getvalue()
+
+    def _convert_unexpected_exception(self, e):
+        if we_are_translated():
+            from rpython.rlib.debug import debug_print_traceback
+            debug_print_traceback()
+            extra = '; internal traceback was dumped to stderr'
+        else:
+            extra = self._convert_unexpected_exception_extra(e)
+        operr = OperationError(self.space.w_SystemError, self.space.wrap(
+            "unexpected internal exception (please report a bug): %r%s" %
+            (e, extra)))
+        pytraceback.record_application_traceback(
+            self.space, operr, self, self.last_instr)
+        raise operr
+
 # ____________________________________________________________
 
 def get_block_class(opname):
diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py
--- a/pypy/interpreter/pyopcode.py
+++ b/pypy/interpreter/pyopcode.py
@@ -70,8 +70,6 @@
             next_instr = self.dispatch_bytecode(co_code, next_instr, ec)
         except OperationError as operr:
             next_instr = self.handle_operation_error(ec, operr)
-        except ExitFrame:
-            raise
         except RaiseWithExplicitTraceback as e:
             next_instr = self.handle_operation_error(ec, e.operr,
                                                      attach_tb=False)
@@ -87,8 +85,6 @@
             next_instr = self.handle_asynchronous_error(ec,
                 self.space.w_RuntimeError,
                 self.space.wrap("maximum recursion depth exceeded"))
-        except Exception as e:      # general fall-back
-            raise self.space._convert_unexpected_exception(e)
         return next_instr
 
     def handle_asynchronous_error(self, ec, w_type, w_value=None):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to