From cdad2724e6f7426372901cc5dedd8a462ba046a6 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 22 Apr 2021 00:52:52 +0200 Subject: bpo-40137: Add pycore_moduleobject.h internal header (GH-25507) Add pycore_moduleobject.h internal header file with static inline functions to access module members: * _PyModule_GetDict() * _PyModule_GetDef() * _PyModule_GetState() These functions don't check at runtime if their argument has a valid type and can be inlined even if Python is not built with LTO. _PyType_GetModuleByDef() uses _PyModule_GetDef(). Replace PyModule_GetState() with _PyModule_GetState() in the extension modules, considered as performance sensitive: * _abc * _functools * _operator * _pickle * _queue * _random * _sre * _struct * _thread * _winapi * array * posix The following extensions are now built with the Py_BUILD_CORE_MODULE macro defined, to be able to use the internal pycore_moduleobject.h header: _abc, array, _operator, _queue, _sre, _struct. --- setup.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'setup.py') diff --git a/setup.py b/setup.py index af38440955..df434d4876 100644 --- a/setup.py +++ b/setup.py @@ -869,7 +869,8 @@ class PyBuildExt(build_ext): # # array objects - self.add(Extension('array', ['arraymodule.c'])) + self.add(Extension('array', ['arraymodule.c'], + extra_compile_args=['-DPy_BUILD_CORE_MODULE'])) # Context Variables self.add(Extension('_contextvars', ['_contextvarsmodule.c'])) @@ -934,9 +935,11 @@ class PyBuildExt(build_ext): self.add(Extension("_asyncio", ["_asynciomodule.c"], extra_compile_args=['-DPy_BUILD_CORE_MODULE'])) # _abc speedups - self.add(Extension("_abc", ["_abc.c"])) + self.add(Extension("_abc", ["_abc.c"], + extra_compile_args=['-DPy_BUILD_CORE_MODULE'])) # _queue module - self.add(Extension("_queue", ["_queuemodule.c"])) + self.add(Extension("_queue", ["_queuemodule.c"], + extra_compile_args=['-DPy_BUILD_CORE_MODULE'])) # _statistics module self.add(Extension("_statistics", ["_statisticsmodule.c"])) @@ -2696,7 +2699,8 @@ def main(): 'install_lib': PyBuildInstallLib}, # The struct module is defined here, because build_ext won't be # called unless there's at least one extension module defined. - ext_modules=[Extension('_struct', ['_struct.c'])], + ext_modules=[Extension('_struct', ['_struct.c'], + extra_compile_args=['-DPy_BUILD_CORE_MODULE'])], # If you change the scripts installed here, you also need to # check the PyBuildScripts command above, and change the links -- cgit v1.2.1