[pypy-commit] pypy cpyext-nowrapper: (antocuni, ronan): try to avoid using the space inside PyErr_NoMemory, so that we can later declare it as no_gc=True

antocuni pypy.commits at gmail.com
Sun Oct 8 18:13:09 EDT 2017


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: cpyext-nowrapper
Changeset: r92664:ab603c05de2d
Date: 2017-10-08 00:41 +0200
http://bitbucket.org/pypy/pypy/changeset/ab603c05de2d/

Log:	(antocuni, ronan): try to avoid using the space inside
	PyErr_NoMemory, so that we can later declare it as no_gc=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
@@ -1114,6 +1114,9 @@
     state.C._PyPy_get_PyType_Type = rffi.llexternal(
         '_PyPy_get_PyType_Type', [], PyTypeObjectPtr,
         compilation_info=eci, _nowrapper=True)
+    state.C._PyPy_get_PyExc_MemoryError = rffi.llexternal(
+        '_PyPy_get_PyExc_MemoryError', [], PyObject,
+        compilation_info=eci, _nowrapper=True)
 
 
 def init_function(func):
@@ -1217,11 +1220,12 @@
                                     ctypes.c_void_p).value
         else:
             if name.startswith('PyExc_'):
-                # we already have the pointer
+                # PyExc_* are C variables of type PyObject*
                 in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
                 py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
             else:
-                # we have a structure, get its address
+                # the other global names actual C structures (NOT pointers to
+                # C structs, as PyExc_*)
                 in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
                 py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
             builder.prepare(py_obj, w_obj)
@@ -1428,7 +1432,7 @@
                          source_dir / "pythread.c",
                          source_dir / "missing.c",
                          source_dir / "pymem.c",
-                         source_dir / "typeobject.c",
+                         source_dir / "_pypy_internal.c",
                          ]
 
 def build_eci(code, use_micronumpy=False, translating=False):
diff --git a/pypy/module/cpyext/include/Python.h b/pypy/module/cpyext/include/Python.h
--- a/pypy/module/cpyext/include/Python.h
+++ b/pypy/module/cpyext/include/Python.h
@@ -130,6 +130,8 @@
 
 /* Missing definitions */
 #include "missing.h"
+#include "_pypy_internal.h"
+
 
 /* The declarations of most API functions are generated in a separate file */
 /* Don't include them while building PyPy, RPython also generated signatures
diff --git a/pypy/module/cpyext/include/_pypy_internal.h b/pypy/module/cpyext/include/_pypy_internal.h
new file mode 100644
--- /dev/null
+++ b/pypy/module/cpyext/include/_pypy_internal.h
@@ -0,0 +1,17 @@
+#ifndef PyPy_INTERNAL_H
+#define PyPy_INTERNAL_H
+
+#include <stdio.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+PyAPI_FUNC(PyTypeObject*) _PyPy_get_PyType_Type(void);
+PyAPI_FUNC(PyObject*) _PyPy_get_PyExc_MemoryError(void);
+
+    
+#ifdef __cplusplus
+}
+#endif
+#endif /* !PyPy_INTERNAL_H */
diff --git a/pypy/module/cpyext/include/object.h b/pypy/module/cpyext/include/object.h
--- a/pypy/module/cpyext/include/object.h
+++ b/pypy/module/cpyext/include/object.h
@@ -330,7 +330,6 @@
 PyAPI_FUNC(int) PyPyType_Register(PyTypeObject *);
 #define PyObject_Length PyObject_Size
 #define _PyObject_GC_Del PyObject_GC_Del
-PyAPI_FUNC(PyTypeObject*) _PyPy_get_PyType_Type(void);
 
 #ifdef __cplusplus
 }
diff --git a/pypy/module/cpyext/pyerrors.py b/pypy/module/cpyext/pyerrors.py
--- a/pypy/module/cpyext/pyerrors.py
+++ b/pypy/module/cpyext/pyerrors.py
@@ -132,7 +132,8 @@
     so an object allocation function can write return PyErr_NoMemory(); when it
     runs out of memory.
     Return value: always NULL."""
-    PyErr_SetNone(space, space.w_MemoryError)
+    state = space.fromcache(State)
+    PyErr_SetNone(space, state.C._PyPy_get_PyExc_MemoryError())
 
 @cpython_api([PyObject], PyObject)
 def PyErr_SetFromErrno(space, w_type):
diff --git a/pypy/module/cpyext/src/typeobject.c b/pypy/module/cpyext/src/_pypy_internal.c
rename from pypy/module/cpyext/src/typeobject.c
rename to pypy/module/cpyext/src/_pypy_internal.c
--- a/pypy/module/cpyext/src/typeobject.c
+++ b/pypy/module/cpyext/src/_pypy_internal.c
@@ -5,3 +5,9 @@
 {
     return &PyType_Type;
 }
+
+PyObject*
+_PyPy_get_PyExc_MemoryError(void)
+{
+    return PyExc_MemoryError;
+}


More information about the pypy-commit mailing list