Issue #4705: Fix the -u ("unbuffered binary stdout and stderr") command-line

flag to work properly. Furthermore, when specifying -u, the text stdout
and stderr streams have line-by-line buffering enabled (the default being
to buffer arbitrary chunks of data). Patch by Victor Stinner, test by me.
This commit is contained in:
Antoine Pitrou 2009-01-09 18:53:14 +00:00
parent 1483140772
commit 0560843b8f
5 changed files with 102 additions and 13 deletions

View file

@ -292,7 +292,6 @@ Py_Main(int argc, wchar_t **argv)
wchar_t *module = NULL;
FILE *fp = stdin;
char *p;
int unbuffered = 0;
int skipfirstline = 0;
int stdin_is_interactive = 0;
int help = 0;
@ -374,7 +373,7 @@ Py_Main(int argc, wchar_t **argv)
break;
case 'u':
unbuffered++;
Py_UnbufferedStdioFlag = 1;
saw_unbuffered_flag = 1;
break;
@ -423,7 +422,7 @@ Py_Main(int argc, wchar_t **argv)
Py_InspectFlag = 1;
if (!saw_unbuffered_flag &&
(p = Py_GETENV("PYTHONUNBUFFERED")) && *p != '\0')
unbuffered = 1;
Py_UnbufferedStdioFlag = 1;
if (!Py_NoUserSiteDirectory &&
(p = Py_GETENV("PYTHONNOUSERSITE")) && *p != '\0')
@ -444,7 +443,7 @@ Py_Main(int argc, wchar_t **argv)
stdin_is_interactive = Py_FdIsInteractive(stdin, (char *)0);
if (unbuffered) {
if (Py_UnbufferedStdioFlag) {
#if defined(MS_WINDOWS) || defined(__CYGWIN__)
_setmode(fileno(stdin), O_BINARY);
_setmode(fileno(stdout), O_BINARY);