[pypy-svn] r72500 - in pypy/trunk/pypy/module/cpyext: . include

afa at codespeak.net afa at codespeak.net
Sun Mar 21 18:04:11 CET 2010


Author: afa
Date: Sun Mar 21 18:04:09 2010
New Revision: 72500

Modified:
   pypy/trunk/pypy/module/cpyext/api.py
   pypy/trunk/pypy/module/cpyext/include/Python.h
   pypy/trunk/pypy/module/cpyext/include/boolobject.h
   pypy/trunk/pypy/module/cpyext/include/object.h
   pypy/trunk/pypy/module/cpyext/include/pyerrors.h
   pypy/trunk/pypy/module/cpyext/include/tupleobject.h
   pypy/trunk/pypy/module/cpyext/include/typeobject.c
Log:
export global symbols from the bridge library


Modified: pypy/trunk/pypy/module/cpyext/api.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/api.py	(original)
+++ pypy/trunk/pypy/module/cpyext/api.py	Sun Mar 21 18:04:09 2010
@@ -68,6 +68,15 @@
 
 FUNCTIONS = {}
 TYPES = {}
+GLOBALS = {
+    'Py_None': ('PyObject*', 'space.w_None'),
+    'Py_True': ('PyObject*', 'space.w_True'),
+    'Py_False': ('PyObject*', 'space.w_False'),
+    'PyExc_Exception': ('PyObject*', 'space.w_Exception'),
+    'PyExc_TypeError': ('PyObject*', 'space.w_TypeError'),
+    'PyType_Type': ('PyTypeObject*', 'space.w_type'),
+    'PyBaseObject_Type': ('PyTypeObject*', 'space.w_object'),
+    }
 
 # It is important that these PyObjects are allocated in a raw fashion
 # Thus we cannot save a forward pointer to the wrapped object
@@ -124,7 +133,7 @@
 def build_bridge(space, rename=True):
     db = LowLevelDatabase()
 
-    export_symbols = list(FUNCTIONS)
+    export_symbols = list(FUNCTIONS) + list(GLOBALS)
 
     structindex = {}
 
@@ -135,11 +144,12 @@
     """
     if rename:
         pypy_rename = []
-        export_symbols = []
-        for name in FUNCTIONS:
+        renamed_symbols = []
+        for name in export_symbols:
             newname = name.replace('Py', 'PyPy')
             pypy_rename.append('#define %s %s' % (name, newname))
-            export_symbols.append(newname)
+            renamed_symbols.append(newname)
+        export_symbols = renamed_symbols
         pypy_rename_h = udir.join('pypy_rename.h')
         pypy_rename_h.write('\n'.join(pypy_rename))
 
@@ -176,18 +186,13 @@
         body = "{ return _pypyAPI.%s(%s); }" % (name, callargs)
         functions.append('%s\n%s\n' % (header, body))
 
-    global_objects = """
-    PyObject *PyPy_None = NULL;
-    PyObject *PyPy_True = NULL;
-    PyObject *PyPy_False = NULL;
-    PyObject *PyPyExc_Exception = NULL;
-    PyObject *PyPyExc_TypeError = NULL;
-    PyTypeObject *PyPyType_Type = NULL;
-    PyTypeObject *PyPyBaseObject_Type = NULL;
-    """
+    global_objects = []
+    for name, (type, expr) in GLOBALS.iteritems():
+        global_objects.append('%s %s = NULL;' % (type, name))
+    global_code = '\n'.join(global_objects)
     code = (prologue +
             struct_declaration_code +
-            global_objects +
+            global_code +
             '\n' +
             '\n'.join(functions))
 
@@ -210,14 +215,10 @@
     pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
 
     # populate static data
-    for name, w_obj in [("PyPy_None", space.w_None),
-                        ("PyPy_True", space.w_True),
-                        ("PyPy_False", space.w_False),
-                        ("PyPyExc_Exception", space.w_Exception),
-                        ("PyPyExc_TypeError", space.w_TypeError),
-                        ("PyPyType_Type", space.w_type),
-                        ("PyPyBaseObject_Type", space.w_object),
-                        ]:
+    for name, (type, expr) in GLOBALS.iteritems():
+        if rename:
+            name = name.replace('Py', 'PyPy')
+        w_obj = eval(expr)
         ptr = ctypes.c_void_p.in_dll(bridge, name)
         ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(make_ref(space, w_obj)),
             ctypes.c_void_p).value

Modified: pypy/trunk/pypy/module/cpyext/include/Python.h
==============================================================================
--- pypy/trunk/pypy/module/cpyext/include/Python.h	(original)
+++ pypy/trunk/pypy/module/cpyext/include/Python.h	Sun Mar 21 18:04:09 2010
@@ -2,16 +2,19 @@
 #define Py_PYTHON_H
 
 /* Compat stuff */
+#ifndef _WIN32
 #include <inttypes.h>
 #include <stdint.h>
-#define Py_ssize_t long
 #define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
+#else
+#define Py_DEPRECATED(VERSION_UNUSED)
+#endif
+#define Py_ssize_t long
 
 #include "object.h"
 
 /* move somewhere else */
-extern PyObject *PyPy_None;
-#define Py_None PyPy_None
+extern PyObject *Py_None;
 
 #define long int /* XXX: same hack as in api.py */
 

Modified: pypy/trunk/pypy/module/cpyext/include/boolobject.h
==============================================================================
--- pypy/trunk/pypy/module/cpyext/include/boolobject.h	(original)
+++ pypy/trunk/pypy/module/cpyext/include/boolobject.h	Sun Mar 21 18:04:09 2010
@@ -7,11 +7,9 @@
 extern "C" {
 #endif
 
-extern PyObject *PyPy_True;
-#define Py_True PyPy_True
+extern PyObject *Py_True;
 
-extern PyObject *PyPy_False;
-#define Py_False PyPy_False
+extern PyObject *Py_False;
 
 /* Macros for returning Py_True or Py_False, respectively */
 #define Py_RETURN_TRUE return Py_INCREF(Py_True), Py_True

Modified: pypy/trunk/pypy/module/cpyext/include/object.h
==============================================================================
--- pypy/trunk/pypy/module/cpyext/include/object.h	(original)
+++ pypy/trunk/pypy/module/cpyext/include/object.h	Sun Mar 21 18:04:09 2010
@@ -34,9 +34,6 @@
 #define Py_SIZE(ob)		(((PyVarObject*)(ob))->obj_size)
 
 
-extern PyObject *PyPy_None;
-#define Py_None PyPy_None
-
 struct _typeobject;
 typedef void (*freefunc)(void *);
 typedef void (*destructor)(PyObject *);
@@ -378,12 +375,9 @@
 #define Py_TPFLAGS_DEFAULT Py_TPFLAGS_DEFAULT_EXTERNAL
 
 
-extern PyTypeObject *PyPyType_Type; /* built-in 'type' */
-#define PyType_Type *PyPyType_Type
-extern PyTypeObject *PyPyBaseObject_Type;
-#define PyBaseObject_Type *PyPyBaseObject_Type
-int PyPyType_Ready(PyTypeObject *);
-#define PyType_Ready PyPyType_Ready
+extern PyTypeObject *PyType_Type; /* built-in 'type' */
+extern PyTypeObject *PyBaseObject_Type;
+int PyType_Ready(PyTypeObject *);
 
 /* objimpl.h ----------------------------------------------*/
 

Modified: pypy/trunk/pypy/module/cpyext/include/pyerrors.h
==============================================================================
--- pypy/trunk/pypy/module/cpyext/include/pyerrors.h	(original)
+++ pypy/trunk/pypy/module/cpyext/include/pyerrors.h	Sun Mar 21 18:04:09 2010
@@ -7,8 +7,7 @@
 extern "C" {
 #endif
 
-extern PyObject *PyPyExc_Exception;
-#define PyExc_Exception PyPyExc_Exception
+extern PyObject *PyExc_Exception;
 
 #ifdef __cplusplus
 }

Modified: pypy/trunk/pypy/module/cpyext/include/tupleobject.h
==============================================================================
--- pypy/trunk/pypy/module/cpyext/include/tupleobject.h	(original)
+++ pypy/trunk/pypy/module/cpyext/include/tupleobject.h	Sun Mar 21 18:04:09 2010
@@ -10,7 +10,6 @@
 PyObject * PyTuple_New(Py_ssize_t size);
 PyObject * PyTuple_Pack(Py_ssize_t, ...);
 PyTuple_SetItem(PyObject *, Py_ssize_t, PyObject *);
-#define PyTuple_Pack PyPyTuple_Pack
 
 #ifdef __cplusplus
 }

Modified: pypy/trunk/pypy/module/cpyext/include/typeobject.c
==============================================================================
--- pypy/trunk/pypy/module/cpyext/include/typeobject.c	(original)
+++ pypy/trunk/pypy/module/cpyext/include/typeobject.c	Sun Mar 21 18:04:09 2010
@@ -3,9 +3,8 @@
 #include <pypy_rename.h>
 #include <Python.h>
 
-    
 int
-PyPyType_Ready(PyTypeObject *type)
+PyType_Ready(PyTypeObject *type)
 {
 	PyObject *dict, *bases;
 	PyTypeObject *base;
@@ -61,7 +60,7 @@
 		if (base == NULL)
 			bases = PyTuple_New(0);
 		else
-			bases = PyTuple_Pack(1, base);
+			bases = PyPyTuple_Pack(1, base);
 		if (bases == NULL)
 			goto error;
 		type->tp_bases = bases;



More information about the Pypy-commit mailing list