public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Janne Blomqvist <blomqvist.janne@gmail.com>
To: Fortran List <fortran@gcc.gnu.org>,
	GCC Patches <gcc-patches@gcc.gnu.org>
Subject: [Patch, libfortran] PR 49296 List read of file without EOR
Date: Sun, 03 Jul 2011 21:57:00 -0000	[thread overview]
Message-ID: <CAO9iq9HxGBkH4v=viKn=3Eojkginsd8XgvAkP_NUXPzedb+OyQ@mail.gmail.com> (raw)

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

Hi,

the attached patch fixes the remaining cases of handling input that
ends in EOF instead of a normal separator for list formatted read of
the primitive types. Ok for trunk and 4.6?

2011-07-04  Janne Blomqvist  <jb@gcc.gnu.org>

	PR libfortran/49296
	* io/list_read.c (read_logical): Don't error out if a valid value
	is followed by EOF instead of a normal separator.
	(read_integer): Likewise.

testsuite:

2011-07-04  Janne Blomqvist  <jb@gcc.gnu.org>

	PR libfortran/49296
	* gfortran.dg/read_list_eof_1.f90: Add tests for integer, real,
	and logical reads.


-- 
Janne Blomqvist

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

diff --git a/libgfortran/io/list_read.c b/libgfortran/io/list_read.c
index baf2f54..c88f232 100644
--- a/libgfortran/io/list_read.c
+++ b/libgfortran/io/list_read.c
@@ -657,22 +657,20 @@ read_logical (st_parameter_dt *dtp, int length)
     {
     case 't':
       v = 1;
-      if ((c = next_char (dtp)) == EOF)
-	goto bad_logical;
+      c = next_char (dtp);
       l_push_char (dtp, c);
 
-      if (!is_separator(c))
+      if (!is_separator(c) && c != EOF)
 	goto possible_name;
 
       unget_char (dtp, c);
       break;
     case 'f':
       v = 0;
-      if ((c = next_char (dtp)) == EOF)
-	goto bad_logical;
+      c = next_char (dtp);
       l_push_char (dtp, c);
 
-      if (!is_separator(c))
+      if (!is_separator(c) && c != EOF)
 	goto possible_name;
 
       unget_char (dtp, c);
@@ -837,6 +835,7 @@ read_integer (st_parameter_dt *dtp, int length)
 	  goto repeat;
 
 	CASE_SEPARATORS:	/* Not a repeat count.  */
+	case EOF:
 	  goto done;
 
 	default:
@@ -886,6 +885,7 @@ read_integer (st_parameter_dt *dtp, int length)
 	  break;
 
 	CASE_SEPARATORS:
+	case EOF:
 	  goto done;
 
 	default:

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

! { dg-do run }
! PR 49296 List formatted read of file without EOR marker (\n).
program read_list_eof_1
  implicit none
  character(len=100) :: s
  integer :: ii
  real :: rr
  logical :: ll

  call genfil ('a')
  open (unit=20, file='read.dat', form='FORMATTED', action='READ', &
       status='OLD')
  read (20, fmt=*) s
  close (20, status='delete')
  if (trim(s) /= "a") then
     call abort ()
  end if

  call genfil ('1')
  open (unit=20, file='read.dat', form='FORMATTED', action='READ', &
       status='OLD')
  read (20, fmt=*) ii
  close (20, status='delete')
  if (ii /= 1) then
     call abort ()
  end if

  call genfil ('1.5')
  open (unit=20, file='read.dat', form='FORMATTED', action='READ', &
       status='OLD')
  read (20, fmt=*) rr
  close (20, status='delete')
  if (rr /= 1.5) then
     call abort ()
  end if

  call genfil ('T')
  open (unit=20, file='read.dat', form='FORMATTED', action='READ', &
       status='OLD')
  read (20, fmt=*) ll
  close (20, status='delete')
  if (.not. ll) then
     call abort ()
  end if

contains
  subroutine genfil(str)
    character(len=*), intent(in) :: str
    open(10, file='read.dat', form='unformatted', action='write', &
         status='replace', access='stream')
    write(10) str
    close(10)
  end subroutine genfil
end program read_list_eof_1

             reply	other threads:[~2011-07-03 21:57 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-03 21:57 Janne Blomqvist [this message]
2011-07-12  9:05 ` Janne Blomqvist
2011-07-12 12:32   ` Jerry DeLisle
  -- strict thread matches above, loose matches on Subject: below --
2011-06-11 10:22 Janne Blomqvist
2011-06-17 19:24 ` Janne Blomqvist
2011-06-18  1:29   ` 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='CAO9iq9HxGBkH4v=viKn=3Eojkginsd8XgvAkP_NUXPzedb+OyQ@mail.gmail.com' \
    --to=blomqvist.janne@gmail.com \
    --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).