summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorOren Milman <orenmn@gmail.com>2017-09-24 18:28:42 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2017-09-24 18:28:42 (GMT)
commit5d3e80021ab33360191eb0fbff34e0246c913884 (patch)
tree0dffddad98a53919973af779ec935c8cb449a4d9 /Python
parent91fb0afe181986b48abfc6092dcca912b39de51d (diff)
downloadcpython-5d3e80021ab33360191eb0fbff34e0246c913884.zip
cpython-5d3e80021ab33360191eb0fbff34e0246c913884.tar.gz
cpython-5d3e80021ab33360191eb0fbff34e0246c913884.tar.bz2
bpo-31566: Fix an assertion failure in _warnings.warn() in case of a bad __name__ global. (#3717)
Diffstat (limited to 'Python')
-rw-r--r--Python/_warnings.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/Python/_warnings.c b/Python/_warnings.c
index f56e92d..4ea9fce 100644
--- a/Python/_warnings.c
+++ b/Python/_warnings.c
@@ -684,13 +684,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__");