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. --- Modules/arraymodule.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'Modules/arraymodule.c') diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c index fb9ebbe9f4..f532678952 100644 --- a/Modules/arraymodule.c +++ b/Modules/arraymodule.c @@ -5,6 +5,7 @@ #define PY_SSIZE_T_CLEAN #include "Python.h" +#include "pycore_moduleobject.h" // _PyModule_GetState() #include "structmember.h" // PyMemberDef #include // offsetof() @@ -63,7 +64,7 @@ typedef struct { static array_state * get_array_state(PyObject *module) { - return (array_state *)PyModule_GetState(module); + return (array_state *)_PyModule_GetState(module); } #define find_array_state_by_type(tp) \ -- cgit v1.2.1