This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[Patch, Fortran] PR 34530 - Fix namelist read
- From: Tobias Burnus <burnus at net-b dot de>
- To: "'fortran at gcc dot gnu dot org'" <fortran at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>, Jerry DeLisle <jvdelisle at verizon dot net>
- Date: Wed, 19 Dec 2007 23:17:15 +0100
- Subject: [Patch, Fortran] PR 34530 - Fix namelist read
Since a recent patch, gfortran was choking on a namelist created as:
write(nnml,*) "&blacklist "
write(nnml,*) " ! This is a comment within the namelist"
write(nnml,*) " file = 'myfile'"
The problem was that as namelist object "!" was tried to read, which
does not make much sense.
The patch now simply skips comment lines (in namelist mode) when it eats
separators.
Build and regtested on x86-64-linux.
OK for the trunk?
Tobias
2007-12-19 Tobias Burnus <burnus@net-b.de>
PR fortran/34530
* io/list_read.c (eat_line): Move up in the file.
(eat_separator): In namelist mode, skip over comment lines.
2007-12-19 Tobias Burnus <burnus@net-b.de>
PR fortran/34530
* gfortran.dg/namelist_44.f90: New.
Index: libgfortran/io/list_read.c
===================================================================
--- libgfortran/io/list_read.c (Revision 131089)
+++ libgfortran/io/list_read.c (Arbeitskopie)
@@ -275,6 +275,20 @@ eat_spaces (st_parameter_dt *dtp)
}
+/* This function reads characters through to the end of the current line and
+ just ignores them. */
+
+static void
+eat_line (st_parameter_dt *dtp)
+{
+ char c;
+ if (!is_internal_unit (dtp))
+ do
+ c = next_char (dtp);
+ while (c != '\n');
+}
+
+
/* Skip over a separator. Technically, we don't always eat the whole
separator. This is because if we've processed the last input item,
then a separator is unnecessary. Plus the fact that operating
@@ -328,7 +342,14 @@ eat_separator (st_parameter_dt *dtp)
if (dtp->u.p.namelist_mode)
{
do
- c = next_char (dtp);
+ {
+ c = next_char (dtp);
+ if (c == '!')
+ {
+ eat_line (dtp);
+ c = next_char (dtp);
+ }
+ }
while (c == '\n' || c == '\r' || c == ' ');
unget_char (dtp, c);
}
@@ -407,20 +428,6 @@ finish_separator (st_parameter_dt *dtp)
}
-/* This function reads characters through to the end of the current line and
- just ignores them. */
-
-static void
-eat_line (st_parameter_dt *dtp)
-{
- char c;
- if (!is_internal_unit (dtp))
- do
- c = next_char (dtp);
- while (c != '\n');
-}
-
-
/* This function is needed to catch bad conversions so that namelist can
attempt to see if dtp->u.p.saved_string contains a new object name rather
than a bad value. */
Index: gcc/testsuite/gfortran.dg/namelist_44.f90
===================================================================
--- gcc/testsuite/gfortran.dg/namelist_44.f90 (Revision 0)
+++ gcc/testsuite/gfortran.dg/namelist_44.f90 (Revision 0)
@@ -0,0 +1,29 @@
+! { dg-do run }
+!
+! PR fortran/34530
+!
+! Skipping over comment line was not working
+!
+! Test case contributed by Harald Anlauf.
+!
+program gfcbug77
+ implicit none
+
+ character(len=128) :: file = ""
+ logical :: default
+ namelist /BLACKLIST/ file, default
+ integer, parameter :: nnml = 10
+ default = .true.
+
+ open (nnml, file='gfcbug77.nml')
+ write(nnml,*) "&blacklist " ! The trailing space breaks gfortran
+ write(nnml,*) " ! This is a comment within the namelist"
+ write(nnml,*) " file = 'myfile'"
+ write(nnml,*) " default = F"
+ write(nnml,*) "/"
+ rewind(nnml)
+ read (nnml, nml=BLACKLIST)
+ close(nnml)
+ if(file /= "myfile" .or. default) call abort()
+! write (*,nml=BLACKLIST)
+end program gfcbug77