summaryrefslogtreecommitdiffstats
path: root/Modules/zlibmodule.c
diff options
context:
space:
mode:
authorHai Shi <shihai1992@gmail.com>2020-03-16 13:15:01 (GMT)
committerGitHub <noreply@github.com>2020-03-16 13:15:01 (GMT)
commitf707d94af68a15afc27c1a9da5835f9456259fea (patch)
tree4c442bdd62c0f213bbf5445a034503280913e4b0 /Modules/zlibmodule.c
parent4ab362cec6dc68c798b3e354f687cf39e207b9a9 (diff)
downloadcpython-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/zlibmodule.c')
-rw-r--r--Modules/zlibmodule.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c
index 3e77080..49d231a 100644
--- a/Modules/zlibmodule.c
+++ b/Modules/zlibmodule.c
@@ -40,7 +40,14 @@ typedef struct {
PyObject *ZlibError;
} _zlibstate;
-#define _zlibstate(o) ((_zlibstate *)PyModule_GetState(o))
+static inline _zlibstate*
+get_zlib_state(PyObject *module)
+{
+ void *state = PyModule_GetState(module);
+ assert(state != NULL);
+ return (_zlibstate *)state;
+}
+
#define _zlibstate_global ((_zlibstate *)PyModule_GetState(PyState_FindModule(&zlibmodule)))
typedef struct
@@ -1364,7 +1371,7 @@ PyDoc_STRVAR(zlib_module_documentation,
static int
zlib_clear(PyObject *m)
{
- _zlibstate *state = _zlibstate(m);
+ _zlibstate *state = get_zlib_state(m);
Py_CLEAR(state->Comptype);
Py_CLEAR(state->Decomptype);
Py_CLEAR(state->ZlibError);
@@ -1374,7 +1381,7 @@ zlib_clear(PyObject *m)
static int
zlib_traverse(PyObject *m, visitproc visit, void *arg)
{
- _zlibstate *state = _zlibstate(m);
+ _zlibstate *state = get_zlib_state(m);
Py_VISIT(state->Comptype);
Py_VISIT(state->Decomptype);
Py_VISIT(state->ZlibError);
@@ -1415,18 +1422,18 @@ PyInit_zlib(void)
PyTypeObject *Comptype = (PyTypeObject *)PyType_FromSpec(&Comptype_spec);
if (Comptype == NULL)
return NULL;
- _zlibstate(m)->Comptype = Comptype;
+ get_zlib_state(m)->Comptype = Comptype;
PyTypeObject *Decomptype = (PyTypeObject *)PyType_FromSpec(&Decomptype_spec);
if (Decomptype == NULL)
return NULL;
- _zlibstate(m)->Decomptype = Decomptype;
+ get_zlib_state(m)->Decomptype = Decomptype;
PyObject *ZlibError = PyErr_NewException("zlib.error", NULL, NULL);
if (ZlibError != NULL) {
Py_INCREF(ZlibError);
PyModule_AddObject(m, "error", ZlibError);
- _zlibstate(m)->ZlibError = ZlibError;
+ get_zlib_state(m)->ZlibError = ZlibError;
}
PyModule_AddIntMacro(m, MAX_WBITS);
PyModule_AddIntMacro(m, DEFLATED);