This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch, libgfortran] Bug 48030 - Implement read_x using fbuf_getc
- From: Jerry DeLisle <jvdelisle at frontier dot com>
- To: gfortran <fortran at gcc dot gnu dot org>
- Cc: gcc patches <gcc-patches at gcc dot gnu dot org>
- Date: Sat, 19 Mar 2011 21:46:34 -0700
- Subject: [patch, libgfortran] Bug 48030 - Implement read_x using fbuf_getc
Hi,
The attached patch re-implements read_x using fbuf_getc. Self explanatory.
Regression tested on x86-64 linux. No new test case needed.
Ok for trunk?
Regards,
Jerry
2011-03-19 Jerry DeLisle <jvdelisle@gcc.gnu.org>
PR libgfortran/48030
* io/read.c (read_x): Re-implement using fbuf_getc.
Index: read.c
===================================================================
--- read.c (revision 171191)
+++ read.c (working copy)
@@ -1186,8 +1186,8 @@
void
read_x (st_parameter_dt *dtp, int n)
{
- int length;
- char *p, q;
+ int length, q, q2;
+ char *p;
if ((dtp->u.p.current_unit->pad_status == PAD_NO || is_internal_unit (dtp))
&& dtp->u.p.current_unit->bytes_left < n)
@@ -1230,34 +1230,34 @@
n = 0;
while (n < length)
{
- q = *p;
- if (q == '\n' || q == '\r')
+ q = fbuf_getc (dtp->u.p.current_unit);
+ if (q == EOF)
+ break;
+ else if (q == '\n' || q == '\r')
{
/* Unexpected end of line. Set the position. */
- fbuf_seek (dtp->u.p.current_unit, n + 1 ,SEEK_CUR);
dtp->u.p.sf_seen_eor = 1;
+ /* If we see an EOR during non-advancing I/O, we need to skip
+ the rest of the I/O statement. Set the corresponding flag. */
+ if (dtp->u.p.advance_status == ADVANCE_NO || dtp->u.p.seen_dollar)
+ dtp->u.p.eor_condition = 1;
+
/* If we encounter a CR, it might be a CRLF. */
if (q == '\r') /* Probably a CRLF */
{
- /* See if there is an LF. Use fbuf_read rather then fbuf_getc so
- the position is not advanced unless it really is an LF. */
- int readlen = 1;
- p = fbuf_read (dtp->u.p.current_unit, &readlen);
- if (*p == '\n' && readlen == 1)
- {
- dtp->u.p.sf_seen_eor = 2;
- fbuf_seek (dtp->u.p.current_unit, 1 ,SEEK_CUR);
- }
+ /* See if there is an LF. */
+ q2 = fbuf_getc (dtp->u.p.current_unit);
+ if (q2 == '\n')
+ dtp->u.p.sf_seen_eor = 2;
+ else if (q2 != EOF) /* Oops, seek back. */
+ fbuf_seek (dtp->u.p.current_unit, -1, SEEK_CUR);
}
goto done;
}
n++;
- p++;
}
- fbuf_seek (dtp->u.p.current_unit, n, SEEK_CUR);
-
done:
if ((dtp->common.flags & IOPARM_DT_HAS_SIZE) != 0)
dtp->u.p.size_used += (GFC_IO_INT) n;