[gfortran] patch for pr 16805--error on list directed internal read

Paul Brook paul@codesourcery.com
Tue Aug 31 21:08:00 GMT 2004


On Sunday 29 August 2004 17:09, Bud Davis wrote:
> list directed I/I wants a '/n' or eoln set true, and these were never
> being set for internal I/O.
>
>
> no additional failures on i686/gnu/linux FC1.
>
>
> 2004-08-29  Bud Davis  <bdavis9659@comcast.net>
>
>  PR fortran/pr16805
>  * io/list_read.c (next_char): handle end for internal reads.

I don't think this is the correct solution.  We should only returning NULL 
from salloc_r on error, not on EOF/EOR.

The real solution is to implement internal files with multiple records (ie 
arrays), then everything should just work.

Until that happens I've applied the fix below, and added your testcase.
Tested on i686-linux.

2004-08-31  Paul Brook  <paul@codesourcery.com>

        PR libfortran/16805
 * io/list_read.c (next_char): Don't signal EOF for internal files.
 * io/unix.c (mem_alloc_r_at): Don't return NULL for incomplete reads.
testsuite/
2004-08-31  Bud Davis  <bdavis9659@comcast.net>

 * gfortran.dg/list_read_2.f90: New test.

Index: io/list_read.c
===================================================================
RCS file: /var/cvsroot/gcc-cvs/gcc/libgfortran/io/list_read.c,v
retrieving revision 1.7
diff -u -p -r1.7 list_read.c
--- io/list_read.c 31 Aug 2004 14:56:09 -0000 1.7
+++ io/list_read.c 31 Aug 2004 19:18:43 -0000
@@ -142,8 +142,17 @@ next_char (void)
     }
 
   if (length == 0)
-    longjmp (g.eof_jump, 1);
-  c = *p;
+    {
+      /* For internal files return a newline instead of signalling EOF.  */
+      /* ??? This isn't quite right, but we don't handle internal files
+  with multiple records.  */
+      if (is_internal_unit ())
+ c = '\n';
+      else
+ longjmp (g.eof_jump, 1);
+    }
+  else
+    c = *p;
 
 done:
   at_eol = (c == '\n');
Index: io/unix.c
===================================================================
RCS file: /var/cvsroot/gcc-cvs/gcc/libgfortran/io/unix.c,v
retrieving revision 1.8
diff -u -p -r1.8 unix.c
--- io/unix.c 31 Aug 2004 15:53:31 -0000 1.8
+++ io/unix.c 31 Aug 2004 19:05:29 -0000
@@ -746,9 +746,6 @@ mem_alloc_r_at (unix_stream * s, int *le
   if (where < s->buffer_offset || where > s->buffer_offset + s->active)
     return NULL;
 
-  if (is_internal_unit() && where + *len > s->file_length)
-    return NULL;
-
   s->logical_offset = where + *len;
 
   n = s->buffer_offset + s->active - where;



More information about the Gcc-patches mailing list