[pypy-svn] r73877 - pypy/branch/cpython-extension/pypy/module/cpyext

afa at codespeak.net afa at codespeak.net
Sun Apr 18 22:18:19 CEST 2010


Author: afa
Date: Sun Apr 18 22:18:17 2010
New Revision: 73877

Modified:
   pypy/branch/cpython-extension/pypy/module/cpyext/api.py
   pypy/branch/cpython-extension/pypy/module/cpyext/typeobject.py
Log:
Move type initialization into typeobject.py


Modified: pypy/branch/cpython-extension/pypy/module/cpyext/api.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/api.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/api.py	Sun Apr 18 22:18:17 2010
@@ -434,55 +434,10 @@
     BOOTSTRAP_FUNCTIONS.append(func)
     return func
 
-def bootstrap_types(space):
-    from pypy.module.cpyext.pyobject import make_ref, create_ref, track_reference
-    from pypy.module.cpyext.typeobject import PyTypeObjectPtr
-
+def run_bootstrap_functions(space):
     for func in BOOTSTRAP_FUNCTIONS:
         func(space)
 
-    # 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 make_ref()
-    state = space.fromcache(State)
-    state.py_objects_w2r[space.w_type] = lltype.nullptr(PyObject.TO)
-    state.py_objects_w2r[space.w_object] = lltype.nullptr(PyObject.TO)
-    state.py_objects_w2r[space.w_tuple] = lltype.nullptr(PyObject.TO)
-
-    # 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)
-
-    # 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
-
-    # Restore the mapping
-    track_reference(space, py_type, space.w_type)
-    track_reference(space, py_object, space.w_object)
-    track_reference(space, py_tuple, space.w_tuple)
-
-
 #_____________________________________________________
 # Build the bridge DLL, Allow extension DLLs to call
 # back into Pypy space functions
@@ -530,7 +485,7 @@
         outputfilename=str(udir / "module_cache" / "pypyapi"))
     modulename = py.path.local(eci.libraries[-1])
 
-    bootstrap_types(space)
+    run_bootstrap_functions(space)
 
     # load the bridge, and init structure
     import ctypes
@@ -686,7 +641,7 @@
 
     eci = build_eci(False, export_symbols, code)
 
-    bootstrap_types(space)
+    run_bootstrap_functions(space)
     setup_va_functions(eci)
 
     # populate static data

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	Sun Apr 18 22:18:17 2010
@@ -17,7 +17,8 @@
     Py_TPFLAGS_READY, Py_TPFLAGS_HEAPTYPE, ADDR, \
     Py_TPFLAGS_HAVE_CLASS, METH_VARARGS, METH_KEYWORDS, \
     CANNOT_FAIL, PyBufferProcs
-from pypy.module.cpyext.pyobject import PyObject, make_ref, from_ref, get_typedescr, make_typedescr
+from pypy.module.cpyext.pyobject import PyObject, make_ref, create_ref, from_ref
+from pypy.module.cpyext.pyobject import get_typedescr, make_typedescr, track_reference
 from pypy.interpreter.module import Module
 from pypy.interpreter.function import FunctionWithFixedCode, StaticMethod
 from pypy.module.cpyext import structmemberdefs
@@ -332,6 +333,48 @@
                    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 make_ref()
+    state = space.fromcache(State)
+    state.py_objects_w2r[space.w_type] = lltype.nullptr(PyObject.TO)
+    state.py_objects_w2r[space.w_object] = lltype.nullptr(PyObject.TO)
+    state.py_objects_w2r[space.w_tuple] = lltype.nullptr(PyObject.TO)
+
+    # 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)
+
+    # 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
+
+    # Restore the mapping
+    track_reference(space, py_type, space.w_type)
+    track_reference(space, py_object, space.w_object)
+    track_reference(space, py_tuple, space.w_tuple)
+
+
 @cpython_api([PyObject], lltype.Void, external=False)
 def subtype_dealloc(space, obj):
     pto = obj.c_ob_type



More information about the Pypy-commit mailing list