Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8311518

Browse files
committed
PyModule_AddObject(): Added missing exceptions.
Closes SF bug #523473.
1 parent b084017 commit 8311518

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

Python/modsupport.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -488,15 +488,22 @@ int
488488
PyModule_AddObject(PyObject *m, char *name, PyObject *o)
489489
{
490490
PyObject *dict;
491-
if (!PyModule_Check(m) || o == NULL)
492-
return -1;
491+
if (!PyModule_Check(m) || o == NULL) {
492+
PyErr_SetString(PyExc_TypeError,
493+
"PyModule_AddObject() needs module as first arg");
494+
return -1;
495+
}
493496
dict = PyModule_GetDict(m);
494-
if (dict == NULL)
497+
if (dict == NULL) {
498+
/* Internal error -- modules must have a dict! */
499+
PyErr_Format(PyExc_SystemError, "module '%s' has no __dict__",
500+
PyModule_GetName(m));
501+
return -1;
502+
}
503+
if (PyDict_SetItemString(dict, name, o))
495504
return -1;
496-
if (PyDict_SetItemString(dict, name, o))
497-
return -1;
498-
Py_DECREF(o);
499-
return 0;
505+
Py_DECREF(o);
506+
return 0;
500507
}
501508

502509
int

0 commit comments

Comments
 (0)