From 2c5d1ab857fa38d1a2233fc5e0046d9509d8e9f7 Mon Sep 17 00:00:00 2001 From: Fred Drake Date: Mon, 17 Jun 2002 17:16:34 +0000 Subject: [PATCH] PyModule_AddObject(): Added missing exceptions. Closes SF bug #523473. --- Python/modsupport.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/Python/modsupport.c b/Python/modsupport.c index 0450a8a1c084..cff9a02aa4c0 100644 --- a/Python/modsupport.c +++ b/Python/modsupport.c @@ -481,15 +481,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 -- 2.47.3