Mercurial > cpython-lru_cache-weakref
diff Python/_warnings.c @ 86802:e035b4656088
Issue #19437: Fix show_warning() of _warnings, stop at the first error to not
call a Python function with an exception set
| author | Victor Stinner <victor.stinner@gmail.com> |
|---|---|
| date | Thu, 31 Oct 2013 14:51:38 +0100 |
| parents | 9b37fbda9043 |
| children | 13a05ed33cf7 |
line wrap: on
line diff
--- a/Python/_warnings.c Thu Oct 31 14:46:00 2013 +0100 +++ b/Python/_warnings.c Thu Oct 31 14:51:38 2013 +0100 @@ -263,23 +263,28 @@ name = _PyObject_GetAttrId(category, &PyId___name__); if (name == NULL) /* XXX Can an object lack a '__name__' attribute? */ - return; + goto error; f_stderr = PySys_GetObject("stderr"); if (f_stderr == NULL) { fprintf(stderr, "lost sys.stderr\n"); - Py_DECREF(name); - return; + goto error; } /* Print "filename:lineno: category: text\n" */ - PyFile_WriteObject(filename, f_stderr, Py_PRINT_RAW); - PyFile_WriteString(lineno_str, f_stderr); - PyFile_WriteObject(name, f_stderr, Py_PRINT_RAW); - PyFile_WriteString(": ", f_stderr); - PyFile_WriteObject(text, f_stderr, Py_PRINT_RAW); - PyFile_WriteString("\n", f_stderr); - Py_XDECREF(name); + if (PyFile_WriteObject(filename, f_stderr, Py_PRINT_RAW) < 0) + goto error; + if (PyFile_WriteString(lineno_str, f_stderr) < 0) + goto error; + if (PyFile_WriteObject(name, f_stderr, Py_PRINT_RAW) < 0) + goto error; + if (PyFile_WriteString(": ", f_stderr) < 0) + goto error; + if (PyFile_WriteObject(text, f_stderr, Py_PRINT_RAW) < 0) + goto error; + if (PyFile_WriteString("\n", f_stderr) < 0) + goto error; + Py_CLEAR(name); /* Print " source_line\n" */ if (sourceline) { @@ -314,6 +319,7 @@ } error: + Py_XDECREF(name); PyErr_Clear(); }
