Skip to content

Commit

Permalink
Merge pull request scipy-lectures#401 from moble/update_numpy_c_api
Browse files Browse the repository at this point in the history
make cos_module_np 2/3 compatible
  • Loading branch information
pdebuyl authored Jan 20, 2019
2 parents 5c006c8 + b32a0b7 commit 4e784cc
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions advanced/interfacing_with_c/numpy_c_api/cos_module_np.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,36 @@ static PyMethodDef CosMethods[] =
{NULL, NULL, 0, NULL}
};


#if PY_MAJOR_VERSION >= 3
/* module initialization */
PyMODINIT_FUNC
initcos_module_np(void)
{
(void) Py_InitModule("cos_module_np", CosMethods);
/* IMPORTANT: this must be called */
import_array();
/* Python version 3*/
static struct PyModuleDef cModPyDem = {
PyModuleDef_HEAD_INIT,
"cos_module", "Some documentation",
-1,
CosMethods
};
PyMODINIT_FUNC PyInit_cos_module_np(void) {
PyObject *module;
module = PyModule_Create(&cModPyDem);
if(module==NULL) return NULL;
/* IMPORTANT: this must be called */
import_array();
if (PyErr_Occurred()) return NULL;
return module;
}

#else
/* module initialization */
/* Python version 2 */
PyMODINIT_FUNC initcos_module_np(void) {
PyObject *module;
module = Py_InitModule("cos_module_np", CosMethods);
if(module==NULL) return;
/* IMPORTANT: this must be called */
import_array();
return;
}

#endif

0 comments on commit 4e784cc

Please sign in to comment.