[pypy-svn] r27844 - in pypy/dist/pypy: interpreter interpreter/test module/_pickle_support

ericvrp at codespeak.net ericvrp at codespeak.net
Mon May 29 14:38:59 CEST 2006


Author: ericvrp
Date: Mon May 29 14:38:57 2006
New Revision: 27844

Modified:
   pypy/dist/pypy/interpreter/pyframe.py
   pypy/dist/pypy/interpreter/test/test_pickle.py
   pypy/dist/pypy/interpreter/typedef.py
   pypy/dist/pypy/module/_pickle_support/__init__.py
   pypy/dist/pypy/module/_pickle_support/maker.py
Log:
* beginning of frame pickling
* improved frame pickling test
* fix for minor typo


Modified: pypy/dist/pypy/interpreter/pyframe.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyframe.py	(original)
+++ pypy/dist/pypy/interpreter/pyframe.py	Mon May 29 14:38:57 2006
@@ -51,7 +51,7 @@
             self.valuestack = Stack()
         self.blockstack = Stack()
         self.last_exception = None
-        self.next_instr = r_uint(0) # Force it unsigned for performace reasons.
+        self.next_instr = r_uint(0) # Force it unsigned for performance reasons.
         self.builtin = space.builtin.pick_builtin(w_globals)
         # regular functions always have CO_OPTIMIZED and CO_NEWLOCALS.
         # class bodies only have CO_NEWLOCALS.
@@ -66,7 +66,20 @@
         self.instr_lb = 0
         self.instr_ub = -1
         self.instr_prev = -1;
-        
+
+    def descr__reduce__(self, space):
+        raise Exception('frame pickling is work in progress')
+        from pypy.interpreter.mixedmodule import MixedModule
+        w_mod    = space.getbuiltinmodule('_pickle_support')
+        mod      = space.interp_w(MixedModule, w_mod)
+        new_inst = mod.get('frame_new')
+        w        = space.wrap
+        tup      = [
+            w(self.pycode),
+            self.w_globals,
+            ]
+        return space.newtuple([new_inst, space.newtuple(tup)])
+
     def hide(self):
         return self.pycode.hidden_applevel
 

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	Mon May 29 14:38:57 2006
@@ -73,6 +73,10 @@
         assert not (cell != result)
     
     def test_pickle_frame(self):
+        '''
+        >>>> dir(frame)
+        ['__class__', '__delattr__', '__doc__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', 'f_back', 'f_builtins', 'f_code', 'f_exc_traceback', 'f_exc_type', 'f_exc_value', 'f_globals', 'f_lasti', 'f_lineno', 'f_locals', 'f_restricted', 'f_trace']
+        '''
         skip("work in progress")
         from sys import exc_info
         def f():
@@ -85,8 +89,22 @@
         frame  = f()
         pckl   = pickle.dumps(frame)
         result = pickle.loads(pckl)
-        assert frame == result
-    
+        assert type(frame) is type(result)
+        assert dir(frame) == dir(result)
+        assert frame.__doc__ == result.__doc__
+        assert type(frame.f_back) is type(result.f_back)
+        assert frame.f_builtins is result.f_builtins
+        assert frame.f_code is result.f_code
+        assert frame.f_exc_traceback is result.f_exc_traceback
+        assert frame.f_exc_type is result.f_exc_type
+        assert frame.f_exc_value is result.f_exc_value
+        assert frame.f_globals is result.f_globals
+        assert frame.f_lasti == result.f_lasti
+        assert frame.f_lineno == result.f_lineno
+        assert list(frame.f_locals) == list(result.f_locals)
+        assert frame.f_restricted is result.f_restricted
+        assert frame.f_trace is result.f_trace
+
     def test_pickle_traceback(self):
         skip("work in progress")
         def f():
@@ -238,7 +256,7 @@
         assert list(result) == [2,3,4]
     
     def test_pickle_generator(self):
-        skip("work in progress")
+        skip("work in progress (implement after frame pickling)")
         import pickle
         def giveme(n):
             x = 0

Modified: pypy/dist/pypy/interpreter/typedef.py
==============================================================================
--- pypy/dist/pypy/interpreter/typedef.py	(original)
+++ pypy/dist/pypy/interpreter/typedef.py	Mon May 29 14:38:57 2006
@@ -521,6 +521,8 @@
     )
 
 PyFrame.typedef = TypeDef('frame',
+    __reduce__   = interp2app(PyFrame.descr__reduce__,
+                                  unwrap_spec=['self', ObjSpace]),
     f_builtins = GetSetProperty(PyFrame.fget_f_builtins),
     f_lineno = GetSetProperty(PyFrame.fget_f_lineno, PyFrame.fset_f_lineno),
     f_back = GetSetProperty(PyFrame.fget_f_back),

Modified: pypy/dist/pypy/module/_pickle_support/__init__.py
==============================================================================
--- pypy/dist/pypy/module/_pickle_support/__init__.py	(original)
+++ pypy/dist/pypy/module/_pickle_support/__init__.py	Mon May 29 14:38:57 2006
@@ -15,4 +15,5 @@
         'dictiter_surrogate_new' : 'maker.dictiter_surrogate_new',
         'seqiter_new'  : 'maker.seqiter_new',
         'reverseseqiter_new' : 'maker.reverseseqiter_new',
+        'frame_new'    : 'maker.frame_new',
     }

Modified: pypy/dist/pypy/module/_pickle_support/maker.py
==============================================================================
--- pypy/dist/pypy/module/_pickle_support/maker.py	(original)
+++ pypy/dist/pypy/module/_pickle_support/maker.py	Mon May 29 14:38:57 2006
@@ -2,6 +2,7 @@
 from pypy.interpreter.pycode import PyCode
 from pypy.interpreter.function import Function, Method
 from pypy.interpreter.module import Module
+from pypy.interpreter.pyframe import PyFrame
 from pypy.rpython.objectmodel import instantiate
 from pypy.interpreter.argument import Arguments
 from pypy.interpreter.baseobjspace import ObjSpace, W_Root
@@ -48,3 +49,7 @@
     w_len = space.len(w_seq)
     index = space.int_w(w_index) - space.int_w(w_len)
     return W_ReverseSeqIterObject(space, w_seq, index)
+    
+def frame_new(space, w_pycode, w_globals):
+    new_frame = PyFrame(space, w_pycode, w_globals, None)
+    return space.wrap(new_frame)



More information about the Pypy-commit mailing list