fix stderr flush mode initialization for Windows

svn: r10630
This commit is contained in:
Matthew Flatt 2008-07-06 11:53:00 +00:00
parent 9629528865
commit 532e805518

View File

@ -334,7 +334,7 @@ OS_SEMAPHORE_TYPE scheme_break_semaphore;
#ifdef MZ_FDS
static Scheme_Object *make_fd_input_port(int fd, Scheme_Object *name, int regfile, int textmode, int *refcount, int internal);
static Scheme_Object *make_fd_output_port(int fd, Scheme_Object *name, int regfile, int textmode, int read_too);
static Scheme_Object *make_fd_output_port(int fd, Scheme_Object *name, int regfile, int textmode, int read_too, int flush_mode);
#endif
#ifdef USE_OSKIT_CONSOLE
static Scheme_Object *make_oskit_console_input_port();
@ -343,8 +343,6 @@ static Scheme_Object *make_oskit_console_input_port();
static void force_close_output_port(Scheme_Object *port);
static void force_close_input_port(Scheme_Object *port);
static void set_fd_flush_mode(Scheme_Object *o, int mode);
static Scheme_Object *text_symbol, *binary_symbol;
static Scheme_Object *append_symbol, *error_symbol, *update_symbol, *can_update_symbol;
static Scheme_Object *replace_symbol, *truncate_symbol, *truncate_replace_symbol;
@ -513,9 +511,10 @@ scheme_init_port (Scheme_Env *env)
#ifdef MZ_FDS
# ifdef WINDOWS_FILE_HANDLES
: make_fd_output_port((int)GetStdHandle(STD_OUTPUT_HANDLE),
scheme_intern_symbol("stdout"), 0, 0, 0)
scheme_intern_symbol("stdout"), 0, 0, 0,
-1)
# else
: make_fd_output_port(1, scheme_intern_symbol("stdout"), 0, 0, 0)
: make_fd_output_port(1, scheme_intern_symbol("stdout"), 0, 0, 0, -1)
# endif
#else
: scheme_make_file_output_port(stdout)
@ -527,21 +526,17 @@ scheme_init_port (Scheme_Env *env)
#ifdef MZ_FDS
# ifdef WINDOWS_FILE_HANDLES
: make_fd_output_port((int)GetStdHandle(STD_ERROR_HANDLE),
scheme_intern_symbol("stderr"), 0, 0, 0)
scheme_intern_symbol("stderr"), 0, 0, 0,
MZ_FLUSH_ALWAYS)
# else
: make_fd_output_port(2, scheme_intern_symbol("stderr"), 0, 0, 0)
: make_fd_output_port(2, scheme_intern_symbol("stderr"), 0, 0, 0,
MZ_FLUSH_ALWAYS)
# endif
#else
: scheme_make_file_output_port(stderr)
#endif
);
#ifdef MZ_FDS
# ifdef WINDOWS_FILE_HANDLES
set_fd_flush_mode(scheme_orig_stderr_port, MZ_FLUSH_ALWAYS);
# endif
#endif
flush_out = SCHEME_TRUEP(scheme_terminal_port_p(1, &scheme_orig_stdout_port));
flush_err = SCHEME_TRUEP(scheme_terminal_port_p(1, &scheme_orig_stderr_port));
@ -3861,7 +3856,7 @@ scheme_do_open_output_file(char *name, int offset, int argc, Scheme_Object *argv
regfile = S_ISREG(buf.st_mode);
scheme_file_open_count++;
return make_fd_output_port(fd, scheme_make_path(filename), regfile, 0, and_read);
return make_fd_output_port(fd, scheme_make_path(filename), regfile, 0, and_read, -1);
#else
# ifdef WINDOWS_FILE_HANDLES
if (!existsok)
@ -3947,7 +3942,7 @@ scheme_do_open_output_file(char *name, int offset, int argc, Scheme_Object *argv
}
scheme_file_open_count++;
return make_fd_output_port((int)fd, scheme_make_path(filename), regfile, mode[1] == 't', and_read);
return make_fd_output_port((int)fd, scheme_make_path(filename), regfile, mode[1] == 't', and_read, -1);
# else
if (scheme_directory_exists(filename)) {
if (!existsok)
@ -6268,7 +6263,8 @@ static int fd_output_buffer_mode(Scheme_Port *p, int mode)
}
static Scheme_Object *
make_fd_output_port(int fd, Scheme_Object *name, int regfile, int win_textmode, int and_read)
make_fd_output_port(int fd, Scheme_Object *name, int regfile, int win_textmode, int and_read,
int flush_mode)
{
Scheme_FD *fop;
unsigned char *bfr;
@ -6295,9 +6291,8 @@ make_fd_output_port(int fd, Scheme_Object *name, int regfile, int win_textmode,
fop->regfile = regfile;
fop->textmode = win_textmode;
if (fd == 2) {
/* No buffering for stderr: */
fop->flush = MZ_FLUSH_ALWAYS;
if (flush_mode > -1) {
fop->flush = flush_mode;
} else if (is_fd_terminal(fd)) {
/* Line-buffering for terminal: */
fop->flush = MZ_FLUSH_BY_LINE;
@ -6332,11 +6327,6 @@ make_fd_output_port(int fd, Scheme_Object *name, int regfile, int win_textmode,
return the_port;
}
static void set_fd_flush_mode(Scheme_Object *o, int mode)
{
((Scheme_FD *)((Scheme_Output_Port *)o)->port_data)->flush = mode;
}
static void flush_if_output_fds(Scheme_Object *o, Scheme_Close_Custodian_Client *f, void *data)
{
if (SCHEME_OUTPUT_PORTP(o)) {
@ -6439,7 +6429,7 @@ Scheme_Object *
scheme_make_fd_output_port(int fd, Scheme_Object *name, int regfile, int textmode, int read_too)
{
#ifdef MZ_FDS
return make_fd_output_port(fd, name, regfile, textmode, read_too);
return make_fd_output_port(fd, name, regfile, textmode, read_too, -1);
#else
return NULL;
#endif
@ -7475,7 +7465,7 @@ static Scheme_Object *subprocess(int c, Scheme_Object *args[])
/*--------------------------------------*/
in = (in ? in : make_fd_input_port(from_subprocess[0], scheme_intern_symbol("subprocess-stdout"), 0, 0, NULL, 0));
out = (out ? out : make_fd_output_port(to_subprocess[1], scheme_intern_symbol("subprocess-stdin"), 0, 0, 0));
out = (out ? out : make_fd_output_port(to_subprocess[1], scheme_intern_symbol("subprocess-stdin"), 0, 0, 0, -1));
err = (err ? err : make_fd_input_port(err_subprocess[0], scheme_intern_symbol("subprocess-stderr"), 0, 0, NULL, 0));
/*--------------------------------------*/