From the Extending Python with C or C++ docs(Python3),
The initialization function must be named PyInit_name()
, where name is the name of the module, and should be the only non-static item defined in the module file:
PyMODINIT_FUNC
PyInit_spam(void)
{
return PyModule_Create(&spammodule);
}
You can also find the same pattern all over the cpython source code(python3)
Whereas in Extending Python with C or C++ docs(Python2)
The initialization function must be named initname()
, where name is the name of the module, and should be the only non-static item defined in the module file:
PyMODINIT_FUNC
initspam(void)
{
(void) Py_InitModule("spam", SpamMethods);
}
So to answer your question the name matters. If you are writing an extension compatible to both python2 and python3 you have to implement the module init like this,
#if PY_MAJOR_VERSION < 3
PyMODINIT_FUNC
init_modulename(void)
{
return yourmoduleinit();
}
#else
PyMODINIT_FUNC
PyInit_modulename(void)
{
return yourmoduleinit();
}
#endif
Note: PyMODINIT_FUNC void init_foo(void) {...}
this one is actually python2 version and the module name used to import this c-extension would be _foo
Convention used to denote [internal c-extension]