comparison Python/sysmodule.c @ 34483:4a1fefdfc793 2.4

Flush std{in,out,err} before closing it. Fixes #1074011.
author Martin v. Löwis <martin@v.loewis.de>
date Sun, 23 Jan 2005 09:50:14 +0000
parents f455bbe7ea7e
children 91038801eb45
comparison
equal deleted inserted replaced
34477:b745595d41d1 34483:4a1fefdfc793
925 settrace() -- set the global debug tracing function\n\ 925 settrace() -- set the global debug tracing function\n\
926 " 926 "
927 ) 927 )
928 /* end of sys_doc */ ; 928 /* end of sys_doc */ ;
929 929
930 static int
931 _check_and_flush (FILE *stream)
932 {
933 int prev_fail = ferror (stream);
934 return fflush (stream) || prev_fail ? EOF : 0;
935 }
936
930 PyObject * 937 PyObject *
931 _PySys_Init(void) 938 _PySys_Init(void)
932 { 939 {
933 PyObject *m, *v, *sysdict; 940 PyObject *m, *v, *sysdict;
934 PyObject *sysin, *sysout, *syserr; 941 PyObject *sysin, *sysout, *syserr;
938 #endif 945 #endif
939 946
940 m = Py_InitModule3("sys", sys_methods, sys_doc); 947 m = Py_InitModule3("sys", sys_methods, sys_doc);
941 sysdict = PyModule_GetDict(m); 948 sysdict = PyModule_GetDict(m);
942 949
943 sysin = PyFile_FromFile(stdin, "<stdin>", "r", NULL); 950 sysin = PyFile_FromFile(stdin, "<stdin>", "r", _check_and_flush);
944 sysout = PyFile_FromFile(stdout, "<stdout>", "w", NULL); 951 sysout = PyFile_FromFile(stdout, "<stdout>", "w", _check_and_flush);
945 syserr = PyFile_FromFile(stderr, "<stderr>", "w", NULL); 952 syserr = PyFile_FromFile(stderr, "<stderr>", "w", _check_and_flush);
946 if (PyErr_Occurred()) 953 if (PyErr_Occurred())
947 return NULL; 954 return NULL;
948 #ifdef MS_WINDOWS 955 #ifdef MS_WINDOWS
949 if(isatty(_fileno(stdin))){ 956 if(isatty(_fileno(stdin))){
950 sprintf(buf, "cp%d", GetConsoleCP()); 957 sprintf(buf, "cp%d", GetConsoleCP());