This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch, libfortran] PR33253 namelist: reading back a string with apostrophe
- From: Jerry DeLisle <jvdelisle at verizon dot net>
- To: Fortran List <fortran at gcc dot gnu dot org>
- Cc: gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 03 Sep 2007 11:59:27 -0700
- Subject: [patch, libfortran] PR33253 namelist: reading back a string with apostrophe
:ADDPATCH fortran:
Hi all,
The title of this PR is a bit misleading. The failure occurs with a string
without the apostrophe as well. The problem here is that when reading a string,
we look at the first character and see if it is a delimiter ' or " . If not we
would skip out and not read the rest of the string.
This patch fixes this by not doing this bail out unless a specific delimiter was
specified in the OPEN statement, otherwise, read_character proceeds to read the
string until it finds a valid separator.
Minor tweaks to namelist_15.f90 and namelist_24.f90 are required. New test case
attached.
Regression tested on x86-64-gnu-linux.
OK for trunk?
Regards,
Jerry
2007-09-03 Jerry DeLisle <jvdelisle@gcc.gnu.org>
PR libfortran/33253
* io/list_read.c (read_character): Use DELIM_APOSTROPHE and DELIM_QUOTE
in check of first character in string.
Index: libgfortran/io/list_read.c
===================================================================
--- libgfortran/io/list_read.c (revision 128052)
+++ libgfortran/io/list_read.c (working copy)
@@ -887,7 +887,9 @@ read_character (st_parameter_dt *dtp, in
goto get_string;
default:
- if (dtp->u.p.namelist_mode)
+ if (dtp->u.p.namelist_mode
+ && (dtp->u.p.current_unit->flags.delim == DELIM_APOSTROPHE
+ || dtp->u.p.current_unit->flags.delim == DELIM_QUOTE))
{
unget_char (dtp,c);
return;
Index: gcc/testsuite/gfortran.dg/namelist_15.f90
===================================================================
--- gcc/testsuite/gfortran.dg/namelist_15.f90 (revision 128052)
+++ gcc/testsuite/gfortran.dg/namelist_15.f90 (working copy)
@@ -20,7 +20,7 @@ program namelist_15
namelist /mynml/ x
- open (10, status = "scratch")
+ open (10, status = "scratch", delim='apostrophe')
write (10, '(A)') "&MYNML"
write (10, '(A)') " x = 3, 4, 'dd', 'ee', 'ff', 'gg',"
write (10, '(A)') " 4, 5, 'hh', 'ii', 'jj', 'kk',"
Index: gcc/testsuite/gfortran.dg/namelist_24.f90
===================================================================
--- gcc/testsuite/gfortran.dg/namelist_24.f90 (revision 128052)
+++ gcc/testsuite/gfortran.dg/namelist_24.f90 (working copy)
@@ -11,7 +11,7 @@
character*(8) names2(nd,nd)
character*(8) names3(nd,nd)
namelist / mynml / names, names2, names3
- open(unit=20,status='scratch')
+ open(unit=20,status='scratch', delim='apostrophe')
write (20, '(a)') "&MYNML"
write (20, '(a)') "NAMES = 25*'0'"
write (20, '(a)') "NAMES2 = 25*'0'"
! { dg-do run }
! PR33253 namelist: reading back a string
! Test case modified from that of the PR by
! Jerry DeLisle <jvdelisle@gcc.gnu.org>
program main
implicit none
character(len=8) :: a
namelist /foo/ a
open(10, status="scratch")
a = "a'a"
write(10,foo)
rewind 10
a = ""
read (10,foo) ! This gave a runtime error before the patch.
if (a.ne."a'a") call abort
close (10)
end program main