[pypy-svn] r32401 - in pypy/dist/pypy/objspace/cpy: . test
arigo at codespeak.net
arigo at codespeak.net
Sun Sep 17 11:27:36 CEST 2006
Author: arigo
Date: Sun Sep 17 11:27:32 2006
New Revision: 32401
Modified:
pypy/dist/pypy/objspace/cpy/function.py
pypy/dist/pypy/objspace/cpy/test/test_function.py
Log:
Support for default arguments in the cpy objspace.
Modified: pypy/dist/pypy/objspace/cpy/function.py
==============================================================================
--- pypy/dist/pypy/objspace/cpy/function.py (original)
+++ pypy/dist/pypy/objspace/cpy/function.py Sun Sep 17 11:27:32 2006
@@ -146,6 +146,9 @@
trampoline.star_arg = tramp.star_arg
trampoline.allow_someobjects = True # annotator hint
trampoline._annspecialcase_ = "specialize:all_someobjects"
+ if func.defs_w:
+ trampoline.func_defaults = tuple([space.unwrap(w_x)
+ for w_x in func.defs_w])
w_result = W_Object(trampoline)
space.wrap_cache[id(w_result)] = w_result, func, follow_annotations
return w_result
Modified: pypy/dist/pypy/objspace/cpy/test/test_function.py
==============================================================================
--- pypy/dist/pypy/objspace/cpy/test/test_function.py (original)
+++ pypy/dist/pypy/objspace/cpy/test/test_function.py Sun Sep 17 11:27:32 2006
@@ -23,6 +23,10 @@
return space.wrap(result)
entrypoint3.unwrap_spec = [ObjSpace, W_Root, 'args_w']
+def entrypoint4(space, x=21):
+ return space.wrap(x*2)
+entrypoint4.unwrap_spec = [ObjSpace, int]
+
def test_builtin_function():
space = CPyObjSpace()
@@ -99,3 +103,15 @@
res = fn()
assert res == -400
+
+def test_default_arg():
+ space = CPyObjSpace()
+ func = interp2app(entrypoint4).__spacebind__(space)
+ bltin = BuiltinFunction(func)
+ w_entrypoint = space.wrap(bltin)
+ w_result = space.call_function(w_entrypoint)
+ result = space.int_w(w_result)
+ assert result == 42
+ w_result = space.call_function(w_entrypoint, space.wrap(10))
+ result = space.int_w(w_result)
+ assert result == 20
More information about the Pypy-commit
mailing list