[pypy-svn] r50944 - in pypy/dist/pypy/objspace: . test
cfbolz at codespeak.net
cfbolz at codespeak.net
Wed Jan 23 19:45:59 CET 2008
Author: cfbolz
Date: Wed Jan 23 19:45:58 2008
New Revision: 50944
Modified:
pypy/dist/pypy/objspace/reflective.py
pypy/dist/pypy/objspace/test/test_reflective.py
Log:
hook into the type unwrapped methods (<typename>_w).
Modified: pypy/dist/pypy/objspace/reflective.py
==============================================================================
--- pypy/dist/pypy/objspace/reflective.py (original)
+++ pypy/dist/pypy/objspace/reflective.py Wed Jan 23 19:45:58 2008
@@ -38,8 +38,8 @@
return args
def make_space_access_method(name, wrappedfn, parentfn):
- if name.startswith("new"):
- # those options cannot call back to applevel, so no need to expose them
+ if name.startswith("new") or name.endswith("_w"):
+ # those methods cannot call back to applevel, so no need to expose them
return
if name == "call_args":
def func(self, space, w_func, args):
@@ -88,12 +88,6 @@
DontWrapMe = [
'wrap',
- 'str_w',
- 'int_w',
- 'float_w',
- 'uint_w',
- 'bigint_w',
- 'unicode_w',
'interpclass_w',
'unwrap',
'is_true',
@@ -105,7 +99,7 @@
def proxymaker(space, opname, parentfn):
if opname in DontWrapMe:
return None
- want_spaceaccess = not opname.startswith("new")
+ want_spaceaccess = True # changed below
def user_hook(*args_w):
w_rspace = get_reflective_space(space)
if w_rspace is not None:
@@ -133,6 +127,7 @@
if w_newobj is not None:
return w_newobj
return w_obj
+ want_spaceaccess = False
elif opname.startswith("new"):
def fn(*args):
w_obj = parentfn(*args)
@@ -140,6 +135,14 @@
if w_newobj is not None:
return w_newobj
return w_obj
+ want_spaceaccess = False
+ elif opname.endswith("_w"):
+ def fn(w_obj):
+ w_newobj = user_hook(w_obj)
+ if w_newobj is not None:
+ w_obj = w_newobj
+ return parentfn(w_obj)
+ want_spaceaccess = False
elif opname == "call_args":
def fn(w_callable, args):
w_rspace = get_reflective_space(space)
Modified: pypy/dist/pypy/objspace/test/test_reflective.py
==============================================================================
--- pypy/dist/pypy/objspace/test/test_reflective.py (original)
+++ pypy/dist/pypy/objspace/test/test_reflective.py Wed Jan 23 19:45:58 2008
@@ -101,6 +101,17 @@
set_reflectivespace(Space())
assert a.f() == 2
+ def test_typed_unwrap(self):
+ from __pypy__ import set_reflectivespace
+ class Space:
+ def int_w(self, i):
+ if isinstance(i, basestring):
+ return int(i)
+ return i
+ set_reflectivespace(Space())
+ assert chr("123") == chr(123)
+
+
def test_autocurry(self):
# rather simplified for now
from __pypy__ import set_reflectivespace
More information about the Pypy-commit
mailing list