public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jerry DeLisle <jvdelisle@verizon.net>
To: Fortran List <fortran@gcc.gnu.org>
Cc: gcc-patches <gcc-patches@gcc.gnu.org>
Subject: [patch, libfortran] PR33253 namelist: reading back a string with  apostrophe
Date: Mon, 03 Sep 2007 19:01:00 -0000	[thread overview]
Message-ID: <46DC598F.50905@verizon.net> (raw)

[-- Attachment #1: Type: text/plain, Size: 879 bytes --]

: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.



[-- Attachment #2: pr33253.diff --]
[-- Type: text/x-patch, Size: 1665 bytes --]

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'"

[-- Attachment #3: namelist_38.f90 --]
[-- Type: text/x-fortran, Size: 415 bytes --]

! { 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

             reply	other threads:[~2007-09-03 19:01 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-03 19:01 Jerry DeLisle [this message]
2007-09-03 19:12 ` Steve Kargl
2007-09-04  9:43 ` Tobias Burnus
2007-09-05  0:35   ` Jerry DeLisle
2007-09-05  5:32   ` Jerry DeLisle
2007-09-05  8:30     ` Tobias Burnus
2007-10-01  5:12 Jerry DeLisle
2007-10-01  6:59 ` FX Coudert
     [not found]   ` <47010739.9060204@verizon.net>
2007-10-02 23:31     ` Jerry DeLisle
2007-10-03  0:21       ` Jerry DeLisle

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=46DC598F.50905@verizon.net \
    --to=jvdelisle@verizon.net \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).