[patch, committed] PR55795 Re: Buffered/unbuffered I/O issues
Jerry DeLisle
jvdelisle@verizon.net
Fri Oct 19 04:22:00 GMT 2007
I reviewed, tested, regression tested, and OKed this patch for FX.
I also updated gfortran.texi to reflect the fix.
See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33795 for further info.
Regards,
Jerry
François-Xavier Coudert wrote:
>> Something like GFORTRAN_UNBUFFERED_STDIO would be perfect.
>
> If think it's OK as it's rather contained. I'd call it
> GFORTRAN_UNBUFFERED_PRECONNECTED, though, because that's what it
> really is in Fortran terms. Possible implementation follows (caveat,
> not even built because I wrote it in the train)...
>
>
> Index: libgfortran.h
> ===================================================================
> --- libgfortran.h (revision 129403)
> +++ libgfortran.h (working copy)
> @@ -349,7 +349,7 @@ typedef struct
> int separator_len;
> const char *separator;
>
> - int use_stderr, all_unbuffered, default_recl;
> + int use_stderr, all_unbuffered, unbuffered_preconnected, default_recl;
> int fpe, dump_core, backtrace;
> }
> options_t;
> Index: io/unix.c
> ===================================================================
> --- io/unix.c (revision 129403)
> +++ io/unix.c (working copy)
> @@ -1411,10 +1411,16 @@ input_stream (void)
> stream *
> output_stream (void)
> {
> + stream * s;
> +
> #if defined(HAVE_CRLF) && defined(HAVE_SETMODE)
> setmode (STDOUT_FILENO, O_BINARY);
> #endif
> - return fd_to_stream (STDOUT_FILENO, PROT_WRITE);
> +
> + s = fd_to_stream (STDOUT_FILENO, PROT_WRITE);
> + if (options.unbuffered_preconnected)
> + ((unix_stream *) s)->unbuffered = 1;
> + return s;
> }
>
>
> @@ -1424,10 +1430,16 @@ output_stream (void)
> stream *
> error_stream (void)
> {
> + stream * s;
> +
> #if defined(HAVE_CRLF) && defined(HAVE_SETMODE)
> setmode (STDERR_FILENO, O_BINARY);
> #endif
> - return fd_to_stream (STDERR_FILENO, PROT_WRITE);
> +
> + s = fd_to_stream (STDERR_FILENO, PROT_WRITE);
> + if (options.unbuffered_preconnected)
> + ((unix_stream *) s)->unbuffered = 1;
> + return s;
> }
>
>
> Index: runtime/environ.c
> ===================================================================
> --- runtime/environ.c (revision 129403)
> +++ runtime/environ.c (working copy)
> @@ -379,6 +379,10 @@ static variable variable_table[] = {
> "If TRUE, all output is unbuffered. This will slow down large writes "
> "but can be\nuseful for forcing data to be displayed immediately.", 0},
>
> + {"GFORTRAN_UNBUFFERED_PRECONNECTED", 0, &options.unbuffered_preconnected,
> + init_boolean, show_boolean,
> + "If TRUE, output to preconnected units is unbuffered.", 0},
> +
> {"GFORTRAN_SHOW_LOCUS", 1, &options.locus, init_boolean, show_boolean,
> "If TRUE, print filename and line number where runtime errors happen.", 0},
>
>
> We also need to remove check_buffered(), of course, and audit for
> other dead code in runtime/environ.c.
>
More information about the Fortran
mailing list