diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-02-10 08:28:06 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-02-10 08:28:06 (GMT) |
commit | 1c496178d2c863f135bd4a43e32e0f099480cd06 (patch) | |
tree | d3db8cca9df26eb21cfcf6eabbc9cd67a64e35b2 /Python | |
parent | 53ae0ba6e308b383c63476177aa185a4b6f6e216 (diff) | |
download | cpython-1c496178d2c863f135bd4a43e32e0f099480cd06.zip cpython-1c496178d2c863f135bd4a43e32e0f099480cd06.tar.gz cpython-1c496178d2c863f135bd4a43e32e0f099480cd06.tar.bz2 |
Issue #25698: Importing module if the stack is too deep no longer replaces
imported module with the empty one.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/import.c | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/Python/import.c b/Python/import.c index e47ce63..96f7d47 100644 --- a/Python/import.c +++ b/Python/import.c @@ -632,27 +632,45 @@ _PyImport_FindExtension(char *name, char *filename) Because the former action is most common, THIS DOES NOT RETURN A 'NEW' REFERENCE! */ -PyObject * -PyImport_AddModule(const char *name) +static PyObject * +_PyImport_AddModuleObject(PyObject *name) { PyObject *modules = PyImport_GetModuleDict(); PyObject *m; - if ((m = PyDict_GetItemString(modules, name)) != NULL && - PyModule_Check(m)) + if ((m = _PyDict_GetItemWithError(modules, name)) != NULL && + PyModule_Check(m)) { return m; - m = PyModule_New(name); - if (m == NULL) + } + if (PyErr_Occurred()) { + return NULL; + } + m = PyModule_New(PyString_AS_STRING(name)); + if (m == NULL) { return NULL; - if (PyDict_SetItemString(modules, name, m) != 0) { + } + if (PyDict_SetItem(modules, name, m) != 0) { Py_DECREF(m); return NULL; } + assert(Py_REFCNT(m) > 1); Py_DECREF(m); /* Yes, it still exists, in modules! */ return m; } +PyObject * +PyImport_AddModule(const char *name) +{ + PyObject *nameobj, *module; + nameobj = PyString_FromString(name); + if (nameobj == NULL) + return NULL; + module = _PyImport_AddModuleObject(nameobj); + Py_DECREF(nameobj); + return module; +} + /* Remove name from sys.modules, if it's there. */ static void remove_module(const char *name) |