mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
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.
This commit is contained in:
parent
a32f8fe713
commit
cdad2724e6
21 changed files with 97 additions and 47 deletions
|
@ -1,5 +1,6 @@
|
|||
#include "Python.h"
|
||||
#include "pycore_long.h" // _PyLong_GetZero()
|
||||
#include "pycore_moduleobject.h" // _PyModule_GetState()
|
||||
#include "pycore_object.h" // _PyObject_GC_TRACK
|
||||
#include "pycore_pystate.h" // _PyThreadState_GET()
|
||||
#include "pycore_tuple.h" // _PyTuple_ITEMS()
|
||||
|
@ -23,7 +24,7 @@ typedef struct _functools_state {
|
|||
static inline _functools_state *
|
||||
get_functools_state(PyObject *module)
|
||||
{
|
||||
void *state = PyModule_GetState(module);
|
||||
void *state = _PyModule_GetState(module);
|
||||
assert(state != NULL);
|
||||
return (_functools_state *)state;
|
||||
}
|
||||
|
@ -53,8 +54,7 @@ get_functools_state_by_type(PyTypeObject *type)
|
|||
if (module == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
_functools_state *state = get_functools_state(module);
|
||||
return state;
|
||||
return get_functools_state(module);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue