]> 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>
Mon, 23 Mar 2015 00:16:01 +0000 (00:16 +0000)
committerJerry DeLisle <jvdelisle@gcc.gnu.org>
Mon, 23 Mar 2015 00:16:01 +0000 (00:16 +0000)
2015-03-22  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

PR libgfortran/60956
Backport from mainline
* 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: r221578

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

index 6b995493057c5cfdc66f80464f76cdf4d38e2383..708e13e7a5d3ec75cec5e936b17aba642bce3224 100644 (file)
@@ -1,3 +1,15 @@
+2015-03-22  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
+
+       PR libgfortran/60956
+       Backport from mainline
+       * 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.
+
 2014-10-30  Release Manager
 
        * GCC 4.9.2 released.
index 170ce9754c906094ec1f193aa13477c252b9c661..0c6ae546518b125282010233521c7a06cb08823a 100644 (file)
@@ -174,6 +174,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 253b2adcf8460ad9754c231122fda70f05455571..d9a16111727916f28518917ace3b0bb9a7638e83 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 3481c83d791b79b2bc1706d3054dd007248474b3..a24727271c01ce286418ee1cc805c6927b9b2b47 100644 (file)
@@ -207,7 +207,7 @@ typedef enum
 unit_advance;
 
 typedef enum
-{READING, WRITING}
+{READING, WRITING, LIST_READING, LIST_WRITING}
 unit_mode;
 
 typedef enum
index b64189afe1f9efdfb4a50ad4606815ad13c7c74c..b95721069ccb20768f655631816c3a54cb5d6748 100644 (file)
@@ -2054,6 +2054,7 @@ cleanup:
       free_line (dtp);
       hit_eof (dtp);
     }
+  fbuf_flush_list (dtp->u.p.current_unit, LIST_READING);
   return err;
 }
 
index f76ec673b34b351d8d7036d36c34579c01840bd5..a43dc0309e5f4fe4034a5fabc773c45a4be5ffa6 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);
 }