[3.6] bpo-31566: Fix an assertion failure in _warnings.warn() in case of a bad __name__ global. (GH-3717) (#3730)

(cherry picked from commit 5d3e80021a)
This commit is contained in:
Miss Islington (bot) 2017-09-24 13:14:41 -07:00 committed by Serhiy Storchaka
parent ce418bf822
commit 415cc1fa57
3 changed files with 16 additions and 3 deletions

View file

@ -694,13 +694,14 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno,
/* Setup module. */
*module = PyDict_GetItemString(globals, "__name__");
if (*module == NULL) {
if (*module == Py_None || (*module != NULL && PyUnicode_Check(*module))) {
Py_INCREF(*module);
}
else {
*module = PyUnicode_FromString("<string>");
if (*module == NULL)
goto handle_error;
}
else
Py_INCREF(*module);
/* Setup filename. */
*filename = PyDict_GetItemString(globals, "__file__");