Commits

Armin Rigo committed d637e2d Draft

test_callback_with_arguments.

  • Participants
  • Parent commits 9f78054
  • Branches stacklet

Comments (0)

Files changed (2)

File pypy/module/_continuation/interp_continuation.py

         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
 
 
 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)
     #
     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

File pypy/module/_continuation/test/test_stacklet.py

         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