Mercurial > cpython-lru_cache-weakref
diff Python/modsupport.c @ 23887:1cef61d59478 2.2
PyModule_AddObject(): Added missing exceptions.
Closes SF bug #523473.
| author | Fred Drake <fdrake@acm.org> |
|---|---|
| date | Mon, 17 Jun 2002 17:16:34 +0000 |
| parents | 7257e87e0720 |
| children | 608735dd2ebc |
line wrap: on
line diff
--- a/Python/modsupport.c Mon Jun 17 15:45:21 2002 +0000 +++ b/Python/modsupport.c Mon Jun 17 17:16:34 2002 +0000 @@ -481,15 +481,22 @@ PyModule_AddObject(PyObject *m, char *name, PyObject *o) { PyObject *dict; - if (!PyModule_Check(m) || o == NULL) - return -1; - dict = PyModule_GetDict(m); - if (dict == NULL) + if (!PyModule_Check(m) || o == NULL) { + PyErr_SetString(PyExc_TypeError, + "PyModule_AddObject() needs module as first arg"); return -1; - if (PyDict_SetItemString(dict, name, o)) - return -1; - Py_DECREF(o); - return 0; + } + dict = PyModule_GetDict(m); + 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; + Py_DECREF(o); + return 0; } int
