Difference between PyMODINIT_FUNC and PyModule_Create
Question: If I'm understanding correctly,

(a) PyMODINIT_FUNC in Python 2.X has been replaced by PyModule_Create in
Python3.X (b) Both return PyObject*, however, in Python 3.X, the module's
initialization function _MUST_ return the PyObject* to the module - i.e.

    
    
    PyMODINIT_FUNC
    PyInit_spam(void)
    {
         return PyModule_Create(&spammodule);
    }
    

whereas in Python2.X, this is not necessary - i.e.

    
    
     PyMODINIT_FUNC
     initspam(void)
     {
          (void) Py_InitModule("spam", SpamMethods);
     }
    

So, my sanity checking questions are: (1) Is my understanding correct? (2) Why
was this change made? Right now, I'm only experimenting with very simple cases
of C-extensions of Python. Perhaps if I were doing more, the answer to this
would be obvious, or maybe if I were trying to embed Python into something
else....


Answer:   1. Yes, your understanding is correct. You must return the new module object from the initing function with return type PyMODINIT_FUNC. (PyMODINIT_FUNC declares the function to return void in python2, and to return PyObject* in python3.)

  2. I can only speculate as to the motivations of the people who made the change, but I believe it was so that errors in importing the module could be more easily identified (you can return NULL from the module-init function in python3 if something went wrong).

