-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
The post on Python modules in C is one of the best introductory post which I have ever seen on that topic. It will be great if it could be updated to work with Python3. To make it work, we need to do the following changes:
- Use
PyModuleDefto define the module in _chi2.c
static PyModuleDef chi2_module = {
PyModuleDef_HEAD_INIT,
.m_name = "_chi2",
.m_doc = module_docstring,
.m_size = -1,
.m_methods = module_methods,
};- Use
PyInit__chi2instead ofinit_chi2, update the function to return NULL when the module does not get initialized andPyModule_Createinstead ofPy_InitModule3. The updated version:
PyMODINIT_FUNC PyInit__chi2(void)
{
PyObject *m = PyModule_Create(&chi2_module);
if (m == NULL) {
return NULL;
}
/* Load numpy functionality */
import_array();
return m;
}Thank you for the wonderful post.
Metadata
Metadata
Assignees
Labels
No labels