]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
PyModule_AddObject(): Added missing exceptions.
authorFred Drake <fdrake@acm.org>
Mon, 17 Jun 2002 17:16:11 +0000 (17:16 +0000)
committerFred Drake <fdrake@acm.org>
Mon, 17 Jun 2002 17:16:11 +0000 (17:16 +0000)
Closes SF bug #523473.

Python/modsupport.c

index 08685898da222abc3bb06f06a92595661eb2df78..1a27afd48c28d52f2faa2b05b080d325c23ecc9a 100644 (file)
@@ -467,15 +467,22 @@ int
 PyModule_AddObject(PyObject *m, char *name, PyObject *o)
 {
        PyObject *dict;
-        if (!PyModule_Check(m) || o == NULL)
-                return -1;
+       if (!PyModule_Check(m) || o == NULL) {
+               PyErr_SetString(PyExc_TypeError,
+                           "PyModule_AddObject() needs module as first arg");
+               return -1;
+       }
        dict = PyModule_GetDict(m);
-       if (dict == NULL)
+       if (dict == NULL) {
+               /* Internal error -- modules must have a dict! */
+               PyErr_Format(PyExc_SystemError, "module '%s' has no __dict__",
+                            PyModule_GetName(m));
+               return -1;
+       }
+       if (PyDict_SetItemString(dict, name, o))
                return -1;
-        if (PyDict_SetItemString(dict, name, o))
-                return -1;
-        Py_DECREF(o);
-        return 0;
+       Py_DECREF(o);
+       return 0;
 }
 
 int