New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
port extension modules' macros of get_module_state()
to inline function.
#84149
Comments
get_xx_state()
to inline function.get_module_state()
to inline function.
get_xx_state()
to inline function.get_module_state()
to inline function.
get_module_state()
to inline function.get_module_state()
to inline function.
get_module_state()
to inline function.get_module_state()
to inline function.
Tim, do you approve of this kind of wholesale macro-to-inline function conversion? My thought is that in most cases, there is no advantage to conversion and that sometimes there will be minor disadvantage in code generation when the macro is used across files. I like inline functions as well as next person, but that doesn't mean all macros have to be rewritten. Mostly, this seems like unnecessary code churn. |
There are multiple good reasons to replace macros with static inline functions:
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!
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. |
Note: Hai Shi is working hard on converting modules to multiphase module initialization (PEP-489) which helps to cleanup the Python state at exit, and subinterpreters will likely benefit of that. This issue is related to this work. |
Oh, I forgot a cool advantage that I discovered late: debuggers and profilers understand inlined code and are able to get the name of the static inline function, whereas it's not possible to do that with macros. If I recall correctly, it works even if the function is inlined. |
Wow, thanks, victor. those msgs is very helpful to me. |
Compile is failure after PR 19017 is merged on macOS. |
I reopen this issue for the above problem |
|
Oh, macOS job was marked as success on PR 19017 :-( But I confirm that I can read there: """ |
yeah, it's weird. This macOS job should be enhanced? |
setup.py skips optional dependencies like readline on purpose. readline is built again onx86-64 macOS 3.x buildbot worker and test_readline passed. I close the issue. Thanks for the quick fix. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: