shithub: aubio

Download patch

ref: 2e4ae1df05117da3dbe3793d2289116bf11a9a4c
parent: 4041a6da578929d7b5d8b65231b3c19e08905e83
author: Paul Brossier <piem@piem.org>
date: Mon Apr 18 18:52:00 EDT 2016

ext/aubiomodule.c: prepare for python 3, see #33

--- a/python/ext/aubiomodule.c
+++ b/python/ext/aubiomodule.c
@@ -248,10 +248,25 @@
   {NULL, NULL} /* Sentinel */
 };
 
-PyMODINIT_FUNC
-init_aubio (void)
+#if PY_MAJOR_VERSION >= 3
+// Python3 module definition
+static struct PyModuleDef moduledef = {
+   PyModuleDef_HEAD_INIT,
+   "_aubio",          /* m_name */
+   aubio_module_doc,  /* m_doc */
+   -1,                /* m_size */
+   aubio_methods,     /* m_methods */
+   NULL,              /* m_reload */
+   NULL,              /* m_traverse */
+   NULL,              /* m_clear */
+   NULL,              /* m_free */
+};
+#endif
+
+static PyObject *
+initaubio (void)
 {
-  PyObject *m;
+  PyObject *m = NULL;
   int err;
 
   // fvec is defined in __init__.py
@@ -265,13 +280,17 @@
       // generated objects
       || (generated_types_ready() < 0 )
   ) {
-    return;
+    return m;
   }
 
+#if PY_MAJOR_VERSION >= 3
+  m = PyModule_Create(&moduledef);
+#else
   m = Py_InitModule3 ("_aubio", aubio_methods, aubio_module_doc);
+#endif
 
   if (m == NULL) {
-    return;
+    return m;
   }
 
   err = _import_array ();
@@ -300,4 +319,20 @@
 
   // add ufunc
   add_ufuncs(m);
+
+  return m;
 }
+
+#if PY_MAJOR_VERSION >= 3
+    // Python3 init
+    PyMODINIT_FUNC PyInit__aubio(void)
+    {
+        return initaubio();
+    }
+#else
+    // Python 2 init
+    PyMODINIT_FUNC init_aubio(void)
+    {
+        initaubio();
+    }
+#endif