This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Buffered/unbuffered I/O issues


> 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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]