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

tismer at codespeak.net tismer at codespeak.net
Sat Jun 10 17:10:52 CEST 2006


Author: tismer
Date: Sat Jun 10 17:10:47 2006
New Revision: 28629

Modified:
   pypy/dist/pypy/interpreter/function.py
   pypy/dist/pypy/interpreter/typedef.py
   pypy/dist/pypy/module/_pickle_support/maker.py
Log:
explicitly creating functions in the __setstate__ phase. More code but less crashes.
Still, something is broken with pickling. I think to add a debug mode to pickling.

Modified: pypy/dist/pypy/interpreter/function.py
==============================================================================
--- pypy/dist/pypy/interpreter/function.py	(original)
+++ pypy/dist/pypy/interpreter/function.py	Sat Jun 10 17:10:47 2006
@@ -179,14 +179,39 @@
             w_closure = space.w_None
         else:
             w_closure = space.newtuple([w(cell) for cell in self.closure])
-        tup      = [
+
+        nt = space.newtuple
+        tup_base = []
+        tup_state = [
+            w(self.name),
+            self.w_doc,
             w(self.code),
             self.w_func_globals,
-            w(self.name),
-            space.newtuple(self.defs_w),
             w_closure,
+            nt(self.defs_w),
+            self.w_func_dict,
+            self.w_module,
         ]
-        return space.newtuple([new_inst, space.newtuple(tup)])
+        return nt([new_inst, nt(tup_base), nt(tup_state)])
+
+    def descr_function__setstate__(self, space, w_args):
+        from pypy.interpreter.pycode import PyCode
+        args_w = space.unpackiterable(w_args)
+        (w_name, w_doc, w_code, w_func_globals, w_closure, w_defs_w,
+         w_func_dict, w_module) = args_w
+
+        self.space = space
+        self.name = space.str_w(w_name)
+        self.w_doc = w_doc
+        self.code = space.interp_w(PyCode, w_code)
+        self.w_func_globals = w_func_globals
+        if w_closure is not space.w_None:
+            self.closure = space.unpackiterable(w_closure)
+        else:
+            self.closure = None
+        self.defs_w    = space.unpackiterable(w_defs_w)
+        self.w_func_dict = w_func_dict
+        self.w_module = w_module
 
     def fget_func_defaults(space, self):
         values_w = self.defs_w

Modified: pypy/dist/pypy/interpreter/typedef.py
==============================================================================
--- pypy/dist/pypy/interpreter/typedef.py	(original)
+++ pypy/dist/pypy/interpreter/typedef.py	Sat Jun 10 17:10:47 2006
@@ -578,6 +578,8 @@
     __repr__ = interp2app(Function.descr_function_repr),
     __reduce__ = interp2app(Function.descr_function__reduce__,
                             unwrap_spec=['self', ObjSpace]),
+    __setstate__ = interp2app(Function.descr_function__setstate__,
+                             unwrap_spec=['self', ObjSpace, W_Root]),
     func_code = getset_func_code,
     func_doc = getset_func_doc,
     func_name = getset_func_name,

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	Sat Jun 10 17:10:47 2006
@@ -24,10 +24,11 @@
     return space.call_args(w_type, __args__)
 code_new.unwrap_spec = [ObjSpace, Arguments]
 
-def func_new(space, __args__):
-    w_type = space.gettypeobject(Function.typedef)
-    return space.call_args(w_type, __args__)
-func_new.unwrap_spec = [ObjSpace, Arguments]
+def func_new(space):
+    fu = instantiate(Function)
+    fu.w_func_dict = space.newdict([])
+    return space.wrap(fu)
+func_new.unwrap_spec = [ObjSpace]
 
 def module_new(space, w_name, w_dict):
     new_mod = Module(space, w_name, w_dict)
@@ -62,7 +63,7 @@
     w = space.wrap
 
     # let the code object create the right kind of frame
-    # the distinction is a littleover-done but computable
+    # the distinction is a little over-done but computable
     Klass = pycode.get_frame_class()
     new_frame = instantiate(Klass)
     return space.wrap(new_frame)



More information about the Pypy-commit mailing list