From 7c0de7535345f7d271c89d5121c7edfabd1e79f7 Mon Sep 17 00:00:00 2001 From: Thomas Koenig <tkoenig@gcc.gnu.org> Date: Sat, 29 Sep 2012 17:38:46 +0000 Subject: [PATCH] re PR fortran/52724 (Internal read with character(kind=4) data) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2012-09-29 Thomas König <tkoenig@gcc.gnu.org> PR fortran/52724 * list_read.c (next_char): Handle kind=4 characters. * unix.c (open_internal4): Correct lenth of internal file. 2012-09-29 Thomas König <tkoenig@gcc.gnu.org> PR fortran/52724 * gfortran.dg/internal_readwrite_3.f90: New test. From-SVN: r191854 --- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gfortran.dg/internal_readwrite_3.f90 | 11 +++++++++++ libgfortran/ChangeLog | 6 ++++++ libgfortran/io/list_read.c | 13 ++++++++++--- libgfortran/io/unix.c | 2 +- 5 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/internal_readwrite_3.f90 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 4a5af28a7658..502ffdc511e5 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2012-09-29 Thomas König <tkoenig@gcc.gnu.org> + + PR fortran/52724 + * gfortran.dg/internal_readwrite_3.f90: New test. + 2012-09-28 Dodji Seketeli <dodji@redhat.com> * g++.dg/warn/Wunused-local-typedefs-3.C: Move the c++-only test diff --git a/gcc/testsuite/gfortran.dg/internal_readwrite_3.f90 b/gcc/testsuite/gfortran.dg/internal_readwrite_3.f90 new file mode 100644 index 000000000000..279fac5a6d84 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/internal_readwrite_3.f90 @@ -0,0 +1,11 @@ +! { dg-do run } +! PR 52724 - this used to generate a "Bad integer" error. +program main + implicit none + integer :: i + character(len=100,kind=4) :: buffer, a + buffer = 4_"123" + read(buffer,*) i + write (a,'(I3)') i + if (a /= 4_"123") call abort +end program main diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog index f8a68d74171a..feeb10a41462 100644 --- a/libgfortran/ChangeLog +++ b/libgfortran/ChangeLog @@ -1,3 +1,9 @@ +2012-09-29 Thomas König <tkoenig@gcc.gnu.org> + + PR fortran/52724 + * list_read.c (next_char): Handle kind=4 characters. + * unix.c (open_internal4): Correct lenth of internal file. + 2012-09-14 David Edelsohn <dje.gcc@gmail.com> * configure: Regenerated. diff --git a/libgfortran/io/list_read.c b/libgfortran/io/list_read.c index 9d301d624189..403e7190a123 100644 --- a/libgfortran/io/list_read.c +++ b/libgfortran/io/list_read.c @@ -199,9 +199,16 @@ next_char (st_parameter_dt *dtp) if (is_internal_unit (dtp)) { - char cc; - length = sread (dtp->u.p.current_unit->s, &cc, 1); - c = cc; + /* Check for kind=4 internal unit. */ + if (dtp->common.unit) + length = sread (dtp->u.p.current_unit->s, &c, sizeof (gfc_char4_t)); + else + { + char cc; + length = sread (dtp->u.p.current_unit->s, &cc, 1); + c = cc; + } + if (length < 0) { generate_error (&dtp->common, LIBERROR_OS, NULL); diff --git a/libgfortran/io/unix.c b/libgfortran/io/unix.c index 1a9faea486e6..805d4bbd205f 100644 --- a/libgfortran/io/unix.c +++ b/libgfortran/io/unix.c @@ -959,7 +959,7 @@ open_internal4 (char *base, int length, gfc_offset offset) s->buffer = base; s->buffer_offset = offset; - s->active = s->file_length = length; + s->active = s->file_length = length * sizeof (gfc_char4_t); s->st.vptr = &mem4_vtable; -- GitLab