Author: Armin Rigo <[email protected]>
Branch: cpyext-bootstrap
Changeset: r81969:3cd5ace97b49
Date: 2016-01-27 13:43 +0100
http://bitbucket.org/pypy/pypy/changeset/3cd5ace97b49/
Log: Kill kill kill the logic in init_typeobject(). It was anyway very
strange, because it would create "heap" type objects, initialize
them carefully, and then forget them happily by calling
track_reference() again (which would crash if DEBUG_REFCOUNT=True)
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
@@ -828,6 +828,9 @@
space.fromcache(State).install_dll(eci)
# populate static data
+ from pypy.module.cpyext.pyobject import track_reference, get_typedescr
+ from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
+ to_attach = []
for name, (typ, expr) in GLOBALS.iteritems():
from pypy.module import cpyext
w_obj = eval(expr)
@@ -861,18 +864,25 @@
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge,
name)
py_obj = ll2ctypes.ctypes2lltype(PyObject,
ctypes.pointer(in_dll))
- from pypy.module.cpyext.pyobject import (
- track_reference, get_typedescr)
- w_type = space.type(w_obj)
- typedescr = get_typedescr(w_type.instancetypedef)
py_obj.c_ob_refcnt = 1
- py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
- make_ref(space, w_type))
- typedescr.attach(space, py_obj, w_obj)
track_reference(space, py_obj, w_obj)
+ to_attach.append((py_obj, w_obj))
else:
assert False, "Unknown static object: %s %s" % (typ, name)
+ space._cpyext_type_init = []
+ for py_obj, w_obj in to_attach:
+ w_type = space.type(w_obj)
+ typedescr = get_typedescr(w_type.instancetypedef)
+ py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
+ make_ref(space, w_type))
+ typedescr.attach(space, py_obj, w_obj)
+ cpyext_type_init = space._cpyext_type_init
+ del space._cpyext_type_init
+ for pto, w_type in cpyext_type_init:
+ finish_type_1(space, pto)
+ finish_type_2(space, pto, w_type)
+
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
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
@@ -310,55 +310,6 @@
realize=type_realize,
dealloc=type_dealloc)
- # some types are difficult to create because of cycles.
- # - object.ob_type = type
- # - type.ob_type = type
- # - tuple.ob_type = type
- # - type.tp_base = object
- # - tuple.tp_base = object
- # - type.tp_bases is a tuple
- # - object.tp_bases is a tuple
- # - tuple.tp_bases is a tuple
-
- # insert null placeholders to please create_ref()
- track_reference(space, lltype.nullptr(PyObject.TO), space.w_type)
- track_reference(space, lltype.nullptr(PyObject.TO), space.w_object)
- track_reference(space, lltype.nullptr(PyObject.TO), space.w_tuple)
- track_reference(space, lltype.nullptr(PyObject.TO), space.w_str)
-
- # create the objects
- py_type = create_ref(space, space.w_type)
- py_object = create_ref(space, space.w_object)
- py_tuple = create_ref(space, space.w_tuple)
- py_str = create_ref(space, space.w_str)
- # XXX py_str is not initialized here correctly, because we are
- # not tracking it, it gets an empty c_ob_type from py_basestring
-
- # form cycles
- pto_type = rffi.cast(PyTypeObjectPtr, py_type)
- py_type.c_ob_type = pto_type
- py_object.c_ob_type = pto_type
- py_tuple.c_ob_type = pto_type
-
- pto_object = rffi.cast(PyTypeObjectPtr, py_object)
- pto_type.c_tp_base = pto_object
- pto_tuple = rffi.cast(PyTypeObjectPtr, py_tuple)
- pto_tuple.c_tp_base = pto_object
-
- pto_type.c_tp_bases.c_ob_type = pto_tuple
- pto_object.c_tp_bases.c_ob_type = pto_tuple
- pto_tuple.c_tp_bases.c_ob_type = pto_tuple
-
- for typ in (py_type, py_object, py_tuple, py_str):
- heaptype = rffi.cast(PyHeapTypeObject, typ)
- heaptype.c_ht_name.c_ob_type = pto_type
-
- # Restore the mapping
- track_reference(space, py_type, space.w_type, replace=True)
- track_reference(space, py_object, space.w_object, replace=True)
- track_reference(space, py_tuple, space.w_tuple, replace=True)
- track_reference(space, py_str, space.w_str, replace=True)
-
@cpython_api([PyObject], lltype.Void, external=False)
def subtype_dealloc(space, obj):
@@ -520,8 +471,11 @@
w_base = best_base(space, w_type.bases_w)
pto.c_tp_base = rffi.cast(PyTypeObjectPtr, make_ref(space, w_base))
- finish_type_1(space, pto)
- finish_type_2(space, pto, w_type)
+ if hasattr(space, '_cpyext_type_init'):
+ space._cpyext_type_init.append((pto, w_type))
+ else:
+ finish_type_1(space, pto)
+ finish_type_2(space, pto, w_type)
pto.c_tp_basicsize = rffi.sizeof(typedescr.basestruct)
if pto.c_tp_base:
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit