[pypy-svn] r22781 - in pypy/dist/pypy/module/stackless: . test

tismer at codespeak.net tismer at codespeak.net
Sat Jan 28 13:48:51 CET 2006


Author: tismer
Date: Sat Jan 28 13:48:48 2006
New Revision: 22781

Modified:
   pypy/dist/pypy/module/stackless/interp_coroutine.py
   pypy/dist/pypy/module/stackless/test/test_interp_coroutine.py
Log:
minimalistic support for coroutine return vales. This is intentionally still a bit less than greenlets

Modified: pypy/dist/pypy/module/stackless/interp_coroutine.py
==============================================================================
--- pypy/dist/pypy/module/stackless/interp_coroutine.py	(original)
+++ pypy/dist/pypy/module/stackless/interp_coroutine.py	Sat Jan 28 13:48:48 2006
@@ -39,17 +39,19 @@
             self.parent = self
         else:
             self.parent = costate.main
+        self.thunk = None
 
     def bind(self, thunk):
         if self.frame is not None:
             raise CoroutineDamage
-        self.frame = self._bind(thunk)
+        self.thunk = thunk
+        self.frame = self._bind()
 
-    def _bind(self, thunk):
+    def _bind(self):
         self.parent = costate.current
         costate.last.frame = yield_current_frame_to_caller()
         try:
-            thunk.call()
+            self.thunk.call()
         except CoroutineExit:
             # ignore a shutdown exception
             pass
@@ -57,6 +59,7 @@
             # redirect all unhandled exceptions to the parent
             costate.things_to_do = True
             costate.temp_exc = e
+        self.thunk = None
         while self.parent.frame is None:
             # greenlet behavior is fine
             self.parent = self.parent.parent
@@ -173,7 +176,7 @@
         self.args = args
 
     def call(self):
-        self.space.call_args(self.w_func, self.args)
+        appcostate.tempval = self.space.call_args(self.w_func, self.args)
 
 
 class AppCoroutine(Coroutine): # XXX, StacklessFlags):
@@ -203,6 +206,8 @@
                 "cannot switch to an unbound Coroutine"))
         self.switch()
         appcostate.current = self
+        ret, appcostate.tempval = appcostate.tempval, space.w_None
+        return ret
 
     def w_kill(self):
         if appcostate.current is self:

Modified: pypy/dist/pypy/module/stackless/test/test_interp_coroutine.py
==============================================================================
--- pypy/dist/pypy/module/stackless/test/test_interp_coroutine.py	(original)
+++ pypy/dist/pypy/module/stackless/test/test_interp_coroutine.py	Sat Jan 28 13:48:48 2006
@@ -168,7 +168,7 @@
     data = wrap_stackless_function(f)
     assert int(data.strip()) == 12345678
 
-def test_kill_raise_coro():
+def test_kill_raise_del_coro():
     class T:
         def __init__(self, func, arg):
             self.func = func



More information about the Pypy-commit mailing list