summaryrefslogtreecommitdiffstats
path: root/Modules/termios.c
diff options
context:
space:
mode:
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;