[pypy-commit] pypy stacklet: test_callback_with_arguments.

arigo noreply at buildbot.pypy.org
Wed Aug 17 21:52:04 CEST 2011


Author: Armin Rigo <arigo at tunes.org>
Branch: stacklet
Changeset: r46569:d637e2d314c5
Date: 2011-08-17 17:54 +0200
http://bitbucket.org/pypy/pypy/changeset/d637e2d314c5/

Log:	test_callback_with_arguments.

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
@@ -33,12 +33,13 @@
         if ec.stacklet_thread is not self.sthread:
             raise geterror(self.space, "inter-thread support is missing")
 
-    def descr_init(self, w_callable):
+    def descr_init(self, w_callable, __args__):
         if self.h:
             raise geterror(self.space, "continuation already __init__ialized")
         sthread = self.build_sthread()
         start_state.origin = self
         start_state.w_callable = w_callable
+        start_state.args = __args__
         try:
             self.h = sthread.new(new_stacklet_callback)
             if sthread.is_empty_handle(self.h):    # early return
@@ -134,8 +135,9 @@
 
 
 def new_stacklet_callback(h, arg):
-    self = start_state.origin
+    self       = start_state.origin
     w_callable = start_state.w_callable
+    args       = start_state.args
     start_state.clear()
     try:
         self.h = self.sthread.switch(h)
@@ -144,7 +146,8 @@
     #
     space = self.space
     try:
-        w_result = space.call_function(w_callable, space.wrap(self))
+        args = args.prepend(space.wrap(self))
+        w_result = space.call_args(w_callable, args)
     except Exception, e:
         start_state.propagate_exception = e
         return 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
@@ -68,22 +68,19 @@
         assert seen == [42]
 
     def test_callback_with_arguments(self):
-        from _continuation import new
+        from _continuation import continuation
         #
-        def empty_callback(h, *args, **kwds):
-            assert h.is_pending()
-            seen.append(h)
+        def empty_callback(c1, *args, **kwds):
+            seen.append(c1)
             seen.append(args)
             seen.append(kwds)
-            return h
+            return 42
         #
         seen = []
-        h = new(empty_callback, 42, 43, foo=44, bar=45)
-        assert h is None
-        assert len(seen) == 3
-        assert not seen[0].is_pending()
-        assert seen[1] == (42, 43)
-        assert seen[2] == {'foo': 44, 'bar': 45}
+        c = continuation(empty_callback, 42, 43, foo=44, bar=45)
+        res = c.switch()
+        assert res == 42
+        assert seen == [c, (42, 43), {'foo': 44, 'bar': 45}]
 
     def test_type_of_h(self):
         from _continuation import new, Continuation


More information about the pypy-commit mailing list