Author: Carl Friedrich Bolz <[email protected]>
Branch: unpickle-coroutine-trampoline
Changeset: r44419:036d74657c0f
Date: 2011-05-25 13:55 +0200
http://bitbucket.org/pypy/pypy/changeset/036d74657c0f/
Log: fix pickling of stackless.tasklet.
diff --git a/lib_pypy/stackless.py b/lib_pypy/stackless.py
--- a/lib_pypy/stackless.py
+++ b/lib_pypy/stackless.py
@@ -200,14 +200,15 @@
# I can't think of a better solution without a real transform.
def rewrite_stackless_primitive(coro_state, alive, tempval):
- flags, state, thunk, parent = coro_state
- for i, frame in enumerate(state):
+ flags, frame, thunk, parent = coro_state
+ while frame is not None:
retval_expr = _stackless_primitive_registry.get(frame.f_code)
if retval_expr:
# this tasklet needs to stop pickling here and return its value.
tempval = eval(retval_expr, globals(), frame.f_locals)
- state = state[:i]
- coro_state = flags, state, thunk, parent
+ coro_state = flags, frame, thunk, parent
+ break
+ frame = frame.f_back
return coro_state, alive, tempval
#
@@ -492,23 +493,22 @@
assert two == ()
# we want to get rid of the parent thing.
# for now, we just drop it
- a, b, c, d = coro_state
-
+ a, frame, c, d = coro_state
+
# Removing all frames related to stackless.py.
# They point to stuff we don't want to be pickled.
- frame_list = list(b)
- new_frame_list = []
- for frame in frame_list:
+
+ pickleframe = frame
+ while frame is not None:
if frame.f_code == schedule.func_code:
# Removing everything including and after the
# call to stackless.schedule()
+ pickleframe = frame.f_back
break
- new_frame_list.append(frame)
- b = tuple(new_frame_list)
-
+ frame = frame.f_back
if d:
assert isinstance(d, coroutine)
- coro_state = a, b, c, None
+ coro_state = a, pickleframe, c, None
coro_state, alive, tempval = rewrite_stackless_primitive(coro_state,
self.alive, self.tempval)
inst_dict = self.__dict__.copy()
inst_dict.pop('tempval', None)
diff --git a/pypy/module/test_lib_pypy/test_stackless.py
b/pypy/module/test_lib_pypy/test_stackless.py
--- a/pypy/module/test_lib_pypy/test_stackless.py
+++ b/pypy/module/test_lib_pypy/test_stackless.py
@@ -8,15 +8,12 @@
space = gettestobjspace(usemodules=('_stackless', '_socket'))
cls.space = space
# cannot test the unpickle part on top of py.py
- cls.w_can_unpickle = space.wrap(bool(option.runappdirect))
def test_pickle(self):
import new, sys
mod = new.module('mod')
sys.modules['mod'] = mod
- mod.can_unpickle = self.can_unpickle
- mod.skip = skip
try:
exec '''
import pickle, sys
@@ -45,8 +42,6 @@
t = stackless.tasklet(demo)(lev)
stackless.run()
assert seen == range(1, lev+1) + range(lev, 0, -1)
-if not can_unpickle:
- skip("cannot test the unpickling part on top of py.py")
print "now running the clone"
tt = pickle.loads(blob)
tt.insert()
@@ -64,8 +59,6 @@
mod = new.module('mod')
sys.modules['mod'] = mod
- mod.can_unpickle = self.can_unpickle
- mod.skip = skip
try:
exec '''
import pickle, sys
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit