Author: fijal Branch: cpyext-injection Changeset: r87936:2bbc5adbc7a4 Date: 2016-10-26 15:35 +0200 http://bitbucket.org/pypy/pypy/changeset/2bbc5adbc7a4/
Log: try to rpythonize the whole mess diff --git a/pypy/interpreter/typedef.py b/pypy/interpreter/typedef.py --- a/pypy/interpreter/typedef.py +++ b/pypy/interpreter/typedef.py @@ -7,19 +7,24 @@ WrappedDefault) from rpython.rlib.jit import promote -from rpython.rlib.objectmodel import compute_identity_hash, specialize +from rpython.rlib.objectmodel import compute_identity_hash, specialize,\ + we_are_translated from rpython.tool.sourcetools import compile2, func_with_new_name +class TypeContainer(object): + _immutable_fields_ = ['w_value?'] + + def __init__(self): + self.w_value = None class TypeDef(object): - _immutable_fields_ = ["w_type_injected?"] def __init__(self, __name, __base=None, __total_ordering__=None, __buffer=None, **rawdict): "NOT_RPYTHON: initialization-time only" self.name = __name self.injected_type = False - self.w_type_injected = None + self.type_injected_container = None if __base is None: bases = [] elif isinstance(__base, tuple): @@ -54,6 +59,16 @@ value.name = key self.rawdict.update(rawdict) + def set_injected_type(self, w_type): + if self.type_injected_container is None and not we_are_translated(): + self.type_injected_container = TypeContainer() + self.type_injected_container.w_value = w_type + + def get_injected_type(self): + if self.type_injected_container is None: + return None + return self.type_injected_container.w_value + def auto_total_ordering(self): assert '__lt__' in self.rawdict, "__total_ordering='auto' requires __lt__" assert '__eq__' in self.rawdict, "__total_ordering='auto' requires __eq__" @@ -64,6 +79,8 @@ def _freeze_(self): # hint for the annotator: track individual constant instances of TypeDef + if self.injected_type: + self.type_injected_container = TypeContainer() return True def __repr__(self): diff --git a/pypy/module/cpyext/typeobject.py b/pypy/module/cpyext/typeobject.py --- a/pypy/module/cpyext/typeobject.py +++ b/pypy/module/cpyext/typeobject.py @@ -467,7 +467,7 @@ newtypedef = inject_operators(space, name, dict_w, pto) if newtypedef is not None: assert newtypedef.injected_type - newtypedef.w_type_injected = self + newtypedef.set_injected_type(self) new_layout = (pto.c_tp_basicsize > rffi.sizeof(PyObject.TO) or pto.c_tp_itemsize > 0 or newtypedef is not None) diff --git a/pypy/objspace/std/objspace.py b/pypy/objspace/std/objspace.py --- a/pypy/objspace/std/objspace.py +++ b/pypy/objspace/std/objspace.py @@ -127,9 +127,10 @@ # unique-for-this-space W_TypeObject instance assert typedef is not None if typedef.injected_type: - assert typedef.w_type_injected is not None - assert typedef.w_type_injected.space is self - return typedef.w_type_injected + w_type_injected = typedef.get_injected_type() + assert w_type_injected is not None + assert w_type_injected.space is self + return w_type_injected return self.fromcache(TypeCache).getorbuild(typedef) @specialize.argtype(1) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit