Difference between PyMODINIT_FUNC and PyModule_Create

后端 未结 1 362
时光说笑
时光说笑 2021-01-04 04:07

If I\'m understanding correctly,

  1. PyMODINIT_FUNC in Python 2.X has been replaced by PyModule_Create in Python3.X
  2. Both return PyO

1条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-04 04:25

    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).

    0 讨论(0)
提交回复
热议问题