[pypy-commit] pypy stacklet: Progress.
arigo
noreply at buildbot.pypy.org
Wed Aug 17 21:52:05 CEST 2011
Author: Armin Rigo <arigo at tunes.org>
Branch: stacklet
Changeset: r46570:381c77ebf04a
Date: 2011-08-17 18:10 +0200
http://bitbucket.org/pypy/pypy/changeset/381c77ebf04a/
Log: Progress.
diff --git a/pypy/module/_continuation/interp_continuation.py b/pypy/module/_continuation/interp_continuation.py
--- a/pypy/module/_continuation/interp_continuation.py
+++ b/pypy/module/_continuation/interp_continuation.py
@@ -48,6 +48,10 @@
raise getmemoryerror(self.space)
def descr_switch(self, w_value=None):
+ if not self.h:
+ raise geterror(self.space, "continuation not initialized yet")
+ if self.sthread.is_empty_handle(self.h):
+ raise geterror(self.space, "continuation already finished")
start_state.w_value = w_value
try:
self.h = self.sthread.switch(self.h)
diff --git a/pypy/module/_continuation/test/test_stacklet.py b/pypy/module/_continuation/test/test_stacklet.py
--- a/pypy/module/_continuation/test/test_stacklet.py
+++ b/pypy/module/_continuation/test/test_stacklet.py
@@ -82,55 +82,40 @@
assert res == 42
assert seen == [c, (42, 43), {'foo': 44, 'bar': 45}]
- def test_type_of_h(self):
- from _continuation import new, Continuation
+ def test_switch(self):
+ from _continuation import continuation
#
- def empty_callback(h):
- seen.append(type(h))
- return h
+ def switchbackonce_callback(c):
+ seen.append(1)
+ res = c.switch('a')
+ assert res == 'b'
+ seen.append(3)
+ return 'c'
#
seen = []
- h = new(empty_callback)
- assert h is None
- assert seen[0] is Continuation
- # cannot directly instantiate this class
- raises(TypeError, Continuation)
- raises(TypeError, Continuation, None)
-
- def test_switch(self):
- from _continuation import new
- #
- def switchbackonce_callback(h):
- seen.append(1)
- assert h.is_pending()
- h2 = h.switch()
- seen.append(3)
- assert not h.is_pending()
- assert h2.is_pending()
- return h2
- #
- seen = []
- h = new(switchbackonce_callback)
+ c = continuation(switchbackonce_callback)
+ seen.append(0)
+ res = c.switch()
+ assert res == 'a'
seen.append(2)
- assert h.is_pending()
- h2 = h.switch()
- assert h2 is None
- assert seen == [1, 2, 3]
+ res = c.switch('b')
+ assert res == 'c'
+ assert seen == [0, 1, 2, 3]
def test_continuation_error(self):
- from _continuation import new, error
+ from _continuation import continuation, error
#
- def empty_callback(h):
- assert h.is_pending()
- seen.append(h)
- return h
+ def empty_callback(c):
+ return 42
#
- seen = []
- h = new(empty_callback)
- assert h is None
- [h] = seen
- assert not h.is_pending()
- raises(error, h.switch)
+ c = continuation(empty_callback)
+ c.switch()
+ raises(error, c.switch)
+
+ def test_not_initialized_yet(self):
+ from _continuation import continuation, error
+ c = continuation.__new__(continuation)
+ raises(error, c.switch)
def test_go_depth2(self):
from _continuation import new
More information about the pypy-commit
mailing list