Commit Graph

120 Commits

Author SHA1 Message Date
Jerry DeLisle 16d962d92c re PR libfortran/31532 (INQUIRE(...,POSITION=...) not standard conforming)
2007-04-27  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libfortran/31532
	* io/file_pos.c (st_backspace): Set flags.position for end of file
	condition and use new function update_position.
	(st_endfile): Use new function update_position.
	* io/io.h: Add prototype for new function.
	* io/inquire.c (inquire_via_unit): If not direct access, set NEXTREC
	to zero.
	* io/unit.c (update_position): New function to update position info
	used by inquire.
	* io/transfer.c (next_record): Fix typo and use new function.

From-SVN: r124252
2007-04-28 02:03:21 +00:00
Thomas Koenig e08e57d0c5 re PR fortran/31618 ([4.2, 4.1 only] backspace intrinsic is not working on an unformatted file)
2007-04-23  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR fortran/31618
	* io/transfer.c (read_block_direct):  Instead of calling us_read,
	set dtp->u.p.current_unit->current_record = 0 so that pre_position
	will read the record marker.
	(data_transfer_init):  For different error conditions, call
	generate_error, then return.

2007-04-23  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR fortran/31618
	* gfortran.dg/backspace_8.f:  New test case.

From-SVN: r124079
2007-04-23 19:43:54 +00:00
Jerry DeLisle 08f9246a45 re PR libfortran/31052 ([4.2 only] Bad IOSTAT values when readings NAMELISTs past EOF)
2007-04-01  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/31052
	* io/open.c (test_endfile): Delete this function.
	(edit_modes): Delete call to test_endfile.
	(new_unit): Likewise.
	* io/io.h: Delete prototype for test_endfile.
	* io/transfer.c (next_record_r): Remove use of test_endfile.
	(st_read):  Add test for end file condition and adjust status.

From-SVN: r123403
2007-04-01 17:32:20 +00:00
Jerry DeLisle 138469296c re PR fortran/31366 ([4.2 only] Last record truncated for read after short write, direct access file)
2007-04-01  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/31366
	* io/transfer.c (read_block_direct): Do not generate error when reading
	past EOF on a short record that is less than the RECL= specified.
	
2007-04-01  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/31207
	* io/unit.c (close_unit_1): If there are bytes previously written from
	ADVANCE="no", move to the end before closing.

From-SVN: r123401
2007-04-01 15:23:48 +00:00
Jerry DeLisle f70ddc12ec re PR libfortran/31052 ([4.2 only] Bad IOSTAT values when readings NAMELISTs past EOF)
2007-03-27  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/31052
	* io/transfer.c (next_record_r): Do not call test_endfile if in namelist
	mode.

From-SVN: r123284
2007-03-28 00:19:39 +00:00
Jerry DeLisle beb6a65e75 re PR fortran/31199 (write with "t1" + nonadvancing transfer format gives wrong output)
2007-03-25  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/31199
	*io/io.h: Add saved_pos to gfc_unit structure.
	*io/open.c (new_unit): Initialize saved_pos.
	*io/transfer.c (data_transfer_init): Set max_pos to value in saved_pos.
	(next_record_w): Fix whitespace.
	(finalze_transfer): Calculate max_pos for ADVANCE="no" and save it for
	later use.  If not ADVANCE="no" set saved_pos to zero.

From-SVN: r123205
2007-03-26 03:23:15 +00:00
Jerry DeLisle 9a7b6ea727 re PR libfortran/31052 ([4.2 only] Bad IOSTAT values when readings NAMELISTs past EOF)
2007-03-22  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/31052
	* file_pos.c: Update Copyright year.
	* io/open.c (test_endfile): Restore test_endfile to fix SPEC regression.
	Update Copyright year.
	* io/io.h: Same.
	* io/unix.c (is_special): Add missing type for this function.
	Update Copyright year.
	* io/transfer.c (next_record_r): Restore test_endfile.
	(st_read): Fix whitespace.  Update Copyright year

From-SVN: r123139
2007-03-23 00:13:19 +00:00
Jerry DeLisle 7ab8aa3620 re PR libfortran/31052 ([4.2 only] Bad IOSTAT values when readings NAMELISTs past EOF)
2007-03-18  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/31052
	* io/file_position (st_rewind): Fix comments. Remove use of
	test_endfile. Don't seek if already at 0 position.  Use new is_special
	function to set endfile state.
	* io/open.c (test_endfile): Delete this function.
	* io/io.h: Delete prototype for test_endfile.  Add prototype
	for is_special.
	* io/unix.c (is_special): New function. Fix whitespace.
	* io/transfer.c (next_record_r): Remove use of test_endfile.

From-SVN: r123038
2007-03-18 18:13:50 +00:00
Jerry DeLisle 22cbc70726 re PR fortran/31051 ([4.2 Only] gfortran bug with x and t format descriptors.)
2007-03-14  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/31051
	* io/transfer.c (formatted_transfer_scalar): Adjust position for pending
	spaces when in writing mode.  Clean up some formatting.

From-SVN: r122940
2007-03-15 01:25:27 +00:00
Jerry DeLisle f4072316a3 re PR libfortran/31099 (Runtime error on legal code using RECL)
2007-03-09  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/31099
	* io/open.c (new_unit): Initialize bytes_left and recl_subrecord.
	* io/transfer.c (next_record_w): Set bytes left to record length for
	sequential unformatted I/O.
	(next_record_r): Ditto.
	(read_block_direct): Fix test for exceeding bytes_left.

From-SVN: r122763
2007-03-09 21:51:39 +00:00
Paul Thomas d4feb3d31a re PR fortran/30284 ([4.1 only] ICE in gfc_add_modify with internal reads)
2007-02-02  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/30284
	PR fortran/30626
	* trans-expr.c (gfc_conv_aliased_arg): Remove static attribute
	from function and make sure that substring lengths are
	translated.
	(is_aliased_array): Remove static attribute.
	* trans.c : Add prototypes for gfc_conv_aliased_arg and
	is_aliased_array.
	* trans-io.c (set_internal_unit): Add the post block to the
	arguments of the function.  Use is_aliased_array to check if
	temporary is needed; if so call gfc_conv_aliased_arg.
	(build_dt): Pass the post block to set_internal_unit and
	add to the block after all io activiy is done.

2007-02-02  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/30284
	PR fortran/30626
	* io/transfer.c (init_loop_spec, next_array_record): Change to
	lbound rather than unity base.

2007-02-02  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/30284
	* gfortran.dg/arrayio_11.f90.f90: New test.

	PR fortran/30626
	* gfortran.dg/arrayio_12.f90.f90: New test.

From-SVN: r121500
2007-02-02 12:35:57 +00:00
Jerry DeLisle cf79465213 re PR libfortran/30014 (INQUIRE (iolength = xx) limited to kind=4)
2006-12-27  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/30014
	*io/io.h (st_parameter_dt): Change *size and *iolength type to
	GFC_IO_INT.
	*io/transfer.c (finalize_transfer): Cast dtp->u.p.size_used to
	GFC_IO_INT.  (iolength_transfer): Cast size * nelems to GFC_IO_INT.

From-SVN: r120234
2006-12-28 01:40:23 +00:00
Jerry DeLisle 87cd572dee re PR fortran/30145 (Fortran 90: write statement fails to ignore zero-sized array...)
2006-12-15  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libfortran/30145
	* io/transfer.c (transfer_array):  Check for negative extent.

From-SVN: r119942
2006-12-15 19:54:52 +00:00
Thomas Koenig b4c811bd14 re PR libfortran/30009 ([4.1 only] Unformatted reads exceeding storage units gives EOF instead of ERR)
2006-12-06  Thomas Koenig  <Thomas.Koenig@online.de>

	PR libfortran/30009
	PR libfortran/30056
	* gfortran.dg/read_eof_4.f90:  Add tests.
	* gfortran.dg/readwrite_unf_direct_eor_1.f90:  New test.
	* gfortran.dg/unf_read_corrupted_1.f90: New test.

2006-12-06  Thomas Koenig  <Thomas.Koenig@online.de>

	PR libfortran/30009
	PR libfortran/30056
	* libgfortran.h:  Add ERROR_CORRUPT_FILE to error_codes.
	* runtime/error.c (translate_error):  Add handling for
	ERROR_CORRUPT_FILE.
	* io/transfer.c (read_block_direct):  Add comment about
	EOR for stream files.
	Remove test for no bytes left for direct access files.
	Generate an ERROR_SHORT_RECORD if the read was short.
	For unformatted sequential files:  Check endfile condition.
	Remove test for no bytes left.  End of file here means
	that the file structure has been corrupted.  Pre-position
	the file for the next record in case of error.
	(write_buf):  Whitespace fix.  Subtract the number of bytes
	written from bytes_left.

From-SVN: r119592
2006-12-06 19:25:44 +00:00
Thomas Koenig 07b3bbf200 re PR libfortran/29568 (implement unformatted files with subrecords (Intel style))
2006-12-01  Thomas Koenig  <Thomas.Koenig@online.de>

	PR libfortran/29568
	* gfortran.dg/convert_implied_open.f90:  Change to
	new default record length.
	* gfortran.dg/unf_short_record_1.f90:  Adapt to
	new error message.
	* gfortran.dg/unformatted_subrecords_1.f90:  New test.

2006-12-01  Thomas Koenig  <Thomas.Koenig@online.de>

	PR libfortran/29568
	* gfortran.h (gfc_option_t):  Add max_subrecord_length.
	(top level): Define MAX_SUBRECORD_LENGTH.
	* lang.opt:  Add option -fmax-subrecord-length=.
	* trans-decl.c:  Add new function set_max_subrecord_length.
	(gfc_generate_function_code): If we are within the main
	program and max_subrecord_length has been set, call
	set_max_subrecord_length.
	* options.c (gfc_init_options):  Add defaults for
	max_subrecord_lenght, convert and record_marker.
	(gfc_handle_option):  Add handling for
	-fmax_subrecord_length.
	* invoke.texi:  Document the new default for
	-frecord-marker=<n>.

2006-12-01  Thomas Koenig  <Thomas.Koenig@online.de>

	PR libfortran/29568
	* libgfortran/libgfortran.h (compile_options_t):  Add
	record_marker. (top level):  Define GFC_MAX_SUBRECORD_LENGTH.
	* runtime/compile_options.c (set_record_marker):  Change
	default to four-byte record marker.
	(set_max_subrecord_length):  New function.
	* runtime/error.c (translate_error):  Change error message
	for short record on unformatted read.
	* io/io.h (gfc_unit):  Add recl_subrecord, bytes_left_subrecord
	and continued.
	* io/file_pos.c (unformatted_backspace):  Change default of record
	marker size to four bytes.  Loop over subrecords.
	* io/open.c:  Default recl is max_offset.  If
	compile_options.max_subrecord_length has been set, set set
	u->recl_subrecord to its value, to the maximum value otherwise.
	* io/transfer.c (top level):  Add prototypes for us_read, us_write,
	next_record_r_unf and next_record_w_unf.
	(read_block_direct):  Separate codepaths for unformatted direct
	and unformatted sequential.  If a recl has been set by the
	user, use the number of bytes left for the record if it is smaller
	than the read request.  Loop over subrecords.  Set an error if the
	user has set a recl and the read was short.
	(write_buf):  Separate codepaths for unformatted direct and
	unformatted sequential. If a recl has been set by the
	user, use the number of bytes left for the record if it is smaller
	than the read request.  Loop over subrecords.  Set an error if the
	user has set a recl and the read was short.
	(us_read):  Add parameter continued (to indicate that bytes_left
	should not be intialized).  Change default of record marker size
	to four bytes. Use subrecord.  If the subrecord length is smaller than
	zero, this indicates a continuation.
	(us_write):  Add parameter continued (to indicate that the continued
	flag should be set).  Use subrecord.
	(pre_position):  Use 0 for continued on us_write and us_read calls.
	(skip_record):  New function.
	(next_record_r_unf):  New function.
	(next_record_r):  Use next_record_r_unf.
	(write_us_marker):  Default size for record markers is four bytes.
	(next_record_w_unf):  New function.
	(next_record_w):  Use next_record_w_unf.

From-SVN: r119412
2006-12-01 21:04:38 +00:00
Jerry DeLisle b0c6db58ad io.h (unit_flags): Add new flag has_recl.
2006-11-22  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	* io/io.h (unit_flags): Add new flag has_recl.
	* io.open.c (new_unit): Set flag if RECL= was specified.
	* io/transfer.c (us_write): If flag set, leave recl as initialized by
	new_unit.

From-SVN: r119087
2006-11-22 07:32:09 +00:00
Jerry DeLisle 54938c1127 re PR fortran/29752 (write(*,*,advance='NO'), READ(): Data not flushed)
2006-11-08  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/29752
	* io/transfer.c (finalize_transfer): Flush on ADVANCE_NO.

From-SVN: r118611
2006-11-09 03:03:40 +00:00
Jerry DeLisle d5fe3b0ea9 transfer.c (next_record_w): Fix indentation.
2006-11-05  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	* io/transfer.c (next_record_w): Fix indentation.

From-SVN: r118508
2006-11-05 17:54:17 +00:00
Jerry DeLisle 97cd182da7 re PR libfortran/25545 (internal file and dollar edit descriptor)
2006-11-04  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/25545
	* io/transfer.c (write_block): Cleanup code paths between
	stream and non-stream I/O.
	(write_buf):  Cleanup.
	(read_block): Cleanup.
	(finalize_transfer): Call next_record for '$' edit descriptor handling
	of internal unit. Cleanup code for readability.

From-SVN: r118506
2006-11-05 17:35:30 +00:00
Thomas Koenig 8a7f7fb6de re PR libfortran/29627 ([4.1 only] partial unformatted reads shouldn't succeed)
2006-10-31  Thomas Koenig  <Thomas.Koenig@online.de>

	PR libfortran/29627
	* libgfortran.h: Add ERROR_SHORT_RECORD
	* runtime/error.c (translate_error): Add case
	for ERROR_SHORT_RECORD.
	* io/transfer.c (read_block_direct):  Separate codepaths
	for stream and record unformatted I/O.  Remove unneeded
	tests for standard input, padding and formatted I/O.
	If the record is short, read in as much data as possible,
	then raise the error.

2006-10-31  Thomas Koenig  <Thomas.Koenig@online.de>

	PR libfortran/29627
	* gfortran.dg/unf_short_record_1.f90:  New test.

From-SVN: r118341
2006-10-31 20:58:26 +00:00
Tobias Burnus 751748ff5a re PR fortran/29625 (Octal edit descriptors allow real variables, even with -std=f95)
2006-10-28 Tobias Burnus <burnus@net-b.de>

	PR fortran/29625
	* io/transfer.c (formatted_transfer_scalar): Allow binary edit
	  descriptors for real variables; give error for BOZ edit
	  descriptor for non-integers when using -std=f*.

From-SVN: r118111
2006-10-28 23:05:42 +02:00
Tobias Burnus 8b6dba81f0 in_pack.m4: Fixed a typo.
2006-10-16  Tobias Burnus  <burnus@net-b.de>

        * m4/in_pack.m4: Fixed a typo.
        * m4/iforeach.m4: Fixed a typo.
        * m4/eoshift1.m4: Fixed a typo.
        * m4/eoshift3.m4: Fixed a typo.
        * m4/cshift1.m4: Fixed a typo.
        * m4/in_unpack.m4: Fixed a typo.
        * m4/reshape.m4: Fixed a typo.
        * m4/ifunction.m4: Fixed a typo.
        * runtime/environ.c: Fixed a typo.
        * runtime/in_pack_generic.c: Fixed a typo.
        * runtime/in_unpack_generic.c: Fixed a typo.
        * runtime/memory.c: Fixed a typo.
        * intrinsics/cshift0.c: Fixed a typo.
        * intrinsics/cpu_time.c: Fixed a typo.
        * intrinsics/pack_generic.c: Fixed a typo.
        * intrinsics/unpack_generic.c: Fixed a typo.
        * intrinsics/eoshift0.c: Fixed a typo.
        * intrinsics/eoshift2.c: Fixed a typo.
        * intrinsics/reshape_generic.c: Fixed a typo.
        * io/open.c: Fixed a typo.
        * io/list_read.c: Fixed a typo.
        * io/io.h: Fixed a typo.
        * io/transfer.c: Fixed a typo.
        * io/write.c: Fixed a typo.

From-SVN: r117857
2006-10-18 19:17:49 +02:00
Jerry DeLisle 09861cbee6 re PR fortran/29277 (Formated stream output: Translate "\n" / achar(10) into "\r\n" on some platforms)
2006-10-17  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/29277
	* io/list_read.c (next_char): Update strm_pos.
	(eat_separator): Delete extra call to unget_char.
	* io/transfer.c (read_block): Use read_sf for formatted stream I/O.
	(next_record_r): Update strm_pos for formatted stream I/O and handle
	end-of-record correctly.
	(next_record_w): Ditto.
	(next_record): Enable next record (r/w) functions and update strm_pos.
	(finalize_transfer): Call next_record to finish the record.

From-SVN: r117846
2006-10-18 04:04:07 +00:00
Jerry DeLisle 701306112e re PR fortran/29053 (Consecutive STREAM I/O file positions mixed up)
2006-09-14  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/29053
	* io.h (gfc_unit): Add variable, strm_pos, to track
	STREAM I/O file position.
	* file_pos.c (st_rewind): Set strm_pos to beginning.
	* open.c (new_unit): Initialize strm_pos.
	* read.c (read_x): Bump strm_pos.
	* inquire.c (inquire_via_unit): Return strm_pos value.
	* transfer.c (read_block),(read_block_direct),(write_block)
	(write_buf): Seek to strm_pos - 1.  Update strm_pos when done.
	(pre_position): Initialize strm_pos.
	(data_transfer_init): Set strm_pos if DT_HAS_REC.
	(finalize_transfer): Flush file, no need to update strm_pos.

From-SVN: r116970
2006-09-15 13:16:15 +00:00
Jerry DeLisle 91b30ee5b9 re PR fortran/25828 ([f2003] ACCESS='STREAM' io support)
2006-08-15  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/25828
	* libgfortran.h: Rename GFC_LARGE_IO_INT to GFC_IO_INT.
	* io/file_pos.c (st_backspace): Ignore if access=STREAM.
	(st_rewind): Handle case of access=STREAM.
	* io/open.c (access_opt): Add STREAM_ACCESS.
	(edit_modes): Set current_record to zero only if not STREAM.
	(new_unit): Initialize maxrec, recl, and last_record for STREAM.
	* io/read.c (read_x): Advance file position for STREAM.
	* io/io.h (enum unit_access): Align IOPARM flags with frontend.
	Add ACCESS_STREAM. Add prototype for is_stream_io () function.
	Use GFC_IO_INT.
	* io/inquire.c (inquire_via_unit): Add text for access = "STREAM".
	* io/unit.c (is_stream_io): New function to return true if access =
	STREAM.
	* io/transfer.c (file_mode): Add modes for unformatted stream and
	formatted stream. (current_mode): Return appropriate file mode based
	on access flags.
	(read_block): Handle formatted stream reads.
	(read_block_direct): Handle unformatted stream reads.
	(write_block): Handle formatted stream writes.
	(write_buf): Handle unformatted stream writes.
	(unformatted_read): Fix up, use temporary for size.
	(pre_position): Position file for STREAM access.
	(data_transfer_init): Initialize for stream access, skip irrelevent
	error checks.
	(next_record_r),(next_record_w), and (next_record): Do nothing for
	stream I/O.
	(finalize_transfer): Flush when all done if stream I/O.

From-SVN: r116172
2006-08-15 23:06:44 +00:00
Janne Blomqvist 6097a89729 transfer.c (transfer_array): Remove stride0 fix.
2006-07-30  Janne Blomqvist  <jb@gcc.gnu.org>

	* io/transfer.c (transfer_array): Remove stride0 fix.

From-SVN: r115818
2006-07-30 13:23:26 +03:00
Jerry DeLisle 397bc09a65 re PR fortran/28339 (gfortran misses a record from a format statement)
2006-07-21  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/28339
	* io/transfer.c (next_record_w): Use next_array_record result to set
	END_FILE. (write_block): Test for END_FILE before the next write occurs.
	* io/unit.c (get_internal_unit): Initialize iunit->endfile for internal
	unit.

From-SVN: r115670
2006-07-22 03:14:27 +00:00
Jerry DeLisle 2e4444278c re PR libfortran/27704 (Incorrect runtime error on multiple OPEN)
2006-07-03  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/27704
	* runtime/error.c (notify_std): Pass common flags into function. Use
	flags to show locus of error or warning.
	* libgfortran.h: Add enum try.  Add prototype for notify_std.
	* io/open.c (edit_modes): Allow status="old" and add extension to
	allow status="scratch"
	*io/list_read.c (nml_read_obj): Update call to notify_std.
	*io/io.h: Remove enum try and prototype for notify_std.
	*io/transfer.c (read_sf): Update call to notify_std.
	*io/format.c (parse_format_list): Update call to notify_std.

From-SVN: r115168
2006-07-04 01:36:31 +00:00
Jerry DeLisle 8bf6519618 re PR libfortran/22423 (Warnings when building libgfortran)
2006-05-19  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/22423
	* io/transfer.c (read_block): Return NULL instead of nothing.

From-SVN: r113923
2006-05-20 03:29:58 +00:00
Jerry DeLisle cacf2b9638 re PR libfortran/27575 (gfortran - does not generate error when trying to read too much data)
2006-05-16  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/27575
	* io/transfer.c (read_block):  Add check for end file condition.
	(read_block_direct): Add check for end file condition.

From-SVN: r113837
2006-05-17 00:36:53 +00:00
Jerry DeLisle c4ee121ad5 re PR fortran/27304 (gfortran: Warn/abort when format in write does not fit passed arguments)
2006-04-28  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/27304
	* io/transfer.c (formatted_transfer_scalar):  Generate error if data
	descriptors are exhausted.
	* io/format.c (next_format0): Fix comment.

From-SVN: r113363
2006-04-28 23:55:30 +00:00
Jerry DeLisle 54ffdb125c re PR libfortran/20257 (Fortran runtime error: End of record occurs when writing large arrays)
2006-04-22  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/20257
	* io/io.h: Add prototypes for get_internal_unit and free_internal_unit.
	* io/unit.c (get_internal_unit): Initialize unit number, not zero.
	(free_internal_unit): New function to consolidate freeing memory.
	(get_unit): Initialize internal_unit_desc to NULL when unit is
	external.
	* io/unix.c (mem_close): Check for not NULL before freeing memory.
	* io/transfer.c (read_block): Reset bytes_left and skip error if unit
	is preconnected and default record length is reached.
	(read_block_direct): Ditto.
	(write_block): Ditto.
	(write_buf): Ditto.
	(data_transfer_init): Only flush if not internal unit.
	(finalize_transfer): Ditto and delete code to free memory used by
	internal units.
	(st_read_done): Use new function - free_internal_unit.
	(st_write_done): Use new function - free_internal unit.

From-SVN: r113190
2006-04-23 02:04:58 +00:00
Jerry DeLisle 6f34d6e078 re PR fortran/26766 ([F2003] Recursive I/O still (again) broken)
2006-04-12  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/26766
	* io/io.h: Add bit to identify associated unit as internal.
	* io/unit.c (get_external_unit): Renamed the find_unit_1 function to
	reflect the external unit functionality vs internal unit.
	(get_internal_unit): New function to allocate and initialize an internal
	unit structure.
	(get_unit): Use get_internal_unit and get_external_unit.
	(is_internal_unit): Revised to use new bit added in io.h.
	* io/transfer.c (data_transfer_init): Fix line width.
	(st_read_done): Free memory allocated for internal unit.
	(st_write_done): Add test to only flush and truncate when not an
	internal unit.  Free memory allocated for internal unit.

From-SVN: r112914
2006-04-13 06:24:58 +00:00
Jerry DeLisle d57d342432 re PR libfortran/26890 (SIZE parameter interacts with same variable in IO list character length specification.)
2006-03-30  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/26890
	* io/io.h: Add size_used to st_parameter_dt, adjust pad size.
	*io/transfer.c (data_transfer_init): Initialize size_used to zero.
	(read_sf): Use size_used.
	(read_block): Likewise.
	(read_block_direct): Likewise.
	(write_block): Likewise.
	(write_buf): Likewise and eliminate erroneous FAILURE return.
	(finalize_transfer): Assign value of size_used to *dtp->size.

From-SVN: r112570
2006-03-31 05:11:03 +00:00
Jerry DeLisle 0853054e96 re PR libfortran/26661 (Sequential formatted read goes too far)
2006-03-25  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/26661
	* io/io.h: Add read_sf so it can be used by read_x.
	* io/transfer.c (read_sf): Pass no_error flag to read_sf.  Use it to
	break out rather than error on EOF or EOR conditions.
	(read_block): Update call to read_sf.
	(read_block_direct): Ditto.
	* io/read.c (read_x): Use the modified read_sf instead of read_block.

From-SVN: r112390
2006-03-26 02:15:44 +00:00
Thomas Koenig 5068c62534 re PR libfortran/26735 ([4.1 only] -fconvert=swap and implied open)
2006-03-25  Thomas Koenig  <Thomas.Koenig@online.de>

	PR libfortran/26735
	* io/transfer.c (data_transfer_init):  Set u_flags.convert
	on an unopened unit if specified by environment variable
	(via get_unformatted_convert) or by compile-time option.

2006-03-25  Thomas Koenig  <Thomas.Koenig@online.de>

	PR libfortran/26735
	* gfortran.dg/convert_implied_open.f90:  New test case.

From-SVN: r112382
2006-03-25 21:31:48 +00:00
Thomas Koenig d67ab5eef8 [multiple changes]
2006-03-22  Thomas Koenig  <Thomas.Koenig@onlien.de>

	PR fortran/19303
	* gfortran.h (gfc_option_t):  Add record_marker.
	* lang.opt:  Add -frecord-marker=4 and -frecord-marker=8.
	* trans-decl.c:  Add gfor_fndecl_set_record_marker.
	(gfc_build_builtin_function_decls): Set
	gfor_fndecl_set_record_marker.
	(gfc_generate_function_code):  If we are in the main program
	and -frecord-marker was provided, call set_record_marker.
	* options.c (gfc_handle_option):  Add handling for
	-frecord-marker=4 and -frecord-marker=8.
	* invoke.texi:  Document -frecord-marker.

2006-03-22  Thomas Koenig  <Thomas.Koenig@onlien.de>

	PR fortran/19303
	* libgfortran.h (compile_options_t):  Add record_marker.
	* runtime/compile_options.c (set_record_marker):
	New function.
	* io/open.c:  If we have four-byte record markers, use
	GFC_INTEGER_4_HUGE as default record length.
	* io/file_pos.c (unformatted_backspace):  Handle
	different size record markers.
	* io/transfer.c (us_read):  Likewise.
	(us_write):  Likewise.
	(next_record_r):  Likewise.
	(write_us_marker):  Likewise.
	(next_record_w):  Likewise.

2006-03-22  Thomas Koenig  <Thomas.Koenig@online.de>

	PR fortran/19303
	* gfortran.dg/record_marker_1.f90:  New test case.
	* gfortran.dg/record_marker_2.f:  New test case.
	* gfortran.dg/record_marker_3.f90:  New test case.

From-SVN: r112290
2006-03-22 19:09:11 +00:00
Jerry DeLisle 54f9e2781e re PR fortran/26509 (incorrect behaviour of error-handler for direct access write)
2006-03-17  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/26509
	* libgfortran.h: Add ERROR_DIRECT_EOR.
	* runtime/error.c (translate_error): Add translation for new error.
	* io/transfer.c (write_buf): Add check for EOR when mode is 
	direct access.

From-SVN: r112198
2006-03-18 01:56:07 +00:00
Jerry DeLisle 99c6db71de re PR libfortran/26499 (gfortran - End of File incorrectly positioned after binary I/O.)
2006-03-09  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/26499
	* io/file_pos (st_rewind): Flush always.
	* io/unix.c (fd_truncate): Return SUCCESS rather than FAILURE for
	special files like /dev/null.
	* io/transfer.c (st_write_done): Remove broken logic that prevented
	calling fd_truncate.

From-SVN: r111924
2006-03-10 03:15:36 +00:00
Jerry DeLisle 9985dd8aaf re PR libfortran/26464 (Runtime I/O error/invald argument on READ)
2006-02-27  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/26464
	* io/file_pos.c (st_backspace): Flush and truncate file
	when in AFTER_ENDFILE condition.
	* io/transfer.c (st_read_done): Remove flush, no longer needed.

From-SVN: r111506
2006-02-28 02:07:00 +00:00
Janne Blomqvist 82b8244c51 re PR libfortran/25949 (Unbounded I/O buffer memory usage for formatted IO)
2006-02-12  Janne Blomqvist  <jb@gcc.gnu.org>

	PR libgfortran/25949
	* io/io.h: Add set function pointer to struct stream.  
	* io/unix.c (fd_seek): Only update offset, don't seek.
	(fd_sset): New function.
	(fd_read): Call lseek directly if necessary.
	(fd_write): Likewise.
	(fd_open): Set pointer to fd_sset.
	(mem_set): New function.
	(open_internal): Set pointer to mem_set.
	* io/transfer.c (write_block_direct): Rename to write_buf, add
	error return, non-pointer length argument.
	(unformatted_write): Update to use write_buf.
	(us_write): Simplify by using swrite instead of salloc_w.
	(write_us_marker): New function.
	(new_record_w): Use sset instead of memset, use write_us_marker,
	simplify by using swrite instead of salloc_w.

From-SVN: r110895
2006-02-12 21:59:32 +02:00
Jerry DeLisle ecc9e67eef re PR libfortran/25835 (Segfault or Bad Address error on unformatted sequential READ)
2006-01-24  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/25835
	* io/transfer.c (st_read_done): Flush buffers when read is done.

From-SVN: r110200
2006-01-25 01:19:11 +00:00
Jerry DeLisle 7b7034ea9a re PR libfortran/25697 (libfortran - Segmentation fault/ Bad Address on unformatted read)
2006-01-17  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/25697
	* io/transfer.c (us_read): Detect end of file condition from previous
	operations and bail out (no need to pre-position).

From-SVN: r109870
2006-01-18 06:21:28 +00:00
Jerry DeLisle 272c35bd98 re PR libfortran/25631 (tl format specifier not working correctly)
2006-01-17  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/25631
	* io/transfer.c (formatted_transfer_scalar): Adjust pending_spaces and
	skips so that TL works correctly when no bytes_used yet.

From-SVN: r109858
2006-01-18 00:52:21 +00:00
Jerry DeLisle 9696b2257c re PR libfortran/25598 (gfortran - Fortran runtime error: Invalid argument)
2006-01-05  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/25598
	* io/file_pos.c (unformatted_backspace): Assure the new file position
	to seek is not less than zero.
	(st_backspace): Set unit bytes_left to zero.
	* io/transfer.c (next_record_r): Fix line lengths, no functional change.

From-SVN: r109405
2006-01-06 01:39:34 +00:00
Jerry DeLisle 844234fb50 re PR libfortran/25139 ("Invalid argument" error on I/O)
2005-12-28  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/25139
	* io/unix.c (fd_truncate): Set s->active to zero.
	PR libgfortran/25510
	* libgfortran.h: Add ERROR_INTERNAL and ERROR_INTERNAL_UNIT.
	* runtime/error.c (translate_error): Add messages for new errors.
	* io/list_read.c (next_char): Use new errors.
	* io/transfer.c (next_record_r) (next_record_w): Use new errors.

From-SVN: r109122
2005-12-28 20:58:08 +00:00
Jerry DeLisle 0a73639369 re PR libfortran/25463 (T edit descriptor and ADVANCE="no")
2005-12-18  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/25463
	* io/transfer.c (finalize_transfer): Fix execution order so that
	next_record is set to zero in all cases.

From-SVN: r108784
2005-12-19 06:52:33 +00:00
Jerry DeLisle 494ef4c254 re PR fortran/25264 (write to internal unit from the string itself gives wrong result ?)
2005-12-16  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/25264
	PR libgfortran/25349
	* io/unit.c (get_unit): Delete code that cleared the string when the
	unit was opened, which is too soon.
	* io/transfer.c (next_record_w): Pass done flag in.  Change logic for
	setting max_pos.  Add code to position unit and pad record as needed.

From-SVN: r108671
2005-12-16 19:32:21 +00:00
Thomas Koenig 181c9f4a9b re PR fortran/23815 (Add -byteswapio flag)
2005-12-10  Thomas Koenig  <Thomas.Koenig@online.de>

	PR fortran/23815
	* io.c (top level):  Add convert to io_tag.
	(resolve_tag):  convert is GFC_STD_GNU.
	(match_open_element):  Add convert.
	(gfc_free_open):  Likewise.
	(gfc_resolve_open):  Likewise.
	(gfc_free_inquire):  Likewise.
	(match_inquire_element):  Likewise.
	* dump-parse-tree.c (gfc_show_code_node):  Add
	convet for open and inquire.
	gfortran.h: Add convert to gfc_open and gfc_inquire.
	* trans-io.c (gfc_trans_open):  Add convert.
	(gfc_trans_inquire):  Likewise.
	* ioparm.def:  Add convert to open and inquire.
	* gfortran.texi:  Document CONVERT.

2005-12-10  Thomas Koenig  <Thomas.Koenig@online.de>

	PR fortran/23815
	* io/file_pos.c (unformatted_backspace):  If flags.convert
	does not equal CONVERT_NATIVE, reverse the record marker.
	* io/open.c:  Add convert_opt[].
	(st_open):  If no convert option is given, set CONVERT_NATIVE.
	If CONVERT_BIG or CONVERT_LITTLE are given, set flags.convert to
	CONVERT_NATIVE or CONVERT_SWAP (depending on wether we have
	a big- or little-endian system).
	* io/transfer.c (unformatted_read):  Remove unused attribute
	from arguments.
	If we need to reverse
	bytes, break up large transfers into a loop.  Split complex
	numbers into its two parts.
	(unformatted_write):  Likewise.
	(us_read):  If flags.convert does not equal CONVERT_NATIVE,
	reverse the record marker.
	(next_record_w): Likewise.
	(reverse_memcpy):  New function.
	* io/inquire.c (inquire_via_unit):  Implement convert.
	* io/io.h (top level):  Add enum unit_convert.
	Add convert to st_parameter_open and st_parameter_inquire.
	Define IOPARM_OPEN_HAS_CONVERT and IOPARM_INQUIRE_HAS_CONVERT.
	Increase padding for st_parameter_dt.
	Declare reverse_memcpy().

2005-12-10  Thomas Koenig  <Thomas.Koenig@online.de>

	PR fortran/23815
	* gfortran.dg/unf_io_convert_1.f90:  New test.
	* gfortran.dg/unf_io_convert_2.f90:  New test.
	* gfortran.dg/unf_io_convert_3.f90:  New test.

From-SVN: r108358
2005-12-10 20:01:56 +00:00
Jerry DeLisle b14c7e14ab re PR libfortran/25039 ([4.1 only] comma short-circuit field width)
2005-12-08  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/25039
	* io/io.h: Create a new flag sf_read_comma to control comma
	separators in numeric reads.
	* io/transfer.c (formatted_transfer_scalar): Initialize the flag.
	(read_sf): Check for commas coming in and if the flag is set,
	shortcut the read.
	* io/read.c (read_a) (read_x): Clear the flag for character reads and
	reset it after the reads.

From-SVN: r108271
2005-12-09 02:53:41 +00:00