[pypy-svn] r29035 - in pypy/dist/pypy/interpreter: . test
pedronis at codespeak.net
pedronis at codespeak.net
Wed Jun 21 00:48:58 CEST 2006
Author: pedronis
Date: Wed Jun 21 00:48:57 2006
New Revision: 29035
Modified:
pypy/dist/pypy/interpreter/baseobjspace.py
pypy/dist/pypy/interpreter/test/test_function.py
Log:
fix some potential segfaults and methods moved up to W_Root. this is a pessimisation but the old code could crash,
see tests. It would be interesting to see the perf difference of using more methods vs isintance here.
Modified: pypy/dist/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/dist/pypy/interpreter/baseobjspace.py (original)
+++ pypy/dist/pypy/interpreter/baseobjspace.py Wed Jun 21 00:48:57 2006
@@ -548,7 +548,8 @@
w_inst = w_func.w_instance
if w_inst is not None:
func = w_func.w_function
- return func.funccall(w_inst, *args_w)
+ if isinstance(func, Function):
+ return func.funccall(w_inst, *args_w)
else:
w_func = w_func.w_function
@@ -566,7 +567,9 @@
w_inst = w_func.w_instance
if w_inst is not None:
func = w_func.w_function
- return func.funccall_obj_valuestack(w_inst, nargs, valuestack)
+ if isinstance(func, Function):
+ return func.funccall_obj_valuestack(w_inst,
+ nargs, valuestack)
else:
w_func = w_func.w_function
Modified: pypy/dist/pypy/interpreter/test/test_function.py
==============================================================================
--- pypy/dist/pypy/interpreter/test/test_function.py (original)
+++ pypy/dist/pypy/interpreter/test/test_function.py Wed Jun 21 00:48:57 2006
@@ -238,6 +238,23 @@
pass
c = C(type='test')
+ def test_method_w_callable(self):
+ class A:
+ def __call__(self, x):
+ return x
+ import new
+ im = new.instancemethod(A(), 3)
+ assert im() == 3
+
+ def test_method_w_callable_call_function(self):
+ class A:
+ def __call__(self, x, y):
+ return x+y
+ import new
+ im = new.instancemethod(A(), 3)
+ assert map(im, [4]) == [7]
+
+
class TestMethod:
def setup_method(self, method):
def c(self, bar):
More information about the Pypy-commit
mailing list