]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR fortran/60956 (error reading (and writing) large text files in gfortran)
authorJerry DeLisle <jvdelisle@gcc.gnu.org>
Sat, 7 Feb 2015 15:13:15 +0000 (15:13 +0000)
committerJerry DeLisle <jvdelisle@gcc.gnu.org>
Sat, 7 Feb 2015 15:13:15 +0000 (15:13 +0000)
2015-02-07  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

PR libgfortran/60956
* io/fbuf.c (fbuf_flush_list): New function that only flushes
if current fbuf position exceeds a limit.
* io/fbuf.h: Declare the new function.
* io/io.h (enum unit_mode): Add two new modes.
* io/list_read.c (list_formatted_read_scalar): Call new function.
* io/write.c: Include fbuf.h. (list_formatted_write_scalar):
Call new function.

From-SVN: r220505

libgfortran/ChangeLog
libgfortran/io/fbuf.c
libgfortran/io/fbuf.h
libgfortran/io/io.h
libgfortran/io/list_read.c
libgfortran/io/write.c

index e228a677105ce16770c35c06d4b9e4ac269370dd..d3b8f8f6e48ebf2b501032cc1a666258ba722c81 100644 (file)
@@ -1,3 +1,14 @@
+2015-02-07  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
+
+       PR libgfortran/60956
+       * io/fbuf.c (fbuf_flush_list): New function that only flushes
+       if current fbuf position exceeds a limit.
+       * io/fbuf.h: Declare the new function.
+       * io/io.h (enum unit_mode): Add two new modes.
+       * io/list_read.c (list_formatted_read_scalar): Call new function.
+       * io/write.c: Include fbuf.h. (list_formatted_write_scalar):
+       Call new function.
+
 2015-01-24  Janne Blomqvist  <jb@gcc.gnu.org>
 
        PR libfortran/64770
index 9a3a486fe40327f99b2b6802d730d45ab09e3356..b3750d21a3ba2348ce5909758a78599fd350325a 100644 (file)
@@ -171,6 +171,42 @@ fbuf_flush (gfc_unit * u, unit_mode mode)
 }
 
 
+/* The mode argument is LIST_WRITING for write mode and LIST_READING for
+   read.  This should only be used for list directed  I/O.
+   Return value is 0 for success, -1 on failure.  */
+
+int
+fbuf_flush_list (gfc_unit * u, unit_mode mode)
+{
+  int nwritten;
+
+  if (!u->fbuf)
+    return 0;
+
+  if (u->fbuf->pos < 524288) /* Upper limit for list writing.  */
+    return 0;
+
+  fbuf_debug (u, "fbuf_flush_list with mode %d: ", mode);
+
+  if (mode == LIST_WRITING)
+    {
+      nwritten = swrite (u->s, u->fbuf->buf, u->fbuf->pos);
+      if (nwritten < 0)
+       return -1;
+    }
+
+  /* Salvage remaining bytes for both reading and writing.  */ 
+  if (u->fbuf->act > u->fbuf->pos)
+    memmove (u->fbuf->buf, u->fbuf->buf + u->fbuf->pos, 
+             u->fbuf->act - u->fbuf->pos);
+
+  u->fbuf->act -= u->fbuf->pos;
+  u->fbuf->pos = 0;
+
+  return 0;
+}
+
+
 int
 fbuf_seek (gfc_unit * u, int off, int whence)
 {
index 902cd6ef8690aed3163ecc43632ec6e3d22268c6..220c8d7b56dc848eed77410264250ebb519669e4 100644 (file)
@@ -59,6 +59,9 @@ internal_proto(fbuf_alloc);
 extern int fbuf_flush (gfc_unit *, unit_mode);
 internal_proto(fbuf_flush);
 
+extern int fbuf_flush_list (gfc_unit *, unit_mode);
+internal_proto(fbuf_flush_list);
+
 extern int fbuf_seek (gfc_unit *, int, int);
 internal_proto(fbuf_seek);
 
index 928123bff346823bfb6ad3d741fc8891ba0791c4..f34d0c34cf6b66803b3d8a710484da6dab2290a4 100644 (file)
@@ -231,7 +231,7 @@ typedef enum
 unit_advance;
 
 typedef enum
-{READING, WRITING}
+{READING, WRITING, LIST_READING, LIST_WRITING}
 unit_mode;
 
 typedef enum
index 640774b2ac1e8ce93c09484db2fc6c35947600b8..45243ed9f3931edd898b46b73ec3d9b84ec16ef9 100644 (file)
@@ -2210,6 +2210,7 @@ cleanup:
       free_line (dtp);
       hit_eof (dtp);
     }
+  fbuf_flush_list (dtp->u.p.current_unit, LIST_READING);
   return err;
 }
 
index 2149456d3dab28de9e9c3757409a3277bef71285..3e890b981d123e19fb1280efab0b66b566ffaaa0 100644 (file)
@@ -25,6 +25,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 <http://www.gnu.org/licenses/>.  */
 
 #include "io.h"
+#include "fbuf.h"
 #include "format.h"
 #include "unix.h"
 #include <assert.h>
@@ -1585,6 +1586,7 @@ list_formatted_write_scalar (st_parameter_dt *dtp, bt type, void *p, int kind,
       internal_error (&dtp->common, "list_formatted_write(): Bad type");
     }
 
+  fbuf_flush_list (dtp->u.p.current_unit, LIST_WRITING);
   dtp->u.p.char_flag = (type == BT_CHARACTER);
 }