[pypy-svn] r28210 - in pypy/dist/pypy: interpreter interpreter/test module/_pickle_support
ericvrp at codespeak.net
ericvrp at codespeak.net
Sun Jun 4 10:38:10 CEST 2006
Author: ericvrp
Date: Sun Jun 4 10:38:06 2006
New Revision: 28210
Modified:
pypy/dist/pypy/interpreter/generator.py
pypy/dist/pypy/interpreter/pyframe.py
pypy/dist/pypy/interpreter/pytraceback.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:
Added Pickling of tracebacks and generator. (enable as described in r28152)
Still todo are pickling of methods, staticmethods and classmethods.
Plus frame pickling needs to be debugged some more.
Modified: pypy/dist/pypy/interpreter/generator.py
==============================================================================
--- pypy/dist/pypy/interpreter/generator.py (original)
+++ pypy/dist/pypy/interpreter/generator.py Sun Jun 4 10:38:06 2006
@@ -43,6 +43,22 @@
self.running = False
self.exhausted = False
+ def descr__reduce__(self, space):
+ raise Exception('generator 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('generator_new')
+ w = space.wrap
+
+ tup = [
+ w(self.frame),
+ w(self.running),
+ w(self.exhausted),
+ ]
+
+ return space.newtuple([new_inst, space.newtuple(tup)])
+
def descr__iter__(self):
"""x.__iter__() <==> iter(x)"""
return self.space.wrap(self)
Modified: pypy/dist/pypy/interpreter/pyframe.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyframe.py (original)
+++ pypy/dist/pypy/interpreter/pyframe.py Sun Jun 4 10:38:06 2006
@@ -65,7 +65,7 @@
# For tracing
self.instr_lb = 0
self.instr_ub = -1
- self.instr_prev = -1;
+ self.instr_prev = -1
def descr__reduce__(self, space):
'''
@@ -86,10 +86,18 @@
else:
f_lineno = self.f_lineno
+ valuestack = [w(item) for item in self.valuestack.items]
+ #print 'XXX valuestack=', valuestack
+
+ blockstack = [w(item) for item in self.blockstack.items]
+ #print 'XXX blockstack=', blockstack
+
tup = [
w(self.f_back),
w(self.builtin),
w(self.pycode),
+ space.w_None, #space.newtuple(valuestack), #XXX <pypy.interpreter.nestedscope.PyNestedScopeFrame object at 0x25545d0> causes AttributeError: 'NoneType' object has no attribute 'getclass'
+ space.w_None, #space.newtuple(blockstack),
w(self.last_exception), #f_exc_traceback, f_exc_type, f_exc_value
self.w_globals,
w(self.last_instr),
@@ -98,10 +106,14 @@
#space.newtuple(self.fastlocals_w), #XXX (application-level) PicklingError: Can't pickle <type 'AppTestInterpObjectPickling'>: it's not found as __builtin__.AppTestInterpObjectPickling
#self.getdictscope(), #XXX (application-level) PicklingError: Can't pickle <type 'AppTestInterpObjectPickling'>: it's not found as __builtin__.AppTestInterpObjectPickling
- space.w_None, #XXX placeholder
+ space.w_None, #XXX placeholder for f_locals
#f_restricted requires no additional data!
self.w_f_trace,
+
+ w(self.instr_lb), #do we need these three (that are for tracing)
+ w(self.instr_ub),
+ w(self.instr_prev),
]
#XXX what to do with valuestack and blockstack here?
@@ -294,7 +306,7 @@
op = ord(code[addr])
if op in (SETUP_LOOP, SETUP_EXCEPT, SETUP_FINALLY):
- delta_iblock += 1;
+ delta_iblock += 1
elif op == POP_BLOCK:
delta_iblock -= 1
if delta_iblock < min_delta_iblock:
Modified: pypy/dist/pypy/interpreter/pytraceback.py
==============================================================================
--- pypy/dist/pypy/interpreter/pytraceback.py (original)
+++ pypy/dist/pypy/interpreter/pytraceback.py Sun Jun 4 10:38:06 2006
@@ -18,6 +18,22 @@
self.lineno = lineno
self.next = next
+ def descr__reduce__(self, space):
+ raise Exception('traceback 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('traceback_new')
+ w = space.wrap
+
+ tup = [
+ w(self.frame),
+ w(self.lasti),
+ w(self.lineno),
+ w(self.next),
+ ]
+
+ return space.newtuple([new_inst, space.newtuple(tup)])
def record_application_traceback(space, operror, frame, last_instruction):
if frame.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 Sun Jun 4 10:38:06 2006
@@ -1,5 +1,5 @@
class AppTestInterpObjectPickling:
-
+
def test_pickle_code(self):
def f():
return 42
@@ -71,7 +71,7 @@
result = pickle.loads(pckl)
assert cell == result
assert not (cell != result)
-
+
def test_pickle_frame(self):
'''
>>>> dir(frame)
@@ -86,32 +86,33 @@
exc_type, exc, tb = exc_info()
return tb.tb_frame
import pickle
- frame = f()
- pckl = pickle.dumps(frame)
- result = pickle.loads(pckl)
- 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 == 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
-
- #print 'frame f_globals =', frame.f_globals #frame f_globals = {'__builtins__': <module object at 0x0167dc70>, '__name__': '__builtin__', 'test_pickle_frame': <function test_pickle_frame at 0x0237adb0>}
- #print 'result.f_globals=', result.f_globals #result.f_globals= {'__builtins__': <module object at 0x0167dc70>, '__name__': '__builtin__', 'test_pickle_frame': <function test_pickle_frame at 0x02c346f0>}
- #assert frame.f_globals == result.f_globals #XXX test_pickle_frame function not same identity (see pickle func tests, we don't compare by identity there!)?
-
- assert frame.f_lasti == result.f_lasti
- assert frame.f_lineno == result.f_lineno
-
- #print 'frame.f_locals=', frame.f_locals #['exc_info', 'tb', 'exc_type', 'exc']
- #print 'result.f_locals=', result.f_locals #[]
- #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
+ f1 = f()
+ pckl = pickle.dumps(f1)
+ f2 = pickle.loads(pckl)
+
+ assert type(f1) is type(f2)
+ assert dir(f1) == dir(f2)
+ assert f1.__doc__ == f2.__doc__
+ assert type(f1.f_back) is type(f2.f_back)
+ assert f1.f_builtins is f2.f_builtins
+ assert f1.f_code == f2.f_code
+ assert f1.f_exc_traceback is f2.f_exc_traceback
+ assert f1.f_exc_type is f2.f_exc_type
+ assert f1.f_exc_value is f2.f_exc_value
+
+ #print 'f1.f_globals =', f1.f_globals #f1.f_globals = {'__builtins__': <module object at 0x0167dc70>, '__name__': '__builtin__', 'test_pickle_frame': <function test_pickle_frame at 0x0237adb0>}
+ #print 'f2.f_globals=', f2.f_globals #f2.f_globals= {'__builtins__': <module object at 0x0167dc70>, '__name__': '__builtin__', 'test_pickle_frame': <function test_pickle_frame at 0x02c346f0>}
+ #assert f1.f_globals == f2.f_globals #XXX test_pickle_frame function not same identity (see pickle func tests, we don't compare by identity there!)?
+
+ assert f1.f_lasti == f2.f_lasti
+ assert f1.f_lineno == f2.f_lineno
+
+ #print 'f1.f_locals=', f1.f_locals #['exc_info', 'tb', 'exc_type', 'exc']
+ #print 'f2.f_locals=', f2.f_locals #[]
+ #assert list(f1.f_locals) == list(f2.f_locals)
+
+ assert f1.f_restricted is f2.f_restricted
+ assert f1.f_trace is f2.f_trace
def test_pickle_traceback(self):
skip("work in progress")
@@ -126,8 +127,39 @@
tb = f()
pckl = pickle.dumps(tb)
result = pickle.loads(pckl)
- assert tb == result
-
+
+ assert type(tb) is type(result)
+ assert tb.tb_lasti == result.tb_lasti
+ assert tb.tb_lineno == result.tb_lineno
+ assert tb.tb_next == result.tb_next
+
+ #XXX silly code duplication from frame pickling test
+ f1 = tb.tb_frame
+ f2 = result.tb_frame
+ assert type(f1) is type(f2)
+ assert dir(f1) == dir(f2)
+ assert f1.__doc__ == f2.__doc__
+ assert type(f1.f_back) is type(f2.f_back)
+ assert f1.f_builtins is f2.f_builtins
+ assert f1.f_code == f2.f_code
+ assert f1.f_exc_traceback is f2.f_exc_traceback
+ assert f1.f_exc_type is f2.f_exc_type
+ assert f1.f_exc_value is f2.f_exc_value
+
+ #print 'f1.f_globals =', f1.f_globals #f1.f_globals = {'__builtins__': <module object at 0x0167dc70>, '__name__': '__builtin__', 'test_pickle_frame': <function test_pickle_frame at 0x0237adb0>}
+ #print 'f2.f_globals=', f2.f_globals #f2.f_globals= {'__builtins__': <module object at 0x0167dc70>, '__name__': '__builtin__', 'test_pickle_frame': <function test_pickle_frame at 0x02c346f0>}
+ #assert f1.f_globals == f2.f_globals #XXX test_pickle_frame function not same identity (see pickle func tests, we don't compare by identity there!)?
+
+ assert f1.f_lasti == f2.f_lasti
+ assert f1.f_lineno == f2.f_lineno
+
+ #print 'f1.f_locals=', f1.f_locals #['exc_info', 'tb', 'exc_type', 'exc']
+ #print 'f2.f_locals=', f2.f_locals #[]
+ #assert list(f1.f_locals) == list(f2.f_locals)
+
+ assert f1.f_restricted is f2.f_restricted
+ assert f1.f_trace is f2.f_trace
+
def test_pickle_module(self):
import pickle
mod = pickle
@@ -270,5 +302,39 @@
x = 0
while x < n:
yield x
- generator = giveme(10)
- print pickle.dumps(generator)
+ g1 = giveme(10)
+ #print 'g1=', g1, dir(g1)
+ pckl = pickle.dumps(g1)
+ g2 = pickle.loads(pckl)
+ #print 'g2=', g2, dir(g2)
+
+ assert type(g1) is type(g2)
+ assert g1.gi_running == g2.gi_running
+ #assert g1.gi_exhausted == g2.gi_exhausted #not exported!
+
+ #XXX silly code duplication from frame pickling test
+ f1 = g1.gi_frame
+ f2 = g2.gi_frame
+ assert type(f1) is type(f2)
+ assert dir(f1) == dir(f2)
+ assert f1.__doc__ == f2.__doc__
+ assert type(f1.f_back) is type(f2.f_back)
+ assert f1.f_builtins is f2.f_builtins
+ assert f1.f_code == f2.f_code
+ assert f1.f_exc_traceback is f2.f_exc_traceback
+ assert f1.f_exc_type is f2.f_exc_type
+ assert f1.f_exc_value is f2.f_exc_value
+
+ #print 'f1.f_globals =', f1.f_globals #f1.f_globals = {'__builtins__': <module object at 0x0167dc70>, '__name__': '__builtin__', 'test_pickle_frame': <function test_pickle_frame at 0x0237adb0>}
+ #print 'f2.f_globals=', f2.f_globals #f2.f_globals= {'__builtins__': <module object at 0x0167dc70>, '__name__': '__builtin__', 'test_pickle_frame': <function test_pickle_frame at 0x02c346f0>}
+ #assert f1.f_globals == f2.f_globals #XXX test_pickle_frame function not same identity (see pickle func tests, we don't compare by identity there!)?
+
+ assert f1.f_lasti == f2.f_lasti
+ assert f1.f_lineno == f2.f_lineno
+
+ #print 'f1.f_locals=', f1.f_locals #['exc_info', 'tb', 'exc_type', 'exc']
+ #print 'f2.f_locals=', f2.f_locals #[]
+ #assert list(f1.f_locals) == list(f2.f_locals)
+
+ assert f1.f_restricted is f2.f_restricted
+ assert f1.f_trace is f2.f_trace
Modified: pypy/dist/pypy/interpreter/typedef.py
==============================================================================
--- pypy/dist/pypy/interpreter/typedef.py (original)
+++ pypy/dist/pypy/interpreter/typedef.py Sun Jun 4 10:38:06 2006
@@ -623,6 +623,8 @@
del BuiltinFunction.typedef.rawdict['__get__']
PyTraceback.typedef = TypeDef("traceback",
+ #__reduce__ = interp2app(PyTraceback.descr__reduce__,
+ # unwrap_spec=['self', ObjSpace]),
tb_frame = interp_attrproperty('frame', cls=PyTraceback),
tb_lasti = interp_attrproperty('lasti', cls=PyTraceback),
tb_lineno = interp_attrproperty('lineno', cls=PyTraceback),
@@ -630,6 +632,8 @@
)
GeneratorIterator.typedef = TypeDef("generator",
+ #__reduce__ = interp2app(GeneratorIterator.descr__reduce__,
+ # unwrap_spec=['self', ObjSpace]),
next = interp2app(GeneratorIterator.descr_next),
__iter__ = interp2app(GeneratorIterator.descr__iter__),
gi_running = interp_attrproperty('running', cls=GeneratorIterator),
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 Sun Jun 4 10:38:06 2006
@@ -16,4 +16,6 @@
'seqiter_new' : 'maker.seqiter_new',
'reverseseqiter_new' : 'maker.reverseseqiter_new',
#'frame_new' : 'maker.frame_new',
+ #'traceback_new' : 'maker.traceback_new',
+ #'generator_new' : 'maker.generator_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 Sun Jun 4 10:38:06 2006
@@ -3,6 +3,8 @@
from pypy.interpreter.function import Function, Method
from pypy.interpreter.module import Module
from pypy.interpreter.pyframe import PyFrame
+from pypy.interpreter.pytraceback import PyTraceback
+from pypy.interpreter.generator import GeneratorIterator
from pypy.rpython.objectmodel import instantiate
from pypy.interpreter.argument import Arguments
from pypy.interpreter.baseobjspace import ObjSpace, W_Root
@@ -53,13 +55,16 @@
def frame_new(space, __args__):
args_w, kwds_w = __args__.unpack() #stolen from std/fake.py
args = [space.unwrap(w_arg) for w_arg in args_w]
- f_back, builtin, pycode, last_exception, globals, last_instr, next_instr,\
- f_lineno, fastlocals, f_trace = args
+ f_back, builtin, pycode, valuestack, blockstack, last_exception,\
+ globals, last_instr, next_instr, f_lineno, fastlocals, f_trace,\
+ instr_lb, instr_ub, instr_prev = args
w = space.wrap
new_frame = PyFrame(space, pycode, w(globals), None)
new_frame.f_back = f_back
new_frame.builtin = builtin
+ #new_frame.blockstack = blockstack
+ #new_frame.valuestack = valuestack
new_frame.last_exception = last_exception
new_frame.last_instr = last_instr
new_frame.next_instr = next_instr
@@ -71,5 +76,26 @@
else:
new_frame.w_f_trace = w(f_trace)
+ new_frame.instr_lb = instr_lb #the three for tracing
+ new_frame.instr_ub = instr_ub
+ new_frame.instr_prev = instr_prev
+
return space.wrap(new_frame)
frame_new.unwrap_spec = [ObjSpace, Arguments]
+
+def traceback_new(space, __args__):
+ args_w, kwds_w = __args__.unpack() #stolen from std/fake.py
+ args = [space.unwrap(w_arg) for w_arg in args_w]
+ frame, lasti, lineno, next = args
+ return PyTraceback(space, frame, lasti, lineno, next)
+traceback_new.unwrap_spec = [ObjSpace, Arguments]
+
+def generator_new(space, __args__):
+ args_w, kwds_w = __args__.unpack() #stolen from std/fake.py
+ args = [space.unwrap(w_arg) for w_arg in args_w]
+ frame, running, exhausted = args
+ new_generator = GeneratorIterator(frame)
+ new_generator.running = running
+ new_generator.exhausted = exhausted
+ return new_generator
+generator_new.unwrap_spec = [ObjSpace, Arguments]
More information about the Pypy-commit
mailing list