Remove the return value of macros having a return value, whereas they should not, to aid detecting bugs in C extensions when the C API is misused. The

PEP 670 -- Convert macros to functions in the Python C API | Python.org

submited by
Style Pass
2021-10-20 16:00:15

Remove the return value of macros having a return value, whereas they should not, to aid detecting bugs in C extensions when the C API is misused.

The use of macros may have unintended adverse effects that are hard to avoid, even for experienced C developers. Some issues have been known for years, while others have been discovered recently in Python. Working around macro pitfalls makes the macro coder harder to read and to maintain.

Converting macros and static inline functions to regular functions makes these regular functions accessible to projects which use Python but cannot use macros and static inline functions.

Static inline functions is a feature added to the C99 standard. Modern C compilers have efficient heuristics to decide if a function should be inlined or not.

When a C compiler decides to not inline, there is likely a good reason. For example, inlining would reuse a register which require to save/restore the register value on the stack and so increase the stack memory usage or be less efficient.

Leave a Comment
Related Posts