mirror of
https://github.com/python/cpython.git
synced 2025-08-02 08:02:56 +00:00
Fix bug introduced in r68451: stdio must always be opened in line-buffered mode
if isatty() is true.
This commit is contained in:
parent
8043cf868c
commit
9169641b8b
1 changed files with 15 additions and 7 deletions
|
@ -734,10 +734,10 @@ create_stdio(PyObject* io,
|
||||||
int fd, int write_mode, char* name,
|
int fd, int write_mode, char* name,
|
||||||
char* encoding, char* errors)
|
char* encoding, char* errors)
|
||||||
{
|
{
|
||||||
PyObject *buf = NULL, *stream = NULL, *text = NULL, *raw = NULL;
|
PyObject *buf = NULL, *stream = NULL, *text = NULL, *raw = NULL, *res;
|
||||||
const char* mode;
|
const char* mode;
|
||||||
const PyObject *line_buffering;
|
PyObject *line_buffering;
|
||||||
int buffering;
|
int buffering, isatty;
|
||||||
|
|
||||||
if (Py_UnbufferedStdioFlag)
|
if (Py_UnbufferedStdioFlag)
|
||||||
buffering = 0;
|
buffering = 0;
|
||||||
|
@ -766,13 +766,21 @@ create_stdio(PyObject* io,
|
||||||
text = PyUnicode_FromString(name);
|
text = PyUnicode_FromString(name);
|
||||||
if (text == NULL || PyObject_SetAttrString(raw, "_name", text) < 0)
|
if (text == NULL || PyObject_SetAttrString(raw, "_name", text) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
Py_CLEAR(raw);
|
res = PyObject_CallMethod(raw, "isatty", "");
|
||||||
Py_CLEAR(text);
|
if (res == NULL)
|
||||||
|
goto error;
|
||||||
if (Py_UnbufferedStdioFlag)
|
isatty = PyObject_IsTrue(res);
|
||||||
|
Py_DECREF(res);
|
||||||
|
if (isatty == -1)
|
||||||
|
goto error;
|
||||||
|
if (isatty || Py_UnbufferedStdioFlag)
|
||||||
line_buffering = Py_True;
|
line_buffering = Py_True;
|
||||||
else
|
else
|
||||||
line_buffering = Py_False;
|
line_buffering = Py_False;
|
||||||
|
|
||||||
|
Py_CLEAR(raw);
|
||||||
|
Py_CLEAR(text);
|
||||||
|
|
||||||
stream = PyObject_CallMethod(io, "TextIOWrapper", "OsssO",
|
stream = PyObject_CallMethod(io, "TextIOWrapper", "OsssO",
|
||||||
buf, encoding, errors,
|
buf, encoding, errors,
|
||||||
"\n", line_buffering);
|
"\n", line_buffering);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue