diff options
author | Victor Stinner <vstinner@python.org> | 2021-04-22 00:52:52 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-22 00:52:52 +0200 |
commit | cdad2724e6f7426372901cc5dedd8a462ba046a6 (patch) | |
tree | ca6a34bfdc6c05ea86d2ff2686ebd116750b2305 /Objects/moduleobject.c | |
parent | a32f8fe7133aad4f3cf8946534e3b79a5f2659da (diff) | |
download | cpython-git-cdad2724e6f7426372901cc5dedd8a462ba046a6.tar.gz |
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.
Diffstat (limited to 'Objects/moduleobject.c')
-rw-r--r-- | Objects/moduleobject.c | 19 |
1 files changed, 4 insertions, 15 deletions
diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c index e57ea86e76..a6eb85bdc2 100644 --- a/Objects/moduleobject.c +++ b/Objects/moduleobject.c @@ -4,6 +4,7 @@ #include "Python.h" #include "pycore_interp.h" // PyInterpreterState.importlib #include "pycore_pystate.h" // _PyInterpreterState_GET() +#include "pycore_moduleobject.h" // _PyModule_GetDef() #include "structmember.h" // PyMemberDef static Py_ssize_t max_module_number; @@ -12,15 +13,6 @@ _Py_IDENTIFIER(__doc__); _Py_IDENTIFIER(__name__); _Py_IDENTIFIER(__spec__); -typedef struct { - PyObject_HEAD - PyObject *md_dict; - struct PyModuleDef *md_def; - void *md_state; - PyObject *md_weaklist; - PyObject *md_name; /* for logging purposes after md_dict is cleared */ -} PyModuleObject; - static PyMemberDef module_members[] = { {"__dict__", T_OBJECT, offsetof(PyModuleObject, md_dict), READONLY}, {0} @@ -469,14 +461,11 @@ PyModule_SetDocString(PyObject *m, const char *doc) PyObject * PyModule_GetDict(PyObject *m) { - PyObject *d; if (!PyModule_Check(m)) { PyErr_BadInternalCall(); return NULL; } - d = ((PyModuleObject *)m) -> md_dict; - assert(d != NULL); - return d; + return _PyModule_GetDict(m); } PyObject* @@ -556,7 +545,7 @@ PyModule_GetDef(PyObject* m) PyErr_BadArgument(); return NULL; } - return ((PyModuleObject *)m)->md_def; + return _PyModule_GetDef(m); } void* @@ -566,7 +555,7 @@ PyModule_GetState(PyObject* m) PyErr_BadArgument(); return NULL; } - return ((PyModuleObject *)m)->md_state; + return _PyModule_GetState(m); } void |