[pypy-svn] r28649 - in pypy/dist/pypy/module: _pickle_support stackless
mwh at codespeak.net
mwh at codespeak.net
Sat Jun 10 22:17:39 CEST 2006
Author: mwh
Date: Sat Jun 10 22:17:38 2006
New Revision: 28649
Modified:
pypy/dist/pypy/module/_pickle_support/__init__.py
pypy/dist/pypy/module/_pickle_support/maker.py
pypy/dist/pypy/module/stackless/coroutine.py
Log:
special case attempts to pickle the main coroutine. ugly, possibly not a good
idea in general, but it enables a coroutine to be successfully pickled.
haven't even tried unpickling yet :-)
also, add a _framestack applevel attribute to AppCoroutine.
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 Sat Jun 10 22:17:38 2006
@@ -19,4 +19,5 @@
'frame_new' : 'maker.frame_new',
'traceback_new' : 'maker.traceback_new',
'generator_new' : 'maker.generator_new',
+ 'return_main' : 'maker.return_main',
}
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 10 22:17:38 2006
@@ -86,6 +86,11 @@
return space.wrap(new_generator)
generator_new.unwrap_spec = [ObjSpace, Arguments]
+def return_main(space):
+ from pypy.module.stackless.coroutine import AppCoroutine
+ return AppCoroutine._get_state(space).main
+return_main.unwrap_spec = [ObjSpace]
+
# ___________________________________________________________________
# Helper functions for internal use
Modified: pypy/dist/pypy/module/stackless/coroutine.py
==============================================================================
--- pypy/dist/pypy/module/stackless/coroutine.py (original)
+++ pypy/dist/pypy/module/stackless/coroutine.py Sat Jun 10 22:17:38 2006
@@ -56,6 +56,7 @@
state = self._get_state(space)
Coroutine.__init__(self, state)
self.flags = 0
+ self.framestack = None
if not is_main:
space.getexecutioncontext().subcontext_new(self)
@@ -121,11 +122,16 @@
from pypy.interpreter.mixedmodule import MixedModule
w_mod = space.getbuiltinmodule('stackless')
mod = space.interp_w(MixedModule, w_mod)
+ w_mod2 = space.getbuiltinmodule('_pickle_support')
+ mod2 = space.interp_w(MixedModule, w_mod2)
new_inst = mod.get('coroutine')
w = space.wrap
nt = space.newtuple
ec = self.space.getexecutioncontext()
+ if self is self._get_state(space).main:
+ return space.newtuple([mod2.get('return_main'), space.newtuple([])])
+
tup_base = [
]
tup_state = [
@@ -142,7 +148,7 @@
ec = self.space.getexecutioncontext()
ec.subcontext_setstate(self, w_state)
self.reconstruct_framechain()
-
+
def reconstruct_framechain(self):
from pypy.interpreter.pyframe import PyFrame
from pypy.rpython.rstack import resume_state_create
@@ -201,6 +207,14 @@
return space.wrap(self.get_is_zombie())
AppCoroutine.w_get_is_zombie = w_get_is_zombie
+def w_descr__framestack(space, self):
+ assert isinstance(self, AppCoroutine)
+ if self.framestack:
+ items = [space.wrap(item) for item in self.framestack.items]
+ return space.newtuple(items)
+ else:
+ return space.newtuple([])
+
def makeStaticMethod(module, classname, funcname):
space = module.space
space.appexec(map(space.wrap, (module, classname, funcname)), """
@@ -226,6 +240,7 @@
switch = interp2app(AppCoroutine.w_switch),
kill = interp2app(AppCoroutine.w_kill),
is_zombie = GetSetProperty(AppCoroutine.w_get_is_zombie, doc=AppCoroutine.get_is_zombie.__doc__),
+ _framestack = GetSetProperty(w_descr__framestack),
getcurrent = interp2app(AppCoroutine.w_getcurrent),
__reduce__ = interp2app(AppCoroutine.descr__reduce__,
unwrap_spec=['self', ObjSpace]),
More information about the Pypy-commit
mailing list