[pypy-svn] r72939 - in pypy/branch/cpython-extension/pypy: module/cpyext objspace/std translator/goal
xoraxax at codespeak.net
xoraxax at codespeak.net
Sat Mar 27 03:15:43 CET 2010
Author: xoraxax
Date: Sat Mar 27 03:15:41 2010
New Revision: 72939
Modified:
pypy/branch/cpython-extension/pypy/module/cpyext/typeobject.py
pypy/branch/cpython-extension/pypy/objspace/std/typeobject.py
pypy/branch/cpython-extension/pypy/translator/goal/ann_override.py
Log:
Use an own flag for us. This is important because we proxy non-heap types in fact but we do not want the optimization of the lookup caches.
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 Sat Mar 27 03:15:41 2010
@@ -6,7 +6,7 @@
from pypy.interpreter.gateway import ObjSpace, W_Root
from pypy.interpreter.gateway import interp2app, unwrap_spec
from pypy.interpreter.baseobjspace import Wrappable
-from pypy.objspace.std.typeobject import W_TypeObject, _HEAPTYPE
+from pypy.objspace.std.typeobject import W_TypeObject, _CPYTYPE
from pypy.objspace.std.objectobject import W_ObjectObject
from pypy.interpreter.typedef import TypeDef, GetSetProperty
from pypy.module.cpyext.api import cpython_api, cpython_api_c, cpython_struct, \
@@ -203,26 +203,20 @@
convert_method_defs(space, dict_w, pto.c_tp_methods, pto)
convert_getset_defs(space, dict_w, pto.c_tp_getset, pto)
# XXX missing: convert_member_defs
- W_TypeObject.__init__(self, space, rffi.charp2str(pto.c_tp_name),
+ full_name = rffi.charp2str(pto.c_tp_name)
+ module_name, extension_name = full_name.split(".", 1)
+ dict_w["__module__"] = space.wrap(module_name)
+ W_TypeObject.__init__(self, space, extension_name,
bases_w or [space.w_object], dict_w)
- self.__flags__ = _HEAPTYPE
+ self.__flags__ = _CPYTYPE
class W_PyCObject(Wrappable):
def __init__(self, space):
self.space = space
-# def __del__(self):
-# space = self.space
-# self.clear_all_weakrefs()
-# w_type = space.type(self)
-# assert isinstance(w_type, W_PyCTypeObject)
-# pto = w_type.pto
-# generic_cpy_call(space, pto.c_tp_dealloc, self)
-
@cpython_api([PyObject], lltype.Void, external=False)
def subtype_dealloc(space, obj):
- print >>sys.stderr, "Dealloc of", obj
pto = rffi.cast(PyTypeObjectPtr, obj.c_obj_type)
assert pto.c_tp_flags & Py_TPFLAGS_HEAPTYPE
base = pto
Modified: pypy/branch/cpython-extension/pypy/objspace/std/typeobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/typeobject.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/typeobject.py Sat Mar 27 03:15:41 2010
@@ -13,6 +13,7 @@
from pypy.rlib.rarithmetic import intmask, r_uint
from copy_reg import _HEAPTYPE
+_CPYTYPE = 1 # used for non-heap types defined in C
# from compiler/misc.py
@@ -82,7 +83,7 @@
w_self.needsdel = False
w_self.weakrefable = False
w_self.weak_subclasses = []
- w_self.__flags__ = 0 # or _HEAPTYPE
+ w_self.__flags__ = 0 # or _HEAPTYPE or _CPYTYPE
w_self.instancetypedef = overridetypedef
if overridetypedef is not None:
@@ -334,6 +335,9 @@
def is_heaptype(w_self):
return w_self.__flags__&_HEAPTYPE
+ def is_cpytype(w_self):
+ return w_self.__flags__ & _CPYTYPE
+
def get_module(w_self):
space = w_self.space
if w_self.is_heaptype() and '__module__' in w_self.dict_w:
Modified: pypy/branch/cpython-extension/pypy/translator/goal/ann_override.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/translator/goal/ann_override.py (original)
+++ pypy/branch/cpython-extension/pypy/translator/goal/ann_override.py Sat Mar 27 03:15:41 2010
@@ -81,7 +81,7 @@
def attach_lookup(pol, t, attr):
cached = "cached_%s" % attr
- if not t.is_heaptype():
+ if not t.is_heaptype() and not t.is_cpytype():
pol._remember_immutable(t, cached)
setattr(t, cached, t._lookup(attr))
return True
@@ -89,7 +89,7 @@
def attach_lookup_in_type_where(pol, t, attr):
cached = "cached_where_%s" % attr
- if not t.is_heaptype():
+ if not t.is_heaptype() and not t.is_cpytype():
pol._remember_immutable(t, cached)
setattr(t, cached, t._lookup_where(attr))
return True
@@ -177,14 +177,14 @@
CACHED_LOOKUP = """
def lookup_%(attr)s(space, w_obj, name):
w_type = space.type(w_obj)
- if not w_type.is_heaptype():
+ if not w_type.is_heaptype() and not w_type.is_cpytype():
return w_type.cached_%(attr)s
return w_type.lookup("%(attr)s")
"""
CACHED_LOOKUP_IN_TYPE_WHERE = """
def lookup_in_type_where_%(attr)s(space, w_type, name):
- if not w_type.is_heaptype():
+ if not w_type.is_heaptype() and not w_type.is_cpytype():
return w_type.cached_where_%(attr)s
return w_type.lookup_where("%(attr)s")
"""
More information about the Pypy-commit
mailing list