public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jerry DeLisle <jvdelisle@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r14-8944] libgfortran: Adjust bytes_left and pos for access="STREAM".
Date: Mon, 12 Feb 2024 23:30:07 +0000 (GMT)	[thread overview]
Message-ID: <20240212233007.3AE693858C52@sourceware.org> (raw)

https://gcc.gnu.org/g:153ce7a78edbe339fa0b1cd314dea0554f59faf0

commit r14-8944-g153ce7a78edbe339fa0b1cd314dea0554f59faf0
Author: Jerry DeLisle <jvdelisle@gcc.gnu.org>
Date:   Mon Feb 12 13:12:08 2024 -0800

    libgfortran: Adjust bytes_left and pos for access="STREAM".
    
    During tab edits, the pos (position) and bytes_used
    Variables were not being set correctly for stream I/O.
    Since stream I/O does not have 'real' records, the
    format buffer active length must be used instead of
    the record length variable.
    
           PR libgfortran/109358
    
    libgfortran/ChangeLog:
    
            * io/transfer.c (formatted_transfer_scalar_write): Adjust
            bytes_used and pos variable for stream access.
    
    gcc/testsuite/ChangeLog:
    
            * gfortran.dg/pr109358.f90: New test.

Diff:
---
 gcc/testsuite/gfortran.dg/pr109358.f90 | 14 ++++++++++++++
 libgfortran/io/transfer.c              | 14 +++++++++-----
 2 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/gcc/testsuite/gfortran.dg/pr109358.f90 b/gcc/testsuite/gfortran.dg/pr109358.f90
new file mode 100644
index 000000000000..5013984095b1
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr109358.f90
@@ -0,0 +1,14 @@
+! { dg-do run }
+! PR109358, test that tabs during stream io are correct.
+program tabs
+  implicit none
+  integer :: fd
+  character(64) :: line
+  open(newunit=fd, file="otabs.txt", form="formatted", access="stream")
+  write(fd, "(i4, t40, i4, t20, i5.5)") 1234, 5555, 67890
+  close(fd)
+  open(newunit=fd, file="otabs.txt", form="formatted")
+  read(fd,"(a)") line
+  close(fd, status='delete')
+  if (line .ne. "1234               67890               5555") stop 10
+end program tabs
diff --git a/libgfortran/io/transfer.c b/libgfortran/io/transfer.c
index 80b60dfeb9f8..99ef96a9e7c8 100644
--- a/libgfortran/io/transfer.c
+++ b/libgfortran/io/transfer.c
@@ -2072,11 +2072,11 @@ formatted_transfer_scalar_write (st_parameter_dt *dtp, bt type, void *p, int kin
 	  dtp->u.p.skips = dtp->u.p.pending_spaces = 0;
 	}
 
-      bytes_used = dtp->u.p.current_unit->recl
-		   - dtp->u.p.current_unit->bytes_left;
-
       if (is_stream_io(dtp))
-	bytes_used = 0;
+	bytes_used = dtp->u.p.current_unit->fbuf->act;
+      else
+	bytes_used = dtp->u.p.current_unit->recl
+		    - dtp->u.p.current_unit->bytes_left;
 
       switch (t)
 	{
@@ -2452,7 +2452,11 @@ formatted_transfer_scalar_write (st_parameter_dt *dtp, bt type, void *p, int kin
 	  p = ((char *) p) + size;
 	}
 
-      pos = dtp->u.p.current_unit->recl - dtp->u.p.current_unit->bytes_left;
+      if (is_stream_io(dtp))
+	pos = dtp->u.p.current_unit->fbuf->act;
+      else
+	pos = dtp->u.p.current_unit->recl - dtp->u.p.current_unit->bytes_left;
+
       dtp->u.p.max_pos = (dtp->u.p.max_pos > pos) ? dtp->u.p.max_pos : pos;
     }

                 reply	other threads:[~2024-02-12 23:30 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240212233007.3AE693858C52@sourceware.org \
    --to=jvdelisle@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).