]> granicus.if.org Git - python/commitdiff
Fix bug introduced in r68451: stdio must always be opened in line-buffered mode
authorAntoine Pitrou <solipsis@pitrou.net>
Fri, 9 Jan 2009 22:12:30 +0000 (22:12 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Fri, 9 Jan 2009 22:12:30 +0000 (22:12 +0000)
if isatty() is true.

Python/pythonrun.c

index 8a1af3bdc5e43342797b649257ceefe5ed43631a..6819be55477949c254a22844de0c8278ab2a30f2 100644 (file)
@@ -734,10 +734,10 @@ create_stdio(PyObject* io,
        int fd, int write_mode, char* name,
        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 PyObject *line_buffering;
-       int buffering;
+       PyObject *line_buffering;
+       int buffering, isatty;
 
        if (Py_UnbufferedStdioFlag)
                buffering = 0;
@@ -766,13 +766,21 @@ create_stdio(PyObject* io,
        text = PyUnicode_FromString(name);
        if (text == NULL || PyObject_SetAttrString(raw, "_name", text) < 0)
                goto error;
-       Py_CLEAR(raw);
-       Py_CLEAR(text);
-
-       if (Py_UnbufferedStdioFlag)
+       res = PyObject_CallMethod(raw, "isatty", "");
+       if (res == NULL)
+               goto error;
+       isatty = PyObject_IsTrue(res);
+       Py_DECREF(res);
+       if (isatty == -1)
+               goto error;
+       if (isatty || Py_UnbufferedStdioFlag)
                line_buffering = Py_True;
        else
                line_buffering = Py_False;
+
+       Py_CLEAR(raw);
+       Py_CLEAR(text);
+
        stream = PyObject_CallMethod(io, "TextIOWrapper", "OsssO",
                                     buf, encoding, errors,
                                     "\n", line_buffering);