[Numpy-svn] r8261 - trunk/numpy/numarray

numpy-svn@scip... numpy-svn@scip...
Wed Feb 24 23:20:19 CST 2010


Author: charris
Date: 2010-02-24 23:20:18 -0600 (Wed, 24 Feb 2010)
New Revision: 8261

Modified:
   trunk/numpy/numarray/_capi.c
Log:
ENH: Try to fix numarray _capi.c for Python >= 3.1. Needs testing that I am not
in a position to do.

Modified: trunk/numpy/numarray/_capi.c
===================================================================
--- trunk/numpy/numarray/_capi.c	2010-02-24 22:05:03 UTC (rev 8260)
+++ trunk/numpy/numarray/_capi.c	2010-02-25 05:20:18 UTC (rev 8261)
@@ -3367,22 +3367,49 @@
 
 #if (!defined(METHOD_TABLE_EXISTS))
 static PyMethodDef _libnumarrayMethods[] = {
-    {NULL,      NULL, 0, NULL}        /* Sentinel */
+    {NULL, NULL, 0, NULL}        /* Sentinel */
 };
 #endif
 
 /* boiler plate API init */
+#if PY_VERSION_HEX >= 0x03010000
+
+#define RETVAL m
+
+static struct PyModuleDef moduledef = {
+        PyModuleDef_HEAD_INIT,
+        "_capi",
+        NULL,
+        -1,
+        _libnumarrayMethods,
+        NULL,
+        NULL,
+        NULL,
+        NULL
+};
+
+PyObject *PyInit___capi(void)
+#else
+
+#define RETVAL
+
 PyMODINIT_FUNC init_capi(void)
+#endif
 {
-    PyObject *m = Py_InitModule("_capi", _libnumarrayMethods);
+    PyObject *m;
     PyObject *c_api_object;
 
     _Error = PyErr_NewException("numpy.numarray._capi.error", NULL, NULL);
 
     /* Create a CObject containing the API pointer array's address */
-#if defined(NPY_PY3K)
+#if PY_VERSION_HEX >= 0x03010000
+    m = PyModule_Create(&moduledef);
     c_api_object = PyCapsule_New((void *)libnumarray_API, NULL, NULL);
+    if (c_api_object == NULL) {
+        PyErr_Clear();
+    }
 #else
+    m = Py_InitModule("_capi", _libnumarrayMethods);
     c_api_object = PyCObject_FromVoidPtr((void *)libnumarray_API, NULL);
 #endif
 
@@ -3393,13 +3420,16 @@
         PyDict_SetItemString(d, "_C_API", c_api_object);
         PyDict_SetItemString(d, "error", _Error);
         Py_DECREF(c_api_object);
-    } else {
-        return;
     }
-    if (PyModule_AddObject(m, "__version__",
-                PyString_FromString("0.9")) < 0) return;
-
-    if (_import_array() < 0) return;
+    else {
+        return RETVAL;
+    }
+    if (PyModule_AddObject(m, "__version__", PyString_FromString("0.9")) < 0) {
+        return RETVAL;
+    }
+    if (_import_array() < 0) {
+        return RETVAL;
+    }
     deferred_libnumarray_init();
-    return;
+    return RETVAL;
 }



More information about the Numpy-svn mailing list