encukou / py3c

A Python 2/3 compatibility layer for C extensions
http://py3c.readthedocs.org
MIT License
59 stars 20 forks source link

Align PyModuleDef with Python 3, fixes encukou/py3c#34 #35

Closed javaprog closed 3 years ago

javaprog commented 3 years ago

By extending the PyModuleDef struct for Python 2 with the fields present in Python 3, client code can provide field initializers to avoid the -Wmissing-field-initializers compiler warning.

encukou commented 3 years ago

Thanks for the PR. py3c should also explicitly check that these are set to NULL in Python 2, so people can't use them where they don't work.

javaprog commented 3 years ago

py3c should also explicitly check that these are set to NULL in Python 2, so people can't use them where they don't work.

Good idea - how would you try to achieve that? My approach would be to turn the macro PyModule_Create into a function and have it check the members of the passed struct before calling PyInit_Module3.

encukou commented 3 years ago

Yes, a static function sounds right for this. I guess it would also be possible to make it a macro using the ternary operator, but that might make it unreadable.

On November 25, 2020 5:02:45 PM GMT+01:00, Michael Rudolf notifications@github.com wrote:

py3c should also explicitly check that these are set to NULL in Python 2, so people can't use them where they don't work.

Good idea - how would you try to achieve that? My approach would be to turn the macro PyModule_Create into a function and have it check the members of the passed struct before calling PyInit_Module3.

-- You are receiving this because you commented. Reply to this email directly or view it on GitHub: https://github.com/encukou/py3c/pull/35#issuecomment-733797503

-- Sent from my Android device with K-9 Mail. Please excuse my brevity.

encukou commented 3 years ago

Thanks! I've added some documentation, and rebased to avoid a CHANGELOG conflict.