This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch, libgfortran] PR47778 reading two arrays of structures from namelist fails
- From: Jerry DeLisle <jvdelisle at frontier dot com>
- To: gfortran <fortran at gcc dot gnu dot org>
- Cc: gcc patches <gcc-patches at gcc dot gnu dot org>
- Date: Sun, 27 Feb 2011 07:34:05 -0800
- Subject: [patch, libgfortran] PR47778 reading two arrays of structures from namelist fails
Hi all,
The attached patch fixes this bug by resetting the pprev_nl pointer to NULL when
the rank of the previous object read was zero. pprev_nl is used to track
multiple reads from the same namelist variable.
Regression tested on x86-64.
OK for trunk? I suggest we should back port to 4.5 and possibly earlier.
Regards,
Jerry
2011-02-27 Jerry DeLisle <jvdelisle@gcc.gnu.org>
PR libgfortran/47778
* io/list_read.c (namelist_read): If pprev_nl was used during the
previous namelist read and the rank was zero, reset the pointer to NULL
for the next namelist read.
Index: io/list_read.c
===================================================================
--- io/list_read.c (revision 170543)
+++ io/list_read.c (working copy)
@@ -3058,6 +3058,8 @@
goto nml_err_ret;
generate_error (&dtp->common, LIBERROR_READ_VALUE, nml_err_msg);
}
+ if (prev_nl && prev_nl->var_rank == 0)
+ prev_nl = NULL;
}
free_saved (dtp);
! { dg-do run }
! PR47778 Reading array of structures from namelist
! Test case derived from the reporters test case.
program test_nml
type field_descr
integer number
end type
type fsetup
type (field_descr), dimension(3) :: vel ! 3 velocity components
type (field_descr), dimension(3) :: scal ! 3 scalars
end type
type (fsetup) field_setup
namelist /nl_setup/ field_setup
field_setup%vel%number = 0
field_setup%scal%number = 0
! write(*,nml=nl_setup)
open(10, status="scratch")
write(10,'(a)') "&nl_setup"
write(10,'(a)') " field_setup%vel(1)%number= 3,"
write(10,'(a)') " field_setup%vel(2)%number= 9,"
write(10,'(a)') " field_setup%vel(3)%number= 27,"
write(10,'(a)') " field_setup%scal(1)%number= 2,"
write(10,'(a)') " field_setup%scal(2)%number= 4,"
write(10,'(a)') " field_setup%scal(3)%number= 8,"
write(10,'(a)') "/"
rewind(10)
read(10,nml=nl_setup)
if (field_setup%vel(1)%number .ne. 3) call abort
if (field_setup%vel(2)%number .ne. 9) call abort
if (field_setup%vel(3)%number .ne. 27) call abort
if (field_setup%scal(1)%number .ne. 2) call abort
if (field_setup%scal(2)%number .ne. 4) call abort
if (field_setup%scal(3)%number .ne. 8) call abort
!write(*,nml=nl_setup)
end program test_nml