mirror of
https://github.com/python/cpython.git
synced 2025-07-07 19:35:27 +00:00
gh-109611: Add convenient C API function _PyFile_Flush() (GH-109612)
This commit is contained in:
parent
92af0cc580
commit
b8d1744e7b
11 changed files with 54 additions and 97 deletions
|
@ -1562,14 +1562,10 @@ _PyErr_Display(PyObject *file, PyObject *unused, PyObject *value, PyObject *tb)
|
|||
Py_XDECREF(ctx.seen);
|
||||
|
||||
/* Call file.flush() */
|
||||
PyObject *res = PyObject_CallMethodNoArgs(file, &_Py_ID(flush));
|
||||
if (!res) {
|
||||
if (_PyFile_Flush(file) < 0) {
|
||||
/* Silently ignore file.flush() error */
|
||||
PyErr_Clear();
|
||||
}
|
||||
else {
|
||||
Py_DECREF(res);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1674,11 +1670,7 @@ flush_io_stream(PyThreadState *tstate, PyObject *name)
|
|||
{
|
||||
PyObject *f = _PySys_GetAttr(tstate, name);
|
||||
if (f != NULL) {
|
||||
PyObject *r = PyObject_CallMethodNoArgs(f, &_Py_ID(flush));
|
||||
if (r) {
|
||||
Py_DECREF(r);
|
||||
}
|
||||
else {
|
||||
if (_PyFile_Flush(f) < 0) {
|
||||
PyErr_Clear();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue