[pypy-svn] r30841 - in pypy/dist/pypy/interpreter: . test

arigo at codespeak.net arigo at codespeak.net
Tue Aug 1 13:56:00 CEST 2006


Author: arigo
Date: Tue Aug  1 13:55:59 2006
New Revision: 30841

Modified:
   pypy/dist/pypy/interpreter/argument.py
   pypy/dist/pypy/interpreter/gateway.py
   pypy/dist/pypy/interpreter/test/test_gateway.py
Log:
To allow *args, **kwargs in app2interp-ed functions, the interp-level
gateway hook function must accept a general Arguments object as its last
argument.  (This will be necessary for dict.update(), but so far it's
not used, so I can only say that it *should* annotate properly.)



Modified: pypy/dist/pypy/interpreter/argument.py
==============================================================================
--- pypy/dist/pypy/interpreter/argument.py	(original)
+++ pypy/dist/pypy/interpreter/argument.py	Tue Aug  1 13:55:59 2006
@@ -3,7 +3,6 @@
 """
 
 from pypy.interpreter.error import OperationError
-import os
 
 class AbstractArguments:
 

Modified: pypy/dist/pypy/interpreter/gateway.py
==============================================================================
--- pypy/dist/pypy/interpreter/gateway.py	(original)
+++ pypy/dist/pypy/interpreter/gateway.py	Tue Aug  1 13:55:59 2006
@@ -17,7 +17,7 @@
 from pypy.interpreter.function import Function, Method
 from pypy.interpreter.baseobjspace import W_Root, ObjSpace, Wrappable
 from pypy.interpreter.baseobjspace import Wrappable, SpaceCache
-from pypy.interpreter.argument import Arguments
+from pypy.interpreter.argument import Arguments, AbstractArguments
 from pypy.tool.sourcetools import NiceCompile, compile2
 
 # internal non-translatable parts: 
@@ -788,7 +788,16 @@
                     ret_w = sc[ApplevelClass](space, self, name, args_w)
                     if ret_w is not None: # it was RPython
                         return ret_w
-            args = Arguments(space, list(args_w))
+            # the last argument can be an Arguments
+            if args_w and isinstance(args_w[-1], AbstractArguments):
+                # ...which is merged with the previous arguments, if any
+                args = args_w[-1]
+                if len(args_w) > 1:
+                    more_args_w, more_kwds_w = args.unpack()
+                    args = Arguments(space, list(args_w[:-1]) + more_args_w,
+                                            more_kwds_w)
+            else:
+                args = Arguments(space, list(args_w))
             w_func = self.wget(space, name) 
             return space.call_args(w_func, args)
         def get_function(space):

Modified: pypy/dist/pypy/interpreter/test/test_gateway.py
==============================================================================
--- pypy/dist/pypy/interpreter/test/test_gateway.py	(original)
+++ pypy/dist/pypy/interpreter/test/test_gateway.py	Tue Aug  1 13:55:59 2006
@@ -91,7 +91,20 @@
             return a+b
         g3 = gateway.app2interp_temp(noapp_g3, gateway.applevelinterp_temp)
         assert self.space.eq_w(g3(self.space, w('foo'), w('bar')), w('foobar'))
-        
+
+    def test_app2interp_general_args(self):
+        w = self.space.wrap
+        def app_general(x, *args, **kwds):
+            assert type(args) is tuple
+            assert type(kwds) is dict
+            return x + 10 * len(args) + 100 * len(kwds)
+        gg = gateway.app2interp_temp(app_general)
+        args = gateway.Arguments(self.space, [w(6), w(7)])
+        assert self.space.int_w(gg(self.space, w(3), args)) == 23
+        args = gateway.Arguments(self.space, [w(6)], {'hello': w(7),
+                                                      'world': w(8)})
+        assert self.space.int_w(gg(self.space, w(3), args)) == 213
+
     def test_interp2app(self):
         space = self.space
         w = space.wrap



More information about the Pypy-commit mailing list