Commit Graph

149 Commits

Author SHA1 Message Date
Jerry DeLisle d8e390ad79 backport: re PR fortran/83225 (runtime error in transfer.c)
2017-12-02  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	Backport from trunk
	PR libgfortran/83225
	* io/io.h (is_internal_unit): Use the unit_is_internal bit.
	* io/transfer.c (data_transfer_init): Set the bit to true for
	internal units. Use that bit for checks for internal unit
	initializations.
	* io/unit.c (insert_unit): As a precaution, set the
	internal_unit_kind to zero when a unit structure is first created.

From-SVN: r255364
2017-12-03 05:05:51 +00:00
Jerry DeLisle 5ed479711f backport: re PR libfortran/78549 (Very slow formatted internal file output)
2017-11-23  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	Backport from trunk
	PR libgfortran/78549
	* io/io.h (newunit_free): Add declaration. Clean some whitespace.
	* io/transfer.c (st_read_done, st_write_done): Call newunit_free.
	* io/unit.c (newunit_free): Change type from static void to void.

From-SVN: r255108
2017-11-23 17:19:18 +00:00
Jerry DeLisle 1f10d710e3 re PR fortran/78881 ([F03] reading from string with DTIO procedure does not work properly)
2017-03-25  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/78881
	* io/io.h (st_parameter_dt): Rename unused component last_char to
	child_saved_iostat. Move comment to gfc_unit.
	* io/list_read.c (list_formatted_read_scalar): After call to
	child READ procedure, save the returned iostat value for later
	check. (finish_list_read): Only finish READ if child_saved_iostat
	was OK.
	* io/transfer.c (read_sf_internal): If there is a saved character
	in last character, seek back one. Add a new check for EOR
	condition. (read_sf): If there is a saved character
	in last character, seek back one. (formatted_transfer_scalar_read):
	Initialize last character before invoking child procedure.
	(data_transfer_init): If child dtio, set advance
	status to nonadvancing. Move update of size and check for EOR
	condition to before child dtio return.

	* gfortran.dg/dtio_26.f90: New test.

From-SVN: r246478
2017-03-25 18:48:01 +00:00
Jakub Jelinek cbe34bb5ed Update copyright years.
From-SVN: r243994
2017-01-01 13:07:43 +01:00
Fritz Reese 6869e9c69f Default missing exponents to 0 with -fdec.
gcc/fortran/
	* gfortran.texi: Document.
	* gfortran.h (gfc_dt): New field default_exp.
	* primary.c (match_real_constant): Default exponent with -fdec.
	* io.c (match_io): Set dt.default_exp with -fdec.
	* ioparm.def (IOPARM_dt_default_exp): New.
	* trans-io.c (build_dt): Set IOPARM_dt_default_exp with -fdec.

	libgfortran/io/
	* io.h (IOPARM_DT_DEFAULT_EXP): New flag bit.
	* list_read.c (parse_real, read_real): Allow omission of exponent with
	IOPARM_DT_DEFAULT_EXP.
	* read.c (read_f): Ditto.

	gcc/testsuite/gfortran.dg/
	* dec_exp_1.f90, dec_exp_2.f90, dec_exp_3.f90: New testcases.

From-SVN: r241828
2016-11-03 18:09:44 +00:00
Fritz Reese 0ef33d4462 New I/O specifiers CARRIAGECONTROL, READONLY, SHARE with -fdec.
gcc/fortran/
	* gfortran.texi: Document.
	* frontend-passes.c (gfc_code_walker): Add SHARE and CARRIAGECONTROL.
	* io.c (gfc_free_open, gfc_resolve_open, gfc_match_open): Ditto.
	* gfortran.h (gfc_open): Add SHARE, CARRIAGECONTROL, and READONLY.
	* io.c (io_tag, match_open_element): Ditto.
	* ioparm.def: Ditto.
	* trans-io.c (gfc_trans_open): Ditto.
	* io.c (match_dec_etag, match_dec_ftag): New functions.

	libgfortran/io/
	* libgfortran.h (IOPARM_OPEN_HAS_READONLY, IOPARM_OPEN_HAS_SHARE,
	IOPARM_OPEN_HAS_CC): New for READONLY, SHARE, and CARRIAGECONTROL.
	* close.c (st_close): Support READONLY.
	* io.h (st_parameter_open, unit_flags): Support SHARE, CARRIAGECONTROL,
	and READONLY.
	* open.c (st_open): Ditto.
	* transfer.c (data_transfer_init): Ditto.
	* io.h (st_parameter_dt): New member 'cc' for CARRIAGECONTROL.
	* write.c (write_check_cc, write_cc): New functions for CARRIAGECONTROL.
	* transfer.c (next_record_cc): Ditto.
	* file_pos.c (st_endfile): Support SHARE and CARRIAGECONTROL.
	* io.h (st_parameter_inquire): Ditto.
	* open.c (edit_modes, new_unit): Ditto.
	* inquire.c (inquire_via_unit, inquire_via_filename): Ditto.
	* io.h (unit_share, unit_cc, cc_fortran, IOPARM_INQUIRE_HAS_SHARE,
	IOPARM_INQUIRE_HAS_CC): New for SHARE and CARRIAGECONTROL.
	* open.c (share_opt, cc_opt): Ditto.
	* read.c (read_x): Support CARRIAGECONTROL.
	* transfer.c (read_sf, next_record_r, next_record_w): Ditto.
	* write.c (list_formatted_write_scalar, write_a): Ditto.
	* unix.h (close_share): New prototype.
	* unix.c (open_share, close_share): New functions to handle SHARE.
	* unix.c (open_external): Handle READONLY. Call open_share.
	* close.c (st_close): Call close_share.

	gcc/testsuite/
	* dec_io_1.f90: New test.
        * dec_io_2.f90: New test.
        * dec_io_3.f90: New test.
        * dec_io_4.f90: New test.
        * dec_io_5.f90: New test.
        * dec_io_6.f90: New test.

From-SVN: r241550
2016-10-26 12:11:44 +00:00
Jerry DeLisle 13926b249f re PR libfortran/77828 (Linking gfortran-7 compiled program with libgfortran of 5.x allowed but crashes when containing write to string)
2016-10-24  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR fortran/77828
	* io/io.h (st_parameter_dt): Reorder for readability and sanity.
	* io/transfer.c (data_transfer_init): Remove TODO and enable the
	runtime error message, rec= specifier not allowed in STREAM
	access.
	* libtool-version: Bump major version of libgfortran to 4.

	* ioparm.def: Reorder dt parameters to match libgfortran.
	* libgfortran.h: Swap definitions of GFC_INTERNAL_UNIT and
	GFC_INTERNAL_UNIT4.

From-SVN: r241497
2016-10-24 21:42:29 +00:00
Jerry DeLisle 8b729f5c8f re PR libfortran/78055 (Many new gfortran test failures)
2016-10-21  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libfortran/78055
	* io/io.h (st_parameter_dt): Restore GFC_IO_INT to maintain
	alignment.

From-SVN: r241422
2016-10-21 18:02:32 +00:00
Jerry DeLisle c680ada5f5 re PR fortran/48298 ([F03] User-Defined Derived-Type IO (DTIO))
2016-10-17  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR fortran/48298
	* io/io.h: Move size_used from dtp to unit structure. Add bool
	has_size to unit structure.
	* read.c (read_x): Use has_size and size_used.
	* transfer.c (read_sf_internal,read_sf,read_block_form,
	read_block_form4): Likewise.
	(data_transfer_init): If parent, initialize the size variables.
	(finalize_transfer): Set the size variable using size_used in
	gfc_unit. (write_block): Delete bogus/dead code.

	* gfortran.dg/dtio_17.f90: New test.

From-SVN: r241294
2016-10-18 04:14:25 +00:00
Janne Blomqvist c04d4ede17 PR 48587 Newunit allocator
Currently GFortran newer reuses unit numbers allocated with NEWUNIT=,
instead having a simple counter that is decremented each time such a
unit is opened.  For a long running program which repeatedly opens
files with NEWUNIT= and closes them, the counter can wrap around and
cause an abort.  This patch replaces the counter with an allocator
that keeps track of which units numbers are allocated, and can reuse
them once they have been deallocated.  Since operating systems tend to
limit the number of simultaneous open files for a process to a
relatively modest number, a relatively simple approach with a linear
scan through an array suffices.  Though as a small optimization there
is a low water indicator keeping track of the index for which all unit
numbers below are already allocated.  This linear scan also ensures
that we always allocate the smallest available unit number.

2016-10-15  Janne Blomqvist  <jb@gcc.gnu.org>

        PR libfortran/48587
        * io/io.h (get_unique_unit_number): Remove prototype.
        (newunit_alloc): New prototype.
        * io/open.c (st_open): Call newunit_alloc.
        * io/unit.c (newunits,newunit_size,newunit_lwi): New static
        variables.
        (GFC_FIRST_NEWUNIT): Rename to NEWUNIT_START.
        (next_available_newunit): Remove variable.
        (get_unit): Call newunit_alloc, don't try to create negative
        external unit.
        (close_unit_1): Call newunit_free.
        (close_units): Free newunits array.
        (get_unique_number): Remove function.
        (newunit_alloc): New function.
        (newunit_free): New function.
        * io/transfer.c (data_transfer_init): Check for invalid unit
        number.

testsuite ChangeLog:

2016-10-15  Janne Blomqvist  <jb@gcc.gnu.org>

        PR libfortran/48587
        * gfortran.dg/negative_unit2.f90: New testcase.

From-SVN: r241199
2016-10-15 16:14:15 +03:00
Janne Blomqvist b923394429 PR 67585 Handle EINTR
Many POSIX systems have the bad habit of not restarting interrupted
syscalls. On these systems it's up to the user to check for an error
with errno == EINTR and restart manually. This patch does this for
libgfortran, so that GFortran users don't have to do it.

2016-10-09  Janne Blomqvist  <jb@gcc.gnu.org>

        PR libfortran/67585
        * io/io.h: TEMP_FAILURE_RETRY: Define macro if not found.
        * io/unix.c (raw_read): Handle EINTR.
        (raw_write): Check for return value -1.
        (raw_seek): Handle EINTR.
        (raw_tell): Likewise.
        (raw_size): Likewise.
        (raw_truncate): Likewise.
        (raw_close): Likewise.
        (buf_flush): Call raw_seek instead of lseek.
        (buf_read): Likewise.
        (buf_write): Likewise.
        (fd_to_stream): Handle EINTR.
        (tempfile_open): Likewise.
        (regular_file2): Likewise.
        (compare_file_filename): Likewise.
        (find_file): Likewise.
        (inquire_sequential): Likewise.
        (inquire_direct): Likewise.
        (inquire_formatted): Likewise.

From-SVN: r240902
2016-10-09 21:05:56 +03:00
Jerry DeLisle 4a8d4422b0 re PR fortran/48298 ([F03] User-Defined Derived-Type IO (DTIO))
2016-09-23  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/48298
	* io/inquire.c (inquire_via_unit): Adjust error check for the
	two possible internal unit KINDs.
	* io/io.h: Adjust defines for is_internal_unit and
	is_char4_unit. (gfc_unit): Add internal unit data to structure.
	(get_internal_unit): Change declaration to set_internal_unit.
	(free_internal_unit): Change name to stash_internal_unit_number.
	(get_unique_unit_number): Adjust parameter argument.
	Define IOPARM_DT_HAS_UDTIO. (gfc_saved_unit): New structure.
	* io/list_read.c (next_char_internal): Use is_char4_unit.
	* io/open.c (st_open): Adjust call to get_unique_unit_number.
	* io/transfer.c (write_block): Use is_char4_unit.
	(data_transfer_init): Update check for unit numbers.
	(st_read_done): Free the various allocated memories used for the
	internal units and stash the negative unit number and pointer to unit
	structure to allow reuse. (st_write_done): Likewise stash the freed
	unit.
	* io/unit.c: Create a fixed size buffer of 16 gfc_saved_unit's to use
	as a stack to save newunit unit numbers and unit structure for reuse.
	(get_external_unit): Change name to get_gfc_unit to better
	reflect what it does. (find_unit): Change call to get_gfc_unit.
	(find_or_create_unit): Likewise. (get_internal_unit): Change
	name to set_internal_unit. Move internal unit from the dtp
	structure to the gfc_unit structure so that it can be passed to
	child I/O statements through the UNIT.
	(free_internal_unit): Change name to stash_internal_unit_number.
	Push the common.unit number onto the newunit stack, saving it
	for possible reuse later. (get_unit): Set the internal unit
	KIND. Use get_unique_unit_number to get a negative unit number
	for the internal unit. Use get_gfc_unit to get the unit structure
	and use set_internal_unit to initialize it.
	(init_units): Initialize the newunit stack.
	(get_unique_unit_number): Check the stack for an available unit
	number and use it. If none there get the next most negative
	number. (close_units): Free any unit structures pointed to from the save
	stack.

2016-09-23  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR fortran/48298
	* gfortran.h (gfc_dt): Add *udtio.
	* ioparm.def: Add bit IOPARM_dt_f2003 to align with library use of bit
	25. Add IOPARM_dt_dtio bit to common flags.
	* resolve.c (resolve_transfer): Set dt->udtio to expression.
	* io.c (gfc_match_inquire): Adjust error message for internal
	unit KIND.
	* libgfortran.h: Adjust defines for GFC_INTERNAL_UNIT4,
	GFC_INTERNAL_UNIT, and GFC_INVALID_UNIT.
	* trans-io.c (build_dt): Set common_unit to reflect the KIND of
	the internal unit. Set mask bit for presence of dt->udtio.

2016-09-23  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR fortran/48298
	* gfortran.dg/negative_unit_check.f90: Update test.
	* gfortran.dg/dtio_14.f90: New test.

From-SVN: r240456
2016-09-23 20:36:21 +00:00
Paul Thomas e73d3ca6d1 [multiple changes]
2016-08-31  Paul Thomas  <pault@gcc.gnu.org>
	Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR fortran/48298

	* decl.c (access_attr_decl): Include case INTERFACE_DTIO as
	appropriate.
	* gfortran.h : Add INTRINSIC_FORMATTED and
	INTRINSIC_UNFORMATTED to gfc_intrinsic_op. Add INTERFACE_DTIO
	to interface type. Add new enum 'dtio_codes'. Add bitfield
	'has_dtio_procs' to symbol_attr. Add prototypes
	'gfc_check_dtio_interfaces' and 'gfc_find_specific_dtio_proc'.
	* interface.c (dtio_op): New function.
	(gfc_match_generic_spec): Match generic DTIO interfaces.
	(gfc_match_interface): Treat DTIO interfaces in the same way as
	(gfc_current_interface_head): Add INTERFACE_DTIO appropriately.
	(check_dtio_arg_TKR_intent): New function.
	(check_dtio_interface1): New function.
	(gfc_check_dtio_interfaces): New function.
	(gfc_find_specific_dtio_proc): New function.
	* io.c : Add FMT_DT to format_token.
	(format_lex): Handle DTIO formatting.
	* match.c (gfc_op2string): Add DTIO operators.
	* resolve.c (derived_inaccessible): Ignore pointer components
	to enclosing derived type.
	(resolve_transfer): Resolve transfers that involve DTIO.
	procedures. Find the specific subroutine for the transfer and
	use its existence to over-ride some of the constraints on
	derived types. If the transfer is recursive, require that the
	subroutine be so qualified.
	(dtio_procs_present): New function.
	(resolve_fl_namelist): Remove inhibition of polymorphic objects
	in namelists if DTIO read and write subroutines exist. Likewise
	for derived types.
	(resolve_types): Invoke 'gfc_verify_dtio_procedures'.
	* symbol.c : Set 'dtio_procs' using 'minit'.
	* trans-decl.c (gfc_finish_var_decl): If a derived-type/class
	object is associated with DTIO procedures, make it TREE_STATIC.
	* trans-expr.c (gfc_get_vptr_from_expr): If the expression
	drills down to a PARM_DECL, extract the vptr correctly.
	(gfc_conv_derived_to_class): Check 'info' in the test for
	'useflags'. If the se expression exists and is a pointer, use
	it as the class _data.
	* trans-io.c : Add IOCALL_X_DERIVED to iocall and the function
	prototype. Likewise for IOCALL_SET_NML_DTIO_VAL.
	(set_parameter_tree): Renamed from 'set_parameter_const', now
	returns void and has new tree argument. Calls modified to match
	new interface.
	(transfer_namelist_element): Transfer DTIO procedure pointer
	and vpointer using the new function IOCALL_SET_NML_DTIO_VAL.
	(get_dtio_proc): New function.
	(transfer_expr): Add new argument for the vptr field of class
	objects. Add the code to call the specific DTIO proc, convert
	derived types to class and call IOCALL_X_DERIVED.
	(trans_transfer): Add BT_CLASS to structures for treatment by
	the scalarizer. Obtain the vptr for the dynamic type, both for
	scalar and array transfer.

2016-08-31  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
	Paul Thomas  <pault@gcc.gnu.org>

	PR libgfortran/48298
	* gfortran.map : Flag _st_set_nml_dtio_var and
	_gfortran_transfer_derived.
	* io/format.c (format_lex): Detect DTIO formatting.
	(parse_format_list): Parse the DTIO format.
	(next_format): Include FMT_DT.
	* io/format.h : Likewise. Add structure 'udf' to structure
	'fnode' to carry the IOTYPE string and the 'vlist'.
	* io/io.h : Add prototypes for the two types of DTIO subroutine
	and a typedef for gfc_class. Also, add to 'namelist_type'
	fields for the pointer to the DTIO procedure and the vtable.
	Add fields to struct st_parameter_dt for pointers to the two
	types of DTIO subroutine. Add to gfc_unit DTIO specific fields.
	(internal_proto): Add prototype for 'read_user_defined' and
	'write_user_defined'.
	* io/list_read.c (check_buffers): Use the 'current_unit' field.
	(unget_char): Likewise.
	(eat_spaces): Likewise.
	(list_formatted_read_scalar): For case BT_CLASS, call the DTIO
	procedure.
	(nml_get_obj_data): Likewise when DTIO procedure is present,.
	* io/transfer.c : Export prototypes for 'transfer_derived' and
	'transfer_derived_write'.
	(unformatted_read): For case BT_CLASS, call the DTIO procedure.
	(unformatted_write): Likewise.
	(formatted_transfer_scalar_read): Likewise.
	(formatted_transfer_scalar_write: Likewise.
	(transfer_derived): New function.
	(data_transfer_init): Set last_char if no child_dtio.
	(finalize_transfer): Return if child_dtio set.
	(st_write_done): Add condition for child_dtio not set.
	Add extra arguments for st_set_nml_var prototype.
	(set_nml_var): New function that contains the contents of the
	old version of st_set_nml_var. Also sets the 'dtio_sub' and
	'vtable' fields of the 'nml' structure.
	(st_set_nml_var): Now just calls set_nml_var with 'dtio_sub'
	and 'vtable' NULL.
	(st_set_nml_dtio_var): New function that calls set_nml_var.
	* io/unit.c (get_external_unit): If the found unit child_dtio
	is non zero, don't do any mutex locking/unlocking.  Just
	return the unit.
	* io/unix.c (tempfile_open): Revert to C style comment.
	* io/write.c (list_formatted_write_scalar): Do the DTIO call.
	(nml_write_obj): Add BT_CLASS and do the DTIO call.

2016-08-31  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
	Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/48298
	* gfortran.dg/dtio_1.f90: New test.
	* gfortran.dg/dtio_2.f90: New test.
	* gfortran.dg/dtio_3.f90: New test.
	* gfortran.dg/dtio_4.f90: New test.
	* gfortran.dg/dtio_5.f90: New test.
	* gfortran.dg/dtio_6.f90: New test.
	* gfortran.dg/dtio_7.f90: New test.
	* gfortran.dg/dtio_8.f90: New test.
	* gfortran.dg/dtio_9.f90: New test.
	* gfortran.dg/dtio_10.f90: New test.

From-SVN: r239880
2016-08-31 05:36:22 +00:00
Jakub Jelinek 818ab71a41 Update copyright years.
From-SVN: r232055
2016-01-04 15:30:50 +01:00
Francois-Xavier Coudert 76b88c5fc9 re PR libfortran/67527 (io.h sanitizer complains on 1 << 31)
PR libfortran/67527
	PR libfortran/67535
	PR libfortran/67536
	* io/io.h: Use unsigned values for 31-bit left shifts.
	* io/unix.c (buf_read): Do not call memcpy() with NULL pointer arg.
	* io/write.c (nml_write_obj): Likewise.

From-SVN: r227705
2015-09-12 12:05:44 +00:00
Jerry DeLisle 1060d9404d re PR fortran/60956 (error reading (and writing) large text files in gfortran)
2015-02-07  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/60956
	* io/fbuf.c (fbuf_flush_list): New function that only flushes
	if current fbuf position exceeds a limit.
	* io/fbuf.h: Declare the new function.
	* io/io.h (enum unit_mode): Add two new modes.
	* io/list_read.c (list_formatted_read_scalar): Call new function.
	* io/write.c: Include fbuf.h. (list_formatted_write_scalar):
	Call new function.

From-SVN: r220505
2015-02-07 15:13:15 +00:00
Jakub Jelinek 5624e564d2 Update copyright years.
From-SVN: r219188
2015-01-05 13:33:28 +01:00
Janne Blomqvist 9cbecd06be PR 47007 and 61847 Locale failures in libgfortran.
2014-11-10  Janne Blomqvist  <jb@gcc.gnu.org>

	PR libfortran/47007
	PR libfortran/61847
	* config.h.in: Regenerated.
	* configure: Regenerated.
	* configure.ac (AC_CHECK_HEADERS_ONCE): Check for xlocale.h.
	(AC_CHECK_FUNCS_ONCE): Check for newlocale, freelocale, uselocale,
	strerror_l.
	* io/io.h (locale.h): Include.
	(xlocale.h): Include if present.
	(c_locale): New variable.
	(old_locale): New variable.
	(old_locale_ctr): New variable.
	(old_locale_lock): New variable.
	(st_parameter_dt): Add old_locale member.
	* io/transfer.c (data_transfer_init): Set locale to "C" if doing
	formatted transfer.
	(finalize_transfer): Reset locale to previous.
	* io/unit.c (c_locale): New variable.
	(old_locale): New variable.
	(old_locale_ctr): New variable.
	(old_locale_lock): New variable.
	(init_units): Init c_locale, init old_locale_lock.
	(close_units): Free c_locale.
	* runtime/error.c (locale.h): Include.
	(xlocale.h): Include if present.
	(gf_strerror): Use strerror_l if available. Reset locale to
	LC_GLOBAL_LOCALE for strerror_r branch.

2014-11-10  Janne Blomqvist  <jb@gcc.gnu.org>

	PR libfortran/47007
	PR libfortran/61847
	* gfortran.texi: Add note about locale issues to thread-safety
	section.

From-SVN: r217273
2014-11-10 02:17:16 +02:00
Janne Blomqvist 0e05c303e5 PR libfortran/62768 Handle filenames with embedded null characters.
testsuite ChangeLog:

2014-09-17  Janne Blomqvist  <jb@gcc.gnu.org>

	PR libfortran/62768
	* gfortran.dg/filename_null.f90: New test.

libgfortran ChangeLog:

2014-09-17  Janne Blomqvist  <jb@gcc.gnu.org>

	PR libfortran/62768
	* io/io.h (gfc_unit): Store C string for the filename.
	* io/close.c (st_close): Use gfc_unit.filename.
	* io/inquire.c (inquire_via_unit): Likewise.
	* io/open.c (new_unit): Likewise.
	(already_open): Likewise, unlink file before freeing filename.
	* io/unit.c (init_units): Likewise.
	(close_unit_1): Likewise.
	(filename_from_unit): Likewise.
	* io/unix.c (compare_file_filename): Likewise.
	(find_file0): Likewise.
	(delete_file): Likewise.

From-SVN: r215307
2014-09-17 00:40:28 +03:00
Jerry DeLisle d428be77b6 re PR libfortran/52539 (I/O: Wrong result for UTF-8/UCS-4 list-directed and namelist read and nml write)
2014-05-17  Jerry DeLisle  <jvdelisle@gcc.gnu>

	PR libfortran/52539
	* io/io.h (gfc_unit): New function pointers *next_char_fn_ptr
	and *push_char_fn_ptr.
	*io/list_read.c (next_char): Create macro with this name to call
	the new function pointer. Split the original next_char function
	into three new functions. (next_char_default, next_char_internal,
	next_char_utf8): New functions. (push_char): Create macro with
	this name to call new function pointer. Split the original
	push_char into three new functions. (push_char_default,
	push_char_internal, push_char4): New functions. (set_workers):
	New function to initilize the function pointers depending on the
	type of IO to be performed. (list_formatted_read_scalar): Use
	set_workers function. (finish_list_read): Likewise.
	(namelist_read): Likewise.
	(nml_get_obj_data): Use push_char_default.

From-SVN: r210574
2014-05-18 02:29:27 +00:00
Jerry DeLisle 2558e2e838 re PR fortran/59700 (Misleading/buggy runtime error message: Bad integer for item 0 in list input)
2014-01-11  Jerry DeLisle  <jvdelisle@gcc.gnu>
	    Dominique d'Humieres  <dominiq@lps.ens.fr>
	    Steven G. Kargl  <kargl@gcc.gnu.org>

	PR libfortran/59700
	PR libfortran/59764
	* io/io.h (struct st_parameter_dt): Assign expanded_read flag to
	unused bit. Define new variable line_buffer_pos.
	* io/list_read.c (free_saved, next_char, l_push_char,
	read_logical, read_real): Replace use of item_count with
	line_buffer_pos for line_buffer look ahead.
	(read_logical, read_integer, parse_real, read_real, check_type):
	Adjust location of free_line to after generating error messages
	to retain the correct item count for the message.

Co-Authored-By: Dominique d'Humieres <dominiq@lps.ens.fr>
Co-Authored-By: Steven G. Kargl <kargl@gcc.gnu.org>

From-SVN: r206553
2014-01-11 18:57:20 +00:00
Richard Sandiford f0bcf62899 Update copyright years in libgfortran/
From-SVN: r206296
2014-01-02 22:25:45 +00:00
Tobias Burnus 82a4f54cc5 re PR libfortran/35862 ([F2003] Implement new rounding modes for run time)
2013-07-21  Tobias Burnus  <burnus@net-b.de>

        PR fortran/35862
        * libgfortran.h (GFC_FPE_DOWNWARD, GFC_FPE_TONEAREST,
        GFC_FPE_TOWARDZERO, GFC_FPE_UPWARD): New defines.

2013-07-21  Tobias Burnus  <burnus@net-b.de>

        PR fortran/35862
        * libgfortran.h (set_fpu_rounding_mode,
        get_fpu_rounding_mode): New prototypes.
        * config/fpu-387.h (set_fpu_rounding_mode,
        get_fpu_rounding_mode): New functions.
        * config/fpu-aix.h (set_fpu_rounding_mode,
        get_fpu_rounding_mode): Ditto.
        * config/fpu-generic.h (set_fpu_rounding_mode,
        get_fpu_rounding_mode): Ditto.
        * config/fpu-glibc.h (set_fpu_rounding_mode,
        get_fpu_rounding_mode): Ditto.
        * config/fpu-sysv.h (set_fpu_rounding_mode,
        get_fpu_rounding_mode): Ditto.
        * configure.ac: Check for fp_rnd and fp_rnd_t.
        * io/io.h (enum unit_round): Use GFC_FPE_* for the value.
        * io/read.c (convert_real): Set FP ronding mode.
        * Makefile.in: Regenerate.
        * aclocal.m4: Regenerate.
        * config.h.in: Regenerate.
        * configure: Regenerate.

2013-07-21  Tobias Burnus  <burnus@net-b.de>

        PR fortran/35862
        * gfortran.dg/round_4.f90: New.


Co-Authored-By: Uros Bizjak <ubizjak@gmail.com>

From-SVN: r201093
2013-07-21 13:54:27 +02:00
Janne Blomqvist facb23dc4e Improve performance of byte-swapped I/O.
2013-01-23  Janne Blomqvist  <jb@gcc.gnu.org>

	* io/file_pos.c (unformatted_backspace): Use __builtin_bswapXX
	instead of reverse_memcpy.
	* io/io.h (reverse_memcpy): Remove prototype.
	* io/transfer.c (reverse_memcpy): Make static, move towards
	beginning of file.
	(bswap_array): New function.
	(unformatted_read): Use bswap_array to byte swap the data
	in-place.
	(unformatted_write): Use a larger temp buffer and bswap_array.
	(us_read): Use __builtin_bswapXX instead of reverse_memcpy.
	(write_us_marker): Likewise.

From-SVN: r195413
2013-01-23 23:56:54 +02:00
Richard Sandiford e3c063ceda Update copyright years in libgfortran.
From-SVN: r195167
2013-01-14 18:20:58 +00:00
Jerry DeLisle 797332eda9 re PR fortran/48976 (INQUIRE with STREAM= not supported)
2012-12-27  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libfortran/48976
	* io/inquire.c (inquire_via_unit): Set user stream inquiry variable to
	appropriate value based on unit access method. (inquire_via_filename):
	Since filename is not associated with an open unit, set stream inquiry
	to UNKNOWN.
	* io/io.h: Define inquire stream parameters.

From-SVN: r194733
2012-12-27 18:07:33 +00:00
Tobias Burnus eea58adb13 decl.c: Fix comment typos.
2012-05-30  Tobias Burnus  <burnus@net-b.de>

        * decl.c: Fix comment typos.
        * expr.c: Ditto.
        * frontend-passes.c: Ditto.
        * match.c: Ditto.
        * resolve.c: Ditto.
        * trans-array.c: Ditto.
        * trans-common.c: Ditto.
        * trans-intrinsic.c: Ditto.
        * trans-types.c: Ditto.

2012-05-30  Tobias Burnus  <burnus@net-b.de>

        * io/io.h: Fix comment typos.
        * io/list_read.c: Ditto.

From-SVN: r188000
2012-05-30 08:26:09 +02:00
Janne Blomqvist 80b91c0b39 PR 52428 Range checking when reading integer values.
gcc/fortran ChangeLog:

2012-05-14  Janne Blomqvist  <jb@gcc.gnu.org>

	PR fortran/52428
	* gfortran.texi: Update _gfortran_set_options documentation.
	* invoke.texi: Remove runtime behavior description of
	-fno-range-check.
	* trans-decl.c (create_main_function): Don't pass the range-check
	setting to the library.


libgfortran ChangeLog:

2012-05-14  Janne Blomqvist  <jb@gcc.gnu.org>

	PR fortran/52428
	* io/io.h (max_value): Rename to si_max, remove second argument.
	* io/list_read.c (convert_integer): Use unsigned types when
	parsing the digits, set max value depending on the sign.
	* io/read.c (max_value): Rename to si_max, remove second argument,
	simplify.
	(read_decimal): Set max value depending on sign, always check
	overflow.
	(read_radix): Calculate max unsigned value directly.
	* libgfortran.h (struct compile_options_t): Remove range_check
	field.
	* runtime/compile_options.c (set_options): Skip handling
	options[7].
	(init_compile_options): Don't set removed field.


gcc/testsuite ChangeLog:

2012-05-14  Janne Blomqvist  <jb@gcc.gnu.org>

	PR fortran/52428
	* gfortran.dg/int_range_io_1.f90: New test.

From-SVN: r187478
2012-05-14 22:39:23 +03:00
Janne Blomqvist 992b0aa1cf Let the compiler decide whether to inline.
2011-11-10  Janne Blomqvist  <jb@gcc.gnu.org>

	* intrinsics/cpu_time.c (__cpu_time_1): Don't force inlining.
	* intrinsics/random.c (rnumber_4): Remove inline attribute.
	(rnumber_8, rnumber_10, rnumber_16): Likewise.
	* intrinsics/system_clock.c (gf_gettime_mono): Likewise.
	* intrinsics/time_1.h (ATTRIBUTE_ALWAYS_INLINE): Remove macro.
	(gf_cputime): Add inline attribute for MingW version.
	* io/format.c (format_hash): Remove inline attribute.
	* io/io.h (memset4): Inline function from transfer.c and write.c
	moved here.
	* io/transfer.c (min_off): Remove inline attribute.
	(memset4): Move to io.h.
	* io/write.c (memset4): Likewise.
	(memcpy4): Remove inline attribute.
	* io/write_float.def (calculate_exp): Likewise.

From-SVN: r181260
2011-11-10 19:08:24 +02:00
Janne Blomqvist eb6a1e56e0 Copyright years and whitespace fix for r180734
From-SVN: r180736
2011-11-01 14:03:38 +02:00
Janne Blomqvist ea5e3c042b Cleanup NEWUNIT allocation.
2011-11-01  Janne Blomqvist  <jb@gcc.gnu.org>

	* io/io.h (next_available_newunit): Remove prototype.
	* io/unit.h (next_available_newunit): Make variable static,
	initialize it.
	(init_units): Don't initialize next_available_newunit.
	(get_unique_unit_number): Use atomic builtin if available.

From-SVN: r180734
2011-11-01 13:44:12 +02:00
Janne Blomqvist 08810e5257 Update file position for inquire lazily.
libgfortran ChangeLog:

2011-10-31  Janne Blomqvist  <jb@gcc.gnu.org>

	* io/inquire.c (inquire_via_unit): Check whether we're at the
	beginning or end if the position is unspecified. If the position
	is not one of the 3 standard ones, return unspecified.
	* io/io.h (update_position): Remove prototype.
	* io/transfer.c (next_record): Set the position to unspecified,
	letting inquire figure it out more exactly when needed.
	* io/unit.c (update_position): Remove function.


testsuite ChangeLog:

2011-10-31  Janne Blomqvist  <jb@gcc.gnu.org>

	* gfortran.dg/inquire_5.f90: Update testcase to match the standard
	and current implementation.

From-SVN: r180703
2011-10-31 16:59:19 +02:00
Janne Blomqvist 44720bef9d Cleanup memsize types
From-SVN: r172340
2011-04-12 22:27:49 +03:00
John David Anglin 458653cc06 re PR libfortran/35667 (HP-UX 10 has broken strtod)
PR fortran/35667
	* io/io.h (convert_infnan): Declare.
	* io/read.c (convert_infnan): New.
	(read_f): Use convert_infnan to convert INFs and NANs.
	* list_read.c (parse_real, read_real): Likewise.

From-SVN: r171182
2011-03-19 17:25:18 +00:00
Janne Blomqvist c86af7f3e4 PR 45629 Remove usage of setjmp/longjmp
From-SVN: r166180
2010-11-02 14:56:38 +02:00
Jerry DeLisle a11930ba8d io.h: Remove definition of the BT enumerator.
2010-10-18  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	* io/io.h: Remove definition of the BT enumerator.
	* libgfortran.h: Replace GFC_DTYPE enumerator with BT.
	* intrinsics/iso_c_generated_procs.c: Likewise
	* intrinsics/date_and_time.c: Likewise.
	* intrinsics/iso_c_binding.c: Likewise.
	* io/list_read.c: Likewise.
	* io/transfer.c: Likewise.
	* io/write.c: Likewise.

2010-10-18  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	* gfortran.h: Remove definition of bt enumerator.
	* libgfortran.h: Add bt enumerator type alighned with defintion.
	Remove the dtype enumerator, no longer used.
	previously given in libgfortran/io.h
	* trans-types.c: Use new bt enumerator.
	* trans-io.c: Likewise.

From-SVN: r165675
2010-10-19 01:28:50 +00:00
Jerry DeLisle 74db2a472a re PR fortran/37077 (Implement Internal Unit I/O for character KIND=4)
2010-07-16  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libfortran/37077
	* io/read.c (read_default_char4): Add support for reading into a
	kind-4 character variable from a character(kind=4) internal unit.
	* io/io.h (read_block_form4): Add prototype.
	* io/unit.c (get_internal_unit): Add call to fbuf_init.
	(free_internal_unit): Add call to fbuf_destroy. (get_unit): Fix
	whitespace.
	* io/transfer.c (read_sf_internal): Use fbuf_alloc to allocate a string
	to recieve the wide characters translated to single byte chracters.
	(read_block_form): Fix whitespace. (read_block_form4): New function to
	read from a character(kind=4) internal unit into a character(kind=4)
	variable. (read_block_direct): Fix whitespace. (write_block): Fix
	whitespace. (formatted_transfer_scalar_read): Likewise.
	(formatted_transfer_scalar_write): Likewise.
	* io/write.c (write_character): Add support for list directed write of
	a kind=1 character string to a character(kind=4) internal unit.

From-SVN: r162260
2010-07-16 14:16:04 +00:00
Jerry DeLisle c7421e06ca re PR fortran/37077 (Implement Internal Unit I/O for character KIND=4)
2010-07-12  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libfortran/37077
	* io/read.c: Fix comment.
	* io/io.h (is_char4_unit): New macro.
	* io/unit.c (get_internal_unit): Call new function open_internal4.
	* io/unix.c (mem_alloc_r4): New function. (mem_alloc_w4): New function.
	(mem_read4): New function, temporary stub. (mem_write4): New function.
	(open_internal4): New function to set stream pointers to use the new
	mem functions.
	* io/transfer.c (write_block): Use new mem_alloc_w4 to access internal
	units of kind=4.
	* io/unix.h: Add prototypes for open_internal4, mem_alloc_w4, and
	mem_alloc_r4.
	* io/write.c (memset4): New helper function. (memcpy4): New helper
	function. (write_default_char4): Use new helper functions.
	(write_a): Likewise. (write_l): Likewise. (write_boz): Likewise.
	(write_decimal): Likewise. (write_x): Likewise.
	(write_integer): Likewise.
	* io/write_float.def (output_float): Add code blocks to handle internal
	unit kind=4 output utilizing gfc_char4_t pointers. (write_infnan): Use
	new helper functions. (OUTPUT_FLOAT_FMT_G): Update this macro likewise.

From-SVN: r162123
2010-07-13 02:12:08 +00:00
Paul Thomas a1ff2ab8e4 transfer.c: Update copyright.
2010-04-01  Paul Thomas  <pault@gcc.gnu.org>

	* io/transfer.c : Update copyright.
	* io/unix.c : ditto
	* io/read.c : ditto
	* io/io.h : ditto
	* io/unix.h : ditto
	* io/inquire.c : ditto
	* io/format.c : ditto
	* io/list_read.c : ditto
	* runtime/error.c : ditto
	* libgfortran.h : ditto
	* intrinsics/date_and_time.c: ditto
	* intrinsics/args.c : ditto

From-SVN: r157924
2010-04-01 18:22:00 +00:00
Jerry DeLisle 260f179b8d re PR fortran/43409 (I/O: INQUIRE for SIZE does not work.)
2010-03-21  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR fortran/43409
	* io/io.h: Fix type of size in st_parameter_inquire structure.

From-SVN: r157618
2010-03-22 02:39:02 +00:00
Jerry DeLisle 59011a60c0 re PR fortran/43265 (No EOF condition if reading with '(x)' from an empty file)
2010-03-17  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libfortran/43265
	* io/io.h: Delete prototype for read_sf, making it static.
	* io/read.c (read_x): Modify to call hit_eof if PAD="no".
	* io/transfer.c (read_sf_internal): New static function extracted from
	read_sf for use on internal units only. Handle empty string case.
	(read_sf): New factoring of this function, make it static.  Add special
	conditions for EOF based on ADVANCE="no", PAD="no", and whether any
	bytes have been previously read from the record.
	(read_block_form): Modify to call read_sf or read_sf_internal.
	(next_record_r): Add a done flag similar to next_record_w. Call hit_eof
	if internal array unit next record returns finished, meaning an EOF was
	found and not done, ie not the last record expected.  For external
	units call hit_eof if item_count is 1 or there are no pending spaces.
	(next_record): Update call to next_record_r.

From-SVN: r157527
2010-03-18 02:38:17 +00:00
Jerry DeLisle 04b98fd2ed re PR fortran/43265 (No EOF condition if reading with '(x)' from an empty file)
2010-03-09  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libfortran/43265
	* io/read.c: Include fbuf.h and unix.h to enable lower level I/O for
	read_x. (read_x): Replace the use of read_sf with equivalent lower level
	I/O, eliminating unneeded code and handling EOF and EOR conditions.
	* io/io.h: Revise prototype for read_sf.
	* io/transfer.c (read_sf): Delete no_error parameter and all uses of it.
	(read_block_form): Likewise.
	(next_record_r): Delete wrong code call to hit_eof.

From-SVN: r157310
2010-03-09 14:41:17 +00:00
Janne Blomqvist 92cbdb6845 Split up io/io.h
From-SVN: r153825
2009-11-02 23:52:59 +02:00
Jerry DeLisle 379924dd59 re PR libfortran/35862 ([F2003] Implement new rounding modes for run time)
2009-09-28  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/35862
	* io.h (gfc_unit): Add round_status.
	(format_token): Add enumerators for rounding format specifiers.
	* transfer.c (round_opt): New options table.
	(formatted_transfer_scalar_read): Add set round_status for each rounding
	format token. (formatted_transfer_scalar_write): Likewise.
	* format.c (format_lex): Tokenize the rounding format specifiers.
	(parse_format_list): Parse the rounding format specifiers.
	* write_float.def (outout_float): Modify rounding code to use new
	variable rchar to set the appropriate rounding. Fix some whitespace.
	* unit.c (get_internal_unit): Initialize rounding mode for internal
	units. (init_units): Likewise.

From-SVN: r152263
2009-09-29 02:47:54 +00:00
Jerry DeLisle e2cec2c358 re PR fortran/41075 ([F2008] Implement unlimited format item)
2009-08-17  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR fortran/41075
	* io/io.h (enum format_token): Add FMT_STAR.
	* io/format.c (format_lex): Add case for FMT_STAR.
	(parse_format_list): Parse FMT_STAR and check for left paren
	after. (next_format0): Modify helper function to check for
	unimited format and return the repeated format node.  Update
	comments to clarify.

From-SVN: r150844
2009-08-17 14:27:29 +00:00
Tobias Burnus ffa61a5ee8 re PR fortran/40588 (Small bug in match_charkind_name)
2009-07-12  Tobias Burnus  <burnus@net-b.de>
            Philippe Marguinaud <philippe.marguinaud@meteo.fr>

        PR fortran/40588
        * primary.c (match_charkind_name): Fix condition for $ matching.

        PR libfortran/22423
        * libgfortran.h: Typedef the GFC_DTYPE_* enum.

2009-07-12  Tobias Burnus  <burnus@net-b.de>

        PR libfortran/22423
        * io/io.h (namelist_type): Use the proper enum for GFC_DTYPE_*.
        * intrinsics/iso_c_binding.c (c_f_pointer_u0): Make sure
        variable is initialized to silence warning.


Co-Authored-By: Philippe Marguinaud <philippe.marguinaud@meteo.fr>

From-SVN: r149545
2009-07-13 08:26:38 +02:00
Jerry DeLisle 2418d0e0e6 re PR libfortran/40330 (incorrect IO)
2009-07-08  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libfortran/40330
	PR libfortran/40662
	* io/io.h (st_parameter_dt): Define format_not_saved bit used to signal
	whether the parsed format data was previously saved. Used to determine
	if the current format data should be freed or not.
	* io/transfer.c (st_read_done): Use the format_not_saved bit.
	(st_write_done): Likewise.
	* io/format.c (parse_format_list): Add boolean pointer to arg list. This
	pointer is used to return status to the caller regarding whether it is
	safe to cache the parsed format data.  Currently, if a FMT_STRING token
	is encounetered, it is not safe to cache. Also, added a local boolean
	variable to hold this information as recursive calls to
	parse_format_list are made.  Remove previous save_format logic.
	(parse_format): Do not use the format caching facility if the current
	unit is an internal unit or if it is not safe to save parsed format
	data.

From-SVN: r149398
2009-07-09 01:20:23 +00:00
Jerry DeLisle dcfddbd49c re PR fortran/40008 (F2008: Add NEWUNIT= for OPEN statement)
2009-06-07  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libfortran/40008
	* libgfortran.h: Define IOPARM_OPEN_HAS_NEWUNIT.
	* io/open.c (st_open): Don't error on negative unit number if NEWUNIT
	was specified. If NEWUNIT is specified, call new function to get the
	unique unit number and assign it.
	* io/io.h (st_parameter_open): Add pointer to newunit.  Add prototype for
	next_available_newunit. Add prototype for new function,
	get_unique_unit_number.
	* io/unit.c: Declare next_available_newunit. Define the first newunit
	number. (init_units): Initialize next_available_unit.
	(get_unique_unit_number): New function. Fix whitespace and comments.
	* io/transfer.c (data_transfer_init): Update error message to not be
	specific to OPEN statements.

From-SVN: r148253
2009-06-07 19:00:47 +00:00
Janne Blomqvist 4e23895d6a io.h (is_preconnected): Remove prototype.
2009-04-17  Janne Blomqvist  <jb@gcc.gnu.org>

	* io/io.h (is_preconnected): Remove prototype.
	* io/unix.c (is_preconnected): Remove function.

From-SVN: r146287
2009-04-17 22:52:02 +03:00
Janne Blomqvist 4dadda8fb0 io.h (move_pos_offset): Remove prototype.
2009-04-10  Janne Blomqvist  <jb@gcc.gnu.org>

        * io/io.h (move_pos_offset): Remove prototype.
        * io/transfer.c (formatted_transfer_scalar_read): Use sseek
        instead of move_pos_offset.
        * io/unix.c (move_pos_offset): Remove.

From-SVN: r145876
2009-04-10 11:26:56 +03:00