Skip to content

Commit 153ce7a

Browse files
author
Jerry DeLisle
committed
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.
1 parent 065dddc commit 153ce7a

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
! { dg-do run }
2+
! PR109358, test that tabs during stream io are correct.
3+
program tabs
4+
implicit none
5+
integer :: fd
6+
character(64) :: line
7+
open(newunit=fd, file="otabs.txt", form="formatted", access="stream")
8+
write(fd, "(i4, t40, i4, t20, i5.5)") 1234, 5555, 67890
9+
close(fd)
10+
open(newunit=fd, file="otabs.txt", form="formatted")
11+
read(fd,"(a)") line
12+
close(fd, status='delete')
13+
if (line .ne. "1234 67890 5555") stop 10
14+
end program tabs

libgfortran/io/transfer.c

+9-5
Original file line numberDiff line numberDiff line change
@@ -2072,11 +2072,11 @@ formatted_transfer_scalar_write (st_parameter_dt *dtp, bt type, void *p, int kin
20722072
dtp->u.p.skips = dtp->u.p.pending_spaces = 0;
20732073
}
20742074

2075-
bytes_used = dtp->u.p.current_unit->recl
2076-
- dtp->u.p.current_unit->bytes_left;
2077-
20782075
if (is_stream_io(dtp))
2079-
bytes_used = 0;
2076+
bytes_used = dtp->u.p.current_unit->fbuf->act;
2077+
else
2078+
bytes_used = dtp->u.p.current_unit->recl
2079+
- dtp->u.p.current_unit->bytes_left;
20802080

20812081
switch (t)
20822082
{
@@ -2452,7 +2452,11 @@ formatted_transfer_scalar_write (st_parameter_dt *dtp, bt type, void *p, int kin
24522452
p = ((char *) p) + size;
24532453
}
24542454

2455-
pos = dtp->u.p.current_unit->recl - dtp->u.p.current_unit->bytes_left;
2455+
if (is_stream_io(dtp))
2456+
pos = dtp->u.p.current_unit->fbuf->act;
2457+
else
2458+
pos = dtp->u.p.current_unit->recl - dtp->u.p.current_unit->bytes_left;
2459+
24562460
dtp->u.p.max_pos = (dtp->u.p.max_pos > pos) ? dtp->u.p.max_pos : pos;
24572461
}
24582462

0 commit comments

Comments
 (0)