]> granicus.if.org Git - python/commitdiff
Use PyModule_AddObject() instead of accessing the module dict directly.
authorFred Drake <fdrake@acm.org>
Thu, 14 Feb 2002 07:11:23 +0000 (07:11 +0000)
committerFred Drake <fdrake@acm.org>
Thu, 14 Feb 2002 07:11:23 +0000 (07:11 +0000)
Modules/structmodule.c
Modules/termios.c

index 8cc494506348dc562479b191554907b3c0455dce..86ac366c9f4acccd0a6692a28724b2336986057a 100644 (file)
@@ -1502,16 +1502,18 @@ static PyMethodDef struct_methods[] = {
 DL_EXPORT(void)
 initstruct(void)
 {
-       PyObject *m, *d;
+       PyObject *m;
 
        /* Create the module and add the functions */
        m = Py_InitModule4("struct", struct_methods, struct__doc__,
                           (PyObject*)NULL, PYTHON_API_VERSION);
 
        /* Add some symbolic constants to the module */
-       d = PyModule_GetDict(m);
-       StructError = PyErr_NewException("struct.error", NULL, NULL);
-       if (StructError == NULL)
-               return;
-       PyDict_SetItemString(d, "error", StructError);
+       if (StructError == NULL) {
+               StructError = PyErr_NewException("struct.error", NULL, NULL);
+               if (StructError == NULL)
+                       return;
+       }
+       Py_INCREF(StructError);
+       PyModule_AddObject(d, "error", StructError);
 }
index 3362e8158c2abaea17b141562b8fae38c9f5065b..aaabe6034f96c722a38c8c27b831eedb73cc4ba4 100644 (file)
@@ -891,15 +891,17 @@ static struct constant {
 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);