Commits

Amaury Forgeot d'Arc  committed 9a6dae3

Don't need to maintain a list of the functions implemented in C.
Instead, they must be declared with the PyAPI_FUNC macro.

  • Participants
  • Parent commits a8df6e2
  • Branches cpyext-init-cleanup

Comments (0)

Files changed (16)

File pypy/module/cpyext/api.py

 
 INTERPLEVEL_API = {}
 FUNCTIONS = {}
-SYMBOLS_C = [
-    'Py_FatalError', 'PyOS_snprintf', 'PyOS_vsnprintf', 'PyArg_Parse',
-    'PyArg_ParseTuple', 'PyArg_UnpackTuple', 'PyArg_ParseTupleAndKeywords',
-    '_PyArg_NoKeywords',
-    'PyString_FromFormat', 'PyString_FromFormatV',
-    'PyModule_AddObject', 'PyModule_AddIntConstant', 'PyModule_AddStringConstant',
-    'Py_BuildValue', 'Py_VaBuildValue', 'PyTuple_Pack',
+SYMBOLS_C = []
 
-    'PyErr_Format', 'PyErr_NewException',
+def gather_PyAPI_symbols():
+    import os, re
+    include_dir = py.path.local(__file__).dirpath() / 'include'
+    for filename in include_dir.listdir("*.h"):
+        for line in filename.open():
+            if 'PyAPI_' not in line:
+                continue
+            if re.match('# *define', line):
+                continue
 
-    'PyEval_CallFunction', 'PyEval_CallMethod', 'PyObject_CallFunction',
-    'PyObject_CallMethod', 'PyObject_CallFunctionObjArgs', 'PyObject_CallMethodObjArgs',
+            match = re.match(r'PyAPI_FUNC\(.+?\)\s+(.+)\(', line)
+            if match:
+                name = match.group(1)
+                SYMBOLS_C.append(name)
+                continue
+            match = re.match(r'PyAPI_DATA\(.+?\)\s+(.+);', line)
+            if match:
+                name = match.group(1)
+                SYMBOLS_C.append(name)
+                continue
 
-    'PyBuffer_FromMemory', 'PyBuffer_FromReadWriteMemory', 'PyBuffer_FromObject',
-    'PyBuffer_FromReadWriteObject', 'PyBuffer_New', 'PyBuffer_Type', 'init_bufferobject',
+            assert False, "unknown PyAPI declaration: %r" % (line,)
+gather_PyAPI_symbols()
 
-    'PyCObject_FromVoidPtr', 'PyCObject_FromVoidPtrAndDesc', 'PyCObject_AsVoidPtr',
-    'PyCObject_GetDesc', 'PyCObject_Import', 'PyCObject_SetVoidPtr',
-    'PyCObject_Type', 'init_pycobject',
-
-    'PyObject_AsReadBuffer', 'PyObject_AsWriteBuffer', 'PyObject_CheckReadBuffer',
-]
 TYPES = {}
 GLOBALS = {}
 FORWARD_DECLS = []
 GlobalStaticPyObject.declare('_Py_NoneStruct', 'space.w_None')
 GlobalStaticPyObject.declare('_Py_TrueStruct', 'space.w_True')
 GlobalStaticPyObject.declare('_Py_ZeroStruct', 'space.w_False')
+GlobalStaticPyObject.declare('_Py_EllipsisObject', 'space.w_Ellipsis')
 GlobalStaticPyObject.declare('_Py_NotImplementedStruct',
                              'space.w_NotImplemented')
 GlobalStructurePointer.declare('PyDateTimeAPI', 'PyDateTime_CAPI*',

File pypy/module/cpyext/include/Python.h

 #include "funcobject.h"
 
 #include "modsupport.h"
+#include "mysnprintf.h"
 #include "pythonrun.h"
 #include "pyerrors.h"
 #include "stringobject.h"
 
 #include <pypy_decl.h>
 
+#include "complexobject.inl"
+
 /* Define macros for inline documentation. */
 #define PyDoc_VAR(name) static char name[]
 #define PyDoc_STRVAR(name,str) PyDoc_VAR(name) = PyDoc_STR(str)

File pypy/module/cpyext/include/bufferobject.h

 
 #define Py_END_OF_BUFFER	(-1)
 
-PyObject* PyBuffer_FromObject(PyObject *base,
-                                           Py_ssize_t offset, Py_ssize_t size);
-PyObject* PyBuffer_FromReadWriteObject(PyObject *base,
-                                                    Py_ssize_t offset,
-                                                    Py_ssize_t size);
+PyAPI_FUNC(PyObject*) PyBuffer_FromObject(PyObject *base,
+                                          Py_ssize_t offset, Py_ssize_t size);
+PyAPI_FUNC(PyObject*) PyBuffer_FromReadWriteObject(PyObject *base,
+                                                   Py_ssize_t offset,
+                                                   Py_ssize_t size);
 
-PyObject* PyBuffer_FromMemory(void *ptr, Py_ssize_t size);
-PyObject* PyBuffer_FromReadWriteMemory(void *ptr, Py_ssize_t size);
+PyAPI_FUNC(PyObject*) PyBuffer_FromMemory(void *ptr, Py_ssize_t size);
+PyAPI_FUNC(PyObject*) PyBuffer_FromReadWriteMemory(void *ptr, Py_ssize_t size);
 
-PyObject* PyBuffer_New(Py_ssize_t size);
+PyAPI_FUNC(PyObject*) PyBuffer_New(Py_ssize_t size);
 
-void init_bufferobject(void);
+PyAPI_FUNC(void) init_bufferobject(void);
 
 #ifdef __cplusplus
 }

File pypy/module/cpyext/include/complexobject.h

     double imag;
 } Py_complex;
 
-/* generated function */
-PyAPI_FUNC(void) _PyComplex_AsCComplex(PyObject *, Py_complex *);
-
-Py_LOCAL_INLINE(Py_complex) PyComplex_AsCComplex(PyObject *obj)
-{
-    Py_complex result;
-    _PyComplex_AsCComplex(obj, &result);
-    return result;
-}
-
 #ifdef __cplusplus
 }
 #endif

File pypy/module/cpyext/include/complexobject.inl

+/* Complex object inline functions */
+
+#ifndef Py_COMPLEXOBJECT_INL
+#define Py_COMPLEXOBJECT_INL
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+Py_LOCAL_INLINE(Py_complex) PyComplex_AsCComplex(PyObject *obj)
+{
+    Py_complex result;
+    _PyComplex_AsCComplex(obj, &result);
+    return result;
+}
+
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* !Py_COMPLEXOBJECT_INL */

File pypy/module/cpyext/include/datetime.h

     PyTypeObject *DeltaType;
 } PyDateTime_CAPI;
 
-PyAPI_DATA(PyDateTime_CAPI*) PyDateTimeAPI;
 #define PyDateTime_IMPORT _PyDateTime_Import()
 
 typedef struct {

File pypy/module/cpyext/include/eval.h

 #define PyEval_CallObject(func,arg) \
         PyEval_CallObjectWithKeywords(func, arg, (PyObject *)NULL)
 
-PyObject * PyEval_CallFunction(PyObject *obj, const char *format, ...);
-PyObject * PyEval_CallMethod(PyObject *obj, const char *name, const char *format, ...);
-PyObject * PyObject_CallFunction(PyObject *obj, char *format, ...);
-PyObject * PyObject_CallMethod(PyObject *obj, char *name, char *format, ...);
-PyObject * PyObject_CallFunctionObjArgs(PyObject *callable, ...);
-PyObject * PyObject_CallMethodObjArgs(PyObject *callable, PyObject *name, ...);
+PyAPI_FUNC(PyObject *) PyEval_CallFunction(PyObject *obj, const char *format, ...);
+PyAPI_FUNC(PyObject *) PyEval_CallMethod(PyObject *obj, const char *name, const char *format, ...);
+PyAPI_FUNC(PyObject *) PyObject_CallFunction(PyObject *obj, char *format, ...);
+PyAPI_FUNC(PyObject *) PyObject_CallMethod(PyObject *obj, char *name, char *format, ...);
+PyAPI_FUNC(PyObject *) PyObject_CallFunctionObjArgs(PyObject *callable, ...);
+PyAPI_FUNC(PyObject *) PyObject_CallMethodObjArgs(PyObject *callable, PyObject *name, ...);
 
 /* These constants are also defined in cpyext/eval.py */
 #define Py_single_input 256

File pypy/module/cpyext/include/modsupport.h

 #define PYTHON_API_VERSION 1013
 #define PYTHON_API_STRING "1013"
 
-int PyArg_Parse(PyObject *, const char *, ...);
-int PyArg_ParseTuple(PyObject *, const char *, ...);
-int PyArg_VaParse(PyObject *, const char *, va_list);
+PyAPI_FUNC(int) PyArg_Parse(PyObject *, const char *, ...);
+PyAPI_FUNC(int) PyArg_ParseTuple(PyObject *, const char *, ...);
+PyAPI_FUNC(int) PyArg_VaParse(PyObject *, const char *, va_list);
 
-int PyArg_ParseTupleAndKeywords(PyObject *, PyObject *,
-				const char *, char **, ...);
-int PyArg_VaParseTupleAndKeywords(PyObject *, PyObject *,
-				const char *, char **, va_list);
+PyAPI_FUNC(int) PyArg_ParseTupleAndKeywords(PyObject *, PyObject *,
+                                            const char *, char **, ...);
+PyAPI_FUNC(int) PyArg_VaParseTupleAndKeywords(PyObject *, PyObject *,
+                                              const char *, char **, va_list);
 
 #define Py_InitModule(name, methods) \
-	Py_InitModule4(name, methods, (char *)NULL, (PyObject *)NULL, \
-		       PYTHON_API_VERSION)
+        Py_InitModule4(name, methods, (char *)NULL, (PyObject *)NULL, \
+                       PYTHON_API_VERSION)
 
 #define Py_InitModule3(name, methods, doc) \
-	Py_InitModule4(name, methods, doc, (PyObject *)NULL, \
-		       PYTHON_API_VERSION)
+        Py_InitModule4(name, methods, doc, (PyObject *)NULL, \
+                       PYTHON_API_VERSION)
 
-int PyModule_AddObject(PyObject *m, const char *name, PyObject *o);
-int PyModule_AddIntConstant(PyObject *m, const char *name, long value);
-int PyModule_AddStringConstant(PyObject *m, const char *name, const char *value);
+PyAPI_FUNC(int) PyModule_AddObject(PyObject *m, const char *name, PyObject *o);
+PyAPI_FUNC(int) PyModule_AddIntConstant(PyObject *m, const char *name, long value);
+PyAPI_FUNC(int) PyModule_AddStringConstant(PyObject *m, const char *name, const char *value);
 
 
-PyObject * Py_BuildValue(const char *, ...);
-PyObject * _Py_BuildValue_SizeT(const char *, ...);
-int _PyArg_NoKeywords(const char *funcname, PyObject *kw);
+PyAPI_FUNC(PyObject *) Py_BuildValue(const char *, ...);
+PyAPI_FUNC(PyObject *) _Py_BuildValue_SizeT(const char *, ...);
+PyAPI_FUNC(PyObject *) Py_VaBuildValue(const char *, va_list va);
+PyAPI_FUNC(PyObject *) _Py_VaBuildValue_SizeT(const char *, va_list va);
+PyAPI_FUNC(int) _PyArg_NoKeywords(const char *funcname, PyObject *kw);
 
-int PyArg_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssize_t max, ...);
+PyAPI_FUNC(int) PyArg_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssize_t max, ...);
 
 /*
  * This is from pyport.h.  Perhaps it belongs elsewhere.

File pypy/module/cpyext/include/mysnprintf.h

+#ifndef Py_MYSNPRINTF_H
+#define Py_MYSNPRINTF_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+PyAPI_FUNC(int) PyOS_snprintf(char *str, size_t size, const  char  *format, ...);
+PyAPI_FUNC(int) PyOS_vsnprintf(char *str, size_t size, const  char  *format, va_list va);
+
+#ifdef __cplusplus
+}
+#endif
+#endif

File pypy/module/cpyext/include/object.h

     ((ob)->ob_type == (tp) || PyType_IsSubtype((ob)->ob_type, (tp)))
 
 /* Copied from CPython ----------------------------- */
-int PyObject_AsReadBuffer(PyObject *, const void **, Py_ssize_t *);
-int PyObject_AsWriteBuffer(PyObject *, void **, Py_ssize_t *);
-int PyObject_CheckReadBuffer(PyObject *);
+PyAPI_FUNC(int) PyObject_AsReadBuffer(PyObject *, const void **, Py_ssize_t *);
+PyAPI_FUNC(int) PyObject_AsWriteBuffer(PyObject *, void **, Py_ssize_t *);
+PyAPI_FUNC(int) PyObject_CheckReadBuffer(PyObject *);
 
 
 /* PyPy internal ----------------------------------- */
-int PyPyType_Register(PyTypeObject *);
 #define PyObject_Length PyObject_Size
 #define _PyObject_GC_Del PyObject_GC_Del
 

File pypy/module/cpyext/include/pycobject.h

     void (*destructor)(void *);
 } PyCObject;
 #endif
- 
+
+PyAPI_FUNC(void) init_pycobject(void);
+
 #ifdef __cplusplus
 }
 #endif

File pypy/module/cpyext/include/pyerrors.h

 extern "C" {
 #endif
 
-PyObject *PyErr_NewException(char *name, PyObject *base, PyObject *dict);
-PyObject *PyErr_Format(PyObject *exception, const char *format, ...);
+PyAPI_FUNC(PyObject *) PyErr_NewException(char *name, PyObject *base, PyObject *dict);
+PyAPI_FUNC(PyObject *) PyErr_Format(PyObject *exception, const char *format, ...);
 
 #ifdef __cplusplus
 }

File pypy/module/cpyext/include/pythonrun.h

 extern "C" {
 #endif
 
-  void Py_FatalError(const char *msg);
+PyAPI_FUNC(void) Py_FatalError(const char *msg);
 
 #ifdef __cplusplus
 }

File pypy/module/cpyext/include/sliceobject.h

 #endif
 
 /* The unique ellipsis object "..." */
-
-PyAPI_DATA(PyObject) _Py_EllipsisObject; /* Don't use this directly */
-
 #define Py_Ellipsis (&_Py_EllipsisObject)
 
 typedef struct {

File pypy/module/cpyext/include/stringobject.h

     Py_ssize_t size;
 } PyStringObject;
 
-PyObject *PyString_FromFormatV(const char *format, va_list vargs);
-PyObject *PyString_FromFormat(const char *format, ...);
+PyAPI_FUNC(PyObject *) PyString_FromFormatV(const char *format, va_list vargs);
+PyAPI_FUNC(PyObject *) PyString_FromFormat(const char *format, ...);
 
 #ifdef __cplusplus
 }

File pypy/module/cpyext/include/tupleobject.h

 #endif
 
 /* defined in varargswrapper.c */
-PyObject * PyTuple_Pack(Py_ssize_t, ...);
+PyAPI_FUNC(PyObject *) PyTuple_Pack(Py_ssize_t, ...);
 
 #define PyTuple_SET_ITEM PyTuple_SetItem
 #define PyTuple_GET_ITEM PyTuple_GetItem