diff options
author | Guido van Rossum <guido@python.org> | 1997-05-22 22:25:11 +0000 |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1997-05-22 22:25:11 +0000 |
commit | f5e45ea0514d8163853e4911ca2681c462465ff3 (patch) | |
tree | 666d9904b4117f817c9a359f4988d01193c6df6d /Objects | |
parent | 03a3bb30b8e8bf111449353bca0d32cee11381dd (diff) | |
download | cpython-f5e45ea0514d8163853e4911ca2681c462465ff3.tar.gz |
PyFile_WriteString now returns an error indicator instead of calling
PyErr_Clear().
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/fileobject.c | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/Objects/fileobject.c b/Objects/fileobject.c index 1d85e20e55..9547d5d82d 100644 --- a/Objects/fileobject.c +++ b/Objects/fileobject.c @@ -997,28 +997,34 @@ PyFile_WriteObject(v, f, flags) return 0; } -void +int PyFile_WriteString(s, f) char *s; PyObject *f; { if (f == NULL) { - /* Do nothing */ + /* Should be caused by a pre-existing error */ + if(!PyErr_Occurred()) + PyErr_SetString(PyExc_SystemError, + "null file for PyFile_WriteString"); + return -1; } else if (PyFile_Check(f)) { FILE *fp = PyFile_AsFile(f); - if (fp != NULL) - fputs(s, fp); + if (fp == NULL) { + err_closed(); + return -1; + } + fputs(s, fp); + return 0; } else if (!PyErr_Occurred()) { PyObject *v = PyString_FromString(s); - if (v == NULL) { - PyErr_Clear(); - } - else { - if (PyFile_WriteObject(v, f, Py_PRINT_RAW) != 0) - PyErr_Clear(); - Py_DECREF(v); - } + int err; + if (v == NULL) + return -1; + err = PyFile_WriteObject(v, f, Py_PRINT_RAW); + Py_DECREF(v); + return err; } } |