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]

Re: [PATCH] Connect stderr to Unit 0 (PR libgfortran/19052)


	Further testing of the fix turned up another failure in
testsuite.  gfortran.dg/write_to_null.f90 explicitly opens /dev/null as a
new unit.  If stderr is connected to /dev/null and unit 0 explicitly has
been connected to stderr, then the testcase now fails.  As discussed on
IRC, the behavior of opening a unit is modified to not error if the file
is preconnected to a standard unit.

Is the revised patch okay for mainline?

Thanks ,David


	PR libgrfortran/19052
	* libgfortran.h (options_t): Add stderr_unit.
	* io/io.h (error_stream): Declare.
	* io/open.c (new_unit): Do not terminate abnormally if opening
	file preconnected to stdin, stdout, or stderr.
	* io/unit.c (init_units): Initialize stderr_unit.
	* io/unix.c (error_stream): New function.
	* runtime/environ.c (GFORTRAN_STDERR_UNIT): New environment variable.

Index: libgfortran.h
===================================================================
RCS file: /cvs/gcc/gcc/libgfortran/libgfortran.h,v
retrieving revision 1.21
diff -c -p -r1.21 libgfortran.h
*** libgfortran.h	12 Jan 2005 21:27:29 -0000	1.21
--- libgfortran.h	17 Jan 2005 19:47:11 -0000
*************** enum
*** 292,298 ****
  
  typedef struct
  {
!   int stdin_unit, stdout_unit, optional_plus;
    int allocate_init_flag, allocate_init_value;
    int locus;
  
--- 292,298 ----
  
  typedef struct
  {
!   int stdin_unit, stdout_unit, stderr_unit, optional_plus;
    int allocate_init_flag, allocate_init_value;
    int locus;
  
Index: io/io.h
===================================================================
RCS file: /cvs/gcc/gcc/libgfortran/io/io.h,v
retrieving revision 1.14
diff -c -p -r1.14 io.h
*** io/io.h	12 Jan 2005 21:27:31 -0000	1.14
--- io/io.h	17 Jan 2005 19:47:11 -0000
*************** internal_proto(input_stream);
*** 409,414 ****
--- 409,417 ----
  extern stream *output_stream (void);
  internal_proto(output_stream);
  
+ extern stream *error_stream (void);
+ internal_proto(error_stream);
+ 
  extern int compare_file_filename (stream *, const char *, int);
  internal_proto(compare_file_filename);
  
Index: io/open.c
===================================================================
RCS file: /cvs/gcc/gcc/libgfortran/io/open.c,v
retrieving revision 1.9
diff -c -p -r1.9 open.c
*** io/open.c	12 Jan 2005 21:27:31 -0000	1.9
--- io/open.c	17 Jan 2005 19:47:11 -0000
*************** new_unit (unit_flags * flags)
*** 323,331 ****
        internal_error ("new_unit(): Bad status");
      }
  
!   /* Make sure the file isn't already open someplace else.  */
  
!   if (find_file () != NULL)
      {
        generate_error (ERROR_ALREADY_OPEN, NULL);
        goto cleanup;
--- 323,336 ----
        internal_error ("new_unit(): Bad status");
      }
  
!   /* Make sure the file isn't already open someplace else.
!      Do not error if opening file preconnected to stdin, stdout, stderr.  */
  
!   u = find_file ();
!   if (u != NULL
!       && (options.stdin_unit < 0 || u->unit_number != options.stdin_unit)
!       && (options.stdout_unit < 0 || u->unit_number != options.stdout_unit)
!       && (options.stderr_unit < 0 || u->unit_number != options.stderr_unit))
      {
        generate_error (ERROR_ALREADY_OPEN, NULL);
        goto cleanup;
Index: io/unit.c
===================================================================
RCS file: /cvs/gcc/gcc/libgfortran/io/unit.c,v
retrieving revision 1.7
diff -c -p -r1.7 unit.c
*** io/unit.c	12 Jan 2005 21:27:31 -0000	1.7
--- io/unit.c	17 Jan 2005 19:47:11 -0000
*************** init_units (void)
*** 334,339 ****
--- 334,360 ----
        insert_unit (u);
      }
  
+   if (options.stderr_unit >= 0)
+     {				/* STDERR */
+       u = get_mem (sizeof (gfc_unit));
+ 
+       u->unit_number = options.stderr_unit;
+       u->s = error_stream ();
+ 
+       u->flags.action = ACTION_WRITE;
+ 
+       u->flags.access = ACCESS_SEQUENTIAL;
+       u->flags.form = FORM_FORMATTED;
+       u->flags.status = STATUS_OLD;
+       u->flags.blank = BLANK_ZERO;
+       u->flags.position = POSITION_ASIS;
+ 
+       u->recl = options.default_recl;
+       u->endfile = AT_ENDFILE;
+ 
+       insert_unit (u);
+     }
+ 
    /* Calculate the maximum file offset in a portable manner.
     * max will be the largest signed number for the type gfc_offset.
     *
Index: io/unix.c
===================================================================
RCS file: /cvs/gcc/gcc/libgfortran/io/unix.c,v
retrieving revision 1.19
diff -c -p -r1.19 unix.c
*** io/unix.c	12 Jan 2005 21:27:31 -0000	1.19
--- io/unix.c	17 Jan 2005 19:47:11 -0000
*************** input_stream (void)
*** 1149,1155 ****
  }
  
  
! /* output_stream()-- Return a stream pointer to the default input stream.
   * Called on initialization. */
  
  stream *
--- 1149,1155 ----
  }
  
  
! /* output_stream()-- Return a stream pointer to the default output stream.
   * Called on initialization. */
  
  stream *
*************** output_stream (void)
*** 1159,1164 ****
--- 1159,1173 ----
  }
  
  
+ /* error_stream()-- Return a stream pointer to the default error stream.
+  * Called on initialization. */
+ 
+ stream *
+ error_stream (void)
+ {
+   return fd_to_stream (STDERR_FILENO, PROT_WRITE);
+ }
+ 
  /* init_error_stream()-- Return a pointer to the error stream.  This
   * subroutine is called when the stream is needed, rather than at
   * initialization.  We want to work even if memory has been seriously
Index: runtime/environ.c
===================================================================
RCS file: /cvs/gcc/gcc/libgfortran/runtime/environ.c,v
retrieving revision 1.6
diff -c -p -r1.6 environ.c
*** runtime/environ.c	12 Jan 2005 21:27:31 -0000	1.6
--- runtime/environ.c	17 Jan 2005 19:47:11 -0000
*************** static variable variable_table[] = {
*** 443,448 ****
--- 443,453 ----
     "Unit number that will be preconnected to standard output\n"
     "(No preconnection if negative)"},
  
+   {"GFORTRAN_STDERR_UNIT", 0, &options.stderr_unit, init_integer,
+    show_integer,
+    "Unit number that will be preconnected to standard error\n"
+    "(No preconnection if negative)"},
+ 
    {"GFORTRAN_USE_STDERR", 1, &options.use_stderr, init_boolean,
     show_boolean,
     "Sends library output to standard error instead of standard output."},



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