mirror of https://github.com/python/cpython
PyFile_WriteString now returns an error indicator instead of calling
PyErr_Clear().
This commit is contained in:
parent
745b8cff08
commit
27a60b147c
|
@ -997,28 +997,34 @@ PyFile_WriteObject(v, f, flags)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
int
|
||||||
PyFile_WriteString(s, f)
|
PyFile_WriteString(s, f)
|
||||||
char *s;
|
char *s;
|
||||||
PyObject *f;
|
PyObject *f;
|
||||||
{
|
{
|
||||||
if (f == NULL) {
|
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)) {
|
else if (PyFile_Check(f)) {
|
||||||
FILE *fp = PyFile_AsFile(f);
|
FILE *fp = PyFile_AsFile(f);
|
||||||
if (fp != NULL)
|
if (fp == NULL) {
|
||||||
|
err_closed();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
fputs(s, fp);
|
fputs(s, fp);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
else if (!PyErr_Occurred()) {
|
else if (!PyErr_Occurred()) {
|
||||||
PyObject *v = PyString_FromString(s);
|
PyObject *v = PyString_FromString(s);
|
||||||
if (v == NULL) {
|
int err;
|
||||||
PyErr_Clear();
|
if (v == NULL)
|
||||||
}
|
return -1;
|
||||||
else {
|
err = PyFile_WriteObject(v, f, Py_PRINT_RAW);
|
||||||
if (PyFile_WriteObject(v, f, Py_PRINT_RAW) != 0)
|
|
||||||
PyErr_Clear();
|
|
||||||
Py_DECREF(v);
|
Py_DECREF(v);
|
||||||
}
|
return err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue