[pypy-svn] r28125 - in pypy/dist/pypy: interpreter interpreter/test module/_pickle_support
ericvrp at codespeak.net
ericvrp at codespeak.net
Sat Jun 3 08:41:47 CEST 2006
Author: ericvrp
Date: Sat Jun 3 08:41:41 2006
New Revision: 28125
Modified:
pypy/dist/pypy/interpreter/pyframe.py
pypy/dist/pypy/interpreter/test/test_pickle.py
pypy/dist/pypy/module/_pickle_support/maker.py
Log:
More support for frame pickling. I'm checking this in so people at the
sprint may have a change to look at it. It has not been crossreferenced
against pricklepit.c of stackless.com. The biggest issue currently is the
pickling of f_locals which still causes some errors. Quite a few XXX's
in the code&test give an indication of what I'm trying to do.
Frame pickling is incomplete plus it's unknown if it will translate.
To enable frame pickling do:
- interpreter/test/test_pickle.py : remove skip from test_pickle_frame
- interpreter/typedef.py : remove comments from PyFrame.typedef
- interpreter/pyframe.py : outcomment line with 'frame pickling is work in progress'
- module/_pickle_support/__init__.py : remove comment from 'frame_new' line
This is rather conservative, hopefully it helps.
Modified: pypy/dist/pypy/interpreter/pyframe.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyframe.py (original)
+++ pypy/dist/pypy/interpreter/pyframe.py Sat Jun 3 08:41:41 2006
@@ -68,16 +68,44 @@
self.instr_prev = -1;
def descr__reduce__(self, space):
+ '''
+ >>>> 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']
+ '''
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 = [
+
+ #XXX how to call PyFrame.fget_f_lineno(..) from here? just make it a staticmethod?
+ #f_lineno = PyFrame.fget_f_lineno(space, self) #TypeError: unbound method fget_f_lineno() must be called with PyFrame instance as first argument (got StdObjSpace instance instead)
+ if self.w_f_trace is None:
+ f_lineno = self.get_last_lineno()
+ else:
+ f_lineno = self.f_lineno
+
+ tup = [
+ w(self.f_back),
+ w(self.builtin),
w(self.pycode),
+ w(self.last_exception), #f_exc_traceback, f_exc_type, f_exc_value
self.w_globals,
+ w(self.last_instr),
+ w(self.next_instr), #not in PyFrame.typedef!
+ w(f_lineno), #why not w(self.f_lineno)? something with self.w_f_trace?
+
+ #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
+
+ #f_restricted requires no additional data!
+ self.w_f_trace,
]
+
+ #XXX what to do with valuestack and blockstack here?
+
return space.newtuple([new_inst, space.newtuple(tup)])
def hide(self):
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 Sat Jun 3 08:41:41 2006
@@ -94,14 +94,22 @@
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_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
- assert frame.f_globals is result.f_globals
+
+ #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
- assert list(frame.f_locals) == list(result.f_locals)
+
+ #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
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 3 08:41:41 2006
@@ -50,6 +50,26 @@
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)
+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
+ w = space.wrap
+
+ new_frame = PyFrame(space, pycode, w(globals), None)
+ new_frame.f_back = f_back
+ new_frame.builtin = builtin
+ new_frame.last_exception = last_exception
+ new_frame.last_instr = last_instr
+ new_frame.next_instr = next_instr
+ new_frame.f_lineno = f_lineno
+ #new_frame.fastlocals_w = w(fastlocals)
+
+ if space.is_w(f_trace, space.w_None):
+ new_frame.w_f_trace = None
+ else:
+ new_frame.w_f_trace = w(f_trace)
+
return space.wrap(new_frame)
+frame_new.unwrap_spec = [ObjSpace, Arguments]
More information about the Pypy-commit
mailing list