Bug 34370 - file positioning after nonadvancing i/o
Summary: file positioning after nonadvancing i/o
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libfortran (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: ---
Assignee: Thomas Koenig
URL:
Keywords: wrong-code
Depends on:
Blocks: 32834
  Show dependency treegraph
 
Reported: 2007-12-06 22:32 UTC by Thomas Koenig
Modified: 2007-12-13 19:39 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2007-12-07 19:18:12


Attachments
proposed patch (1.80 KB, patch)
2007-12-09 23:05 UTC, Thomas Koenig
Details | Diff
an improved version (1.91 KB, patch)
2007-12-12 20:08 UTC, Thomas Koenig
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Koenig 2007-12-06 22:32:56 UTC
... should add a record marker.

F 2003, 9.2.3.1:

If a nonadvancing output statement leaves a file positioned 1 within a current record and no further output
statement is executed for the file before it is closed or a BACKSPACE, ENDFILE, or REWIND statement
is executed for it, the effect is as if the output statement were the corresponding advancing output
statement.

$ cat advance.f90
program main
  open(95, form="formatted")
  write (95, '(A)', advance="no") 'a'
  backspace 95
end program main

$ gfortran advance.f90
$ ./a.out
$ cat fort.95
a$
Comment 1 Jerry DeLisle 2007-12-07 04:32:52 UTC
Thomas, this should be straightforward.  Do you want to work this along with PR 34323 ?
Comment 2 Thomas Koenig 2007-12-07 19:18:12 UTC
(In reply to comment #1)
> Thomas, this should be straightforward.  Do you want to work this along with PR
> 34323 ?

Yes, I'll take it.

Comment 3 Thomas Koenig 2007-12-09 23:05:44 UTC
Created attachment 14715 [details]
proposed patch

This is a first go at PR 34323, 34370 and 34405, so
far untested and missing some test cases.
Comment 4 Thomas Koenig 2007-12-12 20:08:17 UTC
Created attachment 14740 [details]
an improved version

Sanity checking found bugs :-)
Comment 5 Thomas Koenig 2007-12-13 19:35:37 UTC
Subject: Bug 34370

Author: tkoenig
Date: Thu Dec 13 19:35:09 2007
New Revision: 130912

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=130912
Log:
2007-12-13  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR libfortran/34370
	PR libfortran/34323
	PR libfortran/34405
	* io/io.h:  Add previous_nonadvancing_write to gfc_unit.
	Add prototype for finish_last_advance_record.
	* io/file_pos.c (st_backspace):  Generate error if backspace is
	attempted for direct access or unformatted stream.
	If there are bytes left from a previous ADVANCE="no", write
	them out before performing the backspace.
	(st_endfile):  Generate error if endfile is attempted for
	direct access.
	If there are bytes left from a previous ADVANCE="no", write
	them out before performing the endfile.
	(st_rewind):  Generate error if rewind is attempted for
	direct access.
	* unit.c (close_unit_1):  Move functionality to write
	previously written bytes to...
	(finish_last_advance_record):  ... here.
	* transfer.c (data_transfer_init):  If reading, reset
	previous_nonadvancing_write.
	(finalize_transfer):  Set the previous_noadvancing_write
	flag if we are writing and ADVANCE="no" was specified.
	Only call next_record() if advance="no" wasn't specified.

2007-12-13  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR libfortran/34370
	PR libfortran/34323
	PR libfortran/34405
	* gfortran.dg/advance_6.f90:  New test case.
	* gfortran.dg/direct_io_7.f90:  New test case.
	* gfortran.dg/streamio_13.f90:  New test case.


Added:
    trunk/gcc/testsuite/gfortran.dg/advance_6.f90
    trunk/gcc/testsuite/gfortran.dg/direct_io_7.f90
    trunk/gcc/testsuite/gfortran.dg/streamio_13.f90
Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/libgfortran/ChangeLog
    trunk/libgfortran/io/file_pos.c
    trunk/libgfortran/io/io.h
    trunk/libgfortran/io/transfer.c
    trunk/libgfortran/io/unit.c

Comment 6 Thomas Koenig 2007-12-13 19:37:39 UTC
Fixed on trunk.

Closing.
Comment 7 Thomas Koenig 2007-12-13 19:38:34 UTC
Fixed on trunk.

Closing.
Comment 8 Thomas Koenig 2007-12-13 19:39:30 UTC
Actually closing *sigh*