Philip Jenvey avatar Philip Jenvey committed e687186

fix for test_pickle_frame_with_exc, simply support W_OperationError to be
pickled for now. add another test for its __setstate__

Comments (0)

Files changed (5)

pypy/interpreter/pyopcode.py

             unroller.operr.normalize_exception(frame.space)
         return FinallyBlock.handle(self, frame, unroller)
 
-block_classes = {'SETUP_LOOP': LoopBlock,
+block_classes = {'EXCEPT_HANDLER_BLOCK': ExceptHandlerBlock,
+                 'SETUP_LOOP': LoopBlock,
                  'SETUP_EXCEPT': ExceptBlock,
                  'SETUP_FINALLY': FinallyBlock,
                  'SETUP_WITH': WithBlock,
     def __init__(self, operr):
         self.operr = operr
 
+    def descr_reduce(self, space):
+        from pypy.interpreter.mixedmodule import MixedModule
+        w_mod = space.getbuiltinmodule('_pickle_support')
+        mod = space.interp_w(MixedModule, w_mod)
+        w_new_inst = mod.get('operationerror_new')
+        w_args = space.newtuple([])
+        operr = self.operr
+        if operr is None:
+            return space.newtuple([w_new_inst, w_args])
+        w_state = space.newtuple([operr.w_type, operr.get_w_value(space),
+                                  operr.get_traceback()])
+        return space.newtuple([w_new_inst, w_args, w_state])
+
+    def descr_setstate(self, space, w_state):
+        self.operr = OperationError(*space.fixedview(w_state, 3))
 
 def source_as_str(space, w_source, funcname, what, flags):
     """Return source code as str0 with adjusted compiler flags

pypy/interpreter/test/test_zzpickle_and_slow.py

 
         assert read_exc_type(f2) is ValueError
 
+    def test_pickle_frame_with_exc_nested(self):
+        # avoid creating a closure for now
+        self = None
+        def f():
+            try:
+                1/0
+            except:
+                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

pypy/interpreter/typedef.py

 SuspendedUnroller.typedef = TypeDef("SuspendedUnroller")
 SuspendedUnroller.typedef.acceptable_as_base_class = False
 
-W_OperationError.typedef = TypeDef("OperationError")
+W_OperationError.typedef = TypeDef("OperationError",
+    __reduce__ = interp2app(W_OperationError.descr_reduce),
+    __setstate__ = interp2app(W_OperationError.descr_setstate),
+)
+W_OperationError.typedef.acceptable_as_base_class = False

pypy/module/_pickle_support/__init__.py

         'builtin_code': 'maker.builtin_code',
         'builtin_function' : 'maker.builtin_function',
         'enumerate_new': 'maker.enumerate_new',
-        'reversed_new': 'maker.reversed_new'
+        'reversed_new': 'maker.reversed_new',
+        'operationerror_new': 'maker.operationerror_new',
     }

pypy/module/_pickle_support/maker.py

     new_iter = W_RangeIterator(space, w_start, w_step, w_len, w_index)
     return space.wrap(new_iter)
 
+def operationerror_new(space):
+    from pypy.interpreter.pyopcode import W_OperationError
+    return W_OperationError(None)
+
 @unwrap_spec(identifier=str)
 def builtin_code(space, identifier):
     from pypy.interpreter import gateway
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.