summaryrefslogtreecommitdiffstats
path: root/Modules/termios.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/termios.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/termios.c')
-rw-r--r--Modules/termios.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/Modules/termios.c b/Modules/termios.c
index 0fd93c0..75e5e52 100644
--- a/Modules/termios.c
+++ b/Modules/termios.c
@@ -42,8 +42,16 @@ sys.stdin.fileno(), or a file object, such as sys.stdin itself.");
typedef struct {
PyObject *TermiosError;
} termiosmodulestate;
-#define modulestate(o) ((termiosmodulestate *)PyModule_GetState(o))
-#define modulestate_global modulestate(PyState_FindModule(&termiosmodule))
+
+static inline termiosmodulestate*
+get_termios_state(PyObject *module)
+{
+ void *state = PyModule_GetState(module);
+ assert(state != NULL);
+ return (termiosmodulestate *)state;
+}
+
+#define modulestate_global get_termios_state(PyState_FindModule(&termiosmodule))
static int fdconv(PyObject* obj, void* p)
{
@@ -976,12 +984,12 @@ static struct constant {
};
static int termiosmodule_traverse(PyObject *m, visitproc visit, void *arg) {
- Py_VISIT(modulestate(m)->TermiosError);
+ Py_VISIT(get_termios_state(m)->TermiosError);
return 0;
}
static int termiosmodule_clear(PyObject *m) {
- Py_CLEAR(modulestate(m)->TermiosError);
+ Py_CLEAR(get_termios_state(m)->TermiosError);
return 0;
}
@@ -1016,7 +1024,7 @@ PyInit_termios(void)
return NULL;
}
- termiosmodulestate *state = PyModule_GetState(m);
+ termiosmodulestate *state = get_termios_state(m);
state->TermiosError = PyErr_NewException("termios.error", NULL, NULL);
if (state->TermiosError == NULL) {
return NULL;