Skip to content

Commit 78c4095

Browse files
committed
PyModule_AddObject(): Added missing exceptions.
Closes SF bug #523473.
1 parent f89e4dd commit 78c4095

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

Python/modsupport.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -467,15 +467,22 @@ int
467467
PyModule_AddObject(PyObject *m, char *name, PyObject *o)
468468
{
469469
PyObject *dict;
470-
if (!PyModule_Check(m) || o == NULL)
471-
return -1;
470+
if (!PyModule_Check(m) || o == NULL) {
471+
PyErr_SetString(PyExc_TypeError,
472+
"PyModule_AddObject() needs module as first arg");
473+
return -1;
474+
}
472475
dict = PyModule_GetDict(m);
473-
if (dict == NULL)
476+
if (dict == NULL) {
477+
/* Internal error -- modules must have a dict! */
478+
PyErr_Format(PyExc_SystemError, "module '%s' has no __dict__",
479+
PyModule_GetName(m));
480+
return -1;
481+
}
482+
if (PyDict_SetItemString(dict, name, o))
474483
return -1;
475-
if (PyDict_SetItemString(dict, name, o))
476-
return -1;
477-
Py_DECREF(o);
478-
return 0;
484+
Py_DECREF(o);
485+
return 0;
479486
}
480487

481488
int

0 commit comments

Comments
 (0)