This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

[gfortran] patch PR 20788


Dynamically loading libgfortran.so breaks C I/O routines when stdout is redirected to a file (same thing for stdin and stderr). This annoys people dynamically loading Fortran subroutines for use in a C project (example: R,
see PR fortran/20788 for details).


Attached patch fixes this by disabling use of mmap on stdin, stdout and stderr. Profiling shows no performance degradation (all time spent in I/O on preconnected units is formatting).

Regtested on i386-linux. OK for mainline and 4.0?
2005-05-02  Francois-Xavier Coudert  <coudert@clipper.ens.fr>

	PR libfortran/20788
	* io/unix.c (fd_to_stream): Add an avoid_mmap argument indicating
	we don't we to mmap this stream. Use fd_open instead of mmap_open
	in that case.
	(open_external): Call fd_to_stream with avoid_mmap = 0.
	(input_stream): Call fd_to_stream with avoid_mmap = 1.
	(output_stream): Likewise.
	(error_stream): Likewise.
Index: libgfortran/io/unix.c
===================================================================
RCS file: /cvs/gcc/gcc/libgfortran/io/unix.c,v
retrieving revision 1.22
diff -p -u -r1.22 unix.c
--- libgfortran/io/unix.c	29 Apr 2005 14:24:04 -0000	1.22
+++ libgfortran/io/unix.c	2 May 2005 07:22:20 -0000
@@ -892,7 +892,7 @@ open_internal (char *base, int length)
  * around it. */
 
 static stream *
-fd_to_stream (int fd, int prot)
+fd_to_stream (int fd, int prot, int avoid_mmap)
 {
   struct stat statbuf;
   unix_stream *s;
@@ -911,7 +911,10 @@ fd_to_stream (int fd, int prot)
   s->file_length = S_ISREG (statbuf.st_mode) ? statbuf.st_size : -1;
 
 #if HAVE_MMAP
-  mmap_open (s);
+  if (avoid_mmap)
+    fd_open (s);
+  else
+    mmap_open (s);
 #else
   fd_open (s);
 #endif
@@ -1153,7 +1156,7 @@ open_external (unit_flags *flags)
       internal_error ("open_external(): Bad action");
     }
 
-  return fd_to_stream (fd, prot);
+  return fd_to_stream (fd, prot, 0);
 }
 
 
@@ -1163,7 +1166,7 @@ open_external (unit_flags *flags)
 stream *
 input_stream (void)
 {
-  return fd_to_stream (STDIN_FILENO, PROT_READ);
+  return fd_to_stream (STDIN_FILENO, PROT_READ, 1);
 }
 
 
@@ -1173,7 +1176,7 @@ input_stream (void)
 stream *
 output_stream (void)
 {
-  return fd_to_stream (STDOUT_FILENO, PROT_WRITE);
+  return fd_to_stream (STDOUT_FILENO, PROT_WRITE, 1);
 }
 
 
@@ -1183,7 +1186,7 @@ output_stream (void)
 stream *
 error_stream (void)
 {
-  return fd_to_stream (STDERR_FILENO, PROT_WRITE);
+  return fd_to_stream (STDERR_FILENO, PROT_WRITE, 1);
 }
 
 /* init_error_stream()-- Return a pointer to the error stream.  This

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