summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-05-22 22:35:04 (GMT)
committerGuido van Rossum <guido@python.org>1997-05-22 22:35:04 (GMT)
commit78a1ed3d701590201a6865abd0f227ff7d591eb4 (patch)
tree93b87e422513da8c1602b111358786e943b9d87b /Python
parentbe27026c09f24e40ee26db86e8275783c91398a1 (diff)
downloadcpython-78a1ed3d701590201a6865abd0f227ff7d591eb4.zip
cpython-78a1ed3d701590201a6865abd0f227ff7d591eb4.tar.gz
cpython-78a1ed3d701590201a6865abd0f227ff7d591eb4.tar.bz2
Py_FlushLine and PyFile_WriteString now return error indicators
instead of calling PyErr_Clear(). Add checking of those errors.
Diffstat (limited to 'Python')
-rw-r--r--Python/pythonrun.c71
1 files changed, 41 insertions, 30 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index f5405a3..fdfb8c6 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -56,12 +56,6 @@ PERFORMANCE OF THIS SOFTWARE.
#include "windows.h"
#endif
-#ifdef HAVE_GETPID
-#ifndef MS_WINDOWS
-#define HAVE_KILL
-#endif
-#endif
-
extern char *Py_GetPath();
extern grammar _PyParser_Grammar; /* From graminit.c */
@@ -260,7 +254,8 @@ PyRun_InteractiveOne(fp, filename)
return -1;
}
Py_DECREF(v);
- Py_FlushLine();
+ if (Py_FlushLine())
+ PyErr_Clear();
return 0;
}
@@ -302,7 +297,8 @@ PyRun_SimpleFile(fp, filename)
return -1;
}
Py_DECREF(v);
- Py_FlushLine();
+ if (Py_FlushLine())
+ PyErr_Clear();
return 0;
}
@@ -321,20 +317,22 @@ PyRun_SimpleString(command)
return -1;
}
Py_DECREF(v);
- Py_FlushLine();
+ if (Py_FlushLine())
+ PyErr_Clear();
return 0;
}
void
PyErr_Print()
{
+ int err = 0;
PyObject *exception, *v, *tb, *f;
PyErr_Fetch(&exception, &v, &tb);
- Py_FlushLine();
- fflush(stdout);
if (exception == NULL)
- Py_FatalError("PyErr_Print called but no exception");
+ return 0;
if (exception == PyExc_SystemExit) {
+ err = Py_FlushLine();
+ fflush(stdout);
if (v == NULL || v == Py_None)
Py_Exit(0);
if (PyInt_Check(v))
@@ -353,8 +351,11 @@ PyErr_Print()
if (f == NULL)
fprintf(stderr, "lost sys.stderr\n");
else {
- PyTraceBack_Print(tb, f);
- if (exception == PyExc_SyntaxError) {
+ err = Py_FlushLine();
+ fflush(stdout);
+ if (err == 0)
+ err = PyTraceBack_Print(tb, f);
+ if (err == 0 && exception == PyExc_SyntaxError) {
PyObject *message;
char *filename, *text;
int lineno, offset;
@@ -405,33 +406,43 @@ PyErr_Print()
Py_INCREF(message);
Py_DECREF(v);
v = message;
+ /* Can't be bothered to check all those
+ PyFile_WriteString() calls */
+ if (PyErr_Occurred())
+ err = -1;
}
}
- if (PyClass_Check(exception)) {
+ if (err) {
+ /* Don't do anything else */
+ }
+ else if (PyClass_Check(exception)) {
PyObject* className =
((PyClassObject*)exception)->cl_name;
if (className == NULL)
- PyFile_WriteString("<unknown>", f);
- else {
- if (PyFile_WriteObject(className, f,
- Py_PRINT_RAW) != 0)
- PyErr_Clear();
- }
- } else {
- if (PyFile_WriteObject(exception, f,
- Py_PRINT_RAW) != 0)
- PyErr_Clear();
+ err = PyFile_WriteString("<unknown>", f);
+ else
+ err = PyFile_WriteObject(className, f,
+ Py_PRINT_RAW);
}
- if (v != NULL && v != Py_None) {
- PyFile_WriteString(": ", f);
- if (PyFile_WriteObject(v, f, Py_PRINT_RAW) != 0)
- PyErr_Clear();
+ else
+ err = PyFile_WriteObject(exception, f, Py_PRINT_RAW);
+ if (err == 0) {
+ if (v != NULL && v != Py_None) {
+ err = PyFile_WriteString(": ", f);
+ if (err == 0)
+ err = PyFile_WriteObject(v, f, Py_PRINT_RAW);
+ }
}
- PyFile_WriteString("\n", f);
+ if (err == 0)
+ err = PyFile_WriteString("\n", f);
}
Py_XDECREF(exception);
Py_XDECREF(v);
Py_XDECREF(tb);
+ /* If an error happened here, don't show it.
+ XXX This is wrong, but too many callers rely on this behavior. */
+ if (err != 0)
+ PyErr_Clear();
}
PyObject *