History

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

Paul Brossier committed 10 years ago

Commit 2e4ae1d1 parent 4041a6d1 file · +40 −5Browse files

Showing the changes to python (1 of 1 file). Show all

Unified · Split

python/ext/aubiomodule.c+40−5
@@ -248,10 +248,25 @@ static PyMethodDef aubio_methods[] = { · 247 unmodified lines
248248 {NULL, NULL} /* Sentinel */
249249 };
250250
251−PyMODINIT_FUNC
252−init_aubio (void)
251+#if PY_MAJOR_VERSION >= 3
252+// Python3 module definition
253+static struct PyModuleDef moduledef = {
254+ PyModuleDef_HEAD_INIT,
255+ "_aubio", /* m_name */
256+ aubio_module_doc, /* m_doc */
257+ -1, /* m_size */
258+ aubio_methods, /* m_methods */
259+ NULL, /* m_reload */
260+ NULL, /* m_traverse */
261+ NULL, /* m_clear */
262+ NULL, /* m_free */
263+};
264+#endif
265+
266+static PyObject *
267+initaubio (void)
253268 {
254− PyObject *m;
269+ PyObject *m = NULL;
255270 int err;
256271
257272 // fvec is defined in __init__.py
@@ -265,13 +280,17 @@ init_aubio (void) · 7 unmodified lines
265280 // generated objects
266281 || (generated_types_ready() < 0 )
267282 ) {
268− return;
283+ return m;
269284 }
270285
286+#if PY_MAJOR_VERSION >= 3
287+ m = PyModule_Create(&moduledef);
288+#else
271289 m = Py_InitModule3 ("_aubio", aubio_methods, aubio_module_doc);
290+#endif
272291
273292 if (m == NULL) {
274− return;
293+ return m;
275294 }
276295
277296 err = _import_array ();
@@ -300,4 +319,20 @@ init_aubio (void) · 22 unmodified lines
300319
301320 // add ufunc
302321 add_ufuncs(m);
322+
323+ return m;
303324 }
325+
326+#if PY_MAJOR_VERSION >= 3
327+ // Python3 init
328+ PyMODINIT_FUNC PyInit__aubio(void)
329+ {
330+ return initaubio();
331+ }
332+#else
333+ // Python 2 init
334+ PyMODINIT_FUNC init_aubio(void)
335+ {
336+ initaubio();
337+ }
338+#endif

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t