This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: Buffered/unbuffered I/O issues
- From: "François-Xavier Coudert" <fxcoudert at gmail dot com>
- To: "Harald Anlauf" <anlauf at gmx dot de>
- Cc: "Jerry DeLisle" <jvdelisle at verizon dot net>, fortran at gcc dot gnu dot org
- Date: Wed, 17 Oct 2007 10:36:37 +0100
- Subject: Re: Buffered/unbuffered I/O issues
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=+coZwBKCeaDf6PQVzU8PuJGlH9x2KTJlbvNzdpTqfJQ=; b=aVp3ysRfitmvA4OTQ21kkoIfl0yPljREd/rxzwW7GuwyvwsdAOKoyE+1q/abnxIAtqxyncn5/t7X22ygyh0iqL+7GQgcHVO9jlTQbl4uakAWGYdp3hsiK6N0OB7VhOAmxAhBxvAMDY/oTC3/1jvD87at2YSqGZKn0l9JO6nGV9o=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=s2g9enQDzWXRyR5GpEbWsWho/qRspPTG0eZhAkIgAypGDyXr6zHsTdoB7rztOq4c5VL2c0VQuhr6uvtdtt/v3sD9eZFTyjud487tKekBOtEheZPlYy41G+1lsPwGosBO33AijMurJFX16fw2zxEdAXSoRPcH3dIk61yl5cxy0Jk=
- References: <20071016142434.247130@gmx.net> <19c433eb0710160734m314e3194y9f614786b9cd0a5a@mail.gmail.com> <47152E10.9030504@verizon.net> <20071017090453.111340@gmx.net>
> 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.