Bug 33253 - namelist: reading back a string with apostrophe
Summary: namelist: reading back a string with apostrophe
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libfortran (show other bugs)
Version: 4.3.0
: P3 enhancement
Target Milestone: ---
Assignee: Jerry DeLisle
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-08-30 18:55 UTC by Thomas Koenig
Modified: 2007-10-03 00:41 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2007-08-31 20:17:04


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Koenig 2007-08-30 18:55:16 UTC
Reading back a namelist string which contains an
apostrophe doesn't work.

I am marking this as an enhancement because reading back
what we wrote with a namelist isn't guaranteed to work
(see note 10.37 in the working draft).  It does work with
ifort, for example.

$ cat namelist.f90 
program main
  implicit none
  character(len=3) :: a
  namelist /foo/ a
  open(10,status="scratch")
  a = "a'a"
  write(10,foo) 
  write (*,foo)
  rewind 10
  read (10,foo)
end program main
$ gfortran namelist.f90 
$ ./a.out
&FOO
 A=a'a,  /

At line 10 of file namelist.f90 (unit = 10, file = '/tmp/gfortrantmpy3HLPb')
Fortran runtime error: Cannot match namelist object name a'a,
Comment 1 Harald Anlauf 2007-08-31 08:20:06 UTC
(In reply to comment #0)

> It does work with ifort, for example.

I works with g95, but fails with xlf, unless I add an
delim='apostrophe' to the open statement.

I the latter case gfortran still fails, so this might be
a bug.
Comment 2 Harald Anlauf 2007-08-31 19:45:03 UTC
(In reply to comment #1)

If I replace the open by:

  open(10,delim='apostrophe')

then the file fort.10 contains after the crash:

% cat fort.10 
&FOO
 A='a'a',  /


This looks like a quoting bug.

Jerry?
Comment 3 Jerry DeLisle 2007-08-31 20:17:04 UTC
I want to study this a bit.  I think it is a bug.
Comment 4 patchapp@dberlin.org 2007-09-03 19:05:21 UTC
Subject: Bug number PR33253

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2007-09/msg00153.html
Comment 5 Jerry DeLisle 2007-09-03 19:27:59 UTC
Subject: Bug 33253

Author: jvdelisle
Date: Mon Sep  3 19:27:48 2007
New Revision: 128056

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=128056
Log:
2007-09-03  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR fortran/33253
	* gfortran.dg/namelist_15.f90: Update test.
	* gfortran.dg/namelist_24.f90: Update test.
	* gfortran.dg/namelist_38.f90: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/namelist_38.f90
Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/namelist_15.f90
    trunk/gcc/testsuite/gfortran.dg/namelist_24.f90

Comment 6 Jerry DeLisle 2007-09-03 19:29:27 UTC
Subject: Bug 33253

Author: jvdelisle
Date: Mon Sep  3 19:29:17 2007
New Revision: 128057

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=128057
Log:
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.

Modified:
    trunk/libgfortran/ChangeLog
    trunk/libgfortran/io/list_read.c

Comment 7 Jerry DeLisle 2007-09-03 19:32:11 UTC
Fixed on trunk.
Comment 8 Jerry DeLisle 2007-09-06 01:20:21 UTC
Subject: Bug 33253

Author: jvdelisle
Date: Thu Sep  6 01:20:02 2007
New Revision: 128170

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=128170
Log:
2007-09-05  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libfortran/33253
	* io/write.c (nml_write_obj): Set the delimiter correctly before calling
	write_character. (namelist_write): Clean up the code a little and add
	comments to clarify what its doing.

Modified:
    trunk/libgfortran/ChangeLog
    trunk/libgfortran/io/write.c

Comment 9 Jerry DeLisle 2007-09-06 01:24:28 UTC
Subject: Bug 33253

Author: jvdelisle
Date: Thu Sep  6 01:24:17 2007
New Revision: 128171

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=128171
Log:
2007-09-06  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libfortran/33253
	* gfortran.dg/namelist_38.f90: Update test for DELIM= .

Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/namelist_38.f90

Comment 10 Jerry DeLisle 2007-09-28 03:16:25 UTC
Reverted the patch to close pr33421.  Reopening this to find the right solution.
Comment 11 Jerry DeLisle 2007-09-30 01:58:38 UTC
It turns out that the original patch for this bug is probably what we want.  Unfortunately it uncovers a nasty latent bug where an extraneous namelist read is attempted.  It only seems to occur with multiple levels of derived types.  For example:

&MYNML
 x(2)%m(1)%ch(2) ='q', ,
&end

Will read correctly with the initial patch for the bug here if the extra comma is placed at the end.  This is a bugger since it involves both recursive calls and incrementing of loop specs all within a do - while loop.

Still working on it. :)
Comment 12 Jerry DeLisle 2007-10-03 00:33:38 UTC
Subject: Bug 33253

Author: jvdelisle
Date: Wed Oct  3 00:33:09 2007
New Revision: 128973

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=128973
Log:
2007-10-02  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libfortran/33253
	* io/list_read.c (read_character): Use DELIM_APOSTROPHE and DELIM_QUOTE
        and quote value in check of first character in string.

Modified:
    trunk/libgfortran/ChangeLog
    trunk/libgfortran/io/list_read.c

Comment 13 Jerry DeLisle 2007-10-03 00:40:10 UTC
Subject: Bug 33253

Author: jvdelisle
Date: Wed Oct  3 00:39:58 2007
New Revision: 128975

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=128975
Log:
2007-10-03  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libfortran/33253
	* gfortran.dg/namelist_38.f90: New test.
	* gfortran.dg/namelist_39.f90: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/namelist_38.f90
    trunk/gcc/testsuite/gfortran.dg/namelist_39.f90
Modified:
    trunk/gcc/testsuite/ChangeLog

Comment 14 Jerry DeLisle 2007-10-03 00:41:23 UTC
Fixed on trunk.
Comment 15 Jerry DeLisle 2007-10-04 15:57:39 UTC
Subject: Bug 33253

Author: jvdelisle
Date: Thu Oct  4 15:57:28 2007
New Revision: 129016

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=129016
Log:
2007-10-04  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libfortran/33253
	* io/list_read.c (read_character): Use line_buffer to scan ahead for
	object name or string when no delimiter is found.

Modified:
    trunk/libgfortran/ChangeLog
    trunk/libgfortran/io/list_read.c

Comment 16 Jerry DeLisle 2007-10-04 16:02:59 UTC
Subject: Bug 33253

Author: jvdelisle
Date: Thu Oct  4 16:02:42 2007
New Revision: 129018

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=129018
Log:
2007-10-04  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libfortran/33253
	* gfortran.dg/namelist_39.f90: Revise to use long names.

Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/namelist_39.f90

Comment 17 patchapp@dberlin.org 2007-10-06 15:10:03 UTC
Subject: Bug number PR33253

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2007-10/msg00011.html