summaryrefslogtreecommitdiffstats
path: root/Python/pythonrun.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2023-09-23 06:35:30 (GMT)
committerGitHub <noreply@github.com>2023-09-23 06:35:30 (GMT)
commitb8d1744e7ba87a4057350fdfd788b5621095fc59 (patch)
tree367ba89c2a83a1115f74b1e0c83384e047ef4b84 /Python/pythonrun.c
parent92af0cc580051fd1129c7a86af2cbadeb2aa36dc (diff)
downloadcpython-b8d1744e7ba87a4057350fdfd788b5621095fc59.zip
cpython-b8d1744e7ba87a4057350fdfd788b5621095fc59.tar.gz
cpython-b8d1744e7ba87a4057350fdfd788b5621095fc59.tar.bz2
gh-109611: Add convenient C API function _PyFile_Flush() (GH-109612)
Diffstat (limited to 'Python/pythonrun.c')
-rw-r--r--Python/pythonrun.c12
1 files changed, 2 insertions, 10 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index e3d03a8..81ab78e 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -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();
}
}