[pypy-svn] r73088 - in pypy/branch/cpython-extension/pypy: interpreter module/cpyext
afa at codespeak.net
afa at codespeak.net
Mon Mar 29 17:35:24 CEST 2010
Author: afa
Date: Mon Mar 29 17:35:22 2010
New Revision: 73088
Modified:
pypy/branch/cpython-extension/pypy/interpreter/typedef.py
pypy/branch/cpython-extension/pypy/module/cpyext/typeobject.py
Log:
- GetSetProperty() is now RPython, provided that the 'fget' functions are constants.
- Fix translation of api.PyDescr_NewGetSet()
Modified: pypy/branch/cpython-extension/pypy/interpreter/typedef.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/interpreter/typedef.py (original)
+++ pypy/branch/cpython-extension/pypy/interpreter/typedef.py Mon Mar 29 17:35:22 2010
@@ -9,7 +9,7 @@
DescrMismatch
from pypy.interpreter.error import OperationError, operationerrfmt
from pypy.tool.sourcetools import compile2, func_with_new_name
-from pypy.rlib.objectmodel import instantiate, compute_identity_hash
+from pypy.rlib.objectmodel import instantiate, compute_identity_hash, specialize
from pypy.rlib.jit import hint
class TypeDef:
@@ -301,12 +301,17 @@
# ____________________________________________________________
+ at specialize.arg(1)
def make_descr_typecheck_wrapper(func, extraargs=(), cls=None, use_closure=False):
+ if func is None:
+ return None
+ return _make_descr_typecheck_wrapper(func, extraargs, cls, use_closure)
+
+ at specialize.memo()
+def _make_descr_typecheck_wrapper(func, extraargs, cls, use_closure):
# - if cls is None, the wrapped object is passed to the function
# - if cls is a class, an unwrapped instance is passed
# - if cls is a string, XXX unused?
- if func is None:
- return None
if cls is None and use_closure:
return func
if hasattr(func, 'im_func'):
@@ -361,16 +366,16 @@
raise OperationError(space.w_AttributeError,
space.wrap("generic property has no __objclass__"))
-def make_objclass_getter(func, cls, cache={}):
- if hasattr(func, 'im_func'):
+def make_objclass_getter(func, cls):
+ if func and hasattr(func, 'im_func'):
assert not cls or cls is func.im_class
cls = func.im_class
+ return _make_objclass_getter(cls)
+
+ at specialize.memo()
+def _make_objclass_getter(cls):
if not cls:
return unknown_objclass_getter, cls
- try:
- return cache[cls]
- except KeyError:
- pass
miniglobals = {}
if isinstance(cls, str):
assert cls.startswith('<'),"pythontype typecheck should begin with <"
@@ -385,13 +390,11 @@
\n""" % (typeexpr,)
exec compile2(source) in miniglobals
res = miniglobals['objclass_getter'], cls
- cache[cls] = res
return res
class GetSetProperty(Wrappable):
def __init__(self, fget, fset=None, fdel=None, doc=None,
cls=None, use_closure=False):
- "NOT_RPYTHON: initialization-time only"
objclass_getter, cls = make_objclass_getter(fget, cls)
fget = make_descr_typecheck_wrapper(fget, cls=cls,
use_closure=use_closure)
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/typeobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/typeobject.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/typeobject.py Mon Mar 29 17:35:22 2010
@@ -25,13 +25,6 @@
class W_GetSetPropertyEx(GetSetProperty):
- def getter(self, space, w_self):
- return generic_cpy_call(space, self.getset.c_get, w_self, self.getset.c_closure)
-
- def setter(self, space, w_self, w_value):
- return generic_cpy_call(space, self.getset.c_set, w_self, w_value,
- self.getset.c_closure)
-
def __init__(self, getset):
self.getset = getset
self.name = rffi.charp2str(getset.c_name)
@@ -39,10 +32,11 @@
if doc:
doc = rffi.charp2str(getset.c_doc)
if getset.c_get:
- get = self.getter.im_func
+ get = W_PyCObject.getter
if getset.c_set:
- set = self.setter.im_func
- GetSetProperty.__init__(self, get, set, None, doc, W_PyCObject, True)
+ set = W_PyCObject.setter
+ GetSetProperty.__init__(self, get, set, None, doc,
+ cls=W_PyCObject, use_closure=True)
def PyDescr_NewGetSet(space, getset, pto):
return space.wrap(W_GetSetPropertyEx(getset))
@@ -109,6 +103,15 @@
def __init__(self, space):
self.space = space
+ def getter(self, space, w_self):
+ return generic_cpy_call(
+ space, self.getset.c_get, w_self,
+ self.getset.c_closure)
+
+ def setter(self, space, w_self, w_value):
+ return generic_cpy_call(
+ space, self.getset.c_set, w_self, w_value,
+ self.getset.c_closure)
@cpython_api([PyObject], lltype.Void, external=False)
def subtype_dealloc(space, obj):
More information about the Pypy-commit
mailing list