[pypy-svn] r75226 - in pypy/branch/cpyext-init-cleanup/pypy/module/cpyext: . include

afa at codespeak.net afa at codespeak.net
Wed Jun 9 01:38:54 CEST 2010


Author: afa
Date: Wed Jun  9 01:38:52 2010
New Revision: 75226

Added:
   pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/complexobject.inl   (contents, props changed)
   pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/mysnprintf.h   (contents, props changed)
Modified:
   pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/api.py
   pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/Python.h
   pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/bufferobject.h
   pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/complexobject.h
   pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/datetime.h
   pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/eval.h
   pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/modsupport.h
   pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/object.h
   pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/pycobject.h
   pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/pyerrors.h
   pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/pythonrun.h
   pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/sliceobject.h
   pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/stringobject.h
   pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/tupleobject.h
Log:
Don't need to maintain a list of the functions implemented in C.
Instead, they must be declared with the PyAPI_FUNC macro.


Modified: pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/api.py
==============================================================================
--- pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/api.py	(original)
+++ pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/api.py	Wed Jun  9 01:38:52 2010
@@ -306,28 +306,32 @@
 
 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',
-
-    'PyErr_Format', 'PyErr_NewException',
-
-    'PyEval_CallFunction', 'PyEval_CallMethod', 'PyObject_CallFunction',
-    'PyObject_CallMethod', 'PyObject_CallFunctionObjArgs', 'PyObject_CallMethodObjArgs',
-
-    'PyBuffer_FromMemory', 'PyBuffer_FromReadWriteMemory', 'PyBuffer_FromObject',
-    'PyBuffer_FromReadWriteObject', 'PyBuffer_New', 'PyBuffer_Type', 'init_bufferobject',
-
-    'PyCObject_FromVoidPtr', 'PyCObject_FromVoidPtrAndDesc', 'PyCObject_AsVoidPtr',
-    'PyCObject_GetDesc', 'PyCObject_Import', 'PyCObject_SetVoidPtr',
-    'PyCObject_Type', 'init_pycobject',
+SYMBOLS_C = []
+
+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
+
+            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
+
+            assert False, "unknown PyAPI declaration: %r" % (line,)
+gather_PyAPI_symbols()
 
-    'PyObject_AsReadBuffer', 'PyObject_AsWriteBuffer', 'PyObject_CheckReadBuffer',
-]
 TYPES = {}
 GLOBALS = {}
 FORWARD_DECLS = []
@@ -469,6 +473,7 @@
 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*',

Modified: pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/Python.h
==============================================================================
--- pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/Python.h	(original)
+++ pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/Python.h	Wed Jun  9 01:38:52 2010
@@ -82,6 +82,7 @@
 #include "funcobject.h"
 
 #include "modsupport.h"
+#include "mysnprintf.h"
 #include "pythonrun.h"
 #include "pyerrors.h"
 #include "stringobject.h"
@@ -104,6 +105,8 @@
 
 #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)

Modified: pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/bufferobject.h
==============================================================================
--- pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/bufferobject.h	(original)
+++ pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/bufferobject.h	Wed Jun  9 01:38:52 2010
@@ -15,18 +15,18 @@
 
 #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
 }

Modified: pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/complexobject.h
==============================================================================
--- pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/complexobject.h	(original)
+++ pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/complexobject.h	Wed Jun  9 01:38:52 2010
@@ -11,16 +11,6 @@
     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

Added: pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/complexobject.inl
==============================================================================
--- (empty file)
+++ pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/complexobject.inl	Wed Jun  9 01:38:52 2010
@@ -0,0 +1,20 @@
+/* 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 */

Modified: pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/datetime.h
==============================================================================
--- pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/datetime.h	(original)
+++ pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/datetime.h	Wed Jun  9 01:38:52 2010
@@ -13,7 +13,6 @@
     PyTypeObject *DeltaType;
 } PyDateTime_CAPI;
 
-PyAPI_DATA(PyDateTime_CAPI*) PyDateTimeAPI;
 #define PyDateTime_IMPORT _PyDateTime_Import()
 
 typedef struct {

Modified: pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/eval.h
==============================================================================
--- pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/eval.h	(original)
+++ pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/eval.h	Wed Jun  9 01:38:52 2010
@@ -12,12 +12,12 @@
 #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

Modified: pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/modsupport.h
==============================================================================
--- pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/modsupport.h	(original)
+++ pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/modsupport.h	Wed Jun  9 01:38:52 2010
@@ -10,33 +10,35 @@
 #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);
-
-int PyArg_ParseTupleAndKeywords(PyObject *, PyObject *,
-				const char *, char **, ...);
-int PyArg_VaParseTupleAndKeywords(PyObject *, PyObject *,
-				const char *, 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);
+
+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.

Added: pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/mysnprintf.h
==============================================================================
--- (empty file)
+++ pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/mysnprintf.h	Wed Jun  9 01:38:52 2010
@@ -0,0 +1,13 @@
+#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

Modified: pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/object.h
==============================================================================
--- pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/object.h	(original)
+++ pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/object.h	Wed Jun  9 01:38:52 2010
@@ -479,13 +479,12 @@
     ((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
 

Modified: pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/pycobject.h
==============================================================================
--- pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/pycobject.h	(original)
+++ pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/pycobject.h	Wed Jun  9 01:38:52 2010
@@ -47,7 +47,9 @@
     void (*destructor)(void *);
 } PyCObject;
 #endif
- 
+
+PyAPI_FUNC(void) init_pycobject(void);
+
 #ifdef __cplusplus
 }
 #endif

Modified: pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/pyerrors.h
==============================================================================
--- pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/pyerrors.h	(original)
+++ pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/pyerrors.h	Wed Jun  9 01:38:52 2010
@@ -7,8 +7,8 @@
 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
 }

Modified: pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/pythonrun.h
==============================================================================
--- pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/pythonrun.h	(original)
+++ pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/pythonrun.h	Wed Jun  9 01:38:52 2010
@@ -6,7 +6,7 @@
 extern "C" {
 #endif
 
-  void Py_FatalError(const char *msg);
+PyAPI_FUNC(void) Py_FatalError(const char *msg);
 
 #ifdef __cplusplus
 }

Modified: pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/sliceobject.h
==============================================================================
--- pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/sliceobject.h	(original)
+++ pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/sliceobject.h	Wed Jun  9 01:38:52 2010
@@ -5,9 +5,6 @@
 #endif
 
 /* The unique ellipsis object "..." */
-
-PyAPI_DATA(PyObject) _Py_EllipsisObject; /* Don't use this directly */
-
 #define Py_Ellipsis (&_Py_EllipsisObject)
 
 typedef struct {

Modified: pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/stringobject.h
==============================================================================
--- pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/stringobject.h	(original)
+++ pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/stringobject.h	Wed Jun  9 01:38:52 2010
@@ -18,8 +18,8 @@
     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
 }

Modified: pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/tupleobject.h
==============================================================================
--- pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/tupleobject.h	(original)
+++ pypy/branch/cpyext-init-cleanup/pypy/module/cpyext/include/tupleobject.h	Wed Jun  9 01:38:52 2010
@@ -8,7 +8,7 @@
 #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



More information about the Pypy-commit mailing list