diff options
author | Hai Shi <shihai1992@gmail.com> | 2020-03-16 13:15:01 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-16 13:15:01 (GMT) |
commit | f707d94af68a15afc27c1a9da5835f9456259fea (patch) | |
tree | 4c442bdd62c0f213bbf5445a034503280913e4b0 /Modules/_io | |
parent | 4ab362cec6dc68c798b3e354f687cf39e207b9a9 (diff) | |
download | cpython-f707d94af68a15afc27c1a9da5835f9456259fea.zip cpython-f707d94af68a15afc27c1a9da5835f9456259fea.tar.gz cpython-f707d94af68a15afc27c1a9da5835f9456259fea.tar.bz2 |
bpo-39968: Convert extension modules' macros of get_module_state() to inline functions (GH-19017)
Diffstat (limited to 'Modules/_io')
-rw-r--r-- | Modules/_io/_iomodule.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/Modules/_io/_iomodule.c b/Modules/_io/_iomodule.c index 534d7de..5ceae62 100644 --- a/Modules/_io/_iomodule.c +++ b/Modules/_io/_iomodule.c @@ -573,13 +573,20 @@ PyNumber_AsOff_t(PyObject *item, PyObject *err) return result; } +static inline _PyIO_State* +get_io_state(PyObject *module) +{ + void *state = PyModule_GetState(module); + assert(state != NULL); + return (_PyIO_State *)state; +} _PyIO_State * _PyIO_get_module_state(void) { PyObject *mod = PyState_FindModule(&_PyIO_Module); _PyIO_State *state; - if (mod == NULL || (state = IO_MOD_STATE(mod)) == NULL) { + if (mod == NULL || (state = get_io_state(mod)) == NULL) { PyErr_SetString(PyExc_RuntimeError, "could not find io module state " "(interpreter shutdown?)"); @@ -615,7 +622,7 @@ _PyIO_get_locale_module(_PyIO_State *state) static int iomodule_traverse(PyObject *mod, visitproc visit, void *arg) { - _PyIO_State *state = IO_MOD_STATE(mod); + _PyIO_State *state = get_io_state(mod); if (!state->initialized) return 0; if (state->locale_module != NULL) { @@ -628,7 +635,7 @@ iomodule_traverse(PyObject *mod, visitproc visit, void *arg) { static int iomodule_clear(PyObject *mod) { - _PyIO_State *state = IO_MOD_STATE(mod); + _PyIO_State *state = get_io_state(mod); if (!state->initialized) return 0; if (state->locale_module != NULL) @@ -674,7 +681,7 @@ PyInit__io(void) _PyIO_State *state = NULL; if (m == NULL) return NULL; - state = IO_MOD_STATE(m); + state = get_io_state(m); state->initialized = 0; #define ADD_TYPE(type, name) \ |