gcc/libgfortran/io/format.c

1491 lines
31 KiB
C
Raw Normal View History

/* Copyright (C) 2002-2017 Free Software Foundation, Inc.
Contributed by Andy Vaught
PR fortran/25829 28655 2008-04-05 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR fortran/25829 28655 * gfortran.map: Add new symbol, _gfortran_st_wait. * libgfortran.h (st_paramter_common): Add new I/O parameters. * open.c (st_option decimal_opt[], st_option encoding_opt[], st_option round_opt[], st_option sign_opt[], st_option async_opt[]): New parameter option arrays. (edit_modes): Add checks for new parameters. (new_unit): Likewise. (st_open): Likewise. * list_read.c (CASE_SEPERATORS): Add ';' as a valid separator. (eat_separator): Handle deimal comma. (read_logical): Fix whitespace. (parse_real): Handle decimal comma. (read_real): Handle decimal comma. * read.c (read_a): Use decimal status flag to allow comma in place of a decimal point. (read_f): Allow comma as acceptable character in float. According to decimal flag, substitute a period for a comma. (read_x): If decimal status flag is comma, disable the read_comma flag, not allowing comma as a delimiter, an extension otherwise. * io.h: (unit_decimal, unit_encoding, unit_round, unit_sign, unit_async): New enumerators. Add all new I/O parameters. * unix.c (unix_stream, int_stream): Add io_mode asychronous I/O control. (move_pos_offset, fd_alloc_w_at): Fix some whitespace. (fd_sfree): Use new enumerator. (fd_read): Likewise. (fd_write): Likewise. (fd_close): Fix whitespace. (fd_open): Use new enumertors. (tempfile, regular_file, open_external): Fix whitespace. (output_stream, error_stream): Set method. (stream_offset): Fix whitespace. * transfer.c: (st_option decimal_opt[], sign_opt[], blank_opt[]): New option arrays. (formatted_transfer_scalar): Set sf_read_comma flag based on new decimal_status flag. (data_transfer_init): Initialize new parameters. Add checks for decimal, sign, and blank. (st_wait): New stub. * format.c: (format_lex): Add format specifiers DP, DC, and D. (parse_format_list): Parse the new specifiers. * write.c (write_decimal): Use new sign enumerators to set the sign. (write_complex): Handle decimal comma and semi-colon separator. (nml_write_obj): Likewise. * write_float.def: Revise sign enumerators. (calculate_sign): Use new sign enumerators. (output_float): Likewise. Use new decimal_status flag to set the decimal character to a point or a comma. From-SVN: r133943
2008-04-06 00:18:03 +02:00
F2003 I/O support contributed by Jerry DeLisle
2010-05-07 17:55:59 +02:00
This file is part of the GNU Fortran runtime library (libgfortran).
Libgfortran is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
Libgfortran is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Under Section 7 of GPL version 3, you are granted additional
permissions described in the GCC Runtime Library Exception, version
3.1, as published by the Free Software Foundation.
You should have received a copy of the GNU General Public License and
a copy of the GCC Runtime Library Exception along with this program;
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
<http://www.gnu.org/licenses/>. */
/* format.c-- parse a FORMAT string into a binary format suitable for
interpretation during I/O statements. */
minloc1.m4: Update copyright year and ajust headers order. * m4/minloc1.m4: Update copyright year and ajust headers order. * m4/maxloc1.m4: Likewise. * m4/in_pack.m4: Likewise. * m4/sum.m4: Likewise. * m4/fraction.m4: Likewise. * m4/all.m4: Likewise. * m4/set_exponent.m4: Likewise. * m4/transpose.m4: Likewise. * m4/eoshift1.m4: Likewise. * m4/spacing.m4: Likewise. * m4/eoshift3.m4: Likewise. * m4/minval.m4: Likewise. * m4/count.m4: Likewise. * m4/maxval.m4: Likewise. * m4/exponent.m4: Likewise. * m4/shape.m4: Likewise. * m4/head.m4: Likewise. * m4/cshift1.m4: Likewise. * m4/minloc0.m4: Likewise. * m4/nearest.m4: Likewise. * m4/maxloc0.m4: Likewise. * m4/pow.m4: Likewise. * m4/in_unpack.m4: Likewise. * m4/matmull.m4: Likewise. * m4/product.m4: Likewise. * m4/reshape.m4: Likewise. * m4/any.m4: Likewise. * m4/rrspacing.m4: Likewise. * m4/matmul.m4: Likewise. * runtime/backtrace.c: Likewise. * runtime/environ.c: Likewise. * runtime/in_pack_generic.c: Likewise. * runtime/compile_options.c: Likewise. * runtime/in_unpack_generic.c: Likewise. * runtime/main.c: Likewise. * runtime/stop.c: Likewise. * runtime/string.c: Likewise. * runtime/memory.c: Likewise. * runtime/error.c: Likewise. * runtime/pause.c: Likewise. * intrinsics/ierrno.c: Likewise. * intrinsics/system_clock.c: Likewise. * intrinsics/cshift0.c: Likewise. * intrinsics/unlink.c: Likewise. * intrinsics/ctime.c: Likewise. * intrinsics/etime.c: Likewise. * intrinsics/cpu_time.c: Likewise. * intrinsics/malloc.c: Likewise. * intrinsics/hostnm.c: Likewise. * intrinsics/sleep.c: Likewise. * intrinsics/exit.c: Likewise. * intrinsics/perror.c: Likewise. * intrinsics/transpose_generic.c: Likewise. * intrinsics/pack_generic.c: Likewise. * intrinsics/spread_generic.c: Likewise. * intrinsics/stat.c: Likewise. * intrinsics/string_intrinsics.c: Likewise. * intrinsics/getcwd.c: Likewise. * intrinsics/date_and_time.c: Likewise. * intrinsics/unpack_generic.c: Likewise. * intrinsics/move_alloc.c: Likewise. * intrinsics/getlog.c: Likewise. * intrinsics/eoshift0.c: Likewise. * intrinsics/eoshift2.c: Likewise. * intrinsics/reshape_generic.c: Likewise. * intrinsics/system.c: Likewise. * intrinsics/iso_c_binding.c: Likewise. * intrinsics/env.c: Likewise. * intrinsics/kill.c: Likewise. * intrinsics/reshape_packed.c: Likewise. * intrinsics/time.c: Likewise. * intrinsics/gerror.c: Likewise. * intrinsics/access.c: Likewise. * intrinsics/fnum.c: Likewise. * intrinsics/abort.c: Likewise. * intrinsics/rename.c: Likewise. * intrinsics/signal.c: Likewise. * intrinsics/symlnk.c: Likewise. * intrinsics/random.c: Likewise. * intrinsics/umask.c: Likewise. * intrinsics/getXid.c: Likewise. * intrinsics/rand.c: Likewise. * intrinsics/chdir.c: Likewise. * intrinsics/chmod.c: Likewise. * intrinsics/clock.c: Likewise. * intrinsics/args.c: Likewise. * intrinsics/link.c: Likewise. * c99_protos.h: Likewise. * config/fpu-387.h: Likewise. * config/fpu-aix.h: Likewise. * config/fpu-sysv.h: Likewise. * config/fpu-generic.h: Likewise. * config/fpu-glibc.h: Likewise. * io/file_pos.c: Likewise. * io/open.c: Likewise. * io/size_from_kind.c: Likewise. * io/close.c: Likewise. * io/list_read.c: Likewise. * io/read.c: Likewise. * io/inquire.c: Likewise. * io/unit.c: Likewise. * io/unix.c: Likewise. * io/transfer.c: Likewise. * io/intrinsics.c: Likewise. * io/format.c: Likewise. * io/lock.c: Likewise. * io/write.c: Likewise. * io/write_float.def: Likewise. * fmain.c: Likewise. * generated/minval_r8.c: Regenerate. * generated/minloc1_16_r16.c: Regenerate. * generated/maxloc1_4_r8.c: Regenerate. * generated/sum_i8.c: Regenerate. * generated/eoshift3_4.c: Regenerate. * generated/transpose_c8.c: Regenerate. * generated/any_l16.c: Regenerate. * generated/eoshift1_8.c: Regenerate. * generated/pow_r8_i8.c: Regenerate. * generated/reshape_r16.c: Regenerate. * generated/pow_i4_i16.c: Regenerate. * generated/maxval_i2.c: Regenerate. * generated/product_r4.c: Regenerate. * generated/maxloc1_8_i4.c: Regenerate. * generated/exponent_r16.c: Regenerate. * generated/maxloc0_4_r4.c: Regenerate. * generated/fraction_r16.c: Regenerate. * generated/in_unpack_i8.c: Regenerate. * generated/matmul_r8.c: Regenerate. * generated/product_i2.c: Regenerate. * generated/fraction_r4.c: Regenerate. * generated/minloc0_4_r16.c: Regenerate. * generated/reshape_c4.c: Regenerate. * generated/minloc0_4_i1.c: Regenerate. * generated/maxloc0_4_r16.c: Regenerate. * generated/maxloc0_4_i2.c: Regenerate. * generated/minloc1_8_r16.c: Regenerate. * generated/maxloc1_8_r16.c: Regenerate. * generated/set_exponent_r8.c: Regenerate. * generated/in_unpack_i16.c: Regenerate. * generated/transpose_c16.c: Regenerate. * generated/maxloc0_8_i8.c: Regenerate. * generated/pow_c4_i8.c: Regenerate. * generated/sum_r16.c: Regenerate. * generated/sum_i1.c: Regenerate. * generated/minloc1_4_r8.c: Regenerate. * generated/transpose_r10.c: Regenerate. * generated/pow_i8_i4.c: Regenerate. * generated/maxloc1_16_r16.c: Regenerate. * generated/minloc1_16_i4.c: Regenerate. * generated/maxloc1_16_i4.c: Regenerate. * generated/minloc0_16_i8.c: Regenerate. * generated/maxloc0_16_i8.c: Regenerate. * generated/nearest_r8.c: Regenerate. * generated/spacing_r16.c: Regenerate. * generated/transpose_i8.c: Regenerate. * generated/count_16_l16.c: Regenerate. * generated/maxval_r16.c: Regenerate. * generated/count_8_l8.c: Regenerate. * generated/product_c10.c: Regenerate. * generated/minloc1_8_i4.c: Regenerate. * generated/minloc0_16_i16.c: Regenerate. * generated/matmul_r16.c: Regenerate. * generated/eoshift1_16.c: Regenerate. * generated/minloc0_4_r4.c: Regenerate. * generated/pow_c16_i16.c: Regenerate. * generated/set_exponent_r10.c: Regenerate. * generated/pow_i16_i16.c: Regenerate. * generated/product_c4.c: Regenerate. * generated/sum_r4.c: Regenerate. * generated/pow_c16_i4.c: Regenerate. * generated/rrspacing_r10.c: Regenerate. * generated/in_pack_c16.c: Regenerate. * generated/minloc0_4_i2.c: Regenerate. * generated/maxloc0_8_i1.c: Regenerate. * generated/reshape_i4.c: Regenerate. * generated/minloc0_8_i8.c: Regenerate. * generated/matmul_c8.c: Regenerate. * generated/spacing_r4.c: Regenerate. * generated/in_pack_c4.c: Regenerate. * generated/all_l16.c: Regenerate. * generated/minloc1_16_r10.c: Regenerate. * generated/sum_i2.c: Regenerate. * generated/minloc0_16_i1.c: Regenerate. * generated/reshape_c16.c: Regenerate. * generated/maxloc0_16_i1.c: Regenerate. * generated/maxloc1_8_r8.c: Regenerate. * generated/minval_i16.c: Regenerate. * generated/reshape_r10.c: Regenerate. * generated/exponent_r10.c: Regenerate. * generated/maxval_i4.c: Regenerate. * generated/any_l4.c: Regenerate. * generated/minval_i8.c: Regenerate. * generated/maxloc1_4_i8.c: Regenerate. * generated/fraction_r10.c: Regenerate. * generated/maxloc0_16_i16.c: Regenerate. * generated/shape_i4.c: Regenerate. * generated/pow_r16_i8.c: Regenerate. * generated/maxloc0_8_r4.c: Regenerate. * generated/rrspacing_r8.c: Regenerate. * generated/pow_c10_i4.c: Regenerate. * generated/minloc1_4_i16.c: Regenerate. * generated/minloc0_4_r10.c: Regenerate. * generated/maxloc1_4_i16.c: Regenerate. * generated/minloc0_8_i16.c: Regenerate. * generated/maxloc0_4_r10.c: Regenerate. * generated/maxloc0_8_i16.c: Regenerate. * generated/minloc1_8_r10.c: Regenerate. * generated/product_i4.c: Regenerate. * generated/minloc0_16_r4.c: Regenerate. * generated/sum_c16.c: Regenerate. * generated/maxloc1_8_r10.c: Regenerate. * generated/maxloc0_16_r4.c: Regenerate. * generated/transpose_c10.c: Regenerate. * generated/minloc1_16_r8.c: Regenerate. * generated/minloc0_8_i1.c: Regenerate. * generated/maxloc0_4_i4.c: Regenerate. * generated/transpose_r4.c: Regenerate. * generated/maxloc1_16_r8.c: Regenerate. * generated/pow_i16_i8.c: Regenerate. * generated/cshift1_4.c: Regenerate. * generated/maxloc0_8_i2.c: Regenerate. * generated/sum_r10.c: Regenerate. * generated/nearest_r16.c: Regenerate. * generated/sum_c4.c: Regenerate. * generated/maxloc1_16_r10.c: Regenerate. * generated/count_4_l16.c: Regenerate. * generated/pow_c8_i8.c: Regenerate. * generated/matmul_i8.c: Regenerate. * generated/in_pack_i4.c: Regenerate. * generated/pow_i4_i8.c: Regenerate. * generated/minloc0_16_i2.c: Regenerate. * generated/minloc1_8_r8.c: Regenerate. * generated/maxloc0_16_i2.c: Regenerate. * generated/exponent_r4.c: Regenerate. * generated/spacing_r10.c: Regenerate. * generated/matmul_c16.c: Regenerate. * generated/pow_c4_i16.c: Regenerate. * generated/maxval_r10.c: Regenerate. * generated/count_4_l4.c: Regenerate. * generated/shape_i16.c: Regenerate. * generated/minval_i1.c: Regenerate. * generated/maxloc1_4_i1.c: Regenerate. * generated/matmul_r10.c: Regenerate. * generated/minloc1_4_i8.c: Regenerate. * generated/pow_r10_i8.c: Regenerate. * generated/minloc0_8_r4.c: Regenerate. * generated/in_unpack_c4.c: Regenerate. * generated/matmul_l4.c: Regenerate. * generated/product_i16.c: Regenerate. * generated/minloc0_16_r16.c: Regenerate. * generated/reshape_r8.c: Regenerate. * generated/pow_r10_i16.c: Regenerate. * generated/all_l4.c: Regenerate. * generated/in_pack_c10.c: Regenerate. * generated/minloc0_4_i4.c: Regenerate. * generated/minloc0_8_i2.c: Regenerate. * generated/matmul_i1.c: Regenerate. * generated/reshape_c10.c: Regenerate. * generated/minval_r4.c: Regenerate. * generated/maxloc1_4_r4.c: Regenerate. * generated/pow_r8_i16.c: Regenerate. * generated/sum_i4.c: Regenerate. * generated/maxval_r8.c: Regenerate. * generated/count_16_l8.c: Regenerate. * generated/transpose_c4.c: Regenerate. * generated/eoshift1_4.c: Regenerate. * generated/eoshift3_8.c: Regenerate. * generated/minval_r16.c: Regenerate. * generated/minloc1_4_i1.c: Regenerate. * generated/minval_i2.c: Regenerate. * generated/maxloc1_4_i2.c: Regenerate. * generated/pow_i8_i16.c: Regenerate. * generated/product_r8.c: Regenerate. * generated/maxloc1_8_i8.c: Regenerate. * generated/maxloc0_4_r8.c: Regenerate. * generated/maxloc0_16_r16.c: Regenerate. * generated/in_unpack_i4.c: Regenerate. * generated/matmul_r4.c: Regenerate. * generated/sum_c10.c: Regenerate. * generated/minloc1_4_r16.c: Regenerate. * generated/fraction_r8.c: Regenerate. * generated/maxloc1_4_r16.c: Regenerate. * generated/set_exponent_r4.c: Regenerate. * generated/minloc0_8_r16.c: Regenerate. * generated/in_unpack_c16.c: Regenerate. * generated/reshape_c8.c: Regenerate. * generated/maxloc0_8_r16.c: Regenerate. * generated/nearest_r10.c: Regenerate. * generated/maxloc0_8_i4.c: Regenerate. * generated/pow_c4_i4.c: Regenerate. * generated/matmul_i2.c: Regenerate. * generated/minloc1_4_r4.c: Regenerate. * generated/transpose_i16.c: Regenerate. * generated/matmul_c10.c: Regenerate. * generated/minloc0_16_i4.c: Regenerate. * generated/maxloc0_16_i4.c: Regenerate. * generated/pow_i8_i8.c: Regenerate. * generated/nearest_r4.c: Regenerate. * generated/minloc1_16_i8.c: Regenerate. * generated/maxloc1_16_i8.c: Regenerate. * generated/transpose_i4.c: Regenerate. * generated/count_8_l4.c: Regenerate. * generated/minloc1_4_i2.c: Regenerate. * generated/matmul_l16.c: Regenerate. * generated/maxloc1_8_i1.c: Regenerate. * generated/minloc0_16_r10.c: Regenerate. * generated/minloc1_8_i8.c: Regenerate. * generated/minloc0_4_r8.c: Regenerate. * generated/product_r16.c: Regenerate. * generated/product_c8.c: Regenerate. * generated/pow_r16_i16.c: Regenerate. * generated/sum_r8.c: Regenerate. * generated/pow_c16_i8.c: Regenerate. * generated/in_pack_i16.c: Regenerate. * generated/minloc0_8_i4.c: Regenerate. * generated/matmul_c4.c: Regenerate. * generated/minloc1_16_i16.c: Regenerate. * generated/reshape_i8.c: Regenerate. * generated/spacing_r8.c: Regenerate. * generated/in_pack_c8.c: Regenerate. * generated/maxloc1_8_r4.c: Regenerate. * generated/minloc1_16_i1.c: Regenerate. * generated/maxloc1_16_i1.c: Regenerate. * generated/reshape_i16.c: Regenerate. * generated/minval_r10.c: Regenerate. * generated/pow_r4_i8.c: Regenerate. * generated/minloc1_8_i1.c: Regenerate. * generated/minval_i4.c: Regenerate. * generated/maxloc1_4_i4.c: Regenerate. * generated/maxloc1_8_i2.c: Regenerate. * generated/maxval_i8.c: Regenerate. * generated/eoshift3_16.c: Regenerate. * generated/any_l8.c: Regenerate. * generated/maxloc0_16_r10.c: Regenerate. * generated/rrspacing_r4.c: Regenerate. * generated/shape_i8.c: Regenerate. * generated/maxloc0_8_r8.c: Regenerate. * generated/minloc0_4_i16.c: Regenerate. * generated/maxloc0_4_i16.c: Regenerate. * generated/minloc1_4_r10.c: Regenerate. * generated/minloc1_8_i16.c: Regenerate. * generated/pow_c10_i8.c: Regenerate. * generated/maxloc1_4_r10.c: Regenerate. * generated/maxloc1_8_i16.c: Regenerate. * generated/in_unpack_c10.c: Regenerate. * generated/minloc0_8_r10.c: Regenerate. * generated/maxloc0_8_r10.c: Regenerate. * generated/minloc1_16_r4.c: Regenerate. * generated/maxloc1_16_r4.c: Regenerate. * generated/minloc0_16_r8.c: Regenerate. * generated/pow_i16_i4.c: Regenerate. * generated/product_i8.c: Regenerate. * generated/maxloc0_16_r8.c: Regenerate. * generated/sum_i16.c: Regenerate. * generated/maxloc0_4_i8.c: Regenerate. * generated/transpose_r8.c: Regenerate. * generated/cshift1_8.c: Regenerate. * generated/maxloc1_16_i16.c: Regenerate. * generated/matmul_i4.c: Regenerate. * generated/pow_c8_i4.c: Regenerate. * generated/pow_i4_i4.c: Regenerate. * generated/minloc1_8_r4.c: Regenerate. * generated/sum_c8.c: Regenerate. * generated/count_8_l16.c: Regenerate. * generated/minloc1_16_i2.c: Regenerate. * generated/maxloc1_16_i2.c: Regenerate. * generated/in_pack_i8.c: Regenerate. * generated/transpose_r16.c: Regenerate. * generated/maxval_i16.c: Regenerate. * generated/exponent_r8.c: Regenerate. * generated/matmul_i16.c: Regenerate. * generated/count_4_l8.c: Regenerate. * generated/pow_c8_i16.c: Regenerate. * generated/maxval_i1.c: Regenerate. * generated/minloc1_4_i4.c: Regenerate. * generated/minloc1_8_i2.c: Regenerate. * generated/pow_c10_i16.c: Regenerate. * generated/product_c16.c: Regenerate. * generated/reshape_r4.c: Regenerate. * generated/in_unpack_c8.c: Regenerate. * generated/minloc0_8_r8.c: Regenerate. * generated/matmul_l8.c: Regenerate. * generated/product_r10.c: Regenerate. * generated/set_exponent_r16.c: Regenerate. * generated/cshift1_16.c: Regenerate. * generated/product_i1.c: Regenerate. * generated/all_l8.c: Regenerate. * generated/maxloc0_4_i1.c: Regenerate. * generated/rrspacing_r16.c: Regenerate. * generated/minloc0_4_i8.c: Regenerate. * generated/pow_r4_i16.c: Regenerate. * generated/count_16_l4.c: Regenerate. * generated/maxval_r4.c: Regenerate. From-SVN: r127990
2007-08-31 16:01:34 +02:00
#include "io.h"
2009-11-02 22:52:59 +01:00
#include "format.h"
#include <ctype.h>
#include <string.h>
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
static const fnode colon_node = { FMT_COLON, 0, NULL, NULL, {{ 0, 0, 0 }}, 0,
NULL };
[multiple changes] 2009-04-05 Daniel Kraft <d@domob.eu> PR fortran/38654 * io/read.c (read_f): Reworked to speed up floating point parsing. (convert_real): Use pointer-casting instead of memcpy and temporaries. 2009-04-05 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR libfortran/37754 * io/io.h (format_hash_entry): New structure for hash table. (format_hash_table): The hash table itself. (free_format_data): Revise function prototype. (free_format_hash_table, init_format_hash, free_format_hash): New function prototypes. * io/unit.c (close_unit_1): Use free_format_hash_table. * io/transfer.c (st_read_done, st_write_done): Free format data if internal unit. * io/format.c (free_format_hash_table): New function that frees any memory allocated previously for cached format data. (reset_node): New static helper function to reset the format counters for a format node. (reset_fnode_counters): New static function recursively calls reset_node to traverse the fnode tree. (format_hash): New simple hash function based on XOR, probabalistic, tosses collisions. (save_parsed_format): New static function to save the parsed format data to use again. (find_parsed_format): New static function searches the hash table looking for a match. (free_format_data): Revised to accept pointer to format data rather than the dtp pointer so that the function can be used in more places. (format_lex): Editorial. (parse_format_list): Set flag used to determine of format data hashing is to be used. Internal units are not persistent enough for this. (revert): Move to ne location in file. (parse_format): Use new functions to look for previously parsed format strings and use them rather than re-parse. If not found, saves the parsed format data for later use. 2009-04-05 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR libfortran/37754 * io/transfer.c (formatted_transfer_scalar): Remove this function by factoring it into two new functions, one for read and one for write, eliminating all the conditionals for read or write mode. (formatted transfer_scalar_read): New function. (formatted transfer_scalar_write): New function. (formatted_transfer): Use new functions. 2009-04-05 Janne Blomqvist <jb@gcc.gnu.org> PR libfortran/25561 libfortran/37754 * io/io.h (struct stream): Define new stream interface function pointers, and inline functions for accessing it. (struct fbuf): Use int instead of size_t, remove flushed element. (mem_alloc_w): New prototype. (mem_alloc_r): New prototype. (stream_at_bof): Remove prototype. (stream_at_eof): Remove prototype. (file_position): Remove prototype. (flush): Remove prototype. (stream_offset): Remove prototype. (unit_truncate): New prototype. (read_block_form): Change to return pointer, int* argument. (hit_eof): New prototype. (fbuf_init): Change prototype. (fbuf_reset): Change prototype. (fbuf_alloc): Change prototype. (fbuf_flush): Change prototype. (fbuf_seek): Change prototype. (fbuf_read): New prototype. (fbuf_getc_refill): New prototype. (fbuf_getc): New inline function. * io/fbuf.c (fbuf_init): Use int, get rid of flushed. (fbuf_debug): New function. (fbuf_reset): Flush, and return position offset. (fbuf_alloc): Simplify, don't flush, just realloc. (fbuf_flush): Make usable for read mode, salvage remaining bytes. (fbuf_seek): New whence argument. (fbuf_read): New function. (fbuf_getc_refill): New function. * io/file_pos.c (formatted_backspace): Use new stream interface. (unformatted_backspace): Likewise. (st_backspace): Make sure format buffer is reset, use new stream interface, use unit_truncate. (st_endfile): Likewise. (st_rewind): Likewise. * io/intrinsics.c: Use new stream interface. * io/list_read.c (push_char): Don't use u.p.scratch, use realloc to resize. (free_saved): Don't check u.p.scratch. (next_char): Use new stream interface, use fbuf_getc() for external files. (finish_list_read): flush format buffer. (nml_query): Update to use modified interface:s * io/open.c (test_endfile): Use new stream interface. (edit_modes): Likewise. (new_unit): Likewise, set bytes_left to 1 for stream files. * io/read.c (read_l): Use new read_block_form interface. (read_utf8): Likewise. (read_utf8_char1): Likewise. (read_default_char1): Likewise. (read_utf8_char4): Likewise. (read_default_char4): Likewise. (read_a): Likewise. (read_a_char4): Likewise. (read_decimal): Likewise. (read_radix): Likewise. (read_f): Likewise. * io/transfer.c (read_sf): Use fbuf_read and mem_alloc_r, remove usage of u.p.line_buffer. (read_block_form): Update interface to return pointer, use fbuf_read for direct access. (read_block_direct): Update to new stream interface. (write_block): Use mem_alloc_w for internal I/O. (write_buf): Update to new stream interface. (formatted_transfer_scalar): Don't use u.p.line_buffer, use fbuf_seek for external files. (us_read): Update to new stream interface. (us_write): Likewise. (data_transfer_init): Always check if we switch modes and flush. (skip_record): Use new stream interface, fix comparison. (next_record_r): Check for and reset u.p.at_eof, use new stream interface, use fbuf_getc for spacing. (write_us_marker): Update to new stream interface, don't inline. (next_record_w_unf): Likewise. (sset): New function. (next_record_w): Use new stream interface, use fbuf for printing newline. (next_record): Use new stream interface. (finalize_transfer): Remove sfree call, use new stream interface. (st_iolength_done): Don't use u.p.scratch. (st_read): Don't check for end of file. (st_read_done): Don't use u.p.scratch, use unit_truncate. (hit_eof): New function. * io/unit.c (init_units): Always init fbuf for formatted units. (update_position): Use new stream interface. (unit_truncate): New function. (finish_last_advance_record): Use fbuf to print newline. * io/unix.c: Remove unused SSIZE_MAX macro. (BUFFER_SIZE): Make static const variable rather than macro. (struct unix_stream): Remove dirty_offset, len, method, small_buffer. Order elements by decreasing size. (struct int_stream): Remove. (move_pos_offset): Remove usage of dirty_offset. (reset_stream): Remove. (do_read): Rename to raw_read, update to match new stream interface. (do_write): Rename to raw_write, update to new stream interface. (raw_seek): New function. (raw_tell): New function. (raw_truncate): New function. (raw_close): New function. (raw_flush): New function. (raw_init): New function. (fd_alloc): Remove. (fd_alloc_r_at): Remove. (fd_alloc_w_at): Remove. (fd_sfree): Remove. (fd_seek): Remove. (fd_truncate): Remove. (fd_sset): Remove. (fd_read): Remove. (fd_write): Remove. (fd_close): Remove. (fd_open): Remove. (fd_flush): Rename to buf_flush, update to new stream interface and unix_stream. (buf_read): New function. (buf_write): New function. (buf_seek): New function. (buf_tell): New function. (buf_truncate): New function. (buf_close): New function. (buf_init): New function. (mem_alloc_r_at): Rename to mem_alloc_r, change prototype. (mem_alloc_w_at): Rename to mem_alloc_w, change prototype. (mem_read): Change to match new stream interface. (mem_write): Likewise. (mem_seek): Likewise. (mem_tell): Likewise. (mem_truncate): Likewise. (mem_close): Likewise. (mem_flush): New function. (mem_sfree): Remove. (empty_internal_buffer): Cast to correct type. (open_internal): Use correct type, init function pointers. (fd_to_stream): Test whether to open file as buffered or raw. (output_stream): Remove mode set. (error_stream): Likewise. (flush_all_units_1): Use new stream interface. (flush_all_units): Likewise. (stream_at_bof): Remove. (stream_at_eof): Remove. (file_position): Remove. (file_length): Update logic to use stream interface. (flush): Remove. (stream_offset): Remove. * io/write.c (write_utf8_char4): Use int instead of size_t. (write_x): Extra safety check. (namelist_write_newline): Use new stream interface. From-SVN: r145571
2009-04-05 22:13:56 +02:00
/* Error messages. */
static const char posint_required[] = "Positive width required in format",
period_required[] = "Period required in format",
nonneg_required[] = "Nonnegative width required in format",
unexpected_element[] = "Unexpected element '%c' in format\n",
unexpected_end[] = "Unexpected end of format string",
bad_string[] = "Unterminated character constant in format",
bad_hollerith[] = "Hollerith constant extends past the end of the format",
reversion_error[] = "Exhausted data descriptors in format",
zero_width[] = "Zero width in format descriptor";
[multiple changes] 2009-04-05 Daniel Kraft <d@domob.eu> PR fortran/38654 * io/read.c (read_f): Reworked to speed up floating point parsing. (convert_real): Use pointer-casting instead of memcpy and temporaries. 2009-04-05 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR libfortran/37754 * io/io.h (format_hash_entry): New structure for hash table. (format_hash_table): The hash table itself. (free_format_data): Revise function prototype. (free_format_hash_table, init_format_hash, free_format_hash): New function prototypes. * io/unit.c (close_unit_1): Use free_format_hash_table. * io/transfer.c (st_read_done, st_write_done): Free format data if internal unit. * io/format.c (free_format_hash_table): New function that frees any memory allocated previously for cached format data. (reset_node): New static helper function to reset the format counters for a format node. (reset_fnode_counters): New static function recursively calls reset_node to traverse the fnode tree. (format_hash): New simple hash function based on XOR, probabalistic, tosses collisions. (save_parsed_format): New static function to save the parsed format data to use again. (find_parsed_format): New static function searches the hash table looking for a match. (free_format_data): Revised to accept pointer to format data rather than the dtp pointer so that the function can be used in more places. (format_lex): Editorial. (parse_format_list): Set flag used to determine of format data hashing is to be used. Internal units are not persistent enough for this. (revert): Move to ne location in file. (parse_format): Use new functions to look for previously parsed format strings and use them rather than re-parse. If not found, saves the parsed format data for later use. 2009-04-05 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR libfortran/37754 * io/transfer.c (formatted_transfer_scalar): Remove this function by factoring it into two new functions, one for read and one for write, eliminating all the conditionals for read or write mode. (formatted transfer_scalar_read): New function. (formatted transfer_scalar_write): New function. (formatted_transfer): Use new functions. 2009-04-05 Janne Blomqvist <jb@gcc.gnu.org> PR libfortran/25561 libfortran/37754 * io/io.h (struct stream): Define new stream interface function pointers, and inline functions for accessing it. (struct fbuf): Use int instead of size_t, remove flushed element. (mem_alloc_w): New prototype. (mem_alloc_r): New prototype. (stream_at_bof): Remove prototype. (stream_at_eof): Remove prototype. (file_position): Remove prototype. (flush): Remove prototype. (stream_offset): Remove prototype. (unit_truncate): New prototype. (read_block_form): Change to return pointer, int* argument. (hit_eof): New prototype. (fbuf_init): Change prototype. (fbuf_reset): Change prototype. (fbuf_alloc): Change prototype. (fbuf_flush): Change prototype. (fbuf_seek): Change prototype. (fbuf_read): New prototype. (fbuf_getc_refill): New prototype. (fbuf_getc): New inline function. * io/fbuf.c (fbuf_init): Use int, get rid of flushed. (fbuf_debug): New function. (fbuf_reset): Flush, and return position offset. (fbuf_alloc): Simplify, don't flush, just realloc. (fbuf_flush): Make usable for read mode, salvage remaining bytes. (fbuf_seek): New whence argument. (fbuf_read): New function. (fbuf_getc_refill): New function. * io/file_pos.c (formatted_backspace): Use new stream interface. (unformatted_backspace): Likewise. (st_backspace): Make sure format buffer is reset, use new stream interface, use unit_truncate. (st_endfile): Likewise. (st_rewind): Likewise. * io/intrinsics.c: Use new stream interface. * io/list_read.c (push_char): Don't use u.p.scratch, use realloc to resize. (free_saved): Don't check u.p.scratch. (next_char): Use new stream interface, use fbuf_getc() for external files. (finish_list_read): flush format buffer. (nml_query): Update to use modified interface:s * io/open.c (test_endfile): Use new stream interface. (edit_modes): Likewise. (new_unit): Likewise, set bytes_left to 1 for stream files. * io/read.c (read_l): Use new read_block_form interface. (read_utf8): Likewise. (read_utf8_char1): Likewise. (read_default_char1): Likewise. (read_utf8_char4): Likewise. (read_default_char4): Likewise. (read_a): Likewise. (read_a_char4): Likewise. (read_decimal): Likewise. (read_radix): Likewise. (read_f): Likewise. * io/transfer.c (read_sf): Use fbuf_read and mem_alloc_r, remove usage of u.p.line_buffer. (read_block_form): Update interface to return pointer, use fbuf_read for direct access. (read_block_direct): Update to new stream interface. (write_block): Use mem_alloc_w for internal I/O. (write_buf): Update to new stream interface. (formatted_transfer_scalar): Don't use u.p.line_buffer, use fbuf_seek for external files. (us_read): Update to new stream interface. (us_write): Likewise. (data_transfer_init): Always check if we switch modes and flush. (skip_record): Use new stream interface, fix comparison. (next_record_r): Check for and reset u.p.at_eof, use new stream interface, use fbuf_getc for spacing. (write_us_marker): Update to new stream interface, don't inline. (next_record_w_unf): Likewise. (sset): New function. (next_record_w): Use new stream interface, use fbuf for printing newline. (next_record): Use new stream interface. (finalize_transfer): Remove sfree call, use new stream interface. (st_iolength_done): Don't use u.p.scratch. (st_read): Don't check for end of file. (st_read_done): Don't use u.p.scratch, use unit_truncate. (hit_eof): New function. * io/unit.c (init_units): Always init fbuf for formatted units. (update_position): Use new stream interface. (unit_truncate): New function. (finish_last_advance_record): Use fbuf to print newline. * io/unix.c: Remove unused SSIZE_MAX macro. (BUFFER_SIZE): Make static const variable rather than macro. (struct unix_stream): Remove dirty_offset, len, method, small_buffer. Order elements by decreasing size. (struct int_stream): Remove. (move_pos_offset): Remove usage of dirty_offset. (reset_stream): Remove. (do_read): Rename to raw_read, update to match new stream interface. (do_write): Rename to raw_write, update to new stream interface. (raw_seek): New function. (raw_tell): New function. (raw_truncate): New function. (raw_close): New function. (raw_flush): New function. (raw_init): New function. (fd_alloc): Remove. (fd_alloc_r_at): Remove. (fd_alloc_w_at): Remove. (fd_sfree): Remove. (fd_seek): Remove. (fd_truncate): Remove. (fd_sset): Remove. (fd_read): Remove. (fd_write): Remove. (fd_close): Remove. (fd_open): Remove. (fd_flush): Rename to buf_flush, update to new stream interface and unix_stream. (buf_read): New function. (buf_write): New function. (buf_seek): New function. (buf_tell): New function. (buf_truncate): New function. (buf_close): New function. (buf_init): New function. (mem_alloc_r_at): Rename to mem_alloc_r, change prototype. (mem_alloc_w_at): Rename to mem_alloc_w, change prototype. (mem_read): Change to match new stream interface. (mem_write): Likewise. (mem_seek): Likewise. (mem_tell): Likewise. (mem_truncate): Likewise. (mem_close): Likewise. (mem_flush): New function. (mem_sfree): Remove. (empty_internal_buffer): Cast to correct type. (open_internal): Use correct type, init function pointers. (fd_to_stream): Test whether to open file as buffered or raw. (output_stream): Remove mode set. (error_stream): Likewise. (flush_all_units_1): Use new stream interface. (flush_all_units): Likewise. (stream_at_bof): Remove. (stream_at_eof): Remove. (file_position): Remove. (file_length): Update logic to use stream interface. (flush): Remove. (stream_offset): Remove. * io/write.c (write_utf8_char4): Use int instead of size_t. (write_x): Extra safety check. (namelist_write_newline): Use new stream interface. From-SVN: r145571
2009-04-05 22:13:56 +02:00
/* The following routines support caching format data from parsed format strings
into a hash table. This avoids repeatedly parsing duplicate format strings
or format strings in I/O statements that are repeated in loops. */
/* Traverse the table and free all data. */
void
free_format_hash_table (gfc_unit *u)
{
size_t i;
/* free_format_data handles any NULL pointers. */
for (i = 0; i < FORMAT_HASH_SIZE; i++)
{
if (u->format_hash_table[i].hashed_fmt != NULL)
{
free_format_data (u->format_hash_table[i].hashed_fmt);
2010-05-07 17:55:59 +02:00
free (u->format_hash_table[i].key);
}
u->format_hash_table[i].key = NULL;
[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 07:36:22 +02:00
u->format_hash_table[i].key_len = 0;
[multiple changes] 2009-04-05 Daniel Kraft <d@domob.eu> PR fortran/38654 * io/read.c (read_f): Reworked to speed up floating point parsing. (convert_real): Use pointer-casting instead of memcpy and temporaries. 2009-04-05 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR libfortran/37754 * io/io.h (format_hash_entry): New structure for hash table. (format_hash_table): The hash table itself. (free_format_data): Revise function prototype. (free_format_hash_table, init_format_hash, free_format_hash): New function prototypes. * io/unit.c (close_unit_1): Use free_format_hash_table. * io/transfer.c (st_read_done, st_write_done): Free format data if internal unit. * io/format.c (free_format_hash_table): New function that frees any memory allocated previously for cached format data. (reset_node): New static helper function to reset the format counters for a format node. (reset_fnode_counters): New static function recursively calls reset_node to traverse the fnode tree. (format_hash): New simple hash function based on XOR, probabalistic, tosses collisions. (save_parsed_format): New static function to save the parsed format data to use again. (find_parsed_format): New static function searches the hash table looking for a match. (free_format_data): Revised to accept pointer to format data rather than the dtp pointer so that the function can be used in more places. (format_lex): Editorial. (parse_format_list): Set flag used to determine of format data hashing is to be used. Internal units are not persistent enough for this. (revert): Move to ne location in file. (parse_format): Use new functions to look for previously parsed format strings and use them rather than re-parse. If not found, saves the parsed format data for later use. 2009-04-05 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR libfortran/37754 * io/transfer.c (formatted_transfer_scalar): Remove this function by factoring it into two new functions, one for read and one for write, eliminating all the conditionals for read or write mode. (formatted transfer_scalar_read): New function. (formatted transfer_scalar_write): New function. (formatted_transfer): Use new functions. 2009-04-05 Janne Blomqvist <jb@gcc.gnu.org> PR libfortran/25561 libfortran/37754 * io/io.h (struct stream): Define new stream interface function pointers, and inline functions for accessing it. (struct fbuf): Use int instead of size_t, remove flushed element. (mem_alloc_w): New prototype. (mem_alloc_r): New prototype. (stream_at_bof): Remove prototype. (stream_at_eof): Remove prototype. (file_position): Remove prototype. (flush): Remove prototype. (stream_offset): Remove prototype. (unit_truncate): New prototype. (read_block_form): Change to return pointer, int* argument. (hit_eof): New prototype. (fbuf_init): Change prototype. (fbuf_reset): Change prototype. (fbuf_alloc): Change prototype. (fbuf_flush): Change prototype. (fbuf_seek): Change prototype. (fbuf_read): New prototype. (fbuf_getc_refill): New prototype. (fbuf_getc): New inline function. * io/fbuf.c (fbuf_init): Use int, get rid of flushed. (fbuf_debug): New function. (fbuf_reset): Flush, and return position offset. (fbuf_alloc): Simplify, don't flush, just realloc. (fbuf_flush): Make usable for read mode, salvage remaining bytes. (fbuf_seek): New whence argument. (fbuf_read): New function. (fbuf_getc_refill): New function. * io/file_pos.c (formatted_backspace): Use new stream interface. (unformatted_backspace): Likewise. (st_backspace): Make sure format buffer is reset, use new stream interface, use unit_truncate. (st_endfile): Likewise. (st_rewind): Likewise. * io/intrinsics.c: Use new stream interface. * io/list_read.c (push_char): Don't use u.p.scratch, use realloc to resize. (free_saved): Don't check u.p.scratch. (next_char): Use new stream interface, use fbuf_getc() for external files. (finish_list_read): flush format buffer. (nml_query): Update to use modified interface:s * io/open.c (test_endfile): Use new stream interface. (edit_modes): Likewise. (new_unit): Likewise, set bytes_left to 1 for stream files. * io/read.c (read_l): Use new read_block_form interface. (read_utf8): Likewise. (read_utf8_char1): Likewise. (read_default_char1): Likewise. (read_utf8_char4): Likewise. (read_default_char4): Likewise. (read_a): Likewise. (read_a_char4): Likewise. (read_decimal): Likewise. (read_radix): Likewise. (read_f): Likewise. * io/transfer.c (read_sf): Use fbuf_read and mem_alloc_r, remove usage of u.p.line_buffer. (read_block_form): Update interface to return pointer, use fbuf_read for direct access. (read_block_direct): Update to new stream interface. (write_block): Use mem_alloc_w for internal I/O. (write_buf): Update to new stream interface. (formatted_transfer_scalar): Don't use u.p.line_buffer, use fbuf_seek for external files. (us_read): Update to new stream interface. (us_write): Likewise. (data_transfer_init): Always check if we switch modes and flush. (skip_record): Use new stream interface, fix comparison. (next_record_r): Check for and reset u.p.at_eof, use new stream interface, use fbuf_getc for spacing. (write_us_marker): Update to new stream interface, don't inline. (next_record_w_unf): Likewise. (sset): New function. (next_record_w): Use new stream interface, use fbuf for printing newline. (next_record): Use new stream interface. (finalize_transfer): Remove sfree call, use new stream interface. (st_iolength_done): Don't use u.p.scratch. (st_read): Don't check for end of file. (st_read_done): Don't use u.p.scratch, use unit_truncate. (hit_eof): New function. * io/unit.c (init_units): Always init fbuf for formatted units. (update_position): Use new stream interface. (unit_truncate): New function. (finish_last_advance_record): Use fbuf to print newline. * io/unix.c: Remove unused SSIZE_MAX macro. (BUFFER_SIZE): Make static const variable rather than macro. (struct unix_stream): Remove dirty_offset, len, method, small_buffer. Order elements by decreasing size. (struct int_stream): Remove. (move_pos_offset): Remove usage of dirty_offset. (reset_stream): Remove. (do_read): Rename to raw_read, update to match new stream interface. (do_write): Rename to raw_write, update to new stream interface. (raw_seek): New function. (raw_tell): New function. (raw_truncate): New function. (raw_close): New function. (raw_flush): New function. (raw_init): New function. (fd_alloc): Remove. (fd_alloc_r_at): Remove. (fd_alloc_w_at): Remove. (fd_sfree): Remove. (fd_seek): Remove. (fd_truncate): Remove. (fd_sset): Remove. (fd_read): Remove. (fd_write): Remove. (fd_close): Remove. (fd_open): Remove. (fd_flush): Rename to buf_flush, update to new stream interface and unix_stream. (buf_read): New function. (buf_write): New function. (buf_seek): New function. (buf_tell): New function. (buf_truncate): New function. (buf_close): New function. (buf_init): New function. (mem_alloc_r_at): Rename to mem_alloc_r, change prototype. (mem_alloc_w_at): Rename to mem_alloc_w, change prototype. (mem_read): Change to match new stream interface. (mem_write): Likewise. (mem_seek): Likewise. (mem_tell): Likewise. (mem_truncate): Likewise. (mem_close): Likewise. (mem_flush): New function. (mem_sfree): Remove. (empty_internal_buffer): Cast to correct type. (open_internal): Use correct type, init function pointers. (fd_to_stream): Test whether to open file as buffered or raw. (output_stream): Remove mode set. (error_stream): Likewise. (flush_all_units_1): Use new stream interface. (flush_all_units): Likewise. (stream_at_bof): Remove. (stream_at_eof): Remove. (file_position): Remove. (file_length): Update logic to use stream interface. (flush): Remove. (stream_offset): Remove. * io/write.c (write_utf8_char4): Use int instead of size_t. (write_x): Extra safety check. (namelist_write_newline): Use new stream interface. From-SVN: r145571
2009-04-05 22:13:56 +02:00
u->format_hash_table[i].hashed_fmt = NULL;
}
}
/* Traverse the format_data structure and reset the fnode counters. */
static void
reset_node (fnode *fn)
{
fnode *f;
fn->count = 0;
fn->current = NULL;
[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 07:36:22 +02:00
[multiple changes] 2009-04-05 Daniel Kraft <d@domob.eu> PR fortran/38654 * io/read.c (read_f): Reworked to speed up floating point parsing. (convert_real): Use pointer-casting instead of memcpy and temporaries. 2009-04-05 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR libfortran/37754 * io/io.h (format_hash_entry): New structure for hash table. (format_hash_table): The hash table itself. (free_format_data): Revise function prototype. (free_format_hash_table, init_format_hash, free_format_hash): New function prototypes. * io/unit.c (close_unit_1): Use free_format_hash_table. * io/transfer.c (st_read_done, st_write_done): Free format data if internal unit. * io/format.c (free_format_hash_table): New function that frees any memory allocated previously for cached format data. (reset_node): New static helper function to reset the format counters for a format node. (reset_fnode_counters): New static function recursively calls reset_node to traverse the fnode tree. (format_hash): New simple hash function based on XOR, probabalistic, tosses collisions. (save_parsed_format): New static function to save the parsed format data to use again. (find_parsed_format): New static function searches the hash table looking for a match. (free_format_data): Revised to accept pointer to format data rather than the dtp pointer so that the function can be used in more places. (format_lex): Editorial. (parse_format_list): Set flag used to determine of format data hashing is to be used. Internal units are not persistent enough for this. (revert): Move to ne location in file. (parse_format): Use new functions to look for previously parsed format strings and use them rather than re-parse. If not found, saves the parsed format data for later use. 2009-04-05 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR libfortran/37754 * io/transfer.c (formatted_transfer_scalar): Remove this function by factoring it into two new functions, one for read and one for write, eliminating all the conditionals for read or write mode. (formatted transfer_scalar_read): New function. (formatted transfer_scalar_write): New function. (formatted_transfer): Use new functions. 2009-04-05 Janne Blomqvist <jb@gcc.gnu.org> PR libfortran/25561 libfortran/37754 * io/io.h (struct stream): Define new stream interface function pointers, and inline functions for accessing it. (struct fbuf): Use int instead of size_t, remove flushed element. (mem_alloc_w): New prototype. (mem_alloc_r): New prototype. (stream_at_bof): Remove prototype. (stream_at_eof): Remove prototype. (file_position): Remove prototype. (flush): Remove prototype. (stream_offset): Remove prototype. (unit_truncate): New prototype. (read_block_form): Change to return pointer, int* argument. (hit_eof): New prototype. (fbuf_init): Change prototype. (fbuf_reset): Change prototype. (fbuf_alloc): Change prototype. (fbuf_flush): Change prototype. (fbuf_seek): Change prototype. (fbuf_read): New prototype. (fbuf_getc_refill): New prototype. (fbuf_getc): New inline function. * io/fbuf.c (fbuf_init): Use int, get rid of flushed. (fbuf_debug): New function. (fbuf_reset): Flush, and return position offset. (fbuf_alloc): Simplify, don't flush, just realloc. (fbuf_flush): Make usable for read mode, salvage remaining bytes. (fbuf_seek): New whence argument. (fbuf_read): New function. (fbuf_getc_refill): New function. * io/file_pos.c (formatted_backspace): Use new stream interface. (unformatted_backspace): Likewise. (st_backspace): Make sure format buffer is reset, use new stream interface, use unit_truncate. (st_endfile): Likewise. (st_rewind): Likewise. * io/intrinsics.c: Use new stream interface. * io/list_read.c (push_char): Don't use u.p.scratch, use realloc to resize. (free_saved): Don't check u.p.scratch. (next_char): Use new stream interface, use fbuf_getc() for external files. (finish_list_read): flush format buffer. (nml_query): Update to use modified interface:s * io/open.c (test_endfile): Use new stream interface. (edit_modes): Likewise. (new_unit): Likewise, set bytes_left to 1 for stream files. * io/read.c (read_l): Use new read_block_form interface. (read_utf8): Likewise. (read_utf8_char1): Likewise. (read_default_char1): Likewise. (read_utf8_char4): Likewise. (read_default_char4): Likewise. (read_a): Likewise. (read_a_char4): Likewise. (read_decimal): Likewise. (read_radix): Likewise. (read_f): Likewise. * io/transfer.c (read_sf): Use fbuf_read and mem_alloc_r, remove usage of u.p.line_buffer. (read_block_form): Update interface to return pointer, use fbuf_read for direct access. (read_block_direct): Update to new stream interface. (write_block): Use mem_alloc_w for internal I/O. (write_buf): Update to new stream interface. (formatted_transfer_scalar): Don't use u.p.line_buffer, use fbuf_seek for external files. (us_read): Update to new stream interface. (us_write): Likewise. (data_transfer_init): Always check if we switch modes and flush. (skip_record): Use new stream interface, fix comparison. (next_record_r): Check for and reset u.p.at_eof, use new stream interface, use fbuf_getc for spacing. (write_us_marker): Update to new stream interface, don't inline. (next_record_w_unf): Likewise. (sset): New function. (next_record_w): Use new stream interface, use fbuf for printing newline. (next_record): Use new stream interface. (finalize_transfer): Remove sfree call, use new stream interface. (st_iolength_done): Don't use u.p.scratch. (st_read): Don't check for end of file. (st_read_done): Don't use u.p.scratch, use unit_truncate. (hit_eof): New function. * io/unit.c (init_units): Always init fbuf for formatted units. (update_position): Use new stream interface. (unit_truncate): New function. (finish_last_advance_record): Use fbuf to print newline. * io/unix.c: Remove unused SSIZE_MAX macro. (BUFFER_SIZE): Make static const variable rather than macro. (struct unix_stream): Remove dirty_offset, len, method, small_buffer. Order elements by decreasing size. (struct int_stream): Remove. (move_pos_offset): Remove usage of dirty_offset. (reset_stream): Remove. (do_read): Rename to raw_read, update to match new stream interface. (do_write): Rename to raw_write, update to new stream interface. (raw_seek): New function. (raw_tell): New function. (raw_truncate): New function. (raw_close): New function. (raw_flush): New function. (raw_init): New function. (fd_alloc): Remove. (fd_alloc_r_at): Remove. (fd_alloc_w_at): Remove. (fd_sfree): Remove. (fd_seek): Remove. (fd_truncate): Remove. (fd_sset): Remove. (fd_read): Remove. (fd_write): Remove. (fd_close): Remove. (fd_open): Remove. (fd_flush): Rename to buf_flush, update to new stream interface and unix_stream. (buf_read): New function. (buf_write): New function. (buf_seek): New function. (buf_tell): New function. (buf_truncate): New function. (buf_close): New function. (buf_init): New function. (mem_alloc_r_at): Rename to mem_alloc_r, change prototype. (mem_alloc_w_at): Rename to mem_alloc_w, change prototype. (mem_read): Change to match new stream interface. (mem_write): Likewise. (mem_seek): Likewise. (mem_tell): Likewise. (mem_truncate): Likewise. (mem_close): Likewise. (mem_flush): New function. (mem_sfree): Remove. (empty_internal_buffer): Cast to correct type. (open_internal): Use correct type, init function pointers. (fd_to_stream): Test whether to open file as buffered or raw. (output_stream): Remove mode set. (error_stream): Likewise. (flush_all_units_1): Use new stream interface. (flush_all_units): Likewise. (stream_at_bof): Remove. (stream_at_eof): Remove. (file_position): Remove. (file_length): Update logic to use stream interface. (flush): Remove. (stream_offset): Remove. * io/write.c (write_utf8_char4): Use int instead of size_t. (write_x): Extra safety check. (namelist_write_newline): Use new stream interface. From-SVN: r145571
2009-04-05 22:13:56 +02:00
if (fn->format != FMT_LPAREN)
return;
for (f = fn->u.child; f; f = f->next)
{
if (f->format == FMT_RPAREN)
break;
reset_node (f);
}
}
static void
reset_fnode_counters (st_parameter_dt *dtp)
{
fnode *f;
format_data *fmt;
fmt = dtp->u.p.fmt;
/* Clear this pointer at the head so things start at the right place. */
fmt->array.array[0].current = NULL;
for (f = fmt->array.array[0].u.child; f; f = f->next)
[multiple changes] 2009-04-05 Daniel Kraft <d@domob.eu> PR fortran/38654 * io/read.c (read_f): Reworked to speed up floating point parsing. (convert_real): Use pointer-casting instead of memcpy and temporaries. 2009-04-05 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR libfortran/37754 * io/io.h (format_hash_entry): New structure for hash table. (format_hash_table): The hash table itself. (free_format_data): Revise function prototype. (free_format_hash_table, init_format_hash, free_format_hash): New function prototypes. * io/unit.c (close_unit_1): Use free_format_hash_table. * io/transfer.c (st_read_done, st_write_done): Free format data if internal unit. * io/format.c (free_format_hash_table): New function that frees any memory allocated previously for cached format data. (reset_node): New static helper function to reset the format counters for a format node. (reset_fnode_counters): New static function recursively calls reset_node to traverse the fnode tree. (format_hash): New simple hash function based on XOR, probabalistic, tosses collisions. (save_parsed_format): New static function to save the parsed format data to use again. (find_parsed_format): New static function searches the hash table looking for a match. (free_format_data): Revised to accept pointer to format data rather than the dtp pointer so that the function can be used in more places. (format_lex): Editorial. (parse_format_list): Set flag used to determine of format data hashing is to be used. Internal units are not persistent enough for this. (revert): Move to ne location in file. (parse_format): Use new functions to look for previously parsed format strings and use them rather than re-parse. If not found, saves the parsed format data for later use. 2009-04-05 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR libfortran/37754 * io/transfer.c (formatted_transfer_scalar): Remove this function by factoring it into two new functions, one for read and one for write, eliminating all the conditionals for read or write mode. (formatted transfer_scalar_read): New function. (formatted transfer_scalar_write): New function. (formatted_transfer): Use new functions. 2009-04-05 Janne Blomqvist <jb@gcc.gnu.org> PR libfortran/25561 libfortran/37754 * io/io.h (struct stream): Define new stream interface function pointers, and inline functions for accessing it. (struct fbuf): Use int instead of size_t, remove flushed element. (mem_alloc_w): New prototype. (mem_alloc_r): New prototype. (stream_at_bof): Remove prototype. (stream_at_eof): Remove prototype. (file_position): Remove prototype. (flush): Remove prototype. (stream_offset): Remove prototype. (unit_truncate): New prototype. (read_block_form): Change to return pointer, int* argument. (hit_eof): New prototype. (fbuf_init): Change prototype. (fbuf_reset): Change prototype. (fbuf_alloc): Change prototype. (fbuf_flush): Change prototype. (fbuf_seek): Change prototype. (fbuf_read): New prototype. (fbuf_getc_refill): New prototype. (fbuf_getc): New inline function. * io/fbuf.c (fbuf_init): Use int, get rid of flushed. (fbuf_debug): New function. (fbuf_reset): Flush, and return position offset. (fbuf_alloc): Simplify, don't flush, just realloc. (fbuf_flush): Make usable for read mode, salvage remaining bytes. (fbuf_seek): New whence argument. (fbuf_read): New function. (fbuf_getc_refill): New function. * io/file_pos.c (formatted_backspace): Use new stream interface. (unformatted_backspace): Likewise. (st_backspace): Make sure format buffer is reset, use new stream interface, use unit_truncate. (st_endfile): Likewise. (st_rewind): Likewise. * io/intrinsics.c: Use new stream interface. * io/list_read.c (push_char): Don't use u.p.scratch, use realloc to resize. (free_saved): Don't check u.p.scratch. (next_char): Use new stream interface, use fbuf_getc() for external files. (finish_list_read): flush format buffer. (nml_query): Update to use modified interface:s * io/open.c (test_endfile): Use new stream interface. (edit_modes): Likewise. (new_unit): Likewise, set bytes_left to 1 for stream files. * io/read.c (read_l): Use new read_block_form interface. (read_utf8): Likewise. (read_utf8_char1): Likewise. (read_default_char1): Likewise. (read_utf8_char4): Likewise. (read_default_char4): Likewise. (read_a): Likewise. (read_a_char4): Likewise. (read_decimal): Likewise. (read_radix): Likewise. (read_f): Likewise. * io/transfer.c (read_sf): Use fbuf_read and mem_alloc_r, remove usage of u.p.line_buffer. (read_block_form): Update interface to return pointer, use fbuf_read for direct access. (read_block_direct): Update to new stream interface. (write_block): Use mem_alloc_w for internal I/O. (write_buf): Update to new stream interface. (formatted_transfer_scalar): Don't use u.p.line_buffer, use fbuf_seek for external files. (us_read): Update to new stream interface. (us_write): Likewise. (data_transfer_init): Always check if we switch modes and flush. (skip_record): Use new stream interface, fix comparison. (next_record_r): Check for and reset u.p.at_eof, use new stream interface, use fbuf_getc for spacing. (write_us_marker): Update to new stream interface, don't inline. (next_record_w_unf): Likewise. (sset): New function. (next_record_w): Use new stream interface, use fbuf for printing newline. (next_record): Use new stream interface. (finalize_transfer): Remove sfree call, use new stream interface. (st_iolength_done): Don't use u.p.scratch. (st_read): Don't check for end of file. (st_read_done): Don't use u.p.scratch, use unit_truncate. (hit_eof): New function. * io/unit.c (init_units): Always init fbuf for formatted units. (update_position): Use new stream interface. (unit_truncate): New function. (finish_last_advance_record): Use fbuf to print newline. * io/unix.c: Remove unused SSIZE_MAX macro. (BUFFER_SIZE): Make static const variable rather than macro. (struct unix_stream): Remove dirty_offset, len, method, small_buffer. Order elements by decreasing size. (struct int_stream): Remove. (move_pos_offset): Remove usage of dirty_offset. (reset_stream): Remove. (do_read): Rename to raw_read, update to match new stream interface. (do_write): Rename to raw_write, update to new stream interface. (raw_seek): New function. (raw_tell): New function. (raw_truncate): New function. (raw_close): New function. (raw_flush): New function. (raw_init): New function. (fd_alloc): Remove. (fd_alloc_r_at): Remove. (fd_alloc_w_at): Remove. (fd_sfree): Remove. (fd_seek): Remove. (fd_truncate): Remove. (fd_sset): Remove. (fd_read): Remove. (fd_write): Remove. (fd_close): Remove. (fd_open): Remove. (fd_flush): Rename to buf_flush, update to new stream interface and unix_stream. (buf_read): New function. (buf_write): New function. (buf_seek): New function. (buf_tell): New function. (buf_truncate): New function. (buf_close): New function. (buf_init): New function. (mem_alloc_r_at): Rename to mem_alloc_r, change prototype. (mem_alloc_w_at): Rename to mem_alloc_w, change prototype. (mem_read): Change to match new stream interface. (mem_write): Likewise. (mem_seek): Likewise. (mem_tell): Likewise. (mem_truncate): Likewise. (mem_close): Likewise. (mem_flush): New function. (mem_sfree): Remove. (empty_internal_buffer): Cast to correct type. (open_internal): Use correct type, init function pointers. (fd_to_stream): Test whether to open file as buffered or raw. (output_stream): Remove mode set. (error_stream): Likewise. (flush_all_units_1): Use new stream interface. (flush_all_units): Likewise. (stream_at_bof): Remove. (stream_at_eof): Remove. (file_position): Remove. (file_length): Update logic to use stream interface. (flush): Remove. (stream_offset): Remove. * io/write.c (write_utf8_char4): Use int instead of size_t. (write_x): Extra safety check. (namelist_write_newline): Use new stream interface. From-SVN: r145571
2009-04-05 22:13:56 +02:00
reset_node (f);
}
/* A simple hashing function to generate an index into the hash table. */
static uint32_t
format_hash (st_parameter_dt *dtp)
[multiple changes] 2009-04-05 Daniel Kraft <d@domob.eu> PR fortran/38654 * io/read.c (read_f): Reworked to speed up floating point parsing. (convert_real): Use pointer-casting instead of memcpy and temporaries. 2009-04-05 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR libfortran/37754 * io/io.h (format_hash_entry): New structure for hash table. (format_hash_table): The hash table itself. (free_format_data): Revise function prototype. (free_format_hash_table, init_format_hash, free_format_hash): New function prototypes. * io/unit.c (close_unit_1): Use free_format_hash_table. * io/transfer.c (st_read_done, st_write_done): Free format data if internal unit. * io/format.c (free_format_hash_table): New function that frees any memory allocated previously for cached format data. (reset_node): New static helper function to reset the format counters for a format node. (reset_fnode_counters): New static function recursively calls reset_node to traverse the fnode tree. (format_hash): New simple hash function based on XOR, probabalistic, tosses collisions. (save_parsed_format): New static function to save the parsed format data to use again. (find_parsed_format): New static function searches the hash table looking for a match. (free_format_data): Revised to accept pointer to format data rather than the dtp pointer so that the function can be used in more places. (format_lex): Editorial. (parse_format_list): Set flag used to determine of format data hashing is to be used. Internal units are not persistent enough for this. (revert): Move to ne location in file. (parse_format): Use new functions to look for previously parsed format strings and use them rather than re-parse. If not found, saves the parsed format data for later use. 2009-04-05 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR libfortran/37754 * io/transfer.c (formatted_transfer_scalar): Remove this function by factoring it into two new functions, one for read and one for write, eliminating all the conditionals for read or write mode. (formatted transfer_scalar_read): New function. (formatted transfer_scalar_write): New function. (formatted_transfer): Use new functions. 2009-04-05 Janne Blomqvist <jb@gcc.gnu.org> PR libfortran/25561 libfortran/37754 * io/io.h (struct stream): Define new stream interface function pointers, and inline functions for accessing it. (struct fbuf): Use int instead of size_t, remove flushed element. (mem_alloc_w): New prototype. (mem_alloc_r): New prototype. (stream_at_bof): Remove prototype. (stream_at_eof): Remove prototype. (file_position): Remove prototype. (flush): Remove prototype. (stream_offset): Remove prototype. (unit_truncate): New prototype. (read_block_form): Change to return pointer, int* argument. (hit_eof): New prototype. (fbuf_init): Change prototype. (fbuf_reset): Change prototype. (fbuf_alloc): Change prototype. (fbuf_flush): Change prototype. (fbuf_seek): Change prototype. (fbuf_read): New prototype. (fbuf_getc_refill): New prototype. (fbuf_getc): New inline function. * io/fbuf.c (fbuf_init): Use int, get rid of flushed. (fbuf_debug): New function. (fbuf_reset): Flush, and return position offset. (fbuf_alloc): Simplify, don't flush, just realloc. (fbuf_flush): Make usable for read mode, salvage remaining bytes. (fbuf_seek): New whence argument. (fbuf_read): New function. (fbuf_getc_refill): New function. * io/file_pos.c (formatted_backspace): Use new stream interface. (unformatted_backspace): Likewise. (st_backspace): Make sure format buffer is reset, use new stream interface, use unit_truncate. (st_endfile): Likewise. (st_rewind): Likewise. * io/intrinsics.c: Use new stream interface. * io/list_read.c (push_char): Don't use u.p.scratch, use realloc to resize. (free_saved): Don't check u.p.scratch. (next_char): Use new stream interface, use fbuf_getc() for external files. (finish_list_read): flush format buffer. (nml_query): Update to use modified interface:s * io/open.c (test_endfile): Use new stream interface. (edit_modes): Likewise. (new_unit): Likewise, set bytes_left to 1 for stream files. * io/read.c (read_l): Use new read_block_form interface. (read_utf8): Likewise. (read_utf8_char1): Likewise. (read_default_char1): Likewise. (read_utf8_char4): Likewise. (read_default_char4): Likewise. (read_a): Likewise. (read_a_char4): Likewise. (read_decimal): Likewise. (read_radix): Likewise. (read_f): Likewise. * io/transfer.c (read_sf): Use fbuf_read and mem_alloc_r, remove usage of u.p.line_buffer. (read_block_form): Update interface to return pointer, use fbuf_read for direct access. (read_block_direct): Update to new stream interface. (write_block): Use mem_alloc_w for internal I/O. (write_buf): Update to new stream interface. (formatted_transfer_scalar): Don't use u.p.line_buffer, use fbuf_seek for external files. (us_read): Update to new stream interface. (us_write): Likewise. (data_transfer_init): Always check if we switch modes and flush. (skip_record): Use new stream interface, fix comparison. (next_record_r): Check for and reset u.p.at_eof, use new stream interface, use fbuf_getc for spacing. (write_us_marker): Update to new stream interface, don't inline. (next_record_w_unf): Likewise. (sset): New function. (next_record_w): Use new stream interface, use fbuf for printing newline. (next_record): Use new stream interface. (finalize_transfer): Remove sfree call, use new stream interface. (st_iolength_done): Don't use u.p.scratch. (st_read): Don't check for end of file. (st_read_done): Don't use u.p.scratch, use unit_truncate. (hit_eof): New function. * io/unit.c (init_units): Always init fbuf for formatted units. (update_position): Use new stream interface. (unit_truncate): New function. (finish_last_advance_record): Use fbuf to print newline. * io/unix.c: Remove unused SSIZE_MAX macro. (BUFFER_SIZE): Make static const variable rather than macro. (struct unix_stream): Remove dirty_offset, len, method, small_buffer. Order elements by decreasing size. (struct int_stream): Remove. (move_pos_offset): Remove usage of dirty_offset. (reset_stream): Remove. (do_read): Rename to raw_read, update to match new stream interface. (do_write): Rename to raw_write, update to new stream interface. (raw_seek): New function. (raw_tell): New function. (raw_truncate): New function. (raw_close): New function. (raw_flush): New function. (raw_init): New function. (fd_alloc): Remove. (fd_alloc_r_at): Remove. (fd_alloc_w_at): Remove. (fd_sfree): Remove. (fd_seek): Remove. (fd_truncate): Remove. (fd_sset): Remove. (fd_read): Remove. (fd_write): Remove. (fd_close): Remove. (fd_open): Remove. (fd_flush): Rename to buf_flush, update to new stream interface and unix_stream. (buf_read): New function. (buf_write): New function. (buf_seek): New function. (buf_tell): New function. (buf_truncate): New function. (buf_close): New function. (buf_init): New function. (mem_alloc_r_at): Rename to mem_alloc_r, change prototype. (mem_alloc_w_at): Rename to mem_alloc_w, change prototype. (mem_read): Change to match new stream interface. (mem_write): Likewise. (mem_seek): Likewise. (mem_tell): Likewise. (mem_truncate): Likewise. (mem_close): Likewise. (mem_flush): New function. (mem_sfree): Remove. (empty_internal_buffer): Cast to correct type. (open_internal): Use correct type, init function pointers. (fd_to_stream): Test whether to open file as buffered or raw. (output_stream): Remove mode set. (error_stream): Likewise. (flush_all_units_1): Use new stream interface. (flush_all_units): Likewise. (stream_at_bof): Remove. (stream_at_eof): Remove. (file_position): Remove. (file_length): Update logic to use stream interface. (flush): Remove. (stream_offset): Remove. * io/write.c (write_utf8_char4): Use int instead of size_t. (write_x): Extra safety check. (namelist_write_newline): Use new stream interface. From-SVN: r145571
2009-04-05 22:13:56 +02:00
{
char *key;
gfc_charlen_type key_len;
[multiple changes] 2009-04-05 Daniel Kraft <d@domob.eu> PR fortran/38654 * io/read.c (read_f): Reworked to speed up floating point parsing. (convert_real): Use pointer-casting instead of memcpy and temporaries. 2009-04-05 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR libfortran/37754 * io/io.h (format_hash_entry): New structure for hash table. (format_hash_table): The hash table itself. (free_format_data): Revise function prototype. (free_format_hash_table, init_format_hash, free_format_hash): New function prototypes. * io/unit.c (close_unit_1): Use free_format_hash_table. * io/transfer.c (st_read_done, st_write_done): Free format data if internal unit. * io/format.c (free_format_hash_table): New function that frees any memory allocated previously for cached format data. (reset_node): New static helper function to reset the format counters for a format node. (reset_fnode_counters): New static function recursively calls reset_node to traverse the fnode tree. (format_hash): New simple hash function based on XOR, probabalistic, tosses collisions. (save_parsed_format): New static function to save the parsed format data to use again. (find_parsed_format): New static function searches the hash table looking for a match. (free_format_data): Revised to accept pointer to format data rather than the dtp pointer so that the function can be used in more places. (format_lex): Editorial. (parse_format_list): Set flag used to determine of format data hashing is to be used. Internal units are not persistent enough for this. (revert): Move to ne location in file. (parse_format): Use new functions to look for previously parsed format strings and use them rather than re-parse. If not found, saves the parsed format data for later use. 2009-04-05 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR libfortran/37754 * io/transfer.c (formatted_transfer_scalar): Remove this function by factoring it into two new functions, one for read and one for write, eliminating all the conditionals for read or write mode. (formatted transfer_scalar_read): New function. (formatted transfer_scalar_write): New function. (formatted_transfer): Use new functions. 2009-04-05 Janne Blomqvist <jb@gcc.gnu.org> PR libfortran/25561 libfortran/37754 * io/io.h (struct stream): Define new stream interface function pointers, and inline functions for accessing it. (struct fbuf): Use int instead of size_t, remove flushed element. (mem_alloc_w): New prototype. (mem_alloc_r): New prototype. (stream_at_bof): Remove prototype. (stream_at_eof): Remove prototype. (file_position): Remove prototype. (flush): Remove prototype. (stream_offset): Remove prototype. (unit_truncate): New prototype. (read_block_form): Change to return pointer, int* argument. (hit_eof): New prototype. (fbuf_init): Change prototype. (fbuf_reset): Change prototype. (fbuf_alloc): Change prototype. (fbuf_flush): Change prototype. (fbuf_seek): Change prototype. (fbuf_read): New prototype. (fbuf_getc_refill): New prototype. (fbuf_getc): New inline function. * io/fbuf.c (fbuf_init): Use int, get rid of flushed. (fbuf_debug): New function. (fbuf_reset): Flush, and return position offset. (fbuf_alloc): Simplify, don't flush, just realloc. (fbuf_flush): Make usable for read mode, salvage remaining bytes. (fbuf_seek): New whence argument. (fbuf_read): New function. (fbuf_getc_refill): New function. * io/file_pos.c (formatted_backspace): Use new stream interface. (unformatted_backspace): Likewise. (st_backspace): Make sure format buffer is reset, use new stream interface, use unit_truncate. (st_endfile): Likewise. (st_rewind): Likewise. * io/intrinsics.c: Use new stream interface. * io/list_read.c (push_char): Don't use u.p.scratch, use realloc to resize. (free_saved): Don't check u.p.scratch. (next_char): Use new stream interface, use fbuf_getc() for external files. (finish_list_read): flush format buffer. (nml_query): Update to use modified interface:s * io/open.c (test_endfile): Use new stream interface. (edit_modes): Likewise. (new_unit): Likewise, set bytes_left to 1 for stream files. * io/read.c (read_l): Use new read_block_form interface. (read_utf8): Likewise. (read_utf8_char1): Likewise. (read_default_char1): Likewise. (read_utf8_char4): Likewise. (read_default_char4): Likewise. (read_a): Likewise. (read_a_char4): Likewise. (read_decimal): Likewise. (read_radix): Likewise. (read_f): Likewise. * io/transfer.c (read_sf): Use fbuf_read and mem_alloc_r, remove usage of u.p.line_buffer. (read_block_form): Update interface to return pointer, use fbuf_read for direct access. (read_block_direct): Update to new stream interface. (write_block): Use mem_alloc_w for internal I/O. (write_buf): Update to new stream interface. (formatted_transfer_scalar): Don't use u.p.line_buffer, use fbuf_seek for external files. (us_read): Update to new stream interface. (us_write): Likewise. (data_transfer_init): Always check if we switch modes and flush. (skip_record): Use new stream interface, fix comparison. (next_record_r): Check for and reset u.p.at_eof, use new stream interface, use fbuf_getc for spacing. (write_us_marker): Update to new stream interface, don't inline. (next_record_w_unf): Likewise. (sset): New function. (next_record_w): Use new stream interface, use fbuf for printing newline. (next_record): Use new stream interface. (finalize_transfer): Remove sfree call, use new stream interface. (st_iolength_done): Don't use u.p.scratch. (st_read): Don't check for end of file. (st_read_done): Don't use u.p.scratch, use unit_truncate. (hit_eof): New function. * io/unit.c (init_units): Always init fbuf for formatted units. (update_position): Use new stream interface. (unit_truncate): New function. (finish_last_advance_record): Use fbuf to print newline. * io/unix.c: Remove unused SSIZE_MAX macro. (BUFFER_SIZE): Make static const variable rather than macro. (struct unix_stream): Remove dirty_offset, len, method, small_buffer. Order elements by decreasing size. (struct int_stream): Remove. (move_pos_offset): Remove usage of dirty_offset. (reset_stream): Remove. (do_read): Rename to raw_read, update to match new stream interface. (do_write): Rename to raw_write, update to new stream interface. (raw_seek): New function. (raw_tell): New function. (raw_truncate): New function. (raw_close): New function. (raw_flush): New function. (raw_init): New function. (fd_alloc): Remove. (fd_alloc_r_at): Remove. (fd_alloc_w_at): Remove. (fd_sfree): Remove. (fd_seek): Remove. (fd_truncate): Remove. (fd_sset): Remove. (fd_read): Remove. (fd_write): Remove. (fd_close): Remove. (fd_open): Remove. (fd_flush): Rename to buf_flush, update to new stream interface and unix_stream. (buf_read): New function. (buf_write): New function. (buf_seek): New function. (buf_tell): New function. (buf_truncate): New function. (buf_close): New function. (buf_init): New function. (mem_alloc_r_at): Rename to mem_alloc_r, change prototype. (mem_alloc_w_at): Rename to mem_alloc_w, change prototype. (mem_read): Change to match new stream interface. (mem_write): Likewise. (mem_seek): Likewise. (mem_tell): Likewise. (mem_truncate): Likewise. (mem_close): Likewise. (mem_flush): New function. (mem_sfree): Remove. (empty_internal_buffer): Cast to correct type. (open_internal): Use correct type, init function pointers. (fd_to_stream): Test whether to open file as buffered or raw. (output_stream): Remove mode set. (error_stream): Likewise. (flush_all_units_1): Use new stream interface. (flush_all_units): Likewise. (stream_at_bof): Remove. (stream_at_eof): Remove. (file_position): Remove. (file_length): Update logic to use stream interface. (flush): Remove. (stream_offset): Remove. * io/write.c (write_utf8_char4): Use int instead of size_t. (write_x): Extra safety check. (namelist_write_newline): Use new stream interface. From-SVN: r145571
2009-04-05 22:13:56 +02:00
uint32_t hash = 0;
gfc_charlen_type i;
[multiple changes] 2009-04-05 Daniel Kraft <d@domob.eu> PR fortran/38654 * io/read.c (read_f): Reworked to speed up floating point parsing. (convert_real): Use pointer-casting instead of memcpy and temporaries. 2009-04-05 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR libfortran/37754 * io/io.h (format_hash_entry): New structure for hash table. (format_hash_table): The hash table itself. (free_format_data): Revise function prototype. (free_format_hash_table, init_format_hash, free_format_hash): New function prototypes. * io/unit.c (close_unit_1): Use free_format_hash_table. * io/transfer.c (st_read_done, st_write_done): Free format data if internal unit. * io/format.c (free_format_hash_table): New function that frees any memory allocated previously for cached format data. (reset_node): New static helper function to reset the format counters for a format node. (reset_fnode_counters): New static function recursively calls reset_node to traverse the fnode tree. (format_hash): New simple hash function based on XOR, probabalistic, tosses collisions. (save_parsed_format): New static function to save the parsed format data to use again. (find_parsed_format): New static function searches the hash table looking for a match. (free_format_data): Revised to accept pointer to format data rather than the dtp pointer so that the function can be used in more places. (format_lex): Editorial. (parse_format_list): Set flag used to determine of format data hashing is to be used. Internal units are not persistent enough for this. (revert): Move to ne location in file. (parse_format): Use new functions to look for previously parsed format strings and use them rather than re-parse. If not found, saves the parsed format data for later use. 2009-04-05 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR libfortran/37754 * io/transfer.c (formatted_transfer_scalar): Remove this function by factoring it into two new functions, one for read and one for write, eliminating all the conditionals for read or write mode. (formatted transfer_scalar_read): New function. (formatted transfer_scalar_write): New function. (formatted_transfer): Use new functions. 2009-04-05 Janne Blomqvist <jb@gcc.gnu.org> PR libfortran/25561 libfortran/37754 * io/io.h (struct stream): Define new stream interface function pointers, and inline functions for accessing it. (struct fbuf): Use int instead of size_t, remove flushed element. (mem_alloc_w): New prototype. (mem_alloc_r): New prototype. (stream_at_bof): Remove prototype. (stream_at_eof): Remove prototype. (file_position): Remove prototype. (flush): Remove prototype. (stream_offset): Remove prototype. (unit_truncate): New prototype. (read_block_form): Change to return pointer, int* argument. (hit_eof): New prototype. (fbuf_init): Change prototype. (fbuf_reset): Change prototype. (fbuf_alloc): Change prototype. (fbuf_flush): Change prototype. (fbuf_seek): Change prototype. (fbuf_read): New prototype. (fbuf_getc_refill): New prototype. (fbuf_getc): New inline function. * io/fbuf.c (fbuf_init): Use int, get rid of flushed. (fbuf_debug): New function. (fbuf_reset): Flush, and return position offset. (fbuf_alloc): Simplify, don't flush, just realloc. (fbuf_flush): Make usable for read mode, salvage remaining bytes. (fbuf_seek): New whence argument. (fbuf_read): New function. (fbuf_getc_refill): New function. * io/file_pos.c (formatted_backspace): Use new stream interface. (unformatted_backspace): Likewise. (st_backspace): Make sure format buffer is reset, use new stream interface, use unit_truncate. (st_endfile): Likewise. (st_rewind): Likewise. * io/intrinsics.c: Use new stream interface. * io/list_read.c (push_char): Don't use u.p.scratch, use realloc to resize. (free_saved): Don't check u.p.scratch. (next_char): Use new stream interface, use fbuf_getc() for external files. (finish_list_read): flush format buffer. (nml_query): Update to use modified interface:s * io/open.c (test_endfile): Use new stream interface. (edit_modes): Likewise. (new_unit): Likewise, set bytes_left to 1 for stream files. * io/read.c (read_l): Use new read_block_form interface. (read_utf8): Likewise. (read_utf8_char1): Likewise. (read_default_char1): Likewise. (read_utf8_char4): Likewise. (read_default_char4): Likewise. (read_a): Likewise. (read_a_char4): Likewise. (read_decimal): Likewise. (read_radix): Likewise. (read_f): Likewise. * io/transfer.c (read_sf): Use fbuf_read and mem_alloc_r, remove usage of u.p.line_buffer. (read_block_form): Update interface to return pointer, use fbuf_read for direct access. (read_block_direct): Update to new stream interface. (write_block): Use mem_alloc_w for internal I/O. (write_buf): Update to new stream interface. (formatted_transfer_scalar): Don't use u.p.line_buffer, use fbuf_seek for external files. (us_read): Update to new stream interface. (us_write): Likewise. (data_transfer_init): Always check if we switch modes and flush. (skip_record): Use new stream interface, fix comparison. (next_record_r): Check for and reset u.p.at_eof, use new stream interface, use fbuf_getc for spacing. (write_us_marker): Update to new stream interface, don't inline. (next_record_w_unf): Likewise. (sset): New function. (next_record_w): Use new stream interface, use fbuf for printing newline. (next_record): Use new stream interface. (finalize_transfer): Remove sfree call, use new stream interface. (st_iolength_done): Don't use u.p.scratch. (st_read): Don't check for end of file. (st_read_done): Don't use u.p.scratch, use unit_truncate. (hit_eof): New function. * io/unit.c (init_units): Always init fbuf for formatted units. (update_position): Use new stream interface. (unit_truncate): New function. (finish_last_advance_record): Use fbuf to print newline. * io/unix.c: Remove unused SSIZE_MAX macro. (BUFFER_SIZE): Make static const variable rather than macro. (struct unix_stream): Remove dirty_offset, len, method, small_buffer. Order elements by decreasing size. (struct int_stream): Remove. (move_pos_offset): Remove usage of dirty_offset. (reset_stream): Remove. (do_read): Rename to raw_read, update to match new stream interface. (do_write): Rename to raw_write, update to new stream interface. (raw_seek): New function. (raw_tell): New function. (raw_truncate): New function. (raw_close): New function. (raw_flush): New function. (raw_init): New function. (fd_alloc): Remove. (fd_alloc_r_at): Remove. (fd_alloc_w_at): Remove. (fd_sfree): Remove. (fd_seek): Remove. (fd_truncate): Remove. (fd_sset): Remove. (fd_read): Remove. (fd_write): Remove. (fd_close): Remove. (fd_open): Remove. (fd_flush): Rename to buf_flush, update to new stream interface and unix_stream. (buf_read): New function. (buf_write): New function. (buf_seek): New function. (buf_tell): New function. (buf_truncate): New function. (buf_close): New function. (buf_init): New function. (mem_alloc_r_at): Rename to mem_alloc_r, change prototype. (mem_alloc_w_at): Rename to mem_alloc_w, change prototype. (mem_read): Change to match new stream interface. (mem_write): Likewise. (mem_seek): Likewise. (mem_tell): Likewise. (mem_truncate): Likewise. (mem_close): Likewise. (mem_flush): New function. (mem_sfree): Remove. (empty_internal_buffer): Cast to correct type. (open_internal): Use correct type, init function pointers. (fd_to_stream): Test whether to open file as buffered or raw. (output_stream): Remove mode set. (error_stream): Likewise. (flush_all_units_1): Use new stream interface. (flush_all_units): Likewise. (stream_at_bof): Remove. (stream_at_eof): Remove. (file_position): Remove. (file_length): Update logic to use stream interface. (flush): Remove. (stream_offset): Remove. * io/write.c (write_utf8_char4): Use int instead of size_t. (write_x): Extra safety check. (namelist_write_newline): Use new stream interface. From-SVN: r145571
2009-04-05 22:13:56 +02:00
/* Hash the format string. Super simple, but what the heck! */
key = dtp->format;
key_len = dtp->format_len;
for (i = 0; i < key_len; i++)
hash ^= key[i];
hash &= (FORMAT_HASH_SIZE - 1);
return hash;
}
static void
save_parsed_format (st_parameter_dt *dtp)
{
uint32_t hash;
gfc_unit *u;
hash = format_hash (dtp);
u = dtp->u.p.current_unit;
/* Index into the hash table. We are simply replacing whatever is there
relying on probability. */
if (u->format_hash_table[hash].hashed_fmt != NULL)
free_format_data (u->format_hash_table[hash].hashed_fmt);
u->format_hash_table[hash].hashed_fmt = NULL;
free (u->format_hash_table[hash].key);
u->format_hash_table[hash].key = dtp->format;
[multiple changes] 2009-04-05 Daniel Kraft <d@domob.eu> PR fortran/38654 * io/read.c (read_f): Reworked to speed up floating point parsing. (convert_real): Use pointer-casting instead of memcpy and temporaries. 2009-04-05 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR libfortran/37754 * io/io.h (format_hash_entry): New structure for hash table. (format_hash_table): The hash table itself. (free_format_data): Revise function prototype. (free_format_hash_table, init_format_hash, free_format_hash): New function prototypes. * io/unit.c (close_unit_1): Use free_format_hash_table. * io/transfer.c (st_read_done, st_write_done): Free format data if internal unit. * io/format.c (free_format_hash_table): New function that frees any memory allocated previously for cached format data. (reset_node): New static helper function to reset the format counters for a format node. (reset_fnode_counters): New static function recursively calls reset_node to traverse the fnode tree. (format_hash): New simple hash function based on XOR, probabalistic, tosses collisions. (save_parsed_format): New static function to save the parsed format data to use again. (find_parsed_format): New static function searches the hash table looking for a match. (free_format_data): Revised to accept pointer to format data rather than the dtp pointer so that the function can be used in more places. (format_lex): Editorial. (parse_format_list): Set flag used to determine of format data hashing is to be used. Internal units are not persistent enough for this. (revert): Move to ne location in file. (parse_format): Use new functions to look for previously parsed format strings and use them rather than re-parse. If not found, saves the parsed format data for later use. 2009-04-05 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR libfortran/37754 * io/transfer.c (formatted_transfer_scalar): Remove this function by factoring it into two new functions, one for read and one for write, eliminating all the conditionals for read or write mode. (formatted transfer_scalar_read): New function. (formatted transfer_scalar_write): New function. (formatted_transfer): Use new functions. 2009-04-05 Janne Blomqvist <jb@gcc.gnu.org> PR libfortran/25561 libfortran/37754 * io/io.h (struct stream): Define new stream interface function pointers, and inline functions for accessing it. (struct fbuf): Use int instead of size_t, remove flushed element. (mem_alloc_w): New prototype. (mem_alloc_r): New prototype. (stream_at_bof): Remove prototype. (stream_at_eof): Remove prototype. (file_position): Remove prototype. (flush): Remove prototype. (stream_offset): Remove prototype. (unit_truncate): New prototype. (read_block_form): Change to return pointer, int* argument. (hit_eof): New prototype. (fbuf_init): Change prototype. (fbuf_reset): Change prototype. (fbuf_alloc): Change prototype. (fbuf_flush): Change prototype. (fbuf_seek): Change prototype. (fbuf_read): New prototype. (fbuf_getc_refill): New prototype. (fbuf_getc): New inline function. * io/fbuf.c (fbuf_init): Use int, get rid of flushed. (fbuf_debug): New function. (fbuf_reset): Flush, and return position offset. (fbuf_alloc): Simplify, don't flush, just realloc. (fbuf_flush): Make usable for read mode, salvage remaining bytes. (fbuf_seek): New whence argument. (fbuf_read): New function. (fbuf_getc_refill): New function. * io/file_pos.c (formatted_backspace): Use new stream interface. (unformatted_backspace): Likewise. (st_backspace): Make sure format buffer is reset, use new stream interface, use unit_truncate. (st_endfile): Likewise. (st_rewind): Likewise. * io/intrinsics.c: Use new stream interface. * io/list_read.c (push_char): Don't use u.p.scratch, use realloc to resize. (free_saved): Don't check u.p.scratch. (next_char): Use new stream interface, use fbuf_getc() for external files. (finish_list_read): flush format buffer. (nml_query): Update to use modified interface:s * io/open.c (test_endfile): Use new stream interface. (edit_modes): Likewise. (new_unit): Likewise, set bytes_left to 1 for stream files. * io/read.c (read_l): Use new read_block_form interface. (read_utf8): Likewise. (read_utf8_char1): Likewise. (read_default_char1): Likewise. (read_utf8_char4): Likewise. (read_default_char4): Likewise. (read_a): Likewise. (read_a_char4): Likewise. (read_decimal): Likewise. (read_radix): Likewise. (read_f): Likewise. * io/transfer.c (read_sf): Use fbuf_read and mem_alloc_r, remove usage of u.p.line_buffer. (read_block_form): Update interface to return pointer, use fbuf_read for direct access. (read_block_direct): Update to new stream interface. (write_block): Use mem_alloc_w for internal I/O. (write_buf): Update to new stream interface. (formatted_transfer_scalar): Don't use u.p.line_buffer, use fbuf_seek for external files. (us_read): Update to new stream interface. (us_write): Likewise. (data_transfer_init): Always check if we switch modes and flush. (skip_record): Use new stream interface, fix comparison. (next_record_r): Check for and reset u.p.at_eof, use new stream interface, use fbuf_getc for spacing. (write_us_marker): Update to new stream interface, don't inline. (next_record_w_unf): Likewise. (sset): New function. (next_record_w): Use new stream interface, use fbuf for printing newline. (next_record): Use new stream interface. (finalize_transfer): Remove sfree call, use new stream interface. (st_iolength_done): Don't use u.p.scratch. (st_read): Don't check for end of file. (st_read_done): Don't use u.p.scratch, use unit_truncate. (hit_eof): New function. * io/unit.c (init_units): Always init fbuf for formatted units. (update_position): Use new stream interface. (unit_truncate): New function. (finish_last_advance_record): Use fbuf to print newline. * io/unix.c: Remove unused SSIZE_MAX macro. (BUFFER_SIZE): Make static const variable rather than macro. (struct unix_stream): Remove dirty_offset, len, method, small_buffer. Order elements by decreasing size. (struct int_stream): Remove. (move_pos_offset): Remove usage of dirty_offset. (reset_stream): Remove. (do_read): Rename to raw_read, update to match new stream interface. (do_write): Rename to raw_write, update to new stream interface. (raw_seek): New function. (raw_tell): New function. (raw_truncate): New function. (raw_close): New function. (raw_flush): New function. (raw_init): New function. (fd_alloc): Remove. (fd_alloc_r_at): Remove. (fd_alloc_w_at): Remove. (fd_sfree): Remove. (fd_seek): Remove. (fd_truncate): Remove. (fd_sset): Remove. (fd_read): Remove. (fd_write): Remove. (fd_close): Remove. (fd_open): Remove. (fd_flush): Rename to buf_flush, update to new stream interface and unix_stream. (buf_read): New function. (buf_write): New function. (buf_seek): New function. (buf_tell): New function. (buf_truncate): New function. (buf_close): New function. (buf_init): New function. (mem_alloc_r_at): Rename to mem_alloc_r, change prototype. (mem_alloc_w_at): Rename to mem_alloc_w, change prototype. (mem_read): Change to match new stream interface. (mem_write): Likewise. (mem_seek): Likewise. (mem_tell): Likewise. (mem_truncate): Likewise. (mem_close): Likewise. (mem_flush): New function. (mem_sfree): Remove. (empty_internal_buffer): Cast to correct type. (open_internal): Use correct type, init function pointers. (fd_to_stream): Test whether to open file as buffered or raw. (output_stream): Remove mode set. (error_stream): Likewise. (flush_all_units_1): Use new stream interface. (flush_all_units): Likewise. (stream_at_bof): Remove. (stream_at_eof): Remove. (file_position): Remove. (file_length): Update logic to use stream interface. (flush): Remove. (stream_offset): Remove. * io/write.c (write_utf8_char4): Use int instead of size_t. (write_x): Extra safety check. (namelist_write_newline): Use new stream interface. From-SVN: r145571
2009-04-05 22:13:56 +02:00
u->format_hash_table[hash].key_len = dtp->format_len;
u->format_hash_table[hash].hashed_fmt = dtp->u.p.fmt;
}
static format_data *
find_parsed_format (st_parameter_dt *dtp)
{
uint32_t hash;
gfc_unit *u;
hash = format_hash (dtp);
u = dtp->u.p.current_unit;
if (u->format_hash_table[hash].key != NULL)
{
/* See if it matches. */
if (u->format_hash_table[hash].key_len == dtp->format_len)
{
/* So far so good. */
if (strncmp (u->format_hash_table[hash].key,
dtp->format, dtp->format_len) == 0)
return u->format_hash_table[hash].hashed_fmt;
}
}
return NULL;
}
/* next_char()-- Return the next character in the format string.
Returns -1 when the string is done. If the literal flag is set,
spaces are significant, otherwise they are not. */
static int
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
next_char (format_data *fmt, int literal)
{
int c;
do
{
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
if (fmt->format_string_len == 0)
return -1;
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
fmt->format_string_len--;
[multiple changes] 2009-04-05 Daniel Kraft <d@domob.eu> PR fortran/38654 * io/read.c (read_f): Reworked to speed up floating point parsing. (convert_real): Use pointer-casting instead of memcpy and temporaries. 2009-04-05 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR libfortran/37754 * io/io.h (format_hash_entry): New structure for hash table. (format_hash_table): The hash table itself. (free_format_data): Revise function prototype. (free_format_hash_table, init_format_hash, free_format_hash): New function prototypes. * io/unit.c (close_unit_1): Use free_format_hash_table. * io/transfer.c (st_read_done, st_write_done): Free format data if internal unit. * io/format.c (free_format_hash_table): New function that frees any memory allocated previously for cached format data. (reset_node): New static helper function to reset the format counters for a format node. (reset_fnode_counters): New static function recursively calls reset_node to traverse the fnode tree. (format_hash): New simple hash function based on XOR, probabalistic, tosses collisions. (save_parsed_format): New static function to save the parsed format data to use again. (find_parsed_format): New static function searches the hash table looking for a match. (free_format_data): Revised to accept pointer to format data rather than the dtp pointer so that the function can be used in more places. (format_lex): Editorial. (parse_format_list): Set flag used to determine of format data hashing is to be used. Internal units are not persistent enough for this. (revert): Move to ne location in file. (parse_format): Use new functions to look for previously parsed format strings and use them rather than re-parse. If not found, saves the parsed format data for later use. 2009-04-05 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR libfortran/37754 * io/transfer.c (formatted_transfer_scalar): Remove this function by factoring it into two new functions, one for read and one for write, eliminating all the conditionals for read or write mode. (formatted transfer_scalar_read): New function. (formatted transfer_scalar_write): New function. (formatted_transfer): Use new functions. 2009-04-05 Janne Blomqvist <jb@gcc.gnu.org> PR libfortran/25561 libfortran/37754 * io/io.h (struct stream): Define new stream interface function pointers, and inline functions for accessing it. (struct fbuf): Use int instead of size_t, remove flushed element. (mem_alloc_w): New prototype. (mem_alloc_r): New prototype. (stream_at_bof): Remove prototype. (stream_at_eof): Remove prototype. (file_position): Remove prototype. (flush): Remove prototype. (stream_offset): Remove prototype. (unit_truncate): New prototype. (read_block_form): Change to return pointer, int* argument. (hit_eof): New prototype. (fbuf_init): Change prototype. (fbuf_reset): Change prototype. (fbuf_alloc): Change prototype. (fbuf_flush): Change prototype. (fbuf_seek): Change prototype. (fbuf_read): New prototype. (fbuf_getc_refill): New prototype. (fbuf_getc): New inline function. * io/fbuf.c (fbuf_init): Use int, get rid of flushed. (fbuf_debug): New function. (fbuf_reset): Flush, and return position offset. (fbuf_alloc): Simplify, don't flush, just realloc. (fbuf_flush): Make usable for read mode, salvage remaining bytes. (fbuf_seek): New whence argument. (fbuf_read): New function. (fbuf_getc_refill): New function. * io/file_pos.c (formatted_backspace): Use new stream interface. (unformatted_backspace): Likewise. (st_backspace): Make sure format buffer is reset, use new stream interface, use unit_truncate. (st_endfile): Likewise. (st_rewind): Likewise. * io/intrinsics.c: Use new stream interface. * io/list_read.c (push_char): Don't use u.p.scratch, use realloc to resize. (free_saved): Don't check u.p.scratch. (next_char): Use new stream interface, use fbuf_getc() for external files. (finish_list_read): flush format buffer. (nml_query): Update to use modified interface:s * io/open.c (test_endfile): Use new stream interface. (edit_modes): Likewise. (new_unit): Likewise, set bytes_left to 1 for stream files. * io/read.c (read_l): Use new read_block_form interface. (read_utf8): Likewise. (read_utf8_char1): Likewise. (read_default_char1): Likewise. (read_utf8_char4): Likewise. (read_default_char4): Likewise. (read_a): Likewise. (read_a_char4): Likewise. (read_decimal): Likewise. (read_radix): Likewise. (read_f): Likewise. * io/transfer.c (read_sf): Use fbuf_read and mem_alloc_r, remove usage of u.p.line_buffer. (read_block_form): Update interface to return pointer, use fbuf_read for direct access. (read_block_direct): Update to new stream interface. (write_block): Use mem_alloc_w for internal I/O. (write_buf): Update to new stream interface. (formatted_transfer_scalar): Don't use u.p.line_buffer, use fbuf_seek for external files. (us_read): Update to new stream interface. (us_write): Likewise. (data_transfer_init): Always check if we switch modes and flush. (skip_record): Use new stream interface, fix comparison. (next_record_r): Check for and reset u.p.at_eof, use new stream interface, use fbuf_getc for spacing. (write_us_marker): Update to new stream interface, don't inline. (next_record_w_unf): Likewise. (sset): New function. (next_record_w): Use new stream interface, use fbuf for printing newline. (next_record): Use new stream interface. (finalize_transfer): Remove sfree call, use new stream interface. (st_iolength_done): Don't use u.p.scratch. (st_read): Don't check for end of file. (st_read_done): Don't use u.p.scratch, use unit_truncate. (hit_eof): New function. * io/unit.c (init_units): Always init fbuf for formatted units. (update_position): Use new stream interface. (unit_truncate): New function. (finish_last_advance_record): Use fbuf to print newline. * io/unix.c: Remove unused SSIZE_MAX macro. (BUFFER_SIZE): Make static const variable rather than macro. (struct unix_stream): Remove dirty_offset, len, method, small_buffer. Order elements by decreasing size. (struct int_stream): Remove. (move_pos_offset): Remove usage of dirty_offset. (reset_stream): Remove. (do_read): Rename to raw_read, update to match new stream interface. (do_write): Rename to raw_write, update to new stream interface. (raw_seek): New function. (raw_tell): New function. (raw_truncate): New function. (raw_close): New function. (raw_flush): New function. (raw_init): New function. (fd_alloc): Remove. (fd_alloc_r_at): Remove. (fd_alloc_w_at): Remove. (fd_sfree): Remove. (fd_seek): Remove. (fd_truncate): Remove. (fd_sset): Remove. (fd_read): Remove. (fd_write): Remove. (fd_close): Remove. (fd_open): Remove. (fd_flush): Rename to buf_flush, update to new stream interface and unix_stream. (buf_read): New function. (buf_write): New function. (buf_seek): New function. (buf_tell): New function. (buf_truncate): New function. (buf_close): New function. (buf_init): New function. (mem_alloc_r_at): Rename to mem_alloc_r, change prototype. (mem_alloc_w_at): Rename to mem_alloc_w, change prototype. (mem_read): Change to match new stream interface. (mem_write): Likewise. (mem_seek): Likewise. (mem_tell): Likewise. (mem_truncate): Likewise. (mem_close): Likewise. (mem_flush): New function. (mem_sfree): Remove. (empty_internal_buffer): Cast to correct type. (open_internal): Use correct type, init function pointers. (fd_to_stream): Test whether to open file as buffered or raw. (output_stream): Remove mode set. (error_stream): Likewise. (flush_all_units_1): Use new stream interface. (flush_all_units): Likewise. (stream_at_bof): Remove. (stream_at_eof): Remove. (file_position): Remove. (file_length): Update logic to use stream interface. (flush): Remove. (stream_offset): Remove. * io/write.c (write_utf8_char4): Use int instead of size_t. (write_x): Extra safety check. (namelist_write_newline): Use new stream interface. From-SVN: r145571
2009-04-05 22:13:56 +02:00
c = toupper (*fmt->format_string++);
fmt->error_element = c;
}
while ((c == ' ' || c == '\t') && !literal);
return c;
}
/* unget_char()-- Back up one character position. */
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
#define unget_char(fmt) \
{ fmt->format_string--; fmt->format_string_len++; }
/* get_fnode()-- Allocate a new format node, inserting it into the
current singly linked list. These are initially allocated from the
static buffer. */
static fnode *
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
get_fnode (format_data *fmt, fnode **head, fnode **tail, format_token t)
{
fnode *f;
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
if (fmt->avail == &fmt->last->array[FARRAY_SIZE])
{
Combined get_mem and internal_malloc_size. 2012-03-26 Janne Blomqvist <jb@gcc.gnu.org> * runtime/memory.c (get_mem): Rename to xmalloc, check for zero size. (internal_malloc_size): Remove. * libgfortran.h (get_mem): Rename to xmalloc. (internal_malloc_size): Remove prototype. * Makefile.am (i_iall_c): Fix dependency. (i_iany_c): Likewise. (i_iparity_c): Likewise. (i_norm2_c): Likewise. (i_parity_c): Likewise. * Makefile.in: Regenerated. * m4/parity.m4: Fix typo in comment. * generated/all_l1.c: Regenerated. * generated/all_l16.c: Regenerated. * generated/all_l2.c: Regenerated. * generated/all_l4.c: Regenerated. * generated/all_l8.c: Regenerated. * generated/any_l1.c: Regenerated. * generated/any_l16.c: Regenerated. * generated/any_l2.c: Regenerated. * generated/any_l4.c: Regenerated. * generated/any_l8.c: Regenerated. * generated/bessel_r10.c: Regenerated. * generated/bessel_r16.c: Regenerated. * generated/bessel_r4.c: Regenerated. * generated/bessel_r8.c: Regenerated. * generated/count_16_l.c: Regenerated. * generated/count_1_l.c: Regenerated. * generated/count_2_l.c: Regenerated. * generated/count_4_l.c: Regenerated. * generated/count_8_l.c: Regenerated. * generated/cshift1_16.c: Regenerated. * generated/cshift1_4.c: Regenerated. * generated/cshift1_8.c: Regenerated. * generated/eoshift1_16.c: Regenerated. * generated/eoshift1_4.c: Regenerated. * generated/eoshift1_8.c: Regenerated. * generated/eoshift3_16.c: Regenerated. * generated/eoshift3_4.c: Regenerated. * generated/eoshift3_8.c: Regenerated. * generated/iall_i1.c: Regenerated. * generated/iall_i16.c: Regenerated. * generated/iall_i2.c: Regenerated. * generated/iall_i4.c: Regenerated. * generated/iall_i8.c: Regenerated. * generated/iany_i1.c: Regenerated. * generated/iany_i16.c: Regenerated. * generated/iany_i2.c: Regenerated. * generated/iany_i4.c: Regenerated. * generated/iany_i8.c: Regenerated. * generated/in_pack_c10.c: Regenerated. * generated/in_pack_c16.c: Regenerated. * generated/in_pack_c4.c: Regenerated. * generated/in_pack_c8.c: Regenerated. * generated/in_pack_i1.c: Regenerated. * generated/in_pack_i16.c: Regenerated. * generated/in_pack_i2.c: Regenerated. * generated/in_pack_i4.c: Regenerated. * generated/in_pack_i8.c: Regenerated. * generated/in_pack_r10.c: Regenerated. * generated/in_pack_r16.c: Regenerated. * generated/in_pack_r4.c: Regenerated. * generated/in_pack_r8.c: Regenerated. * generated/iparity_i1.c: Regenerated. * generated/iparity_i16.c: Regenerated. * generated/iparity_i2.c: Regenerated. * generated/iparity_i4.c: Regenerated. * generated/iparity_i8.c: Regenerated. * generated/matmul_c10.c: Regenerated. * generated/matmul_c16.c: Regenerated. * generated/matmul_c4.c: Regenerated. * generated/matmul_c8.c: Regenerated. * generated/matmul_i1.c: Regenerated. * generated/matmul_i16.c: Regenerated. * generated/matmul_i2.c: Regenerated. * generated/matmul_i4.c: Regenerated. * generated/matmul_i8.c: Regenerated. * generated/matmul_l16.c: Regenerated. * generated/matmul_l4.c: Regenerated. * generated/matmul_l8.c: Regenerated. * generated/matmul_r10.c: Regenerated. * generated/matmul_r16.c: Regenerated. * generated/matmul_r4.c: Regenerated. * generated/matmul_r8.c: Regenerated. * generated/maxloc0_16_i1.c: Regenerated. * generated/maxloc0_16_i16.c: Regenerated. * generated/maxloc0_16_i2.c: Regenerated. * generated/maxloc0_16_i4.c: Regenerated. * generated/maxloc0_16_i8.c: Regenerated. * generated/maxloc0_16_r10.c: Regenerated. * generated/maxloc0_16_r16.c: Regenerated. * generated/maxloc0_16_r4.c: Regenerated. * generated/maxloc0_16_r8.c: Regenerated. * generated/maxloc0_4_i1.c: Regenerated. * generated/maxloc0_4_i16.c: Regenerated. * generated/maxloc0_4_i2.c: Regenerated. * generated/maxloc0_4_i4.c: Regenerated. * generated/maxloc0_4_i8.c: Regenerated. * generated/maxloc0_4_r10.c: Regenerated. * generated/maxloc0_4_r16.c: Regenerated. * generated/maxloc0_4_r4.c: Regenerated. * generated/maxloc0_4_r8.c: Regenerated. * generated/maxloc0_8_i1.c: Regenerated. * generated/maxloc0_8_i16.c: Regenerated. * generated/maxloc0_8_i2.c: Regenerated. * generated/maxloc0_8_i4.c: Regenerated. * generated/maxloc0_8_i8.c: Regenerated. * generated/maxloc0_8_r10.c: Regenerated. * generated/maxloc0_8_r16.c: Regenerated. * generated/maxloc0_8_r4.c: Regenerated. * generated/maxloc0_8_r8.c: Regenerated. * generated/maxloc1_16_i1.c: Regenerated. * generated/maxloc1_16_i16.c: Regenerated. * generated/maxloc1_16_i2.c: Regenerated. * generated/maxloc1_16_i4.c: Regenerated. * generated/maxloc1_16_i8.c: Regenerated. * generated/maxloc1_16_r10.c: Regenerated. * generated/maxloc1_16_r16.c: Regenerated. * generated/maxloc1_16_r4.c: Regenerated. * generated/maxloc1_16_r8.c: Regenerated. * generated/maxloc1_4_i1.c: Regenerated. * generated/maxloc1_4_i16.c: Regenerated. * generated/maxloc1_4_i2.c: Regenerated. * generated/maxloc1_4_i4.c: Regenerated. * generated/maxloc1_4_i8.c: Regenerated. * generated/maxloc1_4_r10.c: Regenerated. * generated/maxloc1_4_r16.c: Regenerated. * generated/maxloc1_4_r4.c: Regenerated. * generated/maxloc1_4_r8.c: Regenerated. * generated/maxloc1_8_i1.c: Regenerated. * generated/maxloc1_8_i16.c: Regenerated. * generated/maxloc1_8_i2.c: Regenerated. * generated/maxloc1_8_i4.c: Regenerated. * generated/maxloc1_8_i8.c: Regenerated. * generated/maxloc1_8_r10.c: Regenerated. * generated/maxloc1_8_r16.c: Regenerated. * generated/maxloc1_8_r4.c: Regenerated. * generated/maxloc1_8_r8.c: Regenerated. * generated/maxval_i1.c: Regenerated. * generated/maxval_i16.c: Regenerated. * generated/maxval_i2.c: Regenerated. * generated/maxval_i4.c: Regenerated. * generated/maxval_i8.c: Regenerated. * generated/maxval_r10.c: Regenerated. * generated/maxval_r16.c: Regenerated. * generated/maxval_r4.c: Regenerated. * generated/maxval_r8.c: Regenerated. * generated/minloc0_16_i1.c: Regenerated. * generated/minloc0_16_i16.c: Regenerated. * generated/minloc0_16_i2.c: Regenerated. * generated/minloc0_16_i4.c: Regenerated. * generated/minloc0_16_i8.c: Regenerated. * generated/minloc0_16_r10.c: Regenerated. * generated/minloc0_16_r16.c: Regenerated. * generated/minloc0_16_r4.c: Regenerated. * generated/minloc0_16_r8.c: Regenerated. * generated/minloc0_4_i1.c: Regenerated. * generated/minloc0_4_i16.c: Regenerated. * generated/minloc0_4_i2.c: Regenerated. * generated/minloc0_4_i4.c: Regenerated. * generated/minloc0_4_i8.c: Regenerated. * generated/minloc0_4_r10.c: Regenerated. * generated/minloc0_4_r16.c: Regenerated. * generated/minloc0_4_r4.c: Regenerated. * generated/minloc0_4_r8.c: Regenerated. * generated/minloc0_8_i1.c: Regenerated. * generated/minloc0_8_i16.c: Regenerated. * generated/minloc0_8_i2.c: Regenerated. * generated/minloc0_8_i4.c: Regenerated. * generated/minloc0_8_i8.c: Regenerated. * generated/minloc0_8_r10.c: Regenerated. * generated/minloc0_8_r16.c: Regenerated. * generated/minloc0_8_r4.c: Regenerated. * generated/minloc0_8_r8.c: Regenerated. * generated/minloc1_16_i1.c: Regenerated. * generated/minloc1_16_i16.c: Regenerated. * generated/minloc1_16_i2.c: Regenerated. * generated/minloc1_16_i4.c: Regenerated. * generated/minloc1_16_i8.c: Regenerated. * generated/minloc1_16_r10.c: Regenerated. * generated/minloc1_16_r16.c: Regenerated. * generated/minloc1_16_r4.c: Regenerated. * generated/minloc1_16_r8.c: Regenerated. * generated/minloc1_4_i1.c: Regenerated. * generated/minloc1_4_i16.c: Regenerated. * generated/minloc1_4_i2.c: Regenerated. * generated/minloc1_4_i4.c: Regenerated. * generated/minloc1_4_i8.c: Regenerated. * generated/minloc1_4_r10.c: Regenerated. * generated/minloc1_4_r16.c: Regenerated. * generated/minloc1_4_r4.c: Regenerated. * generated/minloc1_4_r8.c: Regenerated. * generated/minloc1_8_i1.c: Regenerated. * generated/minloc1_8_i16.c: Regenerated. * generated/minloc1_8_i2.c: Regenerated. * generated/minloc1_8_i4.c: Regenerated. * generated/minloc1_8_i8.c: Regenerated. * generated/minloc1_8_r10.c: Regenerated. * generated/minloc1_8_r16.c: Regenerated. * generated/minloc1_8_r4.c: Regenerated. * generated/minloc1_8_r8.c: Regenerated. * generated/minval_i1.c: Regenerated. * generated/minval_i16.c: Regenerated. * generated/minval_i2.c: Regenerated. * generated/minval_i4.c: Regenerated. * generated/minval_i8.c: Regenerated. * generated/minval_r10.c: Regenerated. * generated/minval_r16.c: Regenerated. * generated/minval_r4.c: Regenerated. * generated/minval_r8.c: Regenerated. * generated/norm2_r10.c: Regenerated. * generated/norm2_r16.c: Regenerated. * generated/norm2_r4.c: Regenerated. * generated/norm2_r8.c: Regenerated. * generated/pack_c10.c: Regenerated. * generated/pack_c16.c: Regenerated. * generated/pack_c4.c: Regenerated. * generated/pack_c8.c: Regenerated. * generated/pack_i1.c: Regenerated. * generated/pack_i16.c: Regenerated. * generated/pack_i2.c: Regenerated. * generated/pack_i4.c: Regenerated. * generated/pack_i8.c: Regenerated. * generated/pack_r10.c: Regenerated. * generated/pack_r16.c: Regenerated. * generated/pack_r4.c: Regenerated. * generated/pack_r8.c: Regenerated. * generated/parity_l1.c: Regenerated. * generated/parity_l16.c: Regenerated. * generated/parity_l2.c: Regenerated. * generated/parity_l4.c: Regenerated. * generated/parity_l8.c: Regenerated. * generated/product_c10.c: Regenerated. * generated/product_c16.c: Regenerated. * generated/product_c4.c: Regenerated. * generated/product_c8.c: Regenerated. * generated/product_i1.c: Regenerated. * generated/product_i16.c: Regenerated. * generated/product_i2.c: Regenerated. * generated/product_i4.c: Regenerated. * generated/product_i8.c: Regenerated. * generated/product_r10.c: Regenerated. * generated/product_r16.c: Regenerated. * generated/product_r4.c: Regenerated. * generated/product_r8.c: Regenerated. * generated/reshape_c10.c: Regenerated. * generated/reshape_c16.c: Regenerated. * generated/reshape_c4.c: Regenerated. * generated/reshape_c8.c: Regenerated. * generated/reshape_i16.c: Regenerated. * generated/reshape_i4.c: Regenerated. * generated/reshape_i8.c: Regenerated. * generated/reshape_r10.c: Regenerated. * generated/reshape_r16.c: Regenerated. * generated/reshape_r4.c: Regenerated. * generated/reshape_r8.c: Regenerated. * generated/shape_i16.c: Regenerated. * generated/shape_i4.c: Regenerated. * generated/shape_i8.c: Regenerated. * generated/spread_c10.c: Regenerated. * generated/spread_c16.c: Regenerated. * generated/spread_c4.c: Regenerated. * generated/spread_c8.c: Regenerated. * generated/spread_i1.c: Regenerated. * generated/spread_i16.c: Regenerated. * generated/spread_i2.c: Regenerated. * generated/spread_i4.c: Regenerated. * generated/spread_i8.c: Regenerated. * generated/spread_r10.c: Regenerated. * generated/spread_r16.c: Regenerated. * generated/spread_r4.c: Regenerated. * generated/spread_r8.c: Regenerated. * generated/sum_c10.c: Regenerated. * generated/sum_c16.c: Regenerated. * generated/sum_c4.c: Regenerated. * generated/sum_c8.c: Regenerated. * generated/sum_i1.c: Regenerated. * generated/sum_i16.c: Regenerated. * generated/sum_i2.c: Regenerated. * generated/sum_i4.c: Regenerated. * generated/sum_i8.c: Regenerated. * generated/sum_r10.c: Regenerated. * generated/sum_r16.c: Regenerated. * generated/sum_r4.c: Regenerated. * generated/sum_r8.c: Regenerated. * generated/transpose_c10.c: Regenerated. * generated/transpose_c16.c: Regenerated. * generated/transpose_c4.c: Regenerated. * generated/transpose_c8.c: Regenerated. * generated/transpose_i16.c: Regenerated. * generated/transpose_i4.c: Regenerated. * generated/transpose_i8.c: Regenerated. * generated/transpose_r10.c: Regenerated. * generated/transpose_r16.c: Regenerated. * generated/transpose_r4.c: Regenerated. * generated/transpose_r8.c: Regenerated. * generated/unpack_c10.c: Regenerated. * generated/unpack_c16.c: Regenerated. * generated/unpack_c4.c: Regenerated. * generated/unpack_c8.c: Regenerated. * generated/unpack_i1.c: Regenerated. * generated/unpack_i16.c: Regenerated. * generated/unpack_i2.c: Regenerated. * generated/unpack_i4.c: Regenerated. * generated/unpack_i8.c: Regenerated. * generated/unpack_r10.c: Regenerated. * generated/unpack_r16.c: Regenerated. * generated/unpack_r4.c: Regenerated. * generated/unpack_r8.c: Regenerated. * intrinsics/cshift0.c: Use xmalloc. * intrinsics/ctime.c: Likewise. * intrinsics/date_and_time.c: Likewise. * intrinsics/eoshift0.c: Likewise. * intrinsics/eoshift2.c: Likewise. * intrinsics/getlog.c: Likewise. * intrinsics/pack_generic.c: Likewise. * intrinsics/reshape_generic.c: Likewise. * intrinsics/spread_generic.c: Likewise. * intrinsics/string_intrinsics_inc.c: Likewise. * intrinsics/transpose_generic.c: Likewise. * intrinsics/unpack_generic.c: Likewise. * io/fbuf.c: Likewise. * io/format.c: Likewise. * io/intrinsics.c: Likewise. * io/list_read.c: Likewise. * io/open.c: Likewise. * io/transfer.c: Likewise. * io/unit.c: Likewise. * io/unix.c: Likewise. * io/write.c: Likewise. * m4/bessel.m4: Likewise. * m4/cshift1.m4: Likewise. * m4/eoshift1.m4: Likewise. * m4/eoshift3.m4: Likewise. * m4/iforeach.m4: Likewise. * m4/ifunction.m4: Likewise. * m4/ifunction_logical.m4: Likewise. * m4/in_pack.m4: Likewise. * m4/matmul.m4: Likewise. * m4/matmull.m4: Likewise. * m4/pack.m4: Likewise. * m4/reshape.m4: Likewise. * m4/shape.m4: Likewise. * m4/spread.m4: Likewise. * m4/transpose.m4: Likewise. * m4/unpack.m4: Likewise. * runtime/convert_char.c: Likewise. * runtime/environ.c: Likewise. * runtime/in_pack_generic.c: Likewise. From-SVN: r185806
2012-03-26 17:16:05 +02:00
fmt->last->next = xmalloc (sizeof (fnode_array));
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
fmt->last = fmt->last->next;
fmt->last->next = NULL;
fmt->avail = &fmt->last->array[0];
}
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
f = fmt->avail++;
memset (f, '\0', sizeof (fnode));
if (*head == NULL)
*head = *tail = f;
else
{
(*tail)->next = f;
*tail = f;
}
f->format = t;
f->repeat = -1;
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
f->source = fmt->format_string;
return f;
}
/* free_format()-- Free allocated format string. */
void
free_format (st_parameter_dt *dtp)
{
if ((dtp->common.flags & IOPARM_DT_HAS_FORMAT) && dtp->format)
{
free (dtp->format);
dtp->format = NULL;
}
}
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
/* free_format_data()-- Free all allocated format data. */
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
void
[multiple changes] 2009-04-05 Daniel Kraft <d@domob.eu> PR fortran/38654 * io/read.c (read_f): Reworked to speed up floating point parsing. (convert_real): Use pointer-casting instead of memcpy and temporaries. 2009-04-05 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR libfortran/37754 * io/io.h (format_hash_entry): New structure for hash table. (format_hash_table): The hash table itself. (free_format_data): Revise function prototype. (free_format_hash_table, init_format_hash, free_format_hash): New function prototypes. * io/unit.c (close_unit_1): Use free_format_hash_table. * io/transfer.c (st_read_done, st_write_done): Free format data if internal unit. * io/format.c (free_format_hash_table): New function that frees any memory allocated previously for cached format data. (reset_node): New static helper function to reset the format counters for a format node. (reset_fnode_counters): New static function recursively calls reset_node to traverse the fnode tree. (format_hash): New simple hash function based on XOR, probabalistic, tosses collisions. (save_parsed_format): New static function to save the parsed format data to use again. (find_parsed_format): New static function searches the hash table looking for a match. (free_format_data): Revised to accept pointer to format data rather than the dtp pointer so that the function can be used in more places. (format_lex): Editorial. (parse_format_list): Set flag used to determine of format data hashing is to be used. Internal units are not persistent enough for this. (revert): Move to ne location in file. (parse_format): Use new functions to look for previously parsed format strings and use them rather than re-parse. If not found, saves the parsed format data for later use. 2009-04-05 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR libfortran/37754 * io/transfer.c (formatted_transfer_scalar): Remove this function by factoring it into two new functions, one for read and one for write, eliminating all the conditionals for read or write mode. (formatted transfer_scalar_read): New function. (formatted transfer_scalar_write): New function. (formatted_transfer): Use new functions. 2009-04-05 Janne Blomqvist <jb@gcc.gnu.org> PR libfortran/25561 libfortran/37754 * io/io.h (struct stream): Define new stream interface function pointers, and inline functions for accessing it. (struct fbuf): Use int instead of size_t, remove flushed element. (mem_alloc_w): New prototype. (mem_alloc_r): New prototype. (stream_at_bof): Remove prototype. (stream_at_eof): Remove prototype. (file_position): Remove prototype. (flush): Remove prototype. (stream_offset): Remove prototype. (unit_truncate): New prototype. (read_block_form): Change to return pointer, int* argument. (hit_eof): New prototype. (fbuf_init): Change prototype. (fbuf_reset): Change prototype. (fbuf_alloc): Change prototype. (fbuf_flush): Change prototype. (fbuf_seek): Change prototype. (fbuf_read): New prototype. (fbuf_getc_refill): New prototype. (fbuf_getc): New inline function. * io/fbuf.c (fbuf_init): Use int, get rid of flushed. (fbuf_debug): New function. (fbuf_reset): Flush, and return position offset. (fbuf_alloc): Simplify, don't flush, just realloc. (fbuf_flush): Make usable for read mode, salvage remaining bytes. (fbuf_seek): New whence argument. (fbuf_read): New function. (fbuf_getc_refill): New function. * io/file_pos.c (formatted_backspace): Use new stream interface. (unformatted_backspace): Likewise. (st_backspace): Make sure format buffer is reset, use new stream interface, use unit_truncate. (st_endfile): Likewise. (st_rewind): Likewise. * io/intrinsics.c: Use new stream interface. * io/list_read.c (push_char): Don't use u.p.scratch, use realloc to resize. (free_saved): Don't check u.p.scratch. (next_char): Use new stream interface, use fbuf_getc() for external files. (finish_list_read): flush format buffer. (nml_query): Update to use modified interface:s * io/open.c (test_endfile): Use new stream interface. (edit_modes): Likewise. (new_unit): Likewise, set bytes_left to 1 for stream files. * io/read.c (read_l): Use new read_block_form interface. (read_utf8): Likewise. (read_utf8_char1): Likewise. (read_default_char1): Likewise. (read_utf8_char4): Likewise. (read_default_char4): Likewise. (read_a): Likewise. (read_a_char4): Likewise. (read_decimal): Likewise. (read_radix): Likewise. (read_f): Likewise. * io/transfer.c (read_sf): Use fbuf_read and mem_alloc_r, remove usage of u.p.line_buffer. (read_block_form): Update interface to return pointer, use fbuf_read for direct access. (read_block_direct): Update to new stream interface. (write_block): Use mem_alloc_w for internal I/O. (write_buf): Update to new stream interface. (formatted_transfer_scalar): Don't use u.p.line_buffer, use fbuf_seek for external files. (us_read): Update to new stream interface. (us_write): Likewise. (data_transfer_init): Always check if we switch modes and flush. (skip_record): Use new stream interface, fix comparison. (next_record_r): Check for and reset u.p.at_eof, use new stream interface, use fbuf_getc for spacing. (write_us_marker): Update to new stream interface, don't inline. (next_record_w_unf): Likewise. (sset): New function. (next_record_w): Use new stream interface, use fbuf for printing newline. (next_record): Use new stream interface. (finalize_transfer): Remove sfree call, use new stream interface. (st_iolength_done): Don't use u.p.scratch. (st_read): Don't check for end of file. (st_read_done): Don't use u.p.scratch, use unit_truncate. (hit_eof): New function. * io/unit.c (init_units): Always init fbuf for formatted units. (update_position): Use new stream interface. (unit_truncate): New function. (finish_last_advance_record): Use fbuf to print newline. * io/unix.c: Remove unused SSIZE_MAX macro. (BUFFER_SIZE): Make static const variable rather than macro. (struct unix_stream): Remove dirty_offset, len, method, small_buffer. Order elements by decreasing size. (struct int_stream): Remove. (move_pos_offset): Remove usage of dirty_offset. (reset_stream): Remove. (do_read): Rename to raw_read, update to match new stream interface. (do_write): Rename to raw_write, update to new stream interface. (raw_seek): New function. (raw_tell): New function. (raw_truncate): New function. (raw_close): New function. (raw_flush): New function. (raw_init): New function. (fd_alloc): Remove. (fd_alloc_r_at): Remove. (fd_alloc_w_at): Remove. (fd_sfree): Remove. (fd_seek): Remove. (fd_truncate): Remove. (fd_sset): Remove. (fd_read): Remove. (fd_write): Remove. (fd_close): Remove. (fd_open): Remove. (fd_flush): Rename to buf_flush, update to new stream interface and unix_stream. (buf_read): New function. (buf_write): New function. (buf_seek): New function. (buf_tell): New function. (buf_truncate): New function. (buf_close): New function. (buf_init): New function. (mem_alloc_r_at): Rename to mem_alloc_r, change prototype. (mem_alloc_w_at): Rename to mem_alloc_w, change prototype. (mem_read): Change to match new stream interface. (mem_write): Likewise. (mem_seek): Likewise. (mem_tell): Likewise. (mem_truncate): Likewise. (mem_close): Likewise. (mem_flush): New function. (mem_sfree): Remove. (empty_internal_buffer): Cast to correct type. (open_internal): Use correct type, init function pointers. (fd_to_stream): Test whether to open file as buffered or raw. (output_stream): Remove mode set. (error_stream): Likewise. (flush_all_units_1): Use new stream interface. (flush_all_units): Likewise. (stream_at_bof): Remove. (stream_at_eof): Remove. (file_position): Remove. (file_length): Update logic to use stream interface. (flush): Remove. (stream_offset): Remove. * io/write.c (write_utf8_char4): Use int instead of size_t. (write_x): Extra safety check. (namelist_write_newline): Use new stream interface. From-SVN: r145571
2009-04-05 22:13:56 +02:00
free_format_data (format_data *fmt)
{
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
fnode_array *fa, *fa_next;
[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 07:36:22 +02:00
fnode *fnp;
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
if (fmt == NULL)
return;
[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 07:36:22 +02:00
/* Free vlist descriptors in the fnode_array if one was allocated. */
for (fnp = fmt->array.array; fnp < &fmt->array.array[FARRAY_SIZE] &&
fnp->format != FMT_NONE; fnp++)
[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 07:36:22 +02:00
if (fnp->format == FMT_DT)
{
if (GFC_DESCRIPTOR_DATA(fnp->u.udf.vlist))
free (GFC_DESCRIPTOR_DATA(fnp->u.udf.vlist));
free (fnp->u.udf.vlist);
}
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
for (fa = fmt->array.next; fa; fa = fa_next)
{
fa_next = fa->next;
2010-05-07 17:55:59 +02:00
free (fa);
}
2010-05-07 17:55:59 +02:00
free (fmt);
[multiple changes] 2009-04-05 Daniel Kraft <d@domob.eu> PR fortran/38654 * io/read.c (read_f): Reworked to speed up floating point parsing. (convert_real): Use pointer-casting instead of memcpy and temporaries. 2009-04-05 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR libfortran/37754 * io/io.h (format_hash_entry): New structure for hash table. (format_hash_table): The hash table itself. (free_format_data): Revise function prototype. (free_format_hash_table, init_format_hash, free_format_hash): New function prototypes. * io/unit.c (close_unit_1): Use free_format_hash_table. * io/transfer.c (st_read_done, st_write_done): Free format data if internal unit. * io/format.c (free_format_hash_table): New function that frees any memory allocated previously for cached format data. (reset_node): New static helper function to reset the format counters for a format node. (reset_fnode_counters): New static function recursively calls reset_node to traverse the fnode tree. (format_hash): New simple hash function based on XOR, probabalistic, tosses collisions. (save_parsed_format): New static function to save the parsed format data to use again. (find_parsed_format): New static function searches the hash table looking for a match. (free_format_data): Revised to accept pointer to format data rather than the dtp pointer so that the function can be used in more places. (format_lex): Editorial. (parse_format_list): Set flag used to determine of format data hashing is to be used. Internal units are not persistent enough for this. (revert): Move to ne location in file. (parse_format): Use new functions to look for previously parsed format strings and use them rather than re-parse. If not found, saves the parsed format data for later use. 2009-04-05 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR libfortran/37754 * io/transfer.c (formatted_transfer_scalar): Remove this function by factoring it into two new functions, one for read and one for write, eliminating all the conditionals for read or write mode. (formatted transfer_scalar_read): New function. (formatted transfer_scalar_write): New function. (formatted_transfer): Use new functions. 2009-04-05 Janne Blomqvist <jb@gcc.gnu.org> PR libfortran/25561 libfortran/37754 * io/io.h (struct stream): Define new stream interface function pointers, and inline functions for accessing it. (struct fbuf): Use int instead of size_t, remove flushed element. (mem_alloc_w): New prototype. (mem_alloc_r): New prototype. (stream_at_bof): Remove prototype. (stream_at_eof): Remove prototype. (file_position): Remove prototype. (flush): Remove prototype. (stream_offset): Remove prototype. (unit_truncate): New prototype. (read_block_form): Change to return pointer, int* argument. (hit_eof): New prototype. (fbuf_init): Change prototype. (fbuf_reset): Change prototype. (fbuf_alloc): Change prototype. (fbuf_flush): Change prototype. (fbuf_seek): Change prototype. (fbuf_read): New prototype. (fbuf_getc_refill): New prototype. (fbuf_getc): New inline function. * io/fbuf.c (fbuf_init): Use int, get rid of flushed. (fbuf_debug): New function. (fbuf_reset): Flush, and return position offset. (fbuf_alloc): Simplify, don't flush, just realloc. (fbuf_flush): Make usable for read mode, salvage remaining bytes. (fbuf_seek): New whence argument. (fbuf_read): New function. (fbuf_getc_refill): New function. * io/file_pos.c (formatted_backspace): Use new stream interface. (unformatted_backspace): Likewise. (st_backspace): Make sure format buffer is reset, use new stream interface, use unit_truncate. (st_endfile): Likewise. (st_rewind): Likewise. * io/intrinsics.c: Use new stream interface. * io/list_read.c (push_char): Don't use u.p.scratch, use realloc to resize. (free_saved): Don't check u.p.scratch. (next_char): Use new stream interface, use fbuf_getc() for external files. (finish_list_read): flush format buffer. (nml_query): Update to use modified interface:s * io/open.c (test_endfile): Use new stream interface. (edit_modes): Likewise. (new_unit): Likewise, set bytes_left to 1 for stream files. * io/read.c (read_l): Use new read_block_form interface. (read_utf8): Likewise. (read_utf8_char1): Likewise. (read_default_char1): Likewise. (read_utf8_char4): Likewise. (read_default_char4): Likewise. (read_a): Likewise. (read_a_char4): Likewise. (read_decimal): Likewise. (read_radix): Likewise. (read_f): Likewise. * io/transfer.c (read_sf): Use fbuf_read and mem_alloc_r, remove usage of u.p.line_buffer. (read_block_form): Update interface to return pointer, use fbuf_read for direct access. (read_block_direct): Update to new stream interface. (write_block): Use mem_alloc_w for internal I/O. (write_buf): Update to new stream interface. (formatted_transfer_scalar): Don't use u.p.line_buffer, use fbuf_seek for external files. (us_read): Update to new stream interface. (us_write): Likewise. (data_transfer_init): Always check if we switch modes and flush. (skip_record): Use new stream interface, fix comparison. (next_record_r): Check for and reset u.p.at_eof, use new stream interface, use fbuf_getc for spacing. (write_us_marker): Update to new stream interface, don't inline. (next_record_w_unf): Likewise. (sset): New function. (next_record_w): Use new stream interface, use fbuf for printing newline. (next_record): Use new stream interface. (finalize_transfer): Remove sfree call, use new stream interface. (st_iolength_done): Don't use u.p.scratch. (st_read): Don't check for end of file. (st_read_done): Don't use u.p.scratch, use unit_truncate. (hit_eof): New function. * io/unit.c (init_units): Always init fbuf for formatted units. (update_position): Use new stream interface. (unit_truncate): New function. (finish_last_advance_record): Use fbuf to print newline. * io/unix.c: Remove unused SSIZE_MAX macro. (BUFFER_SIZE): Make static const variable rather than macro. (struct unix_stream): Remove dirty_offset, len, method, small_buffer. Order elements by decreasing size. (struct int_stream): Remove. (move_pos_offset): Remove usage of dirty_offset. (reset_stream): Remove. (do_read): Rename to raw_read, update to match new stream interface. (do_write): Rename to raw_write, update to new stream interface. (raw_seek): New function. (raw_tell): New function. (raw_truncate): New function. (raw_close): New function. (raw_flush): New function. (raw_init): New function. (fd_alloc): Remove. (fd_alloc_r_at): Remove. (fd_alloc_w_at): Remove. (fd_sfree): Remove. (fd_seek): Remove. (fd_truncate): Remove. (fd_sset): Remove. (fd_read): Remove. (fd_write): Remove. (fd_close): Remove. (fd_open): Remove. (fd_flush): Rename to buf_flush, update to new stream interface and unix_stream. (buf_read): New function. (buf_write): New function. (buf_seek): New function. (buf_tell): New function. (buf_truncate): New function. (buf_close): New function. (buf_init): New function. (mem_alloc_r_at): Rename to mem_alloc_r, change prototype. (mem_alloc_w_at): Rename to mem_alloc_w, change prototype. (mem_read): Change to match new stream interface. (mem_write): Likewise. (mem_seek): Likewise. (mem_tell): Likewise. (mem_truncate): Likewise. (mem_close): Likewise. (mem_flush): New function. (mem_sfree): Remove. (empty_internal_buffer): Cast to correct type. (open_internal): Use correct type, init function pointers. (fd_to_stream): Test whether to open file as buffered or raw. (output_stream): Remove mode set. (error_stream): Likewise. (flush_all_units_1): Use new stream interface. (flush_all_units): Likewise. (stream_at_bof): Remove. (stream_at_eof): Remove. (file_position): Remove. (file_length): Update logic to use stream interface. (flush): Remove. (stream_offset): Remove. * io/write.c (write_utf8_char4): Use int instead of size_t. (write_x): Extra safety check. (namelist_write_newline): Use new stream interface. From-SVN: r145571
2009-04-05 22:13:56 +02:00
fmt = NULL;
}
/* format_lex()-- Simple lexical analyzer for getting the next token
in a FORMAT string. We support a one-level token pushback in the
fmt->saved_token variable. */
static format_token
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
format_lex (format_data *fmt)
{
format_token token;
int negative_flag;
int c;
char delim;
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
if (fmt->saved_token != FMT_NONE)
{
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
token = fmt->saved_token;
fmt->saved_token = FMT_NONE;
return token;
}
negative_flag = 0;
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
c = next_char (fmt, 0);
switch (c)
{
case '*':
token = FMT_STAR;
break;
[multiple changes] 2009-04-05 Daniel Kraft <d@domob.eu> PR fortran/38654 * io/read.c (read_f): Reworked to speed up floating point parsing. (convert_real): Use pointer-casting instead of memcpy and temporaries. 2009-04-05 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR libfortran/37754 * io/io.h (format_hash_entry): New structure for hash table. (format_hash_table): The hash table itself. (free_format_data): Revise function prototype. (free_format_hash_table, init_format_hash, free_format_hash): New function prototypes. * io/unit.c (close_unit_1): Use free_format_hash_table. * io/transfer.c (st_read_done, st_write_done): Free format data if internal unit. * io/format.c (free_format_hash_table): New function that frees any memory allocated previously for cached format data. (reset_node): New static helper function to reset the format counters for a format node. (reset_fnode_counters): New static function recursively calls reset_node to traverse the fnode tree. (format_hash): New simple hash function based on XOR, probabalistic, tosses collisions. (save_parsed_format): New static function to save the parsed format data to use again. (find_parsed_format): New static function searches the hash table looking for a match. (free_format_data): Revised to accept pointer to format data rather than the dtp pointer so that the function can be used in more places. (format_lex): Editorial. (parse_format_list): Set flag used to determine of format data hashing is to be used. Internal units are not persistent enough for this. (revert): Move to ne location in file. (parse_format): Use new functions to look for previously parsed format strings and use them rather than re-parse. If not found, saves the parsed format data for later use. 2009-04-05 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR libfortran/37754 * io/transfer.c (formatted_transfer_scalar): Remove this function by factoring it into two new functions, one for read and one for write, eliminating all the conditionals for read or write mode. (formatted transfer_scalar_read): New function. (formatted transfer_scalar_write): New function. (formatted_transfer): Use new functions. 2009-04-05 Janne Blomqvist <jb@gcc.gnu.org> PR libfortran/25561 libfortran/37754 * io/io.h (struct stream): Define new stream interface function pointers, and inline functions for accessing it. (struct fbuf): Use int instead of size_t, remove flushed element. (mem_alloc_w): New prototype. (mem_alloc_r): New prototype. (stream_at_bof): Remove prototype. (stream_at_eof): Remove prototype. (file_position): Remove prototype. (flush): Remove prototype. (stream_offset): Remove prototype. (unit_truncate): New prototype. (read_block_form): Change to return pointer, int* argument. (hit_eof): New prototype. (fbuf_init): Change prototype. (fbuf_reset): Change prototype. (fbuf_alloc): Change prototype. (fbuf_flush): Change prototype. (fbuf_seek): Change prototype. (fbuf_read): New prototype. (fbuf_getc_refill): New prototype. (fbuf_getc): New inline function. * io/fbuf.c (fbuf_init): Use int, get rid of flushed. (fbuf_debug): New function. (fbuf_reset): Flush, and return position offset. (fbuf_alloc): Simplify, don't flush, just realloc. (fbuf_flush): Make usable for read mode, salvage remaining bytes. (fbuf_seek): New whence argument. (fbuf_read): New function. (fbuf_getc_refill): New function. * io/file_pos.c (formatted_backspace): Use new stream interface. (unformatted_backspace): Likewise. (st_backspace): Make sure format buffer is reset, use new stream interface, use unit_truncate. (st_endfile): Likewise. (st_rewind): Likewise. * io/intrinsics.c: Use new stream interface. * io/list_read.c (push_char): Don't use u.p.scratch, use realloc to resize. (free_saved): Don't check u.p.scratch. (next_char): Use new stream interface, use fbuf_getc() for external files. (finish_list_read): flush format buffer. (nml_query): Update to use modified interface:s * io/open.c (test_endfile): Use new stream interface. (edit_modes): Likewise. (new_unit): Likewise, set bytes_left to 1 for stream files. * io/read.c (read_l): Use new read_block_form interface. (read_utf8): Likewise. (read_utf8_char1): Likewise. (read_default_char1): Likewise. (read_utf8_char4): Likewise. (read_default_char4): Likewise. (read_a): Likewise. (read_a_char4): Likewise. (read_decimal): Likewise. (read_radix): Likewise. (read_f): Likewise. * io/transfer.c (read_sf): Use fbuf_read and mem_alloc_r, remove usage of u.p.line_buffer. (read_block_form): Update interface to return pointer, use fbuf_read for direct access. (read_block_direct): Update to new stream interface. (write_block): Use mem_alloc_w for internal I/O. (write_buf): Update to new stream interface. (formatted_transfer_scalar): Don't use u.p.line_buffer, use fbuf_seek for external files. (us_read): Update to new stream interface. (us_write): Likewise. (data_transfer_init): Always check if we switch modes and flush. (skip_record): Use new stream interface, fix comparison. (next_record_r): Check for and reset u.p.at_eof, use new stream interface, use fbuf_getc for spacing. (write_us_marker): Update to new stream interface, don't inline. (next_record_w_unf): Likewise. (sset): New function. (next_record_w): Use new stream interface, use fbuf for printing newline. (next_record): Use new stream interface. (finalize_transfer): Remove sfree call, use new stream interface. (st_iolength_done): Don't use u.p.scratch. (st_read): Don't check for end of file. (st_read_done): Don't use u.p.scratch, use unit_truncate. (hit_eof): New function. * io/unit.c (init_units): Always init fbuf for formatted units. (update_position): Use new stream interface. (unit_truncate): New function. (finish_last_advance_record): Use fbuf to print newline. * io/unix.c: Remove unused SSIZE_MAX macro. (BUFFER_SIZE): Make static const variable rather than macro. (struct unix_stream): Remove dirty_offset, len, method, small_buffer. Order elements by decreasing size. (struct int_stream): Remove. (move_pos_offset): Remove usage of dirty_offset. (reset_stream): Remove. (do_read): Rename to raw_read, update to match new stream interface. (do_write): Rename to raw_write, update to new stream interface. (raw_seek): New function. (raw_tell): New function. (raw_truncate): New function. (raw_close): New function. (raw_flush): New function. (raw_init): New function. (fd_alloc): Remove. (fd_alloc_r_at): Remove. (fd_alloc_w_at): Remove. (fd_sfree): Remove. (fd_seek): Remove. (fd_truncate): Remove. (fd_sset): Remove. (fd_read): Remove. (fd_write): Remove. (fd_close): Remove. (fd_open): Remove. (fd_flush): Rename to buf_flush, update to new stream interface and unix_stream. (buf_read): New function. (buf_write): New function. (buf_seek): New function. (buf_tell): New function. (buf_truncate): New function. (buf_close): New function. (buf_init): New function. (mem_alloc_r_at): Rename to mem_alloc_r, change prototype. (mem_alloc_w_at): Rename to mem_alloc_w, change prototype. (mem_read): Change to match new stream interface. (mem_write): Likewise. (mem_seek): Likewise. (mem_tell): Likewise. (mem_truncate): Likewise. (mem_close): Likewise. (mem_flush): New function. (mem_sfree): Remove. (empty_internal_buffer): Cast to correct type. (open_internal): Use correct type, init function pointers. (fd_to_stream): Test whether to open file as buffered or raw. (output_stream): Remove mode set. (error_stream): Likewise. (flush_all_units_1): Use new stream interface. (flush_all_units): Likewise. (stream_at_bof): Remove. (stream_at_eof): Remove. (file_position): Remove. (file_length): Update logic to use stream interface. (flush): Remove. (stream_offset): Remove. * io/write.c (write_utf8_char4): Use int instead of size_t. (write_x): Extra safety check. (namelist_write_newline): Use new stream interface. From-SVN: r145571
2009-04-05 22:13:56 +02:00
case '(':
token = FMT_LPAREN;
break;
case ')':
token = FMT_RPAREN;
break;
case '-':
negative_flag = 1;
/* Fall Through */
case '+':
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
c = next_char (fmt, 0);
if (!isdigit (c))
{
token = FMT_UNKNOWN;
break;
}
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
fmt->value = c - '0';
for (;;)
{
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
c = next_char (fmt, 0);
if (!isdigit (c))
break;
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
fmt->value = 10 * fmt->value + c - '0';
}
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
unget_char (fmt);
if (negative_flag)
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
fmt->value = -fmt->value;
token = FMT_SIGNED_INT;
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
fmt->value = c - '0';
for (;;)
{
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
c = next_char (fmt, 0);
if (!isdigit (c))
break;
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
fmt->value = 10 * fmt->value + c - '0';
}
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
unget_char (fmt);
token = (fmt->value == 0) ? FMT_ZERO : FMT_POSINT;
break;
case '.':
token = FMT_PERIOD;
break;
case ',':
token = FMT_COMMA;
break;
case ':':
token = FMT_COLON;
break;
case '/':
token = FMT_SLASH;
break;
case '$':
token = FMT_DOLLAR;
break;
case 'T':
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
switch (next_char (fmt, 0))
{
case 'L':
token = FMT_TL;
break;
case 'R':
token = FMT_TR;
break;
default:
token = FMT_T;
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
unget_char (fmt);
break;
}
break;
case 'X':
token = FMT_X;
break;
case 'S':
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
switch (next_char (fmt, 0))
{
case 'S':
token = FMT_SS;
break;
case 'P':
token = FMT_SP;
break;
default:
token = FMT_S;
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
unget_char (fmt);
break;
}
break;
case 'B':
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
switch (next_char (fmt, 0))
{
case 'N':
token = FMT_BN;
break;
case 'Z':
token = FMT_BZ;
break;
default:
token = FMT_B;
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
unget_char (fmt);
break;
}
break;
case '\'':
case '"':
delim = c;
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
fmt->string = fmt->format_string;
fmt->value = 0; /* This is the length of the string */
for (;;)
{
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
c = next_char (fmt, 1);
if (c == -1)
{
token = FMT_BADSTRING;
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
fmt->error = bad_string;
break;
}
if (c == delim)
{
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
c = next_char (fmt, 1);
if (c == -1)
{
token = FMT_BADSTRING;
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
fmt->error = bad_string;
break;
}
if (c != delim)
{
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
unget_char (fmt);
token = FMT_STRING;
break;
}
}
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
fmt->value++;
}
break;
case 'P':
token = FMT_P;
break;
case 'I':
token = FMT_I;
break;
case 'O':
token = FMT_O;
break;
case 'Z':
token = FMT_Z;
break;
case 'F':
token = FMT_F;
break;
case 'E':
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
switch (next_char (fmt, 0))
{
case 'N':
token = FMT_EN;
break;
case 'S':
token = FMT_ES;
break;
default:
token = FMT_E;
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
unget_char (fmt);
break;
}
break;
case 'G':
token = FMT_G;
break;
case 'H':
token = FMT_H;
break;
case 'L':
token = FMT_L;
break;
case 'A':
token = FMT_A;
break;
case 'D':
PR fortran/25829 28655 2008-04-05 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR fortran/25829 28655 * gfortran.map: Add new symbol, _gfortran_st_wait. * libgfortran.h (st_paramter_common): Add new I/O parameters. * open.c (st_option decimal_opt[], st_option encoding_opt[], st_option round_opt[], st_option sign_opt[], st_option async_opt[]): New parameter option arrays. (edit_modes): Add checks for new parameters. (new_unit): Likewise. (st_open): Likewise. * list_read.c (CASE_SEPERATORS): Add ';' as a valid separator. (eat_separator): Handle deimal comma. (read_logical): Fix whitespace. (parse_real): Handle decimal comma. (read_real): Handle decimal comma. * read.c (read_a): Use decimal status flag to allow comma in place of a decimal point. (read_f): Allow comma as acceptable character in float. According to decimal flag, substitute a period for a comma. (read_x): If decimal status flag is comma, disable the read_comma flag, not allowing comma as a delimiter, an extension otherwise. * io.h: (unit_decimal, unit_encoding, unit_round, unit_sign, unit_async): New enumerators. Add all new I/O parameters. * unix.c (unix_stream, int_stream): Add io_mode asychronous I/O control. (move_pos_offset, fd_alloc_w_at): Fix some whitespace. (fd_sfree): Use new enumerator. (fd_read): Likewise. (fd_write): Likewise. (fd_close): Fix whitespace. (fd_open): Use new enumertors. (tempfile, regular_file, open_external): Fix whitespace. (output_stream, error_stream): Set method. (stream_offset): Fix whitespace. * transfer.c: (st_option decimal_opt[], sign_opt[], blank_opt[]): New option arrays. (formatted_transfer_scalar): Set sf_read_comma flag based on new decimal_status flag. (data_transfer_init): Initialize new parameters. Add checks for decimal, sign, and blank. (st_wait): New stub. * format.c: (format_lex): Add format specifiers DP, DC, and D. (parse_format_list): Parse the new specifiers. * write.c (write_decimal): Use new sign enumerators to set the sign. (write_complex): Handle decimal comma and semi-colon separator. (nml_write_obj): Likewise. * write_float.def: Revise sign enumerators. (calculate_sign): Use new sign enumerators. (output_float): Likewise. Use new decimal_status flag to set the decimal character to a point or a comma. From-SVN: r133943
2008-04-06 00:18:03 +02:00
switch (next_char (fmt, 0))
{
case 'P':
token = FMT_DP;
break;
case 'C':
token = FMT_DC;
break;
[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 07:36:22 +02:00
case 'T':
token = FMT_DT;
break;
PR fortran/25829 28655 2008-04-05 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR fortran/25829 28655 * gfortran.map: Add new symbol, _gfortran_st_wait. * libgfortran.h (st_paramter_common): Add new I/O parameters. * open.c (st_option decimal_opt[], st_option encoding_opt[], st_option round_opt[], st_option sign_opt[], st_option async_opt[]): New parameter option arrays. (edit_modes): Add checks for new parameters. (new_unit): Likewise. (st_open): Likewise. * list_read.c (CASE_SEPERATORS): Add ';' as a valid separator. (eat_separator): Handle deimal comma. (read_logical): Fix whitespace. (parse_real): Handle decimal comma. (read_real): Handle decimal comma. * read.c (read_a): Use decimal status flag to allow comma in place of a decimal point. (read_f): Allow comma as acceptable character in float. According to decimal flag, substitute a period for a comma. (read_x): If decimal status flag is comma, disable the read_comma flag, not allowing comma as a delimiter, an extension otherwise. * io.h: (unit_decimal, unit_encoding, unit_round, unit_sign, unit_async): New enumerators. Add all new I/O parameters. * unix.c (unix_stream, int_stream): Add io_mode asychronous I/O control. (move_pos_offset, fd_alloc_w_at): Fix some whitespace. (fd_sfree): Use new enumerator. (fd_read): Likewise. (fd_write): Likewise. (fd_close): Fix whitespace. (fd_open): Use new enumertors. (tempfile, regular_file, open_external): Fix whitespace. (output_stream, error_stream): Set method. (stream_offset): Fix whitespace. * transfer.c: (st_option decimal_opt[], sign_opt[], blank_opt[]): New option arrays. (formatted_transfer_scalar): Set sf_read_comma flag based on new decimal_status flag. (data_transfer_init): Initialize new parameters. Add checks for decimal, sign, and blank. (st_wait): New stub. * format.c: (format_lex): Add format specifiers DP, DC, and D. (parse_format_list): Parse the new specifiers. * write.c (write_decimal): Use new sign enumerators to set the sign. (write_complex): Handle decimal comma and semi-colon separator. (nml_write_obj): Likewise. * write_float.def: Revise sign enumerators. (calculate_sign): Use new sign enumerators. (output_float): Likewise. Use new decimal_status flag to set the decimal character to a point or a comma. From-SVN: r133943
2008-04-06 00:18:03 +02:00
default:
token = FMT_D;
unget_char (fmt);
break;
}
break;
case 'R':
switch (next_char (fmt, 0))
{
case 'C':
token = FMT_RC;
break;
case 'D':
token = FMT_RD;
break;
case 'N':
token = FMT_RN;
break;
case 'P':
token = FMT_RP;
break;
case 'U':
token = FMT_RU;
break;
case 'Z':
token = FMT_RZ;
break;
default:
unget_char (fmt);
token = FMT_UNKNOWN;
break;
}
break;
case -1:
token = FMT_END;
break;
default:
token = FMT_UNKNOWN;
break;
}
return token;
}
/* parse_format_list()-- Parse a format list. Assumes that a left
paren has already been seen. Returns a list representing the
parenthesis node which contains the rest of the list. */
static fnode *
parse_format_list (st_parameter_dt *dtp, bool *seen_dd)
{
fnode *head, *tail;
format_token t, u, t2;
int repeat;
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
format_data *fmt = dtp->u.p.fmt;
bool seen_data_desc = false;
head = tail = NULL;
/* Get the next format item */
format_item:
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
t = format_lex (fmt);
format_item_1:
switch (t)
{
case FMT_STAR:
t = format_lex (fmt);
if (t != FMT_LPAREN)
{
fmt->error = "Left parenthesis required after '*'";
goto finished;
}
get_fnode (fmt, &head, &tail, FMT_LPAREN);
tail->repeat = -2; /* Signifies unlimited format. */
tail->u.child = parse_format_list (dtp, &seen_data_desc);
*seen_dd = seen_data_desc;
if (fmt->error != NULL)
goto finished;
if (!seen_data_desc)
{
fmt->error = "'*' requires at least one associated data descriptor";
goto finished;
}
goto between_desc;
case FMT_POSINT:
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
repeat = fmt->value;
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
t = format_lex (fmt);
switch (t)
{
case FMT_LPAREN:
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
get_fnode (fmt, &head, &tail, FMT_LPAREN);
tail->repeat = repeat;
tail->u.child = parse_format_list (dtp, &seen_data_desc);
*seen_dd = seen_data_desc;
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
if (fmt->error != NULL)
goto finished;
goto between_desc;
case FMT_SLASH:
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
get_fnode (fmt, &head, &tail, FMT_SLASH);
tail->repeat = repeat;
goto optional_comma;
case FMT_X:
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
get_fnode (fmt, &head, &tail, FMT_X);
tail->repeat = 1;
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
tail->u.k = fmt->value;
goto between_desc;
case FMT_P:
goto p_descriptor;
default:
goto data_desc;
}
case FMT_LPAREN:
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
get_fnode (fmt, &head, &tail, FMT_LPAREN);
tail->repeat = 1;
tail->u.child = parse_format_list (dtp, &seen_data_desc);
*seen_dd = seen_data_desc;
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
if (fmt->error != NULL)
goto finished;
goto between_desc;
case FMT_SIGNED_INT: /* Signed integer can only precede a P format. */
case FMT_ZERO: /* Same for zero. */
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
t = format_lex (fmt);
if (t != FMT_P)
{
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
fmt->error = "Expected P edit descriptor in format";
goto finished;
}
p_descriptor:
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
get_fnode (fmt, &head, &tail, FMT_P);
tail->u.k = fmt->value;
tail->repeat = 1;
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
t = format_lex (fmt);
if (t == FMT_F || t == FMT_EN || t == FMT_ES || t == FMT_D
|| t == FMT_G || t == FMT_E)
{
repeat = 1;
goto data_desc;
}
if (t != FMT_COMMA && t != FMT_RPAREN && t != FMT_SLASH
&& t != FMT_POSINT)
{
fmt->error = "Comma required after P descriptor";
goto finished;
}
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
fmt->saved_token = t;
goto optional_comma;
case FMT_P: /* P and X require a prior number */
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
fmt->error = "P descriptor requires leading scale factor";
goto finished;
case FMT_X:
/*
EXTENSION!
If we would be pedantic in the library, we would have to reject
an X descriptor without an integer prefix:
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
fmt->error = "X descriptor requires leading space count";
goto finished;
However, this is an extension supported by many Fortran compilers,
including Cray, HP, AIX, and IRIX. Therefore, we allow it in the
runtime library, and make the front end reject it if the compiler
is in pedantic mode. The interpretation of 'X' is '1X'.
*/
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
get_fnode (fmt, &head, &tail, FMT_X);
tail->repeat = 1;
tail->u.k = 1;
goto between_desc;
case FMT_STRING:
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
get_fnode (fmt, &head, &tail, FMT_STRING);
tail->u.string.p = fmt->string;
tail->u.string.length = fmt->value;
tail->repeat = 1;
goto optional_comma;
[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 07:36:22 +02:00
case FMT_RC:
case FMT_RD:
case FMT_RN:
case FMT_RP:
case FMT_RU:
case FMT_RZ:
notify_std (&dtp->common, GFC_STD_F2003, "Fortran 2003: Round "
"descriptor not allowed");
get_fnode (fmt, &head, &tail, t);
tail->repeat = 1;
goto between_desc;
PR fortran/25829 28655 2008-04-05 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR fortran/25829 28655 * gfortran.map: Add new symbol, _gfortran_st_wait. * libgfortran.h (st_paramter_common): Add new I/O parameters. * open.c (st_option decimal_opt[], st_option encoding_opt[], st_option round_opt[], st_option sign_opt[], st_option async_opt[]): New parameter option arrays. (edit_modes): Add checks for new parameters. (new_unit): Likewise. (st_open): Likewise. * list_read.c (CASE_SEPERATORS): Add ';' as a valid separator. (eat_separator): Handle deimal comma. (read_logical): Fix whitespace. (parse_real): Handle decimal comma. (read_real): Handle decimal comma. * read.c (read_a): Use decimal status flag to allow comma in place of a decimal point. (read_f): Allow comma as acceptable character in float. According to decimal flag, substitute a period for a comma. (read_x): If decimal status flag is comma, disable the read_comma flag, not allowing comma as a delimiter, an extension otherwise. * io.h: (unit_decimal, unit_encoding, unit_round, unit_sign, unit_async): New enumerators. Add all new I/O parameters. * unix.c (unix_stream, int_stream): Add io_mode asychronous I/O control. (move_pos_offset, fd_alloc_w_at): Fix some whitespace. (fd_sfree): Use new enumerator. (fd_read): Likewise. (fd_write): Likewise. (fd_close): Fix whitespace. (fd_open): Use new enumertors. (tempfile, regular_file, open_external): Fix whitespace. (output_stream, error_stream): Set method. (stream_offset): Fix whitespace. * transfer.c: (st_option decimal_opt[], sign_opt[], blank_opt[]): New option arrays. (formatted_transfer_scalar): Set sf_read_comma flag based on new decimal_status flag. (data_transfer_init): Initialize new parameters. Add checks for decimal, sign, and blank. (st_wait): New stub. * format.c: (format_lex): Add format specifiers DP, DC, and D. (parse_format_list): Parse the new specifiers. * write.c (write_decimal): Use new sign enumerators to set the sign. (write_complex): Handle decimal comma and semi-colon separator. (nml_write_obj): Likewise. * write_float.def: Revise sign enumerators. (calculate_sign): Use new sign enumerators. (output_float): Likewise. Use new decimal_status flag to set the decimal character to a point or a comma. From-SVN: r133943
2008-04-06 00:18:03 +02:00
case FMT_DC:
case FMT_DP:
notify_std (&dtp->common, GFC_STD_F2003, "Fortran 2003: DC or DP "
"descriptor not allowed");
/* Fall through. */
case FMT_S:
case FMT_SS:
case FMT_SP:
case FMT_BN:
case FMT_BZ:
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
get_fnode (fmt, &head, &tail, t);
tail->repeat = 1;
goto between_desc;
case FMT_COLON:
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
get_fnode (fmt, &head, &tail, FMT_COLON);
tail->repeat = 1;
goto optional_comma;
case FMT_SLASH:
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
get_fnode (fmt, &head, &tail, FMT_SLASH);
tail->repeat = 1;
tail->u.r = 1;
goto optional_comma;
case FMT_DOLLAR:
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
get_fnode (fmt, &head, &tail, FMT_DOLLAR);
tail->repeat = 1;
notify_std (&dtp->common, GFC_STD_GNU, "Extension: $ descriptor");
goto between_desc;
case FMT_T:
case FMT_TL:
case FMT_TR:
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
t2 = format_lex (fmt);
if (t2 != FMT_POSINT)
{
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
fmt->error = posint_required;
goto finished;
}
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
get_fnode (fmt, &head, &tail, t);
tail->u.n = fmt->value;
tail->repeat = 1;
goto between_desc;
case FMT_I:
case FMT_B:
case FMT_O:
case FMT_Z:
case FMT_E:
case FMT_EN:
case FMT_ES:
case FMT_D:
[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 07:36:22 +02:00
case FMT_DT:
case FMT_L:
case FMT_A:
case FMT_F:
case FMT_G:
repeat = 1;
*seen_dd = true;
goto data_desc;
case FMT_H:
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
get_fnode (fmt, &head, &tail, FMT_STRING);
if (fmt->format_string_len < 1)
{
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
fmt->error = bad_hollerith;
goto finished;
}
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
tail->u.string.p = fmt->format_string;
tail->u.string.length = 1;
tail->repeat = 1;
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
fmt->format_string++;
fmt->format_string_len--;
goto between_desc;
case FMT_END:
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
fmt->error = unexpected_end;
goto finished;
case FMT_BADSTRING:
goto finished;
case FMT_RPAREN:
goto finished;
default:
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
fmt->error = unexpected_element;
goto finished;
}
/* In this state, t must currently be a data descriptor. Deal with
things that can/must follow the descriptor */
data_desc:
[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 07:36:22 +02:00
switch (t)
{
case FMT_L:
*seen_dd = true;
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
t = format_lex (fmt);
if (t != FMT_POSINT)
{
if (t == FMT_ZERO)
{
if (notification_std(GFC_STD_GNU) == NOTIFICATION_ERROR)
{
fmt->error = "Extension: Zero width after L descriptor";
goto finished;
}
else
notify_std (&dtp->common, GFC_STD_GNU,
"Zero width after L descriptor");
}
else
{
fmt->saved_token = t;
notify_std (&dtp->common, GFC_STD_GNU,
"Positive width required with L descriptor");
}
fmt->value = 1; /* Default width */
}
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
get_fnode (fmt, &head, &tail, FMT_L);
tail->u.n = fmt->value;
tail->repeat = repeat;
break;
case FMT_A:
*seen_dd = true;
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
t = format_lex (fmt);
if (t == FMT_ZERO)
{
fmt->error = zero_width;
goto finished;
}
if (t != FMT_POSINT)
{
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
fmt->saved_token = t;
fmt->value = -1; /* Width not present */
}
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
get_fnode (fmt, &head, &tail, FMT_A);
tail->repeat = repeat;
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
tail->u.n = fmt->value;
break;
case FMT_D:
case FMT_E:
case FMT_F:
case FMT_G:
case FMT_EN:
case FMT_ES:
*seen_dd = true;
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
get_fnode (fmt, &head, &tail, t);
tail->repeat = repeat;
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
u = format_lex (fmt);
if (t == FMT_G && u == FMT_ZERO)
{
*seen_dd = true;
if (notification_std (GFC_STD_F2008) == NOTIFICATION_ERROR
|| dtp->u.p.mode == READING)
{
fmt->error = zero_width;
goto finished;
}
tail->u.real.w = 0;
u = format_lex (fmt);
if (u != FMT_PERIOD)
{
fmt->saved_token = u;
break;
}
u = format_lex (fmt);
if (u != FMT_POSINT)
{
fmt->error = posint_required;
goto finished;
}
tail->u.real.d = fmt->value;
break;
}
if (t == FMT_F && dtp->u.p.mode == WRITING)
{
*seen_dd = true;
if (u != FMT_POSINT && u != FMT_ZERO)
{
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
fmt->error = nonneg_required;
goto finished;
}
}
else if (u != FMT_POSINT)
{
fmt->error = posint_required;
goto finished;
}
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
tail->u.real.w = fmt->value;
t2 = t;
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
t = format_lex (fmt);
if (t != FMT_PERIOD)
{
/* We treat a missing decimal descriptor as 0. Note: This is only
allowed if -std=legacy, otherwise an error occurs. */
if (compile_options.warn_std != 0)
{
fmt->error = period_required;
goto finished;
}
fmt->saved_token = t;
tail->u.real.d = 0;
tail->u.real.e = -1;
break;
}
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
t = format_lex (fmt);
if (t != FMT_ZERO && t != FMT_POSINT)
{
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
fmt->error = nonneg_required;
goto finished;
}
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
tail->u.real.d = fmt->value;
tail->u.real.e = -1;
if (t2 == FMT_D || t2 == FMT_F)
{
*seen_dd = true;
break;
}
/* Look for optional exponent */
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
t = format_lex (fmt);
if (t != FMT_E)
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
fmt->saved_token = t;
else
{
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
t = format_lex (fmt);
if (t != FMT_POSINT)
{
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
fmt->error = "Positive exponent width required in format";
goto finished;
}
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
tail->u.real.e = fmt->value;
}
break;
[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 07:36:22 +02:00
case FMT_DT:
*seen_dd = true;
get_fnode (fmt, &head, &tail, t);
tail->repeat = repeat;
t = format_lex (fmt);
/* Initialize the vlist to a zero size array. */
tail->u.udf.vlist= xmalloc (sizeof(gfc_array_i4));
GFC_DESCRIPTOR_DATA(tail->u.udf.vlist) = NULL;
GFC_DIMENSION_SET(tail->u.udf.vlist->dim[0],1, 0, 0);
[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 07:36:22 +02:00
if (t == FMT_STRING)
{
/* Get pointer to the optional format string. */
tail->u.udf.string = fmt->string;
tail->u.udf.string_len = fmt->value;
t = format_lex (fmt);
}
if (t == FMT_LPAREN)
{
/* Temporary buffer to hold the vlist values. */
GFC_INTEGER_4 temp[FARRAY_SIZE];
int i = 0;
loop:
t = format_lex (fmt);
if (t != FMT_POSINT)
{
fmt->error = posint_required;
goto finished;
}
/* Save the positive integer value. */
temp[i++] = fmt->value;
t = format_lex (fmt);
if (t == FMT_COMMA)
goto loop;
if (t == FMT_RPAREN)
{
/* We have parsed the complete vlist so initialize the
array descriptor and save it in the format node. */
gfc_array_i4 *vp = tail->u.udf.vlist;
GFC_DESCRIPTOR_DATA(vp) = xmalloc (i * sizeof(GFC_INTEGER_4));
GFC_DIMENSION_SET(vp->dim[0],1, i, 1);
memcpy (GFC_DESCRIPTOR_DATA(vp), temp, i * sizeof(GFC_INTEGER_4));
break;
}
fmt->error = unexpected_element;
goto finished;
}
fmt->saved_token = t;
break;
case FMT_H:
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
if (repeat > fmt->format_string_len)
{
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
fmt->error = bad_hollerith;
goto finished;
}
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
get_fnode (fmt, &head, &tail, FMT_STRING);
tail->u.string.p = fmt->format_string;
tail->u.string.length = repeat;
tail->repeat = 1;
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
fmt->format_string += fmt->value;
fmt->format_string_len -= repeat;
break;
case FMT_I:
case FMT_B:
case FMT_O:
case FMT_Z:
*seen_dd = true;
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
get_fnode (fmt, &head, &tail, t);
tail->repeat = repeat;
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
t = format_lex (fmt);
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
if (dtp->u.p.mode == READING)
{
if (t != FMT_POSINT)
{
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
fmt->error = posint_required;
goto finished;
}
}
else
{
if (t != FMT_ZERO && t != FMT_POSINT)
{
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
fmt->error = nonneg_required;
goto finished;
}
}
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
tail->u.integer.w = fmt->value;
tail->u.integer.m = -1;
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
t = format_lex (fmt);
if (t != FMT_PERIOD)
{
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
fmt->saved_token = t;
}
else
{
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
t = format_lex (fmt);
if (t != FMT_ZERO && t != FMT_POSINT)
{
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
fmt->error = nonneg_required;
goto finished;
}
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
tail->u.integer.m = fmt->value;
}
if (tail->u.integer.w != 0 && tail->u.integer.m > tail->u.integer.w)
{
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
fmt->error = "Minimum digits exceeds field width";
goto finished;
}
break;
default:
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
fmt->error = unexpected_element;
goto finished;
}
/* Between a descriptor and what comes next */
between_desc:
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
t = format_lex (fmt);
switch (t)
{
case FMT_COMMA:
goto format_item;
case FMT_RPAREN:
goto finished;
case FMT_SLASH:
case FMT_COLON:
get_fnode (fmt, &head, &tail, t);
tail->repeat = 1;
goto optional_comma;
case FMT_END:
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
fmt->error = unexpected_end;
goto finished;
default:
/* Assume a missing comma, this is a GNU extension */
goto format_item_1;
}
/* Optional comma is a weird between state where we've just finished
reading a colon, slash or P descriptor. */
optional_comma:
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
t = format_lex (fmt);
switch (t)
{
case FMT_COMMA:
break;
case FMT_RPAREN:
goto finished;
default: /* Assume that we have another format item */
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
fmt->saved_token = t;
break;
}
goto format_item;
finished:
return head;
}
/* format_error()-- Generate an error message for a format statement.
If the node that gives the location of the error is NULL, the error
is assumed to happen at parse time, and the current location of the
parser is shown.
We generate a message showing where the problem is. We take extra
care to print only the relevant part of the format if it is longer
than a standard 80 column display. */
void
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
format_error (st_parameter_dt *dtp, const fnode *f, const char *message)
{
int width, i, offset;
#define BUFLEN 300
char *p, buffer[BUFLEN];
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
format_data *fmt = dtp->u.p.fmt;
if (f != NULL)
p = f->source;
else /* This should not happen. */
p = dtp->format;
if (message == unexpected_element)
snprintf (buffer, BUFLEN, message, fmt->error_element);
else
snprintf (buffer, BUFLEN, "%s\n", message);
/* Get the offset into the format string where the error occurred. */
offset = dtp->format_len - (fmt->reversion_ok ?
(int) strlen(p) : fmt->format_string_len);
width = dtp->format_len;
if (width > 80)
width = 80;
/* Show the format */
p = strchr (buffer, '\0');
if (dtp->format)
memcpy (p, dtp->format, width);
p += width;
*p++ = '\n';
/* Show where the problem is */
for (i = 1; i < offset; i++)
*p++ = ' ';
*p++ = '^';
*p = '\0';
re PR fortran/31675 (Fortran front-end and libgfortran should have a common header file) PR fortran/31675 * libgfortran.h: New file. * iso-fortran-env.def: Use macros in the new header instead of hardcoded integer constants. * Make-lang.in (F95_PARSER_OBJS, GFORTRAN_TRANS_DEPS): Add fortran/libgfortran.h. * gfortran.h (GFC_STD_*, GFC_FPE_*, options_convert, ioerror_codes): Remove. * trans.c (ERROR_ALLOCATION): Remove. (gfc_call_malloc, gfc_allocate_with_status, gfc_allocate_array_with_status): Use LIBERROR_ALLOCATION. * trans-types.h (GFC_DTYPE_*): Remove. * trans-decl.c (gfc_generate_function_code): Use GFC_CONVERT_NATIVE instead of CONVERT_NATIVE. * trans-io.c (set_parameter_value, set_parameter_ref): Use LIBERROR_* macros instead of IOERROR_ macros. * trans-intrinsic.c (gfc_conv_intrinsic_function): Use LIBERROR_END and LIBERROR_EOR instead of hardcoded constants. * options.c (gfc_init_options): Use GFC_CONVERT_NATIVE instead of CONVERT_NATIVE. (gfc_handle_option): Use GFC_CONVERT_* macros instead of CONVERT_*. * libgfortran.h: Include gcc/fortran/libgfortran.h. Remove M_PI, GFC_MAX_DIMENSIONS, GFC_DTYPE_*, GFC_NUM_RANK_BITS, error_codes, GFC_STD_*, GFC_FPE_* and unit_convert. * runtime/environ.c (variable_table): Use GFC_*_UNIT_NUMBER instead of hardcoded constants. (do_parse, init_unformatted): Use GFC_CONVERT_* macros instead of CONVERT_*. * runtime/string.c (find_option): Use LIBERROR_BAD_OPTION instead of ERROR_BAD_OPTION. * runtime/error.c (translate_error, generate_error): Use LIBERROR_* macros instead of ERROR_*. * io/file_pos.c (formatted_backspace, unformatted_backspace, st_backspace, st_rewind, st_flush): Rename macros. * io/open.c (convert_opt, edit_modes, new_unit, already_open, st_open): Likewise. * io/close.c (st_close): Likewise. * io/list_read.c (next_char, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, check_type, list_formatted_read_scalar, namelist_read, nml_err_ret): Likewise. * io/read.c (convert_real, read_l, read_decimal, read_radix, read_f): Likewise. * io/inquire.c (inquire_via_unit): Likewise. * io/unit.c (get_internal_unit): Likewise. * io/transfer.c (read_sf, read_block, read_block_direct, write_block, write_buf, unformatted_read, unformatted_write, formatted_transfer_scalar, us_read, us_write, data_transfer_init, skip_record, next_record_r, write_us_marker, next_record_w_unf, next_record_w, finalize_transfer, st_read, st_write_done): Likewise. * io/format.c (format_error): Likewise. From-SVN: r128050
2007-09-03 18:44:15 +02:00
generate_error (&dtp->common, LIBERROR_FORMAT, buffer);
}
[multiple changes] 2009-04-05 Daniel Kraft <d@domob.eu> PR fortran/38654 * io/read.c (read_f): Reworked to speed up floating point parsing. (convert_real): Use pointer-casting instead of memcpy and temporaries. 2009-04-05 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR libfortran/37754 * io/io.h (format_hash_entry): New structure for hash table. (format_hash_table): The hash table itself. (free_format_data): Revise function prototype. (free_format_hash_table, init_format_hash, free_format_hash): New function prototypes. * io/unit.c (close_unit_1): Use free_format_hash_table. * io/transfer.c (st_read_done, st_write_done): Free format data if internal unit. * io/format.c (free_format_hash_table): New function that frees any memory allocated previously for cached format data. (reset_node): New static helper function to reset the format counters for a format node. (reset_fnode_counters): New static function recursively calls reset_node to traverse the fnode tree. (format_hash): New simple hash function based on XOR, probabalistic, tosses collisions. (save_parsed_format): New static function to save the parsed format data to use again. (find_parsed_format): New static function searches the hash table looking for a match. (free_format_data): Revised to accept pointer to format data rather than the dtp pointer so that the function can be used in more places. (format_lex): Editorial. (parse_format_list): Set flag used to determine of format data hashing is to be used. Internal units are not persistent enough for this. (revert): Move to ne location in file. (parse_format): Use new functions to look for previously parsed format strings and use them rather than re-parse. If not found, saves the parsed format data for later use. 2009-04-05 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR libfortran/37754 * io/transfer.c (formatted_transfer_scalar): Remove this function by factoring it into two new functions, one for read and one for write, eliminating all the conditionals for read or write mode. (formatted transfer_scalar_read): New function. (formatted transfer_scalar_write): New function. (formatted_transfer): Use new functions. 2009-04-05 Janne Blomqvist <jb@gcc.gnu.org> PR libfortran/25561 libfortran/37754 * io/io.h (struct stream): Define new stream interface function pointers, and inline functions for accessing it. (struct fbuf): Use int instead of size_t, remove flushed element. (mem_alloc_w): New prototype. (mem_alloc_r): New prototype. (stream_at_bof): Remove prototype. (stream_at_eof): Remove prototype. (file_position): Remove prototype. (flush): Remove prototype. (stream_offset): Remove prototype. (unit_truncate): New prototype. (read_block_form): Change to return pointer, int* argument. (hit_eof): New prototype. (fbuf_init): Change prototype. (fbuf_reset): Change prototype. (fbuf_alloc): Change prototype. (fbuf_flush): Change prototype. (fbuf_seek): Change prototype. (fbuf_read): New prototype. (fbuf_getc_refill): New prototype. (fbuf_getc): New inline function. * io/fbuf.c (fbuf_init): Use int, get rid of flushed. (fbuf_debug): New function. (fbuf_reset): Flush, and return position offset. (fbuf_alloc): Simplify, don't flush, just realloc. (fbuf_flush): Make usable for read mode, salvage remaining bytes. (fbuf_seek): New whence argument. (fbuf_read): New function. (fbuf_getc_refill): New function. * io/file_pos.c (formatted_backspace): Use new stream interface. (unformatted_backspace): Likewise. (st_backspace): Make sure format buffer is reset, use new stream interface, use unit_truncate. (st_endfile): Likewise. (st_rewind): Likewise. * io/intrinsics.c: Use new stream interface. * io/list_read.c (push_char): Don't use u.p.scratch, use realloc to resize. (free_saved): Don't check u.p.scratch. (next_char): Use new stream interface, use fbuf_getc() for external files. (finish_list_read): flush format buffer. (nml_query): Update to use modified interface:s * io/open.c (test_endfile): Use new stream interface. (edit_modes): Likewise. (new_unit): Likewise, set bytes_left to 1 for stream files. * io/read.c (read_l): Use new read_block_form interface. (read_utf8): Likewise. (read_utf8_char1): Likewise. (read_default_char1): Likewise. (read_utf8_char4): Likewise. (read_default_char4): Likewise. (read_a): Likewise. (read_a_char4): Likewise. (read_decimal): Likewise. (read_radix): Likewise. (read_f): Likewise. * io/transfer.c (read_sf): Use fbuf_read and mem_alloc_r, remove usage of u.p.line_buffer. (read_block_form): Update interface to return pointer, use fbuf_read for direct access. (read_block_direct): Update to new stream interface. (write_block): Use mem_alloc_w for internal I/O. (write_buf): Update to new stream interface. (formatted_transfer_scalar): Don't use u.p.line_buffer, use fbuf_seek for external files. (us_read): Update to new stream interface. (us_write): Likewise. (data_transfer_init): Always check if we switch modes and flush. (skip_record): Use new stream interface, fix comparison. (next_record_r): Check for and reset u.p.at_eof, use new stream interface, use fbuf_getc for spacing. (write_us_marker): Update to new stream interface, don't inline. (next_record_w_unf): Likewise. (sset): New function. (next_record_w): Use new stream interface, use fbuf for printing newline. (next_record): Use new stream interface. (finalize_transfer): Remove sfree call, use new stream interface. (st_iolength_done): Don't use u.p.scratch. (st_read): Don't check for end of file. (st_read_done): Don't use u.p.scratch, use unit_truncate. (hit_eof): New function. * io/unit.c (init_units): Always init fbuf for formatted units. (update_position): Use new stream interface. (unit_truncate): New function. (finish_last_advance_record): Use fbuf to print newline. * io/unix.c: Remove unused SSIZE_MAX macro. (BUFFER_SIZE): Make static const variable rather than macro. (struct unix_stream): Remove dirty_offset, len, method, small_buffer. Order elements by decreasing size. (struct int_stream): Remove. (move_pos_offset): Remove usage of dirty_offset. (reset_stream): Remove. (do_read): Rename to raw_read, update to match new stream interface. (do_write): Rename to raw_write, update to new stream interface. (raw_seek): New function. (raw_tell): New function. (raw_truncate): New function. (raw_close): New function. (raw_flush): New function. (raw_init): New function. (fd_alloc): Remove. (fd_alloc_r_at): Remove. (fd_alloc_w_at): Remove. (fd_sfree): Remove. (fd_seek): Remove. (fd_truncate): Remove. (fd_sset): Remove. (fd_read): Remove. (fd_write): Remove. (fd_close): Remove. (fd_open): Remove. (fd_flush): Rename to buf_flush, update to new stream interface and unix_stream. (buf_read): New function. (buf_write): New function. (buf_seek): New function. (buf_tell): New function. (buf_truncate): New function. (buf_close): New function. (buf_init): New function. (mem_alloc_r_at): Rename to mem_alloc_r, change prototype. (mem_alloc_w_at): Rename to mem_alloc_w, change prototype. (mem_read): Change to match new stream interface. (mem_write): Likewise. (mem_seek): Likewise. (mem_tell): Likewise. (mem_truncate): Likewise. (mem_close): Likewise. (mem_flush): New function. (mem_sfree): Remove. (empty_internal_buffer): Cast to correct type. (open_internal): Use correct type, init function pointers. (fd_to_stream): Test whether to open file as buffered or raw. (output_stream): Remove mode set. (error_stream): Likewise. (flush_all_units_1): Use new stream interface. (flush_all_units): Likewise. (stream_at_bof): Remove. (stream_at_eof): Remove. (file_position): Remove. (file_length): Update logic to use stream interface. (flush): Remove. (stream_offset): Remove. * io/write.c (write_utf8_char4): Use int instead of size_t. (write_x): Extra safety check. (namelist_write_newline): Use new stream interface. From-SVN: r145571
2009-04-05 22:13:56 +02:00
/* revert()-- Do reversion of the format. Control reverts to the left
parenthesis that matches the rightmost right parenthesis. From our
tree structure, we are looking for the rightmost parenthesis node
at the second level, the first level always being a single
parenthesis node. If this node doesn't exit, we use the top
level. */
[multiple changes] 2009-04-05 Daniel Kraft <d@domob.eu> PR fortran/38654 * io/read.c (read_f): Reworked to speed up floating point parsing. (convert_real): Use pointer-casting instead of memcpy and temporaries. 2009-04-05 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR libfortran/37754 * io/io.h (format_hash_entry): New structure for hash table. (format_hash_table): The hash table itself. (free_format_data): Revise function prototype. (free_format_hash_table, init_format_hash, free_format_hash): New function prototypes. * io/unit.c (close_unit_1): Use free_format_hash_table. * io/transfer.c (st_read_done, st_write_done): Free format data if internal unit. * io/format.c (free_format_hash_table): New function that frees any memory allocated previously for cached format data. (reset_node): New static helper function to reset the format counters for a format node. (reset_fnode_counters): New static function recursively calls reset_node to traverse the fnode tree. (format_hash): New simple hash function based on XOR, probabalistic, tosses collisions. (save_parsed_format): New static function to save the parsed format data to use again. (find_parsed_format): New static function searches the hash table looking for a match. (free_format_data): Revised to accept pointer to format data rather than the dtp pointer so that the function can be used in more places. (format_lex): Editorial. (parse_format_list): Set flag used to determine of format data hashing is to be used. Internal units are not persistent enough for this. (revert): Move to ne location in file. (parse_format): Use new functions to look for previously parsed format strings and use them rather than re-parse. If not found, saves the parsed format data for later use. 2009-04-05 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR libfortran/37754 * io/transfer.c (formatted_transfer_scalar): Remove this function by factoring it into two new functions, one for read and one for write, eliminating all the conditionals for read or write mode. (formatted transfer_scalar_read): New function. (formatted transfer_scalar_write): New function. (formatted_transfer): Use new functions. 2009-04-05 Janne Blomqvist <jb@gcc.gnu.org> PR libfortran/25561 libfortran/37754 * io/io.h (struct stream): Define new stream interface function pointers, and inline functions for accessing it. (struct fbuf): Use int instead of size_t, remove flushed element. (mem_alloc_w): New prototype. (mem_alloc_r): New prototype. (stream_at_bof): Remove prototype. (stream_at_eof): Remove prototype. (file_position): Remove prototype. (flush): Remove prototype. (stream_offset): Remove prototype. (unit_truncate): New prototype. (read_block_form): Change to return pointer, int* argument. (hit_eof): New prototype. (fbuf_init): Change prototype. (fbuf_reset): Change prototype. (fbuf_alloc): Change prototype. (fbuf_flush): Change prototype. (fbuf_seek): Change prototype. (fbuf_read): New prototype. (fbuf_getc_refill): New prototype. (fbuf_getc): New inline function. * io/fbuf.c (fbuf_init): Use int, get rid of flushed. (fbuf_debug): New function. (fbuf_reset): Flush, and return position offset. (fbuf_alloc): Simplify, don't flush, just realloc. (fbuf_flush): Make usable for read mode, salvage remaining bytes. (fbuf_seek): New whence argument. (fbuf_read): New function. (fbuf_getc_refill): New function. * io/file_pos.c (formatted_backspace): Use new stream interface. (unformatted_backspace): Likewise. (st_backspace): Make sure format buffer is reset, use new stream interface, use unit_truncate. (st_endfile): Likewise. (st_rewind): Likewise. * io/intrinsics.c: Use new stream interface. * io/list_read.c (push_char): Don't use u.p.scratch, use realloc to resize. (free_saved): Don't check u.p.scratch. (next_char): Use new stream interface, use fbuf_getc() for external files. (finish_list_read): flush format buffer. (nml_query): Update to use modified interface:s * io/open.c (test_endfile): Use new stream interface. (edit_modes): Likewise. (new_unit): Likewise, set bytes_left to 1 for stream files. * io/read.c (read_l): Use new read_block_form interface. (read_utf8): Likewise. (read_utf8_char1): Likewise. (read_default_char1): Likewise. (read_utf8_char4): Likewise. (read_default_char4): Likewise. (read_a): Likewise. (read_a_char4): Likewise. (read_decimal): Likewise. (read_radix): Likewise. (read_f): Likewise. * io/transfer.c (read_sf): Use fbuf_read and mem_alloc_r, remove usage of u.p.line_buffer. (read_block_form): Update interface to return pointer, use fbuf_read for direct access. (read_block_direct): Update to new stream interface. (write_block): Use mem_alloc_w for internal I/O. (write_buf): Update to new stream interface. (formatted_transfer_scalar): Don't use u.p.line_buffer, use fbuf_seek for external files. (us_read): Update to new stream interface. (us_write): Likewise. (data_transfer_init): Always check if we switch modes and flush. (skip_record): Use new stream interface, fix comparison. (next_record_r): Check for and reset u.p.at_eof, use new stream interface, use fbuf_getc for spacing. (write_us_marker): Update to new stream interface, don't inline. (next_record_w_unf): Likewise. (sset): New function. (next_record_w): Use new stream interface, use fbuf for printing newline. (next_record): Use new stream interface. (finalize_transfer): Remove sfree call, use new stream interface. (st_iolength_done): Don't use u.p.scratch. (st_read): Don't check for end of file. (st_read_done): Don't use u.p.scratch, use unit_truncate. (hit_eof): New function. * io/unit.c (init_units): Always init fbuf for formatted units. (update_position): Use new stream interface. (unit_truncate): New function. (finish_last_advance_record): Use fbuf to print newline. * io/unix.c: Remove unused SSIZE_MAX macro. (BUFFER_SIZE): Make static const variable rather than macro. (struct unix_stream): Remove dirty_offset, len, method, small_buffer. Order elements by decreasing size. (struct int_stream): Remove. (move_pos_offset): Remove usage of dirty_offset. (reset_stream): Remove. (do_read): Rename to raw_read, update to match new stream interface. (do_write): Rename to raw_write, update to new stream interface. (raw_seek): New function. (raw_tell): New function. (raw_truncate): New function. (raw_close): New function. (raw_flush): New function. (raw_init): New function. (fd_alloc): Remove. (fd_alloc_r_at): Remove. (fd_alloc_w_at): Remove. (fd_sfree): Remove. (fd_seek): Remove. (fd_truncate): Remove. (fd_sset): Remove. (fd_read): Remove. (fd_write): Remove. (fd_close): Remove. (fd_open): Remove. (fd_flush): Rename to buf_flush, update to new stream interface and unix_stream. (buf_read): New function. (buf_write): New function. (buf_seek): New function. (buf_tell): New function. (buf_truncate): New function. (buf_close): New function. (buf_init): New function. (mem_alloc_r_at): Rename to mem_alloc_r, change prototype. (mem_alloc_w_at): Rename to mem_alloc_w, change prototype. (mem_read): Change to match new stream interface. (mem_write): Likewise. (mem_seek): Likewise. (mem_tell): Likewise. (mem_truncate): Likewise. (mem_close): Likewise. (mem_flush): New function. (mem_sfree): Remove. (empty_internal_buffer): Cast to correct type. (open_internal): Use correct type, init function pointers. (fd_to_stream): Test whether to open file as buffered or raw. (output_stream): Remove mode set. (error_stream): Likewise. (flush_all_units_1): Use new stream interface. (flush_all_units): Likewise. (stream_at_bof): Remove. (stream_at_eof): Remove. (file_position): Remove. (file_length): Update logic to use stream interface. (flush): Remove. (stream_offset): Remove. * io/write.c (write_utf8_char4): Use int instead of size_t. (write_x): Extra safety check. (namelist_write_newline): Use new stream interface. From-SVN: r145571
2009-04-05 22:13:56 +02:00
static void
revert (st_parameter_dt *dtp)
{
fnode *f, *r;
format_data *fmt = dtp->u.p.fmt;
dtp->u.p.reversion_flag = 1;
r = NULL;
for (f = fmt->array.array[0].u.child; f; f = f->next)
if (f->format == FMT_LPAREN)
r = f;
/* If r is NULL because no node was found, the whole tree will be used */
fmt->array.array[0].current = r;
fmt->array.array[0].count = 0;
}
/* parse_format()-- Parse a format string. */
void
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
parse_format (st_parameter_dt *dtp)
{
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
format_data *fmt;
bool format_cache_ok, seen_data_desc = false;
[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 07:36:22 +02:00
/* Don't cache for internal units and set an arbitrary limit on the
size of format strings we will cache. (Avoids memory issues.)
Also, the format_hash_table resides in the current_unit, so
child_dtio procedures would overwrite the parent table */
format_cache_ok = !is_internal_unit (dtp)
&& (dtp->u.p.current_unit->child_dtio == 0);
[multiple changes] 2009-04-05 Daniel Kraft <d@domob.eu> PR fortran/38654 * io/read.c (read_f): Reworked to speed up floating point parsing. (convert_real): Use pointer-casting instead of memcpy and temporaries. 2009-04-05 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR libfortran/37754 * io/io.h (format_hash_entry): New structure for hash table. (format_hash_table): The hash table itself. (free_format_data): Revise function prototype. (free_format_hash_table, init_format_hash, free_format_hash): New function prototypes. * io/unit.c (close_unit_1): Use free_format_hash_table. * io/transfer.c (st_read_done, st_write_done): Free format data if internal unit. * io/format.c (free_format_hash_table): New function that frees any memory allocated previously for cached format data. (reset_node): New static helper function to reset the format counters for a format node. (reset_fnode_counters): New static function recursively calls reset_node to traverse the fnode tree. (format_hash): New simple hash function based on XOR, probabalistic, tosses collisions. (save_parsed_format): New static function to save the parsed format data to use again. (find_parsed_format): New static function searches the hash table looking for a match. (free_format_data): Revised to accept pointer to format data rather than the dtp pointer so that the function can be used in more places. (format_lex): Editorial. (parse_format_list): Set flag used to determine of format data hashing is to be used. Internal units are not persistent enough for this. (revert): Move to ne location in file. (parse_format): Use new functions to look for previously parsed format strings and use them rather than re-parse. If not found, saves the parsed format data for later use. 2009-04-05 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR libfortran/37754 * io/transfer.c (formatted_transfer_scalar): Remove this function by factoring it into two new functions, one for read and one for write, eliminating all the conditionals for read or write mode. (formatted transfer_scalar_read): New function. (formatted transfer_scalar_write): New function. (formatted_transfer): Use new functions. 2009-04-05 Janne Blomqvist <jb@gcc.gnu.org> PR libfortran/25561 libfortran/37754 * io/io.h (struct stream): Define new stream interface function pointers, and inline functions for accessing it. (struct fbuf): Use int instead of size_t, remove flushed element. (mem_alloc_w): New prototype. (mem_alloc_r): New prototype. (stream_at_bof): Remove prototype. (stream_at_eof): Remove prototype. (file_position): Remove prototype. (flush): Remove prototype. (stream_offset): Remove prototype. (unit_truncate): New prototype. (read_block_form): Change to return pointer, int* argument. (hit_eof): New prototype. (fbuf_init): Change prototype. (fbuf_reset): Change prototype. (fbuf_alloc): Change prototype. (fbuf_flush): Change prototype. (fbuf_seek): Change prototype. (fbuf_read): New prototype. (fbuf_getc_refill): New prototype. (fbuf_getc): New inline function. * io/fbuf.c (fbuf_init): Use int, get rid of flushed. (fbuf_debug): New function. (fbuf_reset): Flush, and return position offset. (fbuf_alloc): Simplify, don't flush, just realloc. (fbuf_flush): Make usable for read mode, salvage remaining bytes. (fbuf_seek): New whence argument. (fbuf_read): New function. (fbuf_getc_refill): New function. * io/file_pos.c (formatted_backspace): Use new stream interface. (unformatted_backspace): Likewise. (st_backspace): Make sure format buffer is reset, use new stream interface, use unit_truncate. (st_endfile): Likewise. (st_rewind): Likewise. * io/intrinsics.c: Use new stream interface. * io/list_read.c (push_char): Don't use u.p.scratch, use realloc to resize. (free_saved): Don't check u.p.scratch. (next_char): Use new stream interface, use fbuf_getc() for external files. (finish_list_read): flush format buffer. (nml_query): Update to use modified interface:s * io/open.c (test_endfile): Use new stream interface. (edit_modes): Likewise. (new_unit): Likewise, set bytes_left to 1 for stream files. * io/read.c (read_l): Use new read_block_form interface. (read_utf8): Likewise. (read_utf8_char1): Likewise. (read_default_char1): Likewise. (read_utf8_char4): Likewise. (read_default_char4): Likewise. (read_a): Likewise. (read_a_char4): Likewise. (read_decimal): Likewise. (read_radix): Likewise. (read_f): Likewise. * io/transfer.c (read_sf): Use fbuf_read and mem_alloc_r, remove usage of u.p.line_buffer. (read_block_form): Update interface to return pointer, use fbuf_read for direct access. (read_block_direct): Update to new stream interface. (write_block): Use mem_alloc_w for internal I/O. (write_buf): Update to new stream interface. (formatted_transfer_scalar): Don't use u.p.line_buffer, use fbuf_seek for external files. (us_read): Update to new stream interface. (us_write): Likewise. (data_transfer_init): Always check if we switch modes and flush. (skip_record): Use new stream interface, fix comparison. (next_record_r): Check for and reset u.p.at_eof, use new stream interface, use fbuf_getc for spacing. (write_us_marker): Update to new stream interface, don't inline. (next_record_w_unf): Likewise. (sset): New function. (next_record_w): Use new stream interface, use fbuf for printing newline. (next_record): Use new stream interface. (finalize_transfer): Remove sfree call, use new stream interface. (st_iolength_done): Don't use u.p.scratch. (st_read): Don't check for end of file. (st_read_done): Don't use u.p.scratch, use unit_truncate. (hit_eof): New function. * io/unit.c (init_units): Always init fbuf for formatted units. (update_position): Use new stream interface. (unit_truncate): New function. (finish_last_advance_record): Use fbuf to print newline. * io/unix.c: Remove unused SSIZE_MAX macro. (BUFFER_SIZE): Make static const variable rather than macro. (struct unix_stream): Remove dirty_offset, len, method, small_buffer. Order elements by decreasing size. (struct int_stream): Remove. (move_pos_offset): Remove usage of dirty_offset. (reset_stream): Remove. (do_read): Rename to raw_read, update to match new stream interface. (do_write): Rename to raw_write, update to new stream interface. (raw_seek): New function. (raw_tell): New function. (raw_truncate): New function. (raw_close): New function. (raw_flush): New function. (raw_init): New function. (fd_alloc): Remove. (fd_alloc_r_at): Remove. (fd_alloc_w_at): Remove. (fd_sfree): Remove. (fd_seek): Remove. (fd_truncate): Remove. (fd_sset): Remove. (fd_read): Remove. (fd_write): Remove. (fd_close): Remove. (fd_open): Remove. (fd_flush): Rename to buf_flush, update to new stream interface and unix_stream. (buf_read): New function. (buf_write): New function. (buf_seek): New function. (buf_tell): New function. (buf_truncate): New function. (buf_close): New function. (buf_init): New function. (mem_alloc_r_at): Rename to mem_alloc_r, change prototype. (mem_alloc_w_at): Rename to mem_alloc_w, change prototype. (mem_read): Change to match new stream interface. (mem_write): Likewise. (mem_seek): Likewise. (mem_tell): Likewise. (mem_truncate): Likewise. (mem_close): Likewise. (mem_flush): New function. (mem_sfree): Remove. (empty_internal_buffer): Cast to correct type. (open_internal): Use correct type, init function pointers. (fd_to_stream): Test whether to open file as buffered or raw. (output_stream): Remove mode set. (error_stream): Likewise. (flush_all_units_1): Use new stream interface. (flush_all_units): Likewise. (stream_at_bof): Remove. (stream_at_eof): Remove. (file_position): Remove. (file_length): Update logic to use stream interface. (flush): Remove. (stream_offset): Remove. * io/write.c (write_utf8_char4): Use int instead of size_t. (write_x): Extra safety check. (namelist_write_newline): Use new stream interface. From-SVN: r145571
2009-04-05 22:13:56 +02:00
/* Lookup format string to see if it has already been parsed. */
if (format_cache_ok)
[multiple changes] 2009-04-05 Daniel Kraft <d@domob.eu> PR fortran/38654 * io/read.c (read_f): Reworked to speed up floating point parsing. (convert_real): Use pointer-casting instead of memcpy and temporaries. 2009-04-05 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR libfortran/37754 * io/io.h (format_hash_entry): New structure for hash table. (format_hash_table): The hash table itself. (free_format_data): Revise function prototype. (free_format_hash_table, init_format_hash, free_format_hash): New function prototypes. * io/unit.c (close_unit_1): Use free_format_hash_table. * io/transfer.c (st_read_done, st_write_done): Free format data if internal unit. * io/format.c (free_format_hash_table): New function that frees any memory allocated previously for cached format data. (reset_node): New static helper function to reset the format counters for a format node. (reset_fnode_counters): New static function recursively calls reset_node to traverse the fnode tree. (format_hash): New simple hash function based on XOR, probabalistic, tosses collisions. (save_parsed_format): New static function to save the parsed format data to use again. (find_parsed_format): New static function searches the hash table looking for a match. (free_format_data): Revised to accept pointer to format data rather than the dtp pointer so that the function can be used in more places. (format_lex): Editorial. (parse_format_list): Set flag used to determine of format data hashing is to be used. Internal units are not persistent enough for this. (revert): Move to ne location in file. (parse_format): Use new functions to look for previously parsed format strings and use them rather than re-parse. If not found, saves the parsed format data for later use. 2009-04-05 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR libfortran/37754 * io/transfer.c (formatted_transfer_scalar): Remove this function by factoring it into two new functions, one for read and one for write, eliminating all the conditionals for read or write mode. (formatted transfer_scalar_read): New function. (formatted transfer_scalar_write): New function. (formatted_transfer): Use new functions. 2009-04-05 Janne Blomqvist <jb@gcc.gnu.org> PR libfortran/25561 libfortran/37754 * io/io.h (struct stream): Define new stream interface function pointers, and inline functions for accessing it. (struct fbuf): Use int instead of size_t, remove flushed element. (mem_alloc_w): New prototype. (mem_alloc_r): New prototype. (stream_at_bof): Remove prototype. (stream_at_eof): Remove prototype. (file_position): Remove prototype. (flush): Remove prototype. (stream_offset): Remove prototype. (unit_truncate): New prototype. (read_block_form): Change to return pointer, int* argument. (hit_eof): New prototype. (fbuf_init): Change prototype. (fbuf_reset): Change prototype. (fbuf_alloc): Change prototype. (fbuf_flush): Change prototype. (fbuf_seek): Change prototype. (fbuf_read): New prototype. (fbuf_getc_refill): New prototype. (fbuf_getc): New inline function. * io/fbuf.c (fbuf_init): Use int, get rid of flushed. (fbuf_debug): New function. (fbuf_reset): Flush, and return position offset. (fbuf_alloc): Simplify, don't flush, just realloc. (fbuf_flush): Make usable for read mode, salvage remaining bytes. (fbuf_seek): New whence argument. (fbuf_read): New function. (fbuf_getc_refill): New function. * io/file_pos.c (formatted_backspace): Use new stream interface. (unformatted_backspace): Likewise. (st_backspace): Make sure format buffer is reset, use new stream interface, use unit_truncate. (st_endfile): Likewise. (st_rewind): Likewise. * io/intrinsics.c: Use new stream interface. * io/list_read.c (push_char): Don't use u.p.scratch, use realloc to resize. (free_saved): Don't check u.p.scratch. (next_char): Use new stream interface, use fbuf_getc() for external files. (finish_list_read): flush format buffer. (nml_query): Update to use modified interface:s * io/open.c (test_endfile): Use new stream interface. (edit_modes): Likewise. (new_unit): Likewise, set bytes_left to 1 for stream files. * io/read.c (read_l): Use new read_block_form interface. (read_utf8): Likewise. (read_utf8_char1): Likewise. (read_default_char1): Likewise. (read_utf8_char4): Likewise. (read_default_char4): Likewise. (read_a): Likewise. (read_a_char4): Likewise. (read_decimal): Likewise. (read_radix): Likewise. (read_f): Likewise. * io/transfer.c (read_sf): Use fbuf_read and mem_alloc_r, remove usage of u.p.line_buffer. (read_block_form): Update interface to return pointer, use fbuf_read for direct access. (read_block_direct): Update to new stream interface. (write_block): Use mem_alloc_w for internal I/O. (write_buf): Update to new stream interface. (formatted_transfer_scalar): Don't use u.p.line_buffer, use fbuf_seek for external files. (us_read): Update to new stream interface. (us_write): Likewise. (data_transfer_init): Always check if we switch modes and flush. (skip_record): Use new stream interface, fix comparison. (next_record_r): Check for and reset u.p.at_eof, use new stream interface, use fbuf_getc for spacing. (write_us_marker): Update to new stream interface, don't inline. (next_record_w_unf): Likewise. (sset): New function. (next_record_w): Use new stream interface, use fbuf for printing newline. (next_record): Use new stream interface. (finalize_transfer): Remove sfree call, use new stream interface. (st_iolength_done): Don't use u.p.scratch. (st_read): Don't check for end of file. (st_read_done): Don't use u.p.scratch, use unit_truncate. (hit_eof): New function. * io/unit.c (init_units): Always init fbuf for formatted units. (update_position): Use new stream interface. (unit_truncate): New function. (finish_last_advance_record): Use fbuf to print newline. * io/unix.c: Remove unused SSIZE_MAX macro. (BUFFER_SIZE): Make static const variable rather than macro. (struct unix_stream): Remove dirty_offset, len, method, small_buffer. Order elements by decreasing size. (struct int_stream): Remove. (move_pos_offset): Remove usage of dirty_offset. (reset_stream): Remove. (do_read): Rename to raw_read, update to match new stream interface. (do_write): Rename to raw_write, update to new stream interface. (raw_seek): New function. (raw_tell): New function. (raw_truncate): New function. (raw_close): New function. (raw_flush): New function. (raw_init): New function. (fd_alloc): Remove. (fd_alloc_r_at): Remove. (fd_alloc_w_at): Remove. (fd_sfree): Remove. (fd_seek): Remove. (fd_truncate): Remove. (fd_sset): Remove. (fd_read): Remove. (fd_write): Remove. (fd_close): Remove. (fd_open): Remove. (fd_flush): Rename to buf_flush, update to new stream interface and unix_stream. (buf_read): New function. (buf_write): New function. (buf_seek): New function. (buf_tell): New function. (buf_truncate): New function. (buf_close): New function. (buf_init): New function. (mem_alloc_r_at): Rename to mem_alloc_r, change prototype. (mem_alloc_w_at): Rename to mem_alloc_w, change prototype. (mem_read): Change to match new stream interface. (mem_write): Likewise. (mem_seek): Likewise. (mem_tell): Likewise. (mem_truncate): Likewise. (mem_close): Likewise. (mem_flush): New function. (mem_sfree): Remove. (empty_internal_buffer): Cast to correct type. (open_internal): Use correct type, init function pointers. (fd_to_stream): Test whether to open file as buffered or raw. (output_stream): Remove mode set. (error_stream): Likewise. (flush_all_units_1): Use new stream interface. (flush_all_units): Likewise. (stream_at_bof): Remove. (stream_at_eof): Remove. (file_position): Remove. (file_length): Update logic to use stream interface. (flush): Remove. (stream_offset): Remove. * io/write.c (write_utf8_char4): Use int instead of size_t. (write_x): Extra safety check. (namelist_write_newline): Use new stream interface. From-SVN: r145571
2009-04-05 22:13:56 +02:00
{
dtp->u.p.fmt = find_parsed_format (dtp);
if (dtp->u.p.fmt != NULL)
{
dtp->u.p.fmt->reversion_ok = 0;
dtp->u.p.fmt->saved_token = FMT_NONE;
dtp->u.p.fmt->saved_format = NULL;
reset_fnode_counters (dtp);
return;
}
[multiple changes] 2009-04-05 Daniel Kraft <d@domob.eu> PR fortran/38654 * io/read.c (read_f): Reworked to speed up floating point parsing. (convert_real): Use pointer-casting instead of memcpy and temporaries. 2009-04-05 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR libfortran/37754 * io/io.h (format_hash_entry): New structure for hash table. (format_hash_table): The hash table itself. (free_format_data): Revise function prototype. (free_format_hash_table, init_format_hash, free_format_hash): New function prototypes. * io/unit.c (close_unit_1): Use free_format_hash_table. * io/transfer.c (st_read_done, st_write_done): Free format data if internal unit. * io/format.c (free_format_hash_table): New function that frees any memory allocated previously for cached format data. (reset_node): New static helper function to reset the format counters for a format node. (reset_fnode_counters): New static function recursively calls reset_node to traverse the fnode tree. (format_hash): New simple hash function based on XOR, probabalistic, tosses collisions. (save_parsed_format): New static function to save the parsed format data to use again. (find_parsed_format): New static function searches the hash table looking for a match. (free_format_data): Revised to accept pointer to format data rather than the dtp pointer so that the function can be used in more places. (format_lex): Editorial. (parse_format_list): Set flag used to determine of format data hashing is to be used. Internal units are not persistent enough for this. (revert): Move to ne location in file. (parse_format): Use new functions to look for previously parsed format strings and use them rather than re-parse. If not found, saves the parsed format data for later use. 2009-04-05 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR libfortran/37754 * io/transfer.c (formatted_transfer_scalar): Remove this function by factoring it into two new functions, one for read and one for write, eliminating all the conditionals for read or write mode. (formatted transfer_scalar_read): New function. (formatted transfer_scalar_write): New function. (formatted_transfer): Use new functions. 2009-04-05 Janne Blomqvist <jb@gcc.gnu.org> PR libfortran/25561 libfortran/37754 * io/io.h (struct stream): Define new stream interface function pointers, and inline functions for accessing it. (struct fbuf): Use int instead of size_t, remove flushed element. (mem_alloc_w): New prototype. (mem_alloc_r): New prototype. (stream_at_bof): Remove prototype. (stream_at_eof): Remove prototype. (file_position): Remove prototype. (flush): Remove prototype. (stream_offset): Remove prototype. (unit_truncate): New prototype. (read_block_form): Change to return pointer, int* argument. (hit_eof): New prototype. (fbuf_init): Change prototype. (fbuf_reset): Change prototype. (fbuf_alloc): Change prototype. (fbuf_flush): Change prototype. (fbuf_seek): Change prototype. (fbuf_read): New prototype. (fbuf_getc_refill): New prototype. (fbuf_getc): New inline function. * io/fbuf.c (fbuf_init): Use int, get rid of flushed. (fbuf_debug): New function. (fbuf_reset): Flush, and return position offset. (fbuf_alloc): Simplify, don't flush, just realloc. (fbuf_flush): Make usable for read mode, salvage remaining bytes. (fbuf_seek): New whence argument. (fbuf_read): New function. (fbuf_getc_refill): New function. * io/file_pos.c (formatted_backspace): Use new stream interface. (unformatted_backspace): Likewise. (st_backspace): Make sure format buffer is reset, use new stream interface, use unit_truncate. (st_endfile): Likewise. (st_rewind): Likewise. * io/intrinsics.c: Use new stream interface. * io/list_read.c (push_char): Don't use u.p.scratch, use realloc to resize. (free_saved): Don't check u.p.scratch. (next_char): Use new stream interface, use fbuf_getc() for external files. (finish_list_read): flush format buffer. (nml_query): Update to use modified interface:s * io/open.c (test_endfile): Use new stream interface. (edit_modes): Likewise. (new_unit): Likewise, set bytes_left to 1 for stream files. * io/read.c (read_l): Use new read_block_form interface. (read_utf8): Likewise. (read_utf8_char1): Likewise. (read_default_char1): Likewise. (read_utf8_char4): Likewise. (read_default_char4): Likewise. (read_a): Likewise. (read_a_char4): Likewise. (read_decimal): Likewise. (read_radix): Likewise. (read_f): Likewise. * io/transfer.c (read_sf): Use fbuf_read and mem_alloc_r, remove usage of u.p.line_buffer. (read_block_form): Update interface to return pointer, use fbuf_read for direct access. (read_block_direct): Update to new stream interface. (write_block): Use mem_alloc_w for internal I/O. (write_buf): Update to new stream interface. (formatted_transfer_scalar): Don't use u.p.line_buffer, use fbuf_seek for external files. (us_read): Update to new stream interface. (us_write): Likewise. (data_transfer_init): Always check if we switch modes and flush. (skip_record): Use new stream interface, fix comparison. (next_record_r): Check for and reset u.p.at_eof, use new stream interface, use fbuf_getc for spacing. (write_us_marker): Update to new stream interface, don't inline. (next_record_w_unf): Likewise. (sset): New function. (next_record_w): Use new stream interface, use fbuf for printing newline. (next_record): Use new stream interface. (finalize_transfer): Remove sfree call, use new stream interface. (st_iolength_done): Don't use u.p.scratch. (st_read): Don't check for end of file. (st_read_done): Don't use u.p.scratch, use unit_truncate. (hit_eof): New function. * io/unit.c (init_units): Always init fbuf for formatted units. (update_position): Use new stream interface. (unit_truncate): New function. (finish_last_advance_record): Use fbuf to print newline. * io/unix.c: Remove unused SSIZE_MAX macro. (BUFFER_SIZE): Make static const variable rather than macro. (struct unix_stream): Remove dirty_offset, len, method, small_buffer. Order elements by decreasing size. (struct int_stream): Remove. (move_pos_offset): Remove usage of dirty_offset. (reset_stream): Remove. (do_read): Rename to raw_read, update to match new stream interface. (do_write): Rename to raw_write, update to new stream interface. (raw_seek): New function. (raw_tell): New function. (raw_truncate): New function. (raw_close): New function. (raw_flush): New function. (raw_init): New function. (fd_alloc): Remove. (fd_alloc_r_at): Remove. (fd_alloc_w_at): Remove. (fd_sfree): Remove. (fd_seek): Remove. (fd_truncate): Remove. (fd_sset): Remove. (fd_read): Remove. (fd_write): Remove. (fd_close): Remove. (fd_open): Remove. (fd_flush): Rename to buf_flush, update to new stream interface and unix_stream. (buf_read): New function. (buf_write): New function. (buf_seek): New function. (buf_tell): New function. (buf_truncate): New function. (buf_close): New function. (buf_init): New function. (mem_alloc_r_at): Rename to mem_alloc_r, change prototype. (mem_alloc_w_at): Rename to mem_alloc_w, change prototype. (mem_read): Change to match new stream interface. (mem_write): Likewise. (mem_seek): Likewise. (mem_tell): Likewise. (mem_truncate): Likewise. (mem_close): Likewise. (mem_flush): New function. (mem_sfree): Remove. (empty_internal_buffer): Cast to correct type. (open_internal): Use correct type, init function pointers. (fd_to_stream): Test whether to open file as buffered or raw. (output_stream): Remove mode set. (error_stream): Likewise. (flush_all_units_1): Use new stream interface. (flush_all_units): Likewise. (stream_at_bof): Remove. (stream_at_eof): Remove. (file_position): Remove. (file_length): Update logic to use stream interface. (flush): Remove. (stream_offset): Remove. * io/write.c (write_utf8_char4): Use int instead of size_t. (write_x): Extra safety check. (namelist_write_newline): Use new stream interface. From-SVN: r145571
2009-04-05 22:13:56 +02:00
}
/* Not found so proceed as follows. */
char *fmt_string = fc_strdup_notrim (dtp->format, dtp->format_len);
dtp->format = fmt_string;
Combined get_mem and internal_malloc_size. 2012-03-26 Janne Blomqvist <jb@gcc.gnu.org> * runtime/memory.c (get_mem): Rename to xmalloc, check for zero size. (internal_malloc_size): Remove. * libgfortran.h (get_mem): Rename to xmalloc. (internal_malloc_size): Remove prototype. * Makefile.am (i_iall_c): Fix dependency. (i_iany_c): Likewise. (i_iparity_c): Likewise. (i_norm2_c): Likewise. (i_parity_c): Likewise. * Makefile.in: Regenerated. * m4/parity.m4: Fix typo in comment. * generated/all_l1.c: Regenerated. * generated/all_l16.c: Regenerated. * generated/all_l2.c: Regenerated. * generated/all_l4.c: Regenerated. * generated/all_l8.c: Regenerated. * generated/any_l1.c: Regenerated. * generated/any_l16.c: Regenerated. * generated/any_l2.c: Regenerated. * generated/any_l4.c: Regenerated. * generated/any_l8.c: Regenerated. * generated/bessel_r10.c: Regenerated. * generated/bessel_r16.c: Regenerated. * generated/bessel_r4.c: Regenerated. * generated/bessel_r8.c: Regenerated. * generated/count_16_l.c: Regenerated. * generated/count_1_l.c: Regenerated. * generated/count_2_l.c: Regenerated. * generated/count_4_l.c: Regenerated. * generated/count_8_l.c: Regenerated. * generated/cshift1_16.c: Regenerated. * generated/cshift1_4.c: Regenerated. * generated/cshift1_8.c: Regenerated. * generated/eoshift1_16.c: Regenerated. * generated/eoshift1_4.c: Regenerated. * generated/eoshift1_8.c: Regenerated. * generated/eoshift3_16.c: Regenerated. * generated/eoshift3_4.c: Regenerated. * generated/eoshift3_8.c: Regenerated. * generated/iall_i1.c: Regenerated. * generated/iall_i16.c: Regenerated. * generated/iall_i2.c: Regenerated. * generated/iall_i4.c: Regenerated. * generated/iall_i8.c: Regenerated. * generated/iany_i1.c: Regenerated. * generated/iany_i16.c: Regenerated. * generated/iany_i2.c: Regenerated. * generated/iany_i4.c: Regenerated. * generated/iany_i8.c: Regenerated. * generated/in_pack_c10.c: Regenerated. * generated/in_pack_c16.c: Regenerated. * generated/in_pack_c4.c: Regenerated. * generated/in_pack_c8.c: Regenerated. * generated/in_pack_i1.c: Regenerated. * generated/in_pack_i16.c: Regenerated. * generated/in_pack_i2.c: Regenerated. * generated/in_pack_i4.c: Regenerated. * generated/in_pack_i8.c: Regenerated. * generated/in_pack_r10.c: Regenerated. * generated/in_pack_r16.c: Regenerated. * generated/in_pack_r4.c: Regenerated. * generated/in_pack_r8.c: Regenerated. * generated/iparity_i1.c: Regenerated. * generated/iparity_i16.c: Regenerated. * generated/iparity_i2.c: Regenerated. * generated/iparity_i4.c: Regenerated. * generated/iparity_i8.c: Regenerated. * generated/matmul_c10.c: Regenerated. * generated/matmul_c16.c: Regenerated. * generated/matmul_c4.c: Regenerated. * generated/matmul_c8.c: Regenerated. * generated/matmul_i1.c: Regenerated. * generated/matmul_i16.c: Regenerated. * generated/matmul_i2.c: Regenerated. * generated/matmul_i4.c: Regenerated. * generated/matmul_i8.c: Regenerated. * generated/matmul_l16.c: Regenerated. * generated/matmul_l4.c: Regenerated. * generated/matmul_l8.c: Regenerated. * generated/matmul_r10.c: Regenerated. * generated/matmul_r16.c: Regenerated. * generated/matmul_r4.c: Regenerated. * generated/matmul_r8.c: Regenerated. * generated/maxloc0_16_i1.c: Regenerated. * generated/maxloc0_16_i16.c: Regenerated. * generated/maxloc0_16_i2.c: Regenerated. * generated/maxloc0_16_i4.c: Regenerated. * generated/maxloc0_16_i8.c: Regenerated. * generated/maxloc0_16_r10.c: Regenerated. * generated/maxloc0_16_r16.c: Regenerated. * generated/maxloc0_16_r4.c: Regenerated. * generated/maxloc0_16_r8.c: Regenerated. * generated/maxloc0_4_i1.c: Regenerated. * generated/maxloc0_4_i16.c: Regenerated. * generated/maxloc0_4_i2.c: Regenerated. * generated/maxloc0_4_i4.c: Regenerated. * generated/maxloc0_4_i8.c: Regenerated. * generated/maxloc0_4_r10.c: Regenerated. * generated/maxloc0_4_r16.c: Regenerated. * generated/maxloc0_4_r4.c: Regenerated. * generated/maxloc0_4_r8.c: Regenerated. * generated/maxloc0_8_i1.c: Regenerated. * generated/maxloc0_8_i16.c: Regenerated. * generated/maxloc0_8_i2.c: Regenerated. * generated/maxloc0_8_i4.c: Regenerated. * generated/maxloc0_8_i8.c: Regenerated. * generated/maxloc0_8_r10.c: Regenerated. * generated/maxloc0_8_r16.c: Regenerated. * generated/maxloc0_8_r4.c: Regenerated. * generated/maxloc0_8_r8.c: Regenerated. * generated/maxloc1_16_i1.c: Regenerated. * generated/maxloc1_16_i16.c: Regenerated. * generated/maxloc1_16_i2.c: Regenerated. * generated/maxloc1_16_i4.c: Regenerated. * generated/maxloc1_16_i8.c: Regenerated. * generated/maxloc1_16_r10.c: Regenerated. * generated/maxloc1_16_r16.c: Regenerated. * generated/maxloc1_16_r4.c: Regenerated. * generated/maxloc1_16_r8.c: Regenerated. * generated/maxloc1_4_i1.c: Regenerated. * generated/maxloc1_4_i16.c: Regenerated. * generated/maxloc1_4_i2.c: Regenerated. * generated/maxloc1_4_i4.c: Regenerated. * generated/maxloc1_4_i8.c: Regenerated. * generated/maxloc1_4_r10.c: Regenerated. * generated/maxloc1_4_r16.c: Regenerated. * generated/maxloc1_4_r4.c: Regenerated. * generated/maxloc1_4_r8.c: Regenerated. * generated/maxloc1_8_i1.c: Regenerated. * generated/maxloc1_8_i16.c: Regenerated. * generated/maxloc1_8_i2.c: Regenerated. * generated/maxloc1_8_i4.c: Regenerated. * generated/maxloc1_8_i8.c: Regenerated. * generated/maxloc1_8_r10.c: Regenerated. * generated/maxloc1_8_r16.c: Regenerated. * generated/maxloc1_8_r4.c: Regenerated. * generated/maxloc1_8_r8.c: Regenerated. * generated/maxval_i1.c: Regenerated. * generated/maxval_i16.c: Regenerated. * generated/maxval_i2.c: Regenerated. * generated/maxval_i4.c: Regenerated. * generated/maxval_i8.c: Regenerated. * generated/maxval_r10.c: Regenerated. * generated/maxval_r16.c: Regenerated. * generated/maxval_r4.c: Regenerated. * generated/maxval_r8.c: Regenerated. * generated/minloc0_16_i1.c: Regenerated. * generated/minloc0_16_i16.c: Regenerated. * generated/minloc0_16_i2.c: Regenerated. * generated/minloc0_16_i4.c: Regenerated. * generated/minloc0_16_i8.c: Regenerated. * generated/minloc0_16_r10.c: Regenerated. * generated/minloc0_16_r16.c: Regenerated. * generated/minloc0_16_r4.c: Regenerated. * generated/minloc0_16_r8.c: Regenerated. * generated/minloc0_4_i1.c: Regenerated. * generated/minloc0_4_i16.c: Regenerated. * generated/minloc0_4_i2.c: Regenerated. * generated/minloc0_4_i4.c: Regenerated. * generated/minloc0_4_i8.c: Regenerated. * generated/minloc0_4_r10.c: Regenerated. * generated/minloc0_4_r16.c: Regenerated. * generated/minloc0_4_r4.c: Regenerated. * generated/minloc0_4_r8.c: Regenerated. * generated/minloc0_8_i1.c: Regenerated. * generated/minloc0_8_i16.c: Regenerated. * generated/minloc0_8_i2.c: Regenerated. * generated/minloc0_8_i4.c: Regenerated. * generated/minloc0_8_i8.c: Regenerated. * generated/minloc0_8_r10.c: Regenerated. * generated/minloc0_8_r16.c: Regenerated. * generated/minloc0_8_r4.c: Regenerated. * generated/minloc0_8_r8.c: Regenerated. * generated/minloc1_16_i1.c: Regenerated. * generated/minloc1_16_i16.c: Regenerated. * generated/minloc1_16_i2.c: Regenerated. * generated/minloc1_16_i4.c: Regenerated. * generated/minloc1_16_i8.c: Regenerated. * generated/minloc1_16_r10.c: Regenerated. * generated/minloc1_16_r16.c: Regenerated. * generated/minloc1_16_r4.c: Regenerated. * generated/minloc1_16_r8.c: Regenerated. * generated/minloc1_4_i1.c: Regenerated. * generated/minloc1_4_i16.c: Regenerated. * generated/minloc1_4_i2.c: Regenerated. * generated/minloc1_4_i4.c: Regenerated. * generated/minloc1_4_i8.c: Regenerated. * generated/minloc1_4_r10.c: Regenerated. * generated/minloc1_4_r16.c: Regenerated. * generated/minloc1_4_r4.c: Regenerated. * generated/minloc1_4_r8.c: Regenerated. * generated/minloc1_8_i1.c: Regenerated. * generated/minloc1_8_i16.c: Regenerated. * generated/minloc1_8_i2.c: Regenerated. * generated/minloc1_8_i4.c: Regenerated. * generated/minloc1_8_i8.c: Regenerated. * generated/minloc1_8_r10.c: Regenerated. * generated/minloc1_8_r16.c: Regenerated. * generated/minloc1_8_r4.c: Regenerated. * generated/minloc1_8_r8.c: Regenerated. * generated/minval_i1.c: Regenerated. * generated/minval_i16.c: Regenerated. * generated/minval_i2.c: Regenerated. * generated/minval_i4.c: Regenerated. * generated/minval_i8.c: Regenerated. * generated/minval_r10.c: Regenerated. * generated/minval_r16.c: Regenerated. * generated/minval_r4.c: Regenerated. * generated/minval_r8.c: Regenerated. * generated/norm2_r10.c: Regenerated. * generated/norm2_r16.c: Regenerated. * generated/norm2_r4.c: Regenerated. * generated/norm2_r8.c: Regenerated. * generated/pack_c10.c: Regenerated. * generated/pack_c16.c: Regenerated. * generated/pack_c4.c: Regenerated. * generated/pack_c8.c: Regenerated. * generated/pack_i1.c: Regenerated. * generated/pack_i16.c: Regenerated. * generated/pack_i2.c: Regenerated. * generated/pack_i4.c: Regenerated. * generated/pack_i8.c: Regenerated. * generated/pack_r10.c: Regenerated. * generated/pack_r16.c: Regenerated. * generated/pack_r4.c: Regenerated. * generated/pack_r8.c: Regenerated. * generated/parity_l1.c: Regenerated. * generated/parity_l16.c: Regenerated. * generated/parity_l2.c: Regenerated. * generated/parity_l4.c: Regenerated. * generated/parity_l8.c: Regenerated. * generated/product_c10.c: Regenerated. * generated/product_c16.c: Regenerated. * generated/product_c4.c: Regenerated. * generated/product_c8.c: Regenerated. * generated/product_i1.c: Regenerated. * generated/product_i16.c: Regenerated. * generated/product_i2.c: Regenerated. * generated/product_i4.c: Regenerated. * generated/product_i8.c: Regenerated. * generated/product_r10.c: Regenerated. * generated/product_r16.c: Regenerated. * generated/product_r4.c: Regenerated. * generated/product_r8.c: Regenerated. * generated/reshape_c10.c: Regenerated. * generated/reshape_c16.c: Regenerated. * generated/reshape_c4.c: Regenerated. * generated/reshape_c8.c: Regenerated. * generated/reshape_i16.c: Regenerated. * generated/reshape_i4.c: Regenerated. * generated/reshape_i8.c: Regenerated. * generated/reshape_r10.c: Regenerated. * generated/reshape_r16.c: Regenerated. * generated/reshape_r4.c: Regenerated. * generated/reshape_r8.c: Regenerated. * generated/shape_i16.c: Regenerated. * generated/shape_i4.c: Regenerated. * generated/shape_i8.c: Regenerated. * generated/spread_c10.c: Regenerated. * generated/spread_c16.c: Regenerated. * generated/spread_c4.c: Regenerated. * generated/spread_c8.c: Regenerated. * generated/spread_i1.c: Regenerated. * generated/spread_i16.c: Regenerated. * generated/spread_i2.c: Regenerated. * generated/spread_i4.c: Regenerated. * generated/spread_i8.c: Regenerated. * generated/spread_r10.c: Regenerated. * generated/spread_r16.c: Regenerated. * generated/spread_r4.c: Regenerated. * generated/spread_r8.c: Regenerated. * generated/sum_c10.c: Regenerated. * generated/sum_c16.c: Regenerated. * generated/sum_c4.c: Regenerated. * generated/sum_c8.c: Regenerated. * generated/sum_i1.c: Regenerated. * generated/sum_i16.c: Regenerated. * generated/sum_i2.c: Regenerated. * generated/sum_i4.c: Regenerated. * generated/sum_i8.c: Regenerated. * generated/sum_r10.c: Regenerated. * generated/sum_r16.c: Regenerated. * generated/sum_r4.c: Regenerated. * generated/sum_r8.c: Regenerated. * generated/transpose_c10.c: Regenerated. * generated/transpose_c16.c: Regenerated. * generated/transpose_c4.c: Regenerated. * generated/transpose_c8.c: Regenerated. * generated/transpose_i16.c: Regenerated. * generated/transpose_i4.c: Regenerated. * generated/transpose_i8.c: Regenerated. * generated/transpose_r10.c: Regenerated. * generated/transpose_r16.c: Regenerated. * generated/transpose_r4.c: Regenerated. * generated/transpose_r8.c: Regenerated. * generated/unpack_c10.c: Regenerated. * generated/unpack_c16.c: Regenerated. * generated/unpack_c4.c: Regenerated. * generated/unpack_c8.c: Regenerated. * generated/unpack_i1.c: Regenerated. * generated/unpack_i16.c: Regenerated. * generated/unpack_i2.c: Regenerated. * generated/unpack_i4.c: Regenerated. * generated/unpack_i8.c: Regenerated. * generated/unpack_r10.c: Regenerated. * generated/unpack_r16.c: Regenerated. * generated/unpack_r4.c: Regenerated. * generated/unpack_r8.c: Regenerated. * intrinsics/cshift0.c: Use xmalloc. * intrinsics/ctime.c: Likewise. * intrinsics/date_and_time.c: Likewise. * intrinsics/eoshift0.c: Likewise. * intrinsics/eoshift2.c: Likewise. * intrinsics/getlog.c: Likewise. * intrinsics/pack_generic.c: Likewise. * intrinsics/reshape_generic.c: Likewise. * intrinsics/spread_generic.c: Likewise. * intrinsics/string_intrinsics_inc.c: Likewise. * intrinsics/transpose_generic.c: Likewise. * intrinsics/unpack_generic.c: Likewise. * io/fbuf.c: Likewise. * io/format.c: Likewise. * io/intrinsics.c: Likewise. * io/list_read.c: Likewise. * io/open.c: Likewise. * io/transfer.c: Likewise. * io/unit.c: Likewise. * io/unix.c: Likewise. * io/write.c: Likewise. * m4/bessel.m4: Likewise. * m4/cshift1.m4: Likewise. * m4/eoshift1.m4: Likewise. * m4/eoshift3.m4: Likewise. * m4/iforeach.m4: Likewise. * m4/ifunction.m4: Likewise. * m4/ifunction_logical.m4: Likewise. * m4/in_pack.m4: Likewise. * m4/matmul.m4: Likewise. * m4/matmull.m4: Likewise. * m4/pack.m4: Likewise. * m4/reshape.m4: Likewise. * m4/shape.m4: Likewise. * m4/spread.m4: Likewise. * m4/transpose.m4: Likewise. * m4/unpack.m4: Likewise. * runtime/convert_char.c: Likewise. * runtime/environ.c: Likewise. * runtime/in_pack_generic.c: Likewise. From-SVN: r185806
2012-03-26 17:16:05 +02:00
dtp->u.p.fmt = fmt = xmalloc (sizeof (format_data));
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
fmt->format_string = dtp->format;
fmt->format_string_len = dtp->format_len;
fmt->string = NULL;
fmt->saved_token = FMT_NONE;
fmt->error = NULL;
fmt->value = 0;
/* Initialize variables used during traversal of the tree. */
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
fmt->reversion_ok = 0;
fmt->saved_format = NULL;
[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 07:36:22 +02:00
/* Initialize the fnode_array. */
memset (&(fmt->array), 0, sizeof(fmt->array));
/* Allocate the first format node as the root of the tree. */
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
fmt->last = &fmt->array;
fmt->last->next = NULL;
fmt->avail = &fmt->array.array[0];
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
memset (fmt->avail, 0, sizeof (*fmt->avail));
fmt->avail->format = FMT_LPAREN;
fmt->avail->repeat = 1;
fmt->avail++;
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
if (format_lex (fmt) == FMT_LPAREN)
fmt->array.array[0].u.child = parse_format_list (dtp, &seen_data_desc);
else
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
fmt->error = "Missing initial left parenthesis in format";
if (format_cache_ok)
save_parsed_format (dtp);
else
dtp->u.p.format_not_saved = 1;
if (fmt->error)
format_error (dtp, NULL, fmt->error);
}
/* next_format0()-- Get the next format node without worrying about
reversion. Returns NULL when we hit the end of the list.
Parenthesis nodes are incremented after the list has been
exhausted, other nodes are incremented before they are returned. */
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
static const fnode *
next_format0 (fnode *f)
{
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
const fnode *r;
if (f == NULL)
return NULL;
if (f->format != FMT_LPAREN)
{
f->count++;
if (f->count <= f->repeat)
return f;
f->count = 0;
return NULL;
}
/* Deal with a parenthesis node with unlimited format. */
if (f->repeat == -2) /* -2 signifies unlimited. */
for (;;)
{
if (f->current == NULL)
f->current = f->u.child;
for (; f->current != NULL; f->current = f->current->next)
{
r = next_format0 (f->current);
if (r != NULL)
return r;
}
}
/* Deal with a parenthesis node with specific repeat count. */
for (; f->count < f->repeat; f->count++)
{
if (f->current == NULL)
f->current = f->u.child;
for (; f->current != NULL; f->current = f->current->next)
{
r = next_format0 (f->current);
if (r != NULL)
return r;
}
}
f->count = 0;
return NULL;
}
/* next_format()-- Return the next format node. If the format list
ends up being exhausted, we do reversion. Reversion is only
allowed if we've seen a data descriptor since the
initialization or the last reversion. We return NULL if there
are no more data descriptors to return (which is an error
condition). */
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
const fnode *
next_format (st_parameter_dt *dtp)
{
format_token t;
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
const fnode *f;
format_data *fmt = dtp->u.p.fmt;
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
if (fmt->saved_format != NULL)
{ /* Deal with a pushed-back format node */
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
f = fmt->saved_format;
fmt->saved_format = NULL;
goto done;
}
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
f = next_format0 (&fmt->array.array[0]);
if (f == NULL)
{
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
if (!fmt->reversion_ok)
return NULL;
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
fmt->reversion_ok = 0;
revert (dtp);
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
f = next_format0 (&fmt->array.array[0]);
if (f == NULL)
{
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
format_error (dtp, NULL, reversion_error);
return NULL;
}
/* Push the first reverted token and return a colon node in case
there are no more data items. */
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
fmt->saved_format = f;
return &colon_node;
}
/* If this is a data edit descriptor, then reversion has become OK. */
done:
t = f->format;
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
if (!fmt->reversion_ok &&
(t == FMT_I || t == FMT_B || t == FMT_O || t == FMT_Z || t == FMT_F ||
t == FMT_E || t == FMT_EN || t == FMT_ES || t == FMT_G || t == FMT_L ||
[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 07:36:22 +02:00
t == FMT_A || t == FMT_D || t == FMT_DT))
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
fmt->reversion_ok = 1;
return f;
}
/* unget_format()-- Push the given format back so that it will be
returned on the next call to next_format() without affecting
counts. This is necessary when we've encountered a data
descriptor, but don't know what the data item is yet. The format
node is pushed back, and we return control to the main program,
which calls the library back with the data item (or not). */
void
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
unget_format (st_parameter_dt *dtp, const fnode *f)
{
re PR fortran/14943 (read/write code generation is not thread safe) gcc/fortran/ PR fortran/14943 PR fortran/21647 * Make-lang.in (fortran/trans-io.o): Depend on fortran/ioparm.def. * dump-parse-tree.c (gfc_show_code_node): Dump c->block for EXEC_{READ,WRITE,IOLENGTH} nodes. * io.c (terminate_io, match_io, gfc_match_inquire): Put data transfer commands into EXEC_{READ,WRITE,IOLENGTH}'s code->block. * resolve.c (resolve_blocks): Handle EXEC_{READ,WRITE,IOLENGTH}. * trans-io.c (ioparm_unit, ioparm_err, ioparm_end, ioparm_eor, ioparm_list_format, ioparm_library_return, ioparm_iostat, ioparm_exist, ioparm_opened, ioparm_number, ioparm_named, ioparm_rec, ioparm_nextrec, ioparm_size, ioparm_recl_in, ioparm_recl_out, ioparm_iolength, ioparm_file, ioparm_file_len, ioparm_status, ioparm_status_len, ioparm_access, ioparm_access_len, ioparm_form, ioparm_form_len, ioparm_blank, ioparm_blank_len, ioparm_position, ioparm_position_len, ioparm_action, ioparm_action_len, ioparm_delim, ioparm_delim_len, ioparm_pad, ioparm_pad_len, ioparm_format, ioparm_format_len, ioparm_advance, ioparm_advance_len, ioparm_name, ioparm_name_len, ioparm_internal_unit, ioparm_internal_unit_len, ioparm_internal_unit_desc, ioparm_sequential, ioparm_sequential_len, ioparm_direct, ioparm_direct_len, ioparm_formatted, ioparm_formatted_len, ioparm_unformatted, ioparm_unformatted_len, ioparm_read, ioparm_read_len, ioparm_write, ioparm_write_len, ioparm_readwrite, ioparm_readwrite_len, ioparm_namelist_name, ioparm_namelist_name_len, ioparm_namelist_read_mode, ioparm_iomsg, ioparm_iomsg_len, ioparm_var): Remove. (enum ioparam_type, enum iofield_type, enum iofield, enum iocall): New enums. (gfc_st_parameter_field, gfc_st_parameter): New typedefs. (st_parameter, st_parameter_field, iocall): New variables. (ADD_FIELD, ADD_STRING): Remove. (dt_parm, dt_post_end_block): New variables. (gfc_build_st_parameter): New function. (gfc_build_io_library_fndecls): Use it. Initialize iocall array rather than ioparm_*, add extra first arguments to the function types. (set_parameter_const): New function. (set_parameter_value): Add type argument, return a bitmask. Changed to set a field in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_parameter_ref): Likewise. If requested var has different size than what field should point to, call with a temporary and then copy into the user variable. Add postblock argument. (set_string): Remove var_len argument, add type argument, return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_internal_unit): Remove iunit, iunit_len, iunit_desc arguments, add var argument. Return a bitmask. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_ioparm variable. (set_flag): Removed. (io_result): Add var argument. Changed to read common.flags field from automatic structure variable and bitwise AND it with 3. (set_error_locus): Add var argument. Changed to set fields in automatic structure variable rather than set a field in a global _gfortran_{filename,line} variables. (gfc_trans_open): Use gfc_start_block rather than gfc_init_block. Create a temporary st_parameter_* structure. Adjust callers of all above mentioned functions. Pass address of the temporary variable as first argument to the generated function call. Use iocall array rather than ioparm_* separate variables. (gfc_trans_close, build_filepos, gfc_trans_inquire): Likewise. (build_dt): Likewise. Change first argument to tree from tree *. Don't dereference code->ext.dt if last_dt == INQUIRE. Emit IOLENGTH argument setup here. Set dt_parm/dt_post_end_block variables and gfc_trans_code the nested data transfer commands in code->block. (gfc_trans_iolength): Just set last_dt and call build_dt immediately. (transfer_namelist_element): Pass address of dt_parm variable to generated functions. Use iocall array rather than ioparm_* separate variables. (gfc_trans_backspace, gfc_trans_endfile, gfc_trans_rewind, gfc_trans_flush, gfc_trans_read, gfc_trans_write): Use iocall array rather than ioparm_* separate variables. (gfc_trans_dt_end): Likewise. Pass address of dt_parm variable as first argument to generated function. Adjust io_result caller. Prepend dt_post_end_block before io_result code. (transfer_expr): Use iocall array rather than ioparm_* separate variables. Pass address of dt_parm variables as first argument to generated functions. * ioparm.def: New file. gcc/testsuite/ PR fortran/24774 * gfortran.dg/inquire_9.f90: New test. PR fortran/21647 * gfortran.fortran-torture/execute/inquire_5.f90: New test. libgfortran/ PR fortran/24774 PR fortran/14943 PR fortran/21647 * Makefile.am (AM_CPPFLAGS): Add gcc directories as -I paths, add -D_GNU_SOURCE. * Makefile.in: Regenerated. * acinclude.m4 (LIBGFOR_CHECK_SYNC_FETCH_AND_ADD, LIBGFOR_CHECK_GTHR_DEFAULT, LIBGFOR_CHECK_PRAGMA_WEAK): New macros. * configure.ac: Add them. * configure: Rebuilt. * config.h.in: Rebuilt. * libtool-version: Bump libgfortran.so SONAME to libgfortran.so.1. * libgfortran.h (library_start, show_locus, internal_error, generate_error, find_option): Add st_parameter_common * argument. (library_end): Change into a dummy macro. * io/io.h: Include gthr.h. (SUPPORTS_WEAK): Define if HAVE_PRAGMA_WEAK. (CHARACTER): Remove define. (st_parameter, global_t): Remove typedef. (ioparm, g, ionml, current_unit): Remove variables. (init_error_stream): Remove prototype. (CHARACTER1, CHARACTER2): Define. (st_parameter_common, st_parameter_open, st_parameter_close, st_parameter_filepos, st_parameter_inquire, st_parameter_dt): New typedefs. (IOPARM_LIBRETURN_MASK, IOPARM_LIBRETURN_OK, IOPARM_LIBRETURN_ERROR, IOPARM_LIBRETURN_END, IOPARM_LIBRETURN_EOR, IOPARM_ERR, IOPARM_END, IOPARM_EOR, IOPARM_HAS_IOSTAT, IOPARM_HAS_IOMSG, IOPARM_COMMON_MASK, IOPARM_OPEN_HAS_RECL_IN, IOPARM_OPEN_HAS_FILE, IOPARM_OPEN_HAS_STATUS, IOPARM_OPEN_HAS_ACCESS, IOPARM_OPEN_HAS_FORM, IOPARM_OPEN_HAS_BLANK, IOPARM_OPEN_HAS_POSITION, IOPARM_OPEN_HAS_ACTION, IOPARM_OPEN_HAS_DELIM, IOPARM_OPEN_HAS_PAD, IOPARM_CLOSE_HAS_STATUS, IOPARM_INQUIRE_HAS_EXIST, IOPARM_INQUIRE_HAS_OPENED, IOPARM_INQUIRE_HAS_NUMBER, IOPARM_INQUIRE_HAS_NAMED, IOPARM_INQUIRE_HAS_NEXTREC, IOPARM_INQUIRE_HAS_RECL_OUT, IOPARM_INQUIRE_HAS_FILE, IOPARM_INQUIRE_HAS_ACCESS, IOPARM_INQUIRE_HAS_FORM, IOPARM_INQUIRE_HAS_BLANK, IOPARM_INQUIRE_HAS_POSITION, IOPARM_INQUIRE_HAS_ACTION, IOPARM_INQUIRE_HAS_DELIM, IOPARM_INQUIRE_HAS_PAD, IOPARM_INQUIRE_HAS_NAME, IOPARM_INQUIRE_HAS_SEQUENTIAL, IOPARM_INQUIRE_HAS_DIRECT, IOPARM_INQUIRE_HAS_FORMATTED, IOPARM_INQUIRE_HAS_UNFORMATTED, IOPARM_INQUIRE_HAS_READ, IOPARM_INQUIRE_HAS_WRITE, IOPARM_INQUIRE_HAS_READWRITE, IOPARM_DT_LIST_FORMAT, IOPARM_DT_NAMELIST_READ_MODE, IOPARM_DT_HAS_REC, IOPARM_DT_HAS_SIZE, IOPARM_DT_HAS_IOLENGTH, IOPARM_DT_HAS_FORMAT, IOPARM_DT_HAS_ADVANCE, IOPARM_DT_HAS_INTERNAL_UNIT, IOPARM_DT_HAS_NAMELIST_NAME, IOPARM_DT_IONML_SET): Define. (gfc_unit): Add lock, waiting and close fields. Change file from flexible array member into pointer to char. (open_external): Add st_parameter_open * argument. (find_file, file_exists): Add file and file_len arguments. (flush_all_units): New prototype. (max_offset, unit_root, unit_lock): New variable. (is_internal_unit, is_array_io, next_array_record, parse_format, next_format, unget_format, format_error, read_block, write_block, next_record, convert_real, read_a, read_f, read_l, read_x, read_radix, read_decimal, list_formatted_read, finish_list_read, namelist_read, namelist_write, write_a, write_b, write_d, write_e, write_en, write_es, write_f, write_i, write_l, write_o, write_x, write_z, list_formatted_write, get_unit): Add st_parameter_dt * argument. (insert_unit): Remove prototype. (find_or_create_unit, unlock_unit): New prototype. (new_unit): Return gfc_unit *. Add st_parameter_open * and gfc_unit * arguments. (free_fnodes): Remove prototype. (free_format_data): New prototype. (scratch): Remove. (init_at_eol): Remove prototype. (free_ionml): New prototype. (inc_waiting_locked, predec_waiting_locked, dec_waiting_unlocked): New inline functions. * io/unit.c (max_offset, unit_root, unit_lock): New variables. (insert): Adjust os_error caller. (insert_unit): Made static. Allocate memory here, initialize lock and after inserting it return it, locked. (delete_unit): Adjust for deletion of g. (find_unit_1): New function. (find_unit): Use it. (find_or_create_unit): New function. (get_unit): Add dtp argument, change meaning of the int argument as creation request flag. Adjust for different st_* calling conventions, lock internal unit's lock before returning it and removal of g. Call find_unit_1 instead of find_unit. (is_internal_unit, is_array_io): Add dtp argument, adjust for removal of most of global variables. (init_units): Initialize unit_lock. Adjust insert_unit callers and adjust for g removal. (close_unit_1): New function. (close_unit): Use it. (unlock_unit): New function. (close_units): Lock unit_lock, use close_unit_1 rather than close_unit. * io/close.c (st_close): Add clp argument. Adjust for new st_* calling conventions and internal function API changes. * io/file_pos.c (st_backspace, st_endfile, st_rewind, st_flush): Add fpp argument. Adjust for new st_* calling conventions and internal function API changes. (formatted_backspace, unformatted_backspace): Likewise. Add u argument. * io/open.c (edit_modes, st_open): Add opp argument. Adjust for new st_* calling conventions and internal function API changes. (already_open): Likewise. If not HAVE_UNLINK_OPEN_FILE, unlink scratch file. Instead of calling close_unit just call sclose, free u->file if any and clear a few u fields before calling new_unit. (new_unit): Return gfc_unit *. Add opp and u arguments. Adjust for new st_* calling conventions and internal function API changes. Don't allocate unit here, rather than work with already created unit u already locked on entry. In case of failure, close_unit it. * io/unix.c: Include unix.h. (BUFFER_SIZE, unix_stream): Moved to unix.h. (unit_to_fd): Add unlock_unit call. (tempfile): Add opp argument, use its fields rather than ioparm. (regular_file): Likewise. (open_external): Likewise. Only unlink file if fd >= 0. (init_error_stream): Add error argument, set structure it points to rather than filling static variable and returning its address. (FIND_FILE0_DECL, FIND_FILE0_ARGS): Define. (find_file0): Use them. Don't crash if u->s == NULL. (find_file): Add file and file_len arguments, use them instead of ioparm. Add locking. Pass either an array of 2 struct stat or file and file_len pair to find_file0. (flush_all_units_1, flush_all_units): New functions. (file_exists): Add file and file_len arguments, use them instead of ioparm. * io/unix.h: New file. * io/lock.c (ioparm, g, ionml): Remove variables. (library_start): Add cmp argument, adjust for new st_* calling conventions. (library_end): Remove. (free_ionml): New function. * io/inquire.c (inquire_via_unit, inquire_via_filename, st_inquire): Add iqp argument, adjust for new st_* calling conventions and internal function API changes. * io/format.c (FARRAY_SIZE): Decrease to 64. (fnode_array, format_data): New typedefs. (avail, array, format_string, string, error, saved_token, value, format_string_len, reversion_ok, saved_format): Remove variables. (colon_node): Add const. (free_fnode, free_fnodes): Remove. (free_format_data): New function. (next_char, unget_char, get_fnode, format_lex, parse_format_list, format_error, parse_format, revert, unget_format, next_test): Add fmt or dtp arguments, pass it all around, adjust for internal function API changes and adjust for removal of global variables. (next_format): Likewise. Constify return type. (next_format0): Constify return type. * io/transfer.c (current_unit, sf_seen_eor, eor_condition, max_pos, skips, pending_spaces, scratch, line_buffer, advance_status, transfer): Remove variables. (transfer_integer, transfer_real, transfer_logical, transfer_character, transfer_complex, transfer_array, current_mode, read_sf, read_block, read_block_direct, write_block, write_block_direct, unformatted_read, unformatted_write, type_name, write_constant_string, require_type, formatted_transfer_scalar, us_read, us_write, pre_position, data_transfer_init, next_record_r, next_record_w, next_record, finalize_transfer, iolength_transfer, iolength_transfer_init, st_iolength, st_iolength_done, st_read, st_read_done, st_write, st_write_done, st_set_nml_var, st_set_nml_var_dim, next_array_record): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. * io/list_read.c (repeat_count, saved_length, saved_used, input_complete, at_eol, comma_flag, last_char, saved_string, saved_type, namelist_mode, nml_read_error, value, parse_err_msg, nml_err_msg, prev_nl): Remove variables. (push_char, free_saved, next_char, unget_char, eat_spaces, eat_separator, finish_separator, nml_bad_return, convert_integer, parse_repeat, read_logical, read_integer, read_character, parse_real, read_complex, read_real, check_type, list_formatted_read_scalar, list_formatted_read, finish_list_read, find_nml_node, nml_untouch_nodes, nml_match_name, nml_query, namelist_read): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (nml_parse_qualifier): Likewise. Add parse_err_msg argument. (nml_read_obj): Likewise. Add pprev_nl, nml_err_msg, clow and chigh arguments. (nml_get_obj_data): Likewise. Add pprev_nl and nml_err_msg arguments. (init_at_eol): Removed. * io/read.c (convert_real, read_l, read_a, next_char, read_decimal, read_radix, read_f, read_x): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (set_integer): Adjust internal_error caller. * io/write.c (no_leading_blank, nml_delim): Remove variables. (write_a, calculate_sign, calculate_G_format, output_float, write_l, write_float, write_int, write_decimal, write_i, write_b, write_o, write_z, write_d, write_e, write_f, write_en, write_es, write_x, write_char, write_logical, write_integer, write_character, write_real, write_complex, write_separator, list_formatted_write_scalar, list_formatted_write, nml_write_obj, namelist_write): Add dtp argument, pass it all around, adjust for internal function API changes and removal of global variables. (extract_int, extract_uint, extract_real): Adjust internal_error callers. * runtime/fpu.c (_GNU_SOURCE): Don't define here. * runtime/error.c: Include ../io/unix.h. (filename, line): Remove variables. (st_printf): Pass address of a local variable to init_error_stream. (show_locus): Add cmp argument. Use fields it points to rather than filename and line variables. (os_error, runtime_error): Remove show_locus calls. (internal_error): Add cmp argument. Pass it down to show_locus. (generate_error): Likewise. Use flags bitmask instead of non-NULL check for iostat and iomsg parameter presence, adjust for st_* calling convention changes. * runtime/stop.c (stop_numeric, stop_string): Remove show_locus calls. * runtime/pause.c (pause_numeric, pause_string): Likewise. * runtime/string.c: Include ../io/io.h. (find_option): Add cmp argument. Pass it down to generate_error. * intrinsics/flush.c (recursive_flush): Remove. (flush_i4, flush_i8): Use flush_all_units. Add unlock_unit call. * intrinsics/rand.c: Include ../io/io.h. (rand_seed_lock): New variable. (srand, irand): Add locking. (init): New constructor function. * intrinsics/random.c: Include ../io/io.h. (random_lock): New variable. (random_r4, random_r8, arandom_r4, arandom_r8): Add locking. (random_seed): Likewise. open failed if fd < 0. Set i correctly. (init): New constructor function. * intrinsics/system_clock.c (tp0, t0): Remove. (system_clock_4, system_clock_8): Don't subtract tp0/t0 from current time, use just integer arithmetics. * intrinsics/tty.c (isatty_l4, isatty_l8, ttynam_sub): Add unlock_unit calls. From-SVN: r107328
2005-11-21 23:03:56 +01:00
dtp->u.p.fmt->saved_format = f;
}