[pypy-commit] pypy cpyext-gc-support: Translates and crashes

arigo noreply at buildbot.pypy.org
Sat Oct 24 05:11:43 EDT 2015


Author: Armin Rigo <arigo at tunes.org>
Branch: cpyext-gc-support
Changeset: r80419:a14224c473b0
Date: 2015-10-24 10:15 +0100
http://bitbucket.org/pypy/pypy/changeset/a14224c473b0/

Log:	Translates and crashes

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
@@ -25,7 +25,7 @@
 from pypy.objspace.std.sliceobject import W_SliceObject
 from pypy.module.__builtin__.descriptor import W_Property
 from pypy.module.__builtin__.interp_classobj import W_ClassObject
-from pypy.module.micronumpy.base import W_NDimArray
+#from pypy.module.micronumpy.base import W_NDimArray ZZZ
 from rpython.rlib.entrypoint import entrypoint_lowlevel
 from rpython.rlib.rposix import is_valid_fd, validate_fd
 from rpython.rlib.unroll import unrolling_iterable
@@ -497,7 +497,7 @@
         "PyComplex_Type": "space.w_complex",
         "PyByteArray_Type": "space.w_bytearray",
         "PyMemoryView_Type": "space.w_memoryview",
-        "PyArray_Type": "space.gettypeobject(W_NDimArray.typedef)",
+        #"PyArray_Type": "space.gettypeobject(W_NDimArray.typedef)", ZZZ
         "PyBaseObject_Type": "space.w_object",
         'PyNone_Type': 'space.type(space.w_None)',
         'PyNotImplemented_Type': 'space.type(space.w_NotImplemented)',
@@ -871,7 +871,7 @@
     # populate static data
     to_fill = []
     for name, (typ, expr) in GLOBALS.iteritems():
-        from pypy.module import cpyext
+        from pypy.module import cpyext    # for the eval() below
         w_obj = eval(expr)
         if name.endswith('#'):
             name = name[:-1]
@@ -1049,7 +1049,7 @@
         if name.endswith('#'):
             structs.append('%s %s;' % (typ[:-1], name[:-1]))
         elif name.startswith('PyExc_'):
-            structs.append('extern PyTypeObject _%s;' % (name,))
+            structs.append('PyTypeObject _%s;' % (name,))
             structs.append('PyObject* %s = (PyObject*)&_%s;' % (name, name))
         elif typ == 'PyDateTime_CAPI*':
             structs.append('%s %s = NULL;' % (typ, name))
@@ -1125,35 +1125,35 @@
     # emit uninitialized static data
     static_objs_w = []
     static_pyobjs = []
-    lines = []
-    entries = []
+    lines = ['PyObject *pypy_static_pyobjs[] = {\n']
+    include_lines = ['RPY_EXTERN PyObject *pypy_static_pyobjs[];\n']
     for name, (typ, expr) in sorted(GLOBALS.items()):
-        name = name.replace("#", "")
-        if name.startswith('PyExc_'):
+        if name.endswith('#'):
+            assert typ in ('PyObject*', 'PyTypeObject*')
+            typ, name = typ[:-1], name[:-1]
+        elif name.startswith('PyExc_'):
+            typ = 'PyTypeObject'
             name = '_' + name
-        if typ in ('PyObject*', 'PyTypeObject*'):
-            w_obj = eval(expr)
-            static_objs_w.append(w_obj)
-            lines.append('%s %s;\n' % (typ, name))
-            if typ == 'PyObject*':
-                entries.append('\t%s,\n' % (name,))
-            else:
-                entries.append('\t(PyObject *)%s,\n' % (name,))
         elif typ == 'PyDateTime_CAPI*':
             continue
         else:
             assert False, "Unknown static data: %s %s" % (typ, name)
-    lines.append('\n')
-    lines.append('PyObject *pypy_static_pyobjs[] = {\n')
-    lines.extend(entries)
+
+        from pypy.module import cpyext     # for the eval() below
+        w_obj = eval(expr)
+        static_objs_w.append(w_obj)
+        lines.append('\t(PyObject *)&%s,\n' % (name,))
+        include_lines.append('RPY_EXPORTED %s %s;\n' % (typ, name))
+
     lines.append('};\n')
-    eci2 = ExternalCompilationInfo(
-        separate_module_sources = ''.join(lines),
-        post_include_bits = ['RPY_EXTERN PyObject *pypy_static_pyobjs[];\n'],
-        )
+    eci2 = CConfig._compilation_info_.merge(ExternalCompilationInfo(
+        separate_module_sources = [''.join(lines)],
+        post_include_bits = [''.join(include_lines)],
+        ))
     state.static_objs_w = static_objs_w
-    state.static_pyobjs = rffi.CExternVariable(
-        PyObjectP, 'pypy_static_pyobjs', eci2, c_type='PyObject **')
+    state.get_static_pyobjs = rffi.CExternVariable(
+        PyObjectP, 'pypy_static_pyobjs', eci2, c_type='PyObject **',
+        getter_only=True, declare_as_extern=False)
 
     for name, func in FUNCTIONS.iteritems():
         newname = mangle_name('PyPy', name) or name
@@ -1165,10 +1165,12 @@
     copy_header_files(trunk_include)
 
 def init_static_data_translated(space):
+    from pypy.module.cpyext.pyobject import setup_prebuilt_pyobj
     # populate static data
     state = space.fromcache(State)
+    static_pyobjs = state.get_static_pyobjs()
     for i, w_obj in enumerate(state.static_objs_w):
-        py_obj = state.static_pyobjs[i]
+        py_obj = static_pyobjs[i]
         setup_prebuilt_pyobj(w_obj, py_obj)
     # step 2
     for w_obj in state.static_objs_w:
diff --git a/rpython/rlib/exports.py b/rpython/rlib/exports.py
--- a/rpython/rlib/exports.py
+++ b/rpython/rlib/exports.py
@@ -1,5 +1,7 @@
 from rpython.rtyper.lltypesystem.lltype import typeOf, ContainerType
 
+# XXX kill me
+
 def export_struct(name, struct):
     assert name not in EXPORTS_names, "Duplicate export " + name
     assert isinstance(typeOf(struct), ContainerType)
diff --git a/rpython/rtyper/lltypesystem/rffi.py b/rpython/rtyper/lltypesystem/rffi.py
--- a/rpython/rtyper/lltypesystem/rffi.py
+++ b/rpython/rtyper/lltypesystem/rffi.py
@@ -643,7 +643,8 @@
 
 def CExternVariable(TYPE, name, eci, _CConstantClass=CConstant,
                     sandboxsafe=False, _nowrapper=False,
-                    c_type=None, getter_only=False):
+                    c_type=None, getter_only=False,
+                    declare_as_extern=(sys.platform != 'win32')):
     """Return a pair of functions - a getter and a setter - to access
     the given global C variable.
     """
@@ -673,7 +674,7 @@
     c_setter = "void %(setter_name)s (%(c_type)s v) { %(name)s = v; }" % locals()
 
     lines = ["#include <%s>" % i for i in eci.includes]
-    if sys.platform != 'win32':
+    if declare_as_extern:
         lines.append('extern %s %s;' % (c_type, name))
     lines.append(c_getter)
     if not getter_only:


More information about the pypy-commit mailing list