This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch,libgfortran] PR37707 Namelist read of array of derived type incorrect - round 2
- 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: Sun, 19 Oct 2008 11:50:11 -0700
- Subject: [patch,libgfortran] PR37707 Namelist read of array of derived type incorrect - round 2
Hi all,
This patch actually fixes a latent bug uncovered after the first patch was applied.
The standard requires that namelist delimit character strings with a quote or
apostrophe. Our previous code was attempting to determine the difference between
a string value and a namelist object name by looking ahead in the list for an
"=" that what identify it as a name rather than a character value. This code
was not working in the context of the test case.
To bring us closer to the standard I have simply eliminated that somewhat
complex code.
Also, in writing namelist character values, we were not using a delimiter by
default as required by the standard. I have revised this to default to a quote
and allow the user to specify an apostrophe. If delim=none is given, it is
simply ignored and the default is used.
Regression tested on x86-64. I will prepare two test cases. One from the
second more complex case that Toon provided in the PR and one from Tobias
example of the namelist write problem. I have to run out so I will get the
Changelog made up as well when I get back. The patch is pretty clear.
OK to commit?
Regards,
Jerry
Index: list_read.c
===================================================================
--- list_read.c (revision 141218)
+++ list_read.c (working copy)
@@ -929,52 +929,8 @@ read_character (st_parameter_dt *dtp, in
default:
if (dtp->u.p.namelist_mode)
{
- if (dtp->u.p.current_unit->delim_status == DELIM_APOSTROPHE
- || dtp->u.p.current_unit->delim_status == DELIM_QUOTE
- || c == '&' || c == '$' || c == '/')
- {
- unget_char (dtp, c);
- return;
- }
-
- /* Check to see if we are seeing a namelist object name by using the
- line buffer and looking ahead for an '=' or '('. */
- l_push_char (dtp, c);
-
- int i;
- for(i = 0; i < 63; i++)
- {
- c = next_char (dtp);
- if (is_separator(c))
- {
- unget_char (dtp, c);
- eat_separator (dtp);
- c = next_char (dtp);
- if (c != '=')
- {
- l_push_char (dtp, c);
- dtp->u.p.item_count = 0;
- dtp->u.p.line_buffer_enabled = 1;
- goto get_string;
- }
- }
-
- l_push_char (dtp, c);
-
- if (c == '=' || c == '(')
- {
- dtp->u.p.item_count = 0;
- dtp->u.p.nml_read_error = 1;
- dtp->u.p.line_buffer_enabled = 1;
- return;
- }
- }
-
- /* The string is too long to be a valid object name so assume that it
- is a string to be read in as a value. */
- dtp->u.p.item_count = 0;
- dtp->u.p.line_buffer_enabled = 1;
- goto get_string;
+ unget_char (dtp, c);
+ return;
}
push_char (dtp, c);
Index: write.c
===================================================================
--- write.c (revision 141218)
+++ write.c (working copy)
@@ -1442,20 +1442,8 @@ namelist_write (st_parameter_dt *dtp)
/* Set the delimiter for namelist output. */
tmp_delim = dtp->u.p.current_unit->delim_status;
- switch (tmp_delim)
- {
- case (DELIM_QUOTE):
- dtp->u.p.nml_delim = '"';
- break;
-
- case (DELIM_APOSTROPHE):
- dtp->u.p.nml_delim = '\'';
- break;
-
- default:
- dtp->u.p.nml_delim = '\0';
- break;
- }
+
+ dtp->u.p.nml_delim = tmp_delim == DELIM_APOSTROPHE ? '\'' : '"';
/* Temporarily disable namelist delimters. */
dtp->u.p.current_unit->delim_status = DELIM_NONE;