From: Fred Drake Date: Mon, 17 Jun 2002 17:16:11 +0000 (+0000) Subject: PyModule_AddObject(): Added missing exceptions. X-Git-Tag: 2.1~31 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=78c4095d521ceb1625e4a36f3695c8546e620bbb;p=thirdparty%2FPython%2Fcpython.git PyModule_AddObject(): Added missing exceptions. Closes SF bug #523473. --- diff --git a/Python/modsupport.c b/Python/modsupport.c index 08685898da22..1a27afd48c28 100644 --- a/Python/modsupport.c +++ b/Python/modsupport.c @@ -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