[pypy-svn] r29015 - in pypy/dist/pypy: interpreter interpreter/test module/_stackless/test

pedronis at codespeak.net pedronis at codespeak.net
Tue Jun 20 18:08:32 CEST 2006


Author: pedronis
Date: Tue Jun 20 18:08:30 2006
New Revision: 29015

Modified:
   pypy/dist/pypy/interpreter/pyframe.py
   pypy/dist/pypy/interpreter/test/test_pickle.py
   pypy/dist/pypy/module/_stackless/test/test_pickle.py
Log:
(pedronis, arre)

some support for pickling frame with raised exceptions. test_exception in test_pickle passes



Modified: pypy/dist/pypy/interpreter/pyframe.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyframe.py	(original)
+++ pypy/dist/pypy/interpreter/pyframe.py	Tue Jun 20 18:08:30 2006
@@ -96,13 +96,22 @@
         tup_base = [
             w(self.pycode),
             ]
+
+        if self.last_exception is None:
+            w_exc_value = space.w_None
+            w_tb = space.w_None
+        else:
+            w_exc_value = self.last_exception.w_value
+            w_tb = w(self.last_exception.application_traceback)
+        
         tup_state = [
             w(self.f_back),
             w(self.builtin),
             w(self.pycode),
             w_valuestack,
             w_blockstack,
-            space.w_None, ## w(self.last_exception), #f_exc_traceback, f_exc_type, f_exc_value
+            w_exc_value, # last_exception
+            w_tb,        #
             self.w_globals,
             w(self.last_instr),
             w(self.next_instr),
@@ -127,7 +136,7 @@
         from pypy.interpreter.module import Module
         from pypy.interpreter.nestedscope import PyNestedScopeFrame, Cell
         args_w = space.unpackiterable(w_args)
-        w_f_back, w_builtin, w_pycode, w_valuestack, w_blockstack, w_last_exception,\
+        w_f_back, w_builtin, w_pycode, w_valuestack, w_blockstack, w_exc_value, w_tb,\
             w_globals, w_last_instr, w_next_instr, w_f_lineno, w_fastlocals, w_f_locals, \
             w_f_trace, w_instr_lb, w_instr_ub, w_instr_prev, w_cells = args_w
 
@@ -147,7 +156,14 @@
         valstack = new_frame.valuestack
         for w_value in values_w:
             valstack.push(w_value)
-        new_frame.last_exception = None#XXX (w_last_exception)
+        if space.is_w(w_exc_value, space.w_None):
+            new_frame.last_exception = None
+        else:
+            from pypy.interpreter.pytraceback import PyTraceback
+            tb = space.interp_w(PyTraceback, w_tb)
+            new_frame.last_exception = OperationError(space.type(w_exc_value),
+                                                      w_exc_value, tb
+                                                      )
         new_frame.last_instr = space.int_w(w_last_instr)
         new_frame.next_instr = space.int_w(w_next_instr)
         new_frame.f_lineno = space.int_w(w_f_lineno)

Modified: pypy/dist/pypy/interpreter/test/test_pickle.py
==============================================================================
--- pypy/dist/pypy/interpreter/test/test_pickle.py	(original)
+++ pypy/dist/pypy/interpreter/test/test_pickle.py	Tue Jun 20 18:08:30 2006
@@ -15,6 +15,12 @@
             w_frame = w_frame.f_back
         w_frame.f_back = w_saved
 
+    def read_exc_type(space, w_frame):
+        if w_frame.last_exception is None:
+            return space.w_None
+        else:
+            return w_frame.last_exception.w_type
+
     from pypy.interpreter import gateway
 
     hide_gw = gateway.interp2app(hide_top_frame)
@@ -26,6 +32,11 @@
                   space.wrap('restore_top_frame'),
                   space.wrap(restore_gw))
 
+    read_exc_type_gw = gateway.interp2app(read_exc_type)
+    space.setitem(space.builtin.w_dict,
+                  space.wrap('read_exc_type'),
+                  space.wrap(read_exc_type_gw))
+    
 def _detatch_helpers(space):
     space.delitem(space.builtin.w_dict,
                   space.wrap('hide_top_frame'))
@@ -144,6 +155,27 @@
         assert f1.f_restricted is f2.f_restricted
         assert f1.f_trace is f2.f_trace
 
+    def test_pickle_frame_with_exc(self):
+        #import sys
+        # avoid creating a closure for now
+        del self
+        def f():
+            try:
+                raise ValueError
+            except:
+                import sys, pickle
+                f = sys._getframe()
+                saved = hide_top_frame(f)
+                pckl = pickle.dumps(f)
+                restore_top_frame(f, saved)
+                return pckl
+
+        import pickle
+        pckl   = f()
+        f2     = pickle.loads(pckl)
+
+        assert read_exc_type(f2) is ValueError
+
     def test_pickle_frame_clos(self):
         # similar to above, therefore skipping the asserts.
         # we just want to see that the closure works

Modified: pypy/dist/pypy/module/_stackless/test/test_pickle.py
==============================================================================
--- pypy/dist/pypy/module/_stackless/test/test_pickle.py	(original)
+++ pypy/dist/pypy/module/_stackless/test/test_pickle.py	Tue Jun 20 18:08:30 2006
@@ -79,7 +79,6 @@
             del sys.modules['mod']
 
     def test_exception(self):
-        skip("saving of exceptions is not working")
         import new, sys
 
         mod = new.module('mod')



More information about the Pypy-commit mailing list