[pypy-svn] r26394 - in pypy/dist/pypy/interpreter: . test
ericvrp at codespeak.net
ericvrp at codespeak.net
Thu Apr 27 06:34:37 CEST 2006
Author: ericvrp
Date: Thu Apr 27 06:34:31 2006
New Revision: 26394
Modified:
pypy/dist/pypy/interpreter/nestedscope.py
pypy/dist/pypy/interpreter/pycode.py
pypy/dist/pypy/interpreter/test/test_pickle.py
pypy/dist/pypy/interpreter/typedef.py
Log:
(pedronis, ericvrp)
Added support for pickling code objects.
(commiting to test translation on faster machine)
Modified: pypy/dist/pypy/interpreter/nestedscope.py
==============================================================================
--- pypy/dist/pypy/interpreter/nestedscope.py (original)
+++ pypy/dist/pypy/interpreter/nestedscope.py Thu Apr 27 06:34:31 2006
@@ -38,11 +38,12 @@
def descr__reduce__(self, space):
w_mod = space.getbuiltinmodule('_pickle_support')
mod = space.interp_w(MixedModule, w_mod)
- cell_new = mod.get('cell_new')
+ new_inst = mod.get('cell_new')
if self.w_value is None: #when would this happen?
- return space.newtuple([cell_new, space.newtuple([])])
- return space.newtuple([cell_new, space.newtuple([]),
- space.newtuple([self.w_value])])
+ return space.newtuple([new_inst, space.newtuple([])])
+ tup = [self.w_value]
+ return space.newtuple([new_inst, space.newtuple([]),
+ space.newtuple(tup)])
def descr__setstate__(self, space, w_state):
self.w_value = space.getitem(w_state, space.wrap(0))
Modified: pypy/dist/pypy/interpreter/pycode.py
==============================================================================
--- pypy/dist/pypy/interpreter/pycode.py (original)
+++ pypy/dist/pypy/interpreter/pycode.py Thu Apr 27 06:34:31 2006
@@ -10,6 +10,7 @@
from pypy.interpreter.error import OperationError
from pypy.interpreter.gateway import NoneNotWrapped
from pypy.interpreter.baseobjspace import ObjSpace, W_Root
+from pypy.interpreter.mixedmodule import MixedModule
# helper
@@ -380,3 +381,26 @@
return space.wrap(code)
descr_code__new__.unwrap_spec = unwrap_spec
+ def descr__reduce__(self, space):
+ w_mod = space.getbuiltinmodule('_pickle_support')
+ mod = space.interp_w(MixedModule, w_mod)
+ new_inst = mod.get('code_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
+ ]
+ return space.newtuple([new_inst, space.newtuple(tup)])
\ No newline at end of file
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 06:34:31 2006
@@ -1,5 +1,17 @@
class AppTestInterpObjectPickling:
-
+
+ def test_pickle_code(self):
+ import pickle
+ def f():
+ return 42
+ code = f.func_code
+ pckl = pickle.dumps(code)
+ result = pickle.loads(pckl)
+ assert code == result
+
+ def DONTtest_pickle_func(self):
+ pass
+
def test_pickle_cell(self):
import pickle
def g():
@@ -14,6 +26,42 @@
assert cell == result
assert not (cell != result)
+ def DONTtest_pickle_frame(self):
+ pass
+
+ def DONTtest_pickle_traceback(self):
+ pass
+
+ def DONTtest_pickle_module(self):
+ pass
+
+ def DONTtest_pickle_moduledict(self):
+ pass
+
+ def DONTtest_pickle_iter(self):
+ pass
+
+ def DONTtest_pickle_method(self):
+ pass
+
+ def DONTtest_pickle_dictiter(self):
+ pass
+
+ def DONTtest_pickle_enum(self):
+ pass
+
+ def DONTtest_pickle_enumfactory(self):
+ pass
+
+ def DONTtest_pickle_listiter(self):
+ pass
+
+ def DONTtest_pickle_rangeiter(self):
+ pass
+
+ def DONTtest_pickle_tupleiter(self):
+ pass
+
#def test_pickle_generator(self):
# import pickle
# def giveme(n):
@@ -22,28 +70,3 @@
# yield x
# generator = giveme(10)
# print pickle.dumps(generator)
-
-#TODO: test pickling of code objects
-#TODO: test pickling of function objects
-#TODO: test pickling of frame objects
-#TODO: test pickling of tracebacks
-#TODO: test pickling of modules
-
-'''
-etc. etc. etc.
-init_codetype()
-init_functype()
-init_celltype()
-init_frametype()
-init_tracebacktype()
-init_moduletype()
-init_moduledicttype()
-init_itertype()
-init_methodtype()
-init_dictitertype()
-init_enumtype()
-init_enumfactorytype()
-init_listitertype()
-init_rangeitertype()
-init_tupleitertype()
-'''
Modified: pypy/dist/pypy/interpreter/typedef.py
==============================================================================
--- pypy/dist/pypy/interpreter/typedef.py (original)
+++ pypy/dist/pypy/interpreter/typedef.py Thu Apr 27 06:34:31 2006
@@ -415,6 +415,8 @@
__new__ = interp2app(PyCode.descr_code__new__.im_func),
__eq__ = interp2app(PyCode.descr_code__eq__),
__ne__ = descr_generic_ne,
+ __reduce__ = interp2app(PyCode.descr__reduce__,
+ unwrap_spec=['self', ObjSpace]),
co_argcount = interp_attrproperty('co_argcount', cls=PyCode),
co_nlocals = interp_attrproperty('co_nlocals', cls=PyCode),
co_stacksize = interp_attrproperty('co_stacksize', cls=PyCode),
More information about the Pypy-commit
mailing list