[pypy-svn] r79664 - in pypy/trunk/pypy: interpreter module/__pypy__ module/__pypy__/test
arigo at codespeak.net
arigo at codespeak.net
Tue Nov 30 13:01:34 CET 2010
Author: arigo
Date: Tue Nov 30 13:01:29 2010
New Revision: 79664
Modified:
pypy/trunk/pypy/interpreter/function.py
pypy/trunk/pypy/module/__pypy__/__init__.py
pypy/trunk/pypy/module/__pypy__/interp_magic.py
pypy/trunk/pypy/module/__pypy__/test/test_special.py
Log:
Remove the app-level constructor 'builtin_function_type(f)',
and replace it with a custom helper in the __pypy__ module.
Modified: pypy/trunk/pypy/interpreter/function.py
==============================================================================
--- pypy/trunk/pypy/interpreter/function.py (original)
+++ pypy/trunk/pypy/interpreter/function.py Tue Nov 30 13:01:29 2010
@@ -612,11 +612,9 @@
self.w_func_dict = func.w_func_dict
self.w_module = func.w_module
- def descr_builtinfunction__new__(space, w_subtype, w_func):
- func = space.interp_w(Function, w_func)
- bltin = space.allocate_instance(BuiltinFunction, w_subtype)
- BuiltinFunction.__init__(bltin, func)
- return space.wrap(bltin)
+ def descr_builtinfunction__new__(space, w_subtype):
+ raise OperationError(space.w_TypeError,
+ space.wrap("cannot create 'builtin_function' instances"))
def descr_function_repr(self):
return self.space.wrap('<built-in function %s>' % (self.name,))
Modified: pypy/trunk/pypy/module/__pypy__/__init__.py
==============================================================================
--- pypy/trunk/pypy/module/__pypy__/__init__.py (original)
+++ pypy/trunk/pypy/module/__pypy__/__init__.py Tue Nov 30 13:01:29 2010
@@ -15,6 +15,7 @@
'debug_print' : 'interp_debug.debug_print',
'debug_stop' : 'interp_debug.debug_stop',
'debug_print_once' : 'interp_debug.debug_print_once',
+ 'builtinify' : 'interp_magic.builtinify',
}
def setup_after_space_initialization(self):
Modified: pypy/trunk/pypy/module/__pypy__/interp_magic.py
==============================================================================
--- pypy/trunk/pypy/module/__pypy__/interp_magic.py (original)
+++ pypy/trunk/pypy/module/__pypy__/interp_magic.py Tue Nov 30 13:01:29 2010
@@ -51,3 +51,9 @@
return space.newtuple([space.newint(cache.hits.get(name, 0)),
space.newint(cache.misses.get(name, 0))])
mapdict_cache_counter.unwrap_spec = [ObjSpace, str]
+
+def builtinify(space, w_func):
+ from pypy.interpreter.function import Function, BuiltinFunction
+ func = space.interp_w(Function, w_func)
+ bltn = BuiltinFunction(func)
+ return space.wrap(bltn)
Modified: pypy/trunk/pypy/module/__pypy__/test/test_special.py
==============================================================================
--- pypy/trunk/pypy/module/__pypy__/test/test_special.py (original)
+++ pypy/trunk/pypy/module/__pypy__/test/test_special.py Tue Nov 30 13:01:29 2010
@@ -21,3 +21,18 @@
def test_cpumodel(self):
import __pypy__
assert hasattr(__pypy__, 'cpumodel')
+
+ def test_builtinify(self):
+ import __pypy__
+ class A(object):
+ a = lambda *args: args
+ b = __pypy__.builtinify(a)
+ my = A()
+ assert my.a() == (my,)
+ assert my.b() == ()
+ assert A.a(my) == (my,)
+ assert A.b(my) == (my,)
+ assert A.a.im_func(my) == (my,)
+ assert not hasattr(A.b, 'im_func')
+ assert A.a is not A.__dict__['a']
+ assert A.b is A.__dict__['b']
More information about the Pypy-commit
mailing list