[pypy-svn] r26438 - in pypy/dist: lib-python/modified-2.4.1 pypy/interpreter pypy/interpreter/test
ericvrp at codespeak.net
ericvrp at codespeak.net
Thu Apr 27 13:10:23 CEST 2006
Author: ericvrp
Date: Thu Apr 27 13:10:11 2006
New Revision: 26438
Added:
pypy/dist/lib-python/modified-2.4.1/pickle.py
- copied, changed from r26388, pypy/dist/lib-python/2.4.1/pickle.py
Modified:
pypy/dist/pypy/interpreter/function.py
pypy/dist/pypy/interpreter/test/test_pickle.py
Log:
(pedronis, ericvrp)
More support for making function pickling work. We need to check and port some
more code from stackless' pickle.py to make this work.
Modified: pypy/dist/pypy/interpreter/function.py
==============================================================================
--- pypy/dist/pypy/interpreter/function.py (original)
+++ pypy/dist/pypy/interpreter/function.py Thu Apr 27 13:10:11 2006
@@ -170,32 +170,21 @@
return self.getrepr(self.space, 'function %s' % (self.name,))
def descr__reduce__(self, space):
- '''
+ from pypy.interpreter.mixedmodule import MixedModule
w_mod = space.getbuiltinmodule('_pickle_support')
mod = space.interp_w(MixedModule, w_mod)
- new_inst = mod.get('code_new')
+ new_inst = mod.get('func_new')
w = space.wrap
tup = [
- w(self.co_argcount),
- w(self.co_nlocals),
- w(self.co_stacksize),
- w(self.co_flags),
- w(self.co_code),
- space.newtuple(self.co_consts_w),
- space.newtuple(self.co_names_w),
- space.newtuple([w(v) for v in self.co_varnames]),
- w(self.co_filename),
- w(self.co_name),
- w(self.co_firstlineno),
- w(self.co_lnotab),
- space.newtuple([w(v) for v in self.co_freevars]),
- space.newtuple([w(v) for v in self.co_cellvars]),
- #hidden_applevel=False, magic = 62061 | 0x0a0d0000
+ w(self.code),
+ #space.newdict([]), #XXX because pickle.py has no _pickle_moduledict yet...
+ self.w_func_globals,
+ w(self.name),
+ space.newtuple(self.defs_w),
+ w(self.closure),
]
return space.newtuple([new_inst, space.newtuple(tup)])
- '''
- raise Exception('Function.desc__reduce__ here')
-
+
def fget_func_defaults(space, self):
values_w = self.defs_w
if not values_w:
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 Thu Apr 27 13:10:11 2006
@@ -9,13 +9,34 @@
result = pickle.loads(pckl)
assert code == result
- def test_pickle_func(self):
- skip("work in progress")
+ def test_pickle_global_func(self):
+ import new
+ mod = new.module('mod')
+ import sys
+ sys.modules['mod'] = mod
def func():
return 42
+ mod.__dict__['func'] = func
+ func.__module__ = 'mod'
import pickle
pckl = pickle.dumps(func)
result = pickle.loads(pckl)
+ assert func is result
+ del sys.modules['mod']
+
+ def test_pickle_builtin_func(self):
+ import pickle
+ pckl = pickle.dumps(map)
+ result = pickle.loads(pckl)
+ assert map is result
+
+ def test_pickle_nested_func(self):
+ skip("work in progress")
+ def func():
+ return 42
+ import pickle
+ pckl = pickle.dumps(func)
+ result = pickle.loads(pckl)
assert func == result
def test_pickle_cell(self):
More information about the Pypy-commit
mailing list