Use PyModule_AddObject() instead of accessing the module dict directly.
diff --git a/Modules/termios.c b/Modules/termios.c
index 3362e81..aaabe60 100644
--- a/Modules/termios.c
+++ b/Modules/termios.c
@@ -891,15 +891,17 @@
 DL_EXPORT(void)
 PyInit_termios(void)
 {
-	PyObject *m, *d;
+	PyObject *m;
 	struct constant *constant = termios_constants;
 
 	m = Py_InitModule4("termios", termios_methods, termios__doc__,
                            (PyObject *)NULL, PYTHON_API_VERSION);
 
-	d = PyModule_GetDict(m);
-	TermiosError = PyErr_NewException("termios.error", NULL, NULL);
-	PyDict_SetItemString(d, "error", TermiosError);
+	if (TermiosError == NULL) {
+		TermiosError = PyErr_NewException("termios.error", NULL, NULL);
+	}
+	Py_INCREF(TermiosError);
+	PyModule_AddObject(m, "error", TermiosError);
 
 	while (constant->name != NULL) {
 		PyModule_AddIntConstant(m, constant->name, constant->value);