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/_posixsubprocess.c | |
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/_posixsubprocess.c')
-rw-r--r-- | Modules/_posixsubprocess.c | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/Modules/_posixsubprocess.c b/Modules/_posixsubprocess.c index f9919c3..7d5a7fe 100644 --- a/Modules/_posixsubprocess.c +++ b/Modules/_posixsubprocess.c @@ -68,8 +68,15 @@ typedef struct { static struct PyModuleDef _posixsubprocessmodule; -#define _posixsubprocessstate(o) ((_posixsubprocessstate *)PyModule_GetState(o)) -#define _posixsubprocessstate_global _posixsubprocessstate(PyState_FindModule(&_posixsubprocessmodule)) +static inline _posixsubprocessstate* +get_posixsubprocess_state(PyObject *module) +{ + void *state = PyModule_GetState(module); + assert(state != NULL); + return (_posixsubprocessstate *)state; +} + +#define _posixsubprocessstate_global get_posixsubprocess_state(PyState_FindModule(&_posixsubprocessmodule)) /* If gc was disabled, call gc.enable(). Return 0 on success. */ static int @@ -944,16 +951,16 @@ static PyMethodDef module_methods[] = { static int _posixsubprocess_traverse(PyObject *m, visitproc visit, void *arg) { - Py_VISIT(_posixsubprocessstate(m)->disable); - Py_VISIT(_posixsubprocessstate(m)->enable); - Py_VISIT(_posixsubprocessstate(m)->isenabled); + Py_VISIT(get_posixsubprocess_state(m)->disable); + Py_VISIT(get_posixsubprocess_state(m)->enable); + Py_VISIT(get_posixsubprocess_state(m)->isenabled); return 0; } static int _posixsubprocess_clear(PyObject *m) { - Py_CLEAR(_posixsubprocessstate(m)->disable); - Py_CLEAR(_posixsubprocessstate(m)->enable); - Py_CLEAR(_posixsubprocessstate(m)->isenabled); + Py_CLEAR(get_posixsubprocess_state(m)->disable); + Py_CLEAR(get_posixsubprocess_state(m)->enable); + Py_CLEAR(get_posixsubprocess_state(m)->isenabled); return 0; } @@ -989,9 +996,9 @@ PyInit__posixsubprocess(void) return NULL; } - _posixsubprocessstate(m)->disable = PyUnicode_InternFromString("disable"); - _posixsubprocessstate(m)->enable = PyUnicode_InternFromString("enable"); - _posixsubprocessstate(m)->isenabled = PyUnicode_InternFromString("isenabled"); + get_posixsubprocess_state(m)->disable = PyUnicode_InternFromString("disable"); + get_posixsubprocess_state(m)->enable = PyUnicode_InternFromString("enable"); + get_posixsubprocess_state(m)->isenabled = PyUnicode_InternFromString("isenabled"); PyState_AddModule(m, &_posixsubprocessmodule); return m; |