summaryrefslogtreecommitdiffstats
path: root/Python/bltinmodule.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/bltinmodule.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/bltinmodule.c')
-rw-r--r--Python/bltinmodule.c22
1 files changed, 7 insertions, 15 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 8e234e0..69056bf 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -2083,11 +2083,9 @@ builtin_print_impl(PyObject *module, PyObject *args, PyObject *sep,
}
if (flush) {
- PyObject *tmp = PyObject_CallMethodNoArgs(file, &_Py_ID(flush));
- if (tmp == NULL) {
+ if (_PyFile_Flush(file) < 0) {
return NULL;
}
- Py_DECREF(tmp);
}
Py_RETURN_NONE;
@@ -2146,11 +2144,9 @@ builtin_input_impl(PyObject *module, PyObject *prompt)
}
/* First of all, flush stderr */
- tmp = PyObject_CallMethodNoArgs(ferr, &_Py_ID(flush));
- if (tmp == NULL)
+ if (_PyFile_Flush(ferr) < 0) {
PyErr_Clear();
- else
- Py_DECREF(tmp);
+ }
/* We should only use (GNU) readline if Python's sys.stdin and
sys.stdout are the same as C's stdin and stdout, because we
@@ -2218,11 +2214,9 @@ builtin_input_impl(PyObject *module, PyObject *prompt)
if (stdin_errors_str == NULL) {
goto _readline_errors;
}
- tmp = PyObject_CallMethodNoArgs(fout, &_Py_ID(flush));
- if (tmp == NULL)
+ if (_PyFile_Flush(fout) < 0) {
PyErr_Clear();
- else
- Py_DECREF(tmp);
+ }
if (prompt != NULL) {
/* We have a prompt, encode it as stdout would */
const char *stdout_encoding_str, *stdout_errors_str;
@@ -2325,11 +2319,9 @@ builtin_input_impl(PyObject *module, PyObject *prompt)
if (PyFile_WriteObject(prompt, fout, Py_PRINT_RAW) != 0)
return NULL;
}
- tmp = PyObject_CallMethodNoArgs(fout, &_Py_ID(flush));
- if (tmp == NULL)
+ if (_PyFile_Flush(fout) < 0) {
PyErr_Clear();
- else
- Py_DECREF(tmp);
+ }
return PyFile_GetLine(fin, -1);
}