summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2017-09-24 20:14:41 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2017-09-24 20:14:41 (GMT)
commit415cc1fa57710614ed3384d0cafc58ccf7adee8c (patch)
treeb460136b8b15d4deec84f82cc232caa1d5694d31 /Python
parentce418bf8228c9a6a19702638e5f5c2fb66ad0588 (diff)
downloadcpython-415cc1fa57710614ed3384d0cafc58ccf7adee8c.zip
cpython-415cc1fa57710614ed3384d0cafc58ccf7adee8c.tar.gz
cpython-415cc1fa57710614ed3384d0cafc58ccf7adee8c.tar.bz2
[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 5d3e80021ab33360191eb0fbff34e0246c913884)
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 7270d2c..b074788 100644
--- a/Python/_warnings.c
+++ b/Python/_warnings.c
@@ -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__");