Author: Armin Rigo <ar...@tunes.org> Branch: cpyext-bootstrap Changeset: r81974:a11965258086 Date: 2016-01-27 17:39 +0100 http://bitbucket.org/pypy/pypy/changeset/a11965258086/
Log: Some translation fixes diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py --- a/pypy/module/cpyext/api.py +++ b/pypy/module/cpyext/api.py @@ -506,7 +506,9 @@ def get_structtype_for_ctype(ctype): from pypy.module.cpyext.typeobjectdefs import PyTypeObjectPtr from pypy.module.cpyext.cdatetime import PyDateTime_CAPI + from pypy.module.cpyext.intobject import PyIntObject return {"PyObject*": PyObject, "PyTypeObject*": PyTypeObjectPtr, + "PyIntObject*": PyIntObject, "PyDateTime_CAPI*": lltype.Ptr(PyDateTime_CAPI)}[ctype] PyTypeObject = lltype.ForwardReference() @@ -1088,7 +1090,7 @@ def setup_library(space): "NOT_RPYTHON" - from pypy.module.cpyext.pyobject import get_typedescr, make_ref + from pypy.module.cpyext.pyobject import make_ref export_symbols = list(FUNCTIONS) + SYMBOLS_C + list(GLOBALS) from rpython.translator.c.database import LowLevelDatabase @@ -1108,25 +1110,22 @@ from pypy.module import cpyext # for eval() below - # Set up the types. This version of the code really allocates - # them: this is different from build_bridge(), where they are set - # up at the static address from the bridge library. This needs - # special logic to solve the cycles issue; otherwise, we could - # simply leave everything to make_ref() in the "populate static - # data" loop below. + # Set up the types. Needs a special case, because of the + # immediate cycle involving 'c_ob_type', and because we don't + # want these types to be Py_TPFLAGS_HEAPTYPE. + static_types = {} + for name, (typ, expr) in GLOBALS.items(): + if typ == 'PyTypeObject*': + pto = lltype.malloc(PyTypeObject, immortal=True, + zero=True, flavor='raw') + pto.c_ob_refcnt = 1 + pto.c_tp_basicsize = -1 + static_types[name] = pto builder = StaticObjectBuilder(space) - for name, (typ, expr) in GLOBALS.iteritems(): - if typ == 'PyTypeObject*': - w_type = eval(expr) - w_typetype = space.type(w_type) - if not space.is_w(w_typetype, space.w_type): - continue # skip types with a custom metaclass - typedescr = get_typedescr(w_typetype.instancetypedef) - py_obj = typedescr.allocate(space, None) - builder.prepare(py_obj, w_type) - py_typetype = rffi.cast(PyTypeObjectPtr, make_ref(space, space.w_type)) - for py_obj, w_type in builder.to_attach: - py_obj.c_ob_type = py_typetype + for name, pto in static_types.items(): + pto.c_ob_type = static_types['PyType_Type#'] + w_type = eval(GLOBALS[name][1]) + builder.prepare(rffi.cast(PyObject, pto), w_type) builder.attach_all() # populate static data 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 @@ -146,7 +146,7 @@ assert len(slot_names) == 2 struct = getattr(pto, slot_names[0]) if not struct: - assert not space.config.translating + #assert not space.config.translating assert not pto.c_tp_flags & Py_TPFLAGS_HEAPTYPE if slot_names[0] == 'c_tp_as_number': STRUCT_TYPE = PyNumberMethods @@ -427,6 +427,8 @@ pto.c_tp_as_sequence = heaptype.c_as_sequence pto.c_tp_as_mapping = heaptype.c_as_mapping pto.c_tp_as_buffer = heaptype.c_as_buffer + pto.c_tp_basicsize = -1 # hopefully this makes malloc bail out + pto.c_tp_itemsize = 0 return rffi.cast(PyObject, heaptype) @@ -462,8 +464,6 @@ pto.c_tp_name = PyString_AsString(space, heaptype.c_ht_name) else: pto.c_tp_name = rffi.str2charp(w_type.name) - pto.c_tp_basicsize = -1 # hopefully this makes malloc bail out - pto.c_tp_itemsize = 0 # uninitialized fields: # c_tp_print, c_tp_getattr, c_tp_setattr # XXX implement _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit