This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients petr.viktorin, rhettinger, shihai1991, tim.peters, vstinner
Date 2020-03-16.13:21:03
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1584364863.54.0.0203350964586.issue39968@roundup.psfhosted.org>
In-reply-to
Content
There are multiple good reasons to replace macros with static inline functions:

* Parameter types and return value are well defined
* Less error-prone: avoid completely https://gcc.gnu.org/onlinedocs/gcc-9.3.0/cpp/Macro-Pitfalls.html#Macro-Pitfalls
* Variables have a well defined scope, reduce the risk of unexpected side effects

I merged the PR 19017: it uses better names for the function and it adds assert(state != NULL).

Be careful of bpo-39824: in some cases, the module state *can* be NULL: but I checked, and it's not the case here. Moreover, bpo-39824 may prevent NULL module state (let's see ;-)).

Thanks Hai Shi!


> minor disadvantage in code generation

Micro-benchmarks and machine code analysis was done in previous issues replacing macros with static inline functions, and the outcome is that there is no effect on performance. See for example bpo-35059: performance critical Py_INCREF() and Py_DECREF() functions are now static inline functions.

If someone is curious about the the machine code, you should use -O3 with PGO+LTO, which is what should be used on Linux distributions. If static inline functions are not inlined for whatever reason, I suggest to tune the compiler rather than moving back to ugly macros.

If you use configure --enable-shared, I now also strongly suggest to use -fno-semantic-interposition: it's now used on Fedora and RHEL to build Python libpython.

Note: Support for "static inline" is now explicitly required by the PEP 7 to build Python, since Python 3.6. And it's more and more used in Python header files.
History
Date User Action Args
2020-03-16 13:21:03vstinnersetrecipients: + vstinner, tim.peters, rhettinger, petr.viktorin, shihai1991
2020-03-16 13:21:03vstinnersetmessageid: <1584364863.54.0.0203350964586.issue39968@roundup.psfhosted.org>
2020-03-16 13:21:03vstinnerlinkissue39968 messages
2020-03-16 13:21:03vstinnercreate