[pypy-svn] r28615 - in pypy/dist/pypy/module/stackless: . test
arigo at codespeak.net
arigo at codespeak.net
Sat Jun 10 15:08:02 CEST 2006
Author: arigo
Date: Sat Jun 10 15:07:59 2006
New Revision: 28615
Modified:
pypy/dist/pypy/module/stackless/interp_coroutine.py
pypy/dist/pypy/module/stackless/test/test_interp_coroutine.py
Log:
Long test and one-liner fix for coroutines and app-coroutines,
broken in pypy-c.
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 Jun 10 15:07:59 2006
@@ -236,7 +236,7 @@
left = state.last
left.frame = incoming_frame
left.goodbye()
- self.hello()
+ state.current.hello()
main_costate_getter._get_default_costate().do_things_to_do()
def kill(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 Jun 10 15:07:59 2006
@@ -278,6 +278,43 @@
output = self.wrap_stackless_function(ep)
assert output == int('0110')
+ def test_hello_goodbye(self):
+
+ class C(Coroutine):
+ n = 2
+ def __init__(self, n):
+ Coroutine.__init__(self)
+ self.n = n
+ def hello(self):
+ costate.hello_goodbye *= 10
+ costate.hello_goodbye += self.n
+ def goodbye(self):
+ costate.hello_goodbye *= 10
+ costate.hello_goodbye += self.n + 1
+
+ class T(AbstractThunk):
+ def call(self):
+ pass
+
+ costate = main_costate_getter._get_default_costate()
+ costate.current.__class__ = C
+ costate.hello_goodbye = 0
+
+ def ep():
+ costate.hello_goodbye = 0
+ c1 = C(4)
+ c1.bind(T())
+ c1.switch()
+ return costate.hello_goodbye
+
+ output = self.wrap_stackless_function(ep)
+ # expected result:
+ # goodbye main 3
+ # hello c1 4
+ # goodbye c1 5
+ # hello main 2
+ assert output == 3452
+
TestCoroutine = _TestCoroutine # to activate
class TestCoroutineOnCPython(_TestCoroutine):
def wrap_stackless_function(self, func):
More information about the Pypy-commit
mailing list