summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2013-10-31 13:51:38 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2013-10-31 13:51:38 (GMT)
commitae233eab5cc9a932a80063003602fd0a62e4be05 (patch)
tree97402ba791b6cef9fad69ca4279c41fa23b01c56
parent3cd04aa1b2ddf27d089d5837c0d2e3ba34b02c5c (diff)
downloadcpython-ae233eab5cc9a932a80063003602fd0a62e4be05.zip
cpython-ae233eab5cc9a932a80063003602fd0a62e4be05.tar.gz
cpython-ae233eab5cc9a932a80063003602fd0a62e4be05.tar.bz2
Issue #19437: Fix show_warning() of _warnings, stop at the first error to not
call a Python function with an exception set
-rw-r--r--Python/_warnings.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/Python/_warnings.c b/Python/_warnings.c
index 74ac8c6..d9f3297 100644
--- a/Python/_warnings.c
+++ b/Python/_warnings.c
@@ -263,23 +263,28 @@ show_warning(PyObject *filename, int lineno, PyObject *text, PyObject
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 @@ show_warning(PyObject *filename, int lineno, PyObject *text, PyObject
}
error:
+ Py_XDECREF(name);
PyErr_Clear();
}