public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch, libfortran] PR 49296 List read of file without EOR
@ 2011-06-11 10:22 Janne Blomqvist
  2011-06-17 19:24 ` Janne Blomqvist
  0 siblings, 1 reply; 6+ messages in thread
From: Janne Blomqvist @ 2011-06-11 10:22 UTC (permalink / raw)
  To: Fortran List, GCC Patches

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

Hi,

attached patch fixes PR 49296. A new test for the testsuite is also included.

Regtested on x86_64-unknown-linux-gnu, Ok for trunk?

2011-06-11  Janne Blomqvist  <jb@gcc.gnu.org>

	PR libfortran/49296
	* io/list_read.c (read_character): Accept EOF as a separator when
	reading string.


-- 
Janne Blomqvist

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

diff --git a/libgfortran/io/list_read.c b/libgfortran/io/list_read.c
index 38a92e1..baf2f54 100644
--- a/libgfortran/io/list_read.c
+++ b/libgfortran/io/list_read.c
@@ -1022,7 +1022,7 @@ read_character (st_parameter_dt *dtp, int length __attribute__ ((unused)))
   for (;;)
     {
       if ((c = next_char (dtp)) == EOF)
-	goto eof;
+	goto done_eof;
       switch (c)
 	{
 	case '"':
@@ -1068,26 +1068,26 @@ read_character (st_parameter_dt *dtp, int length __attribute__ ((unused)))
      invalid.  */
  done:
   c = next_char (dtp);
- eof:
-  if (is_separator (c) || c == '!')
+ done_eof:
+  if (is_separator (c) || c == '!' || c == EOF)
     {
       unget_char (dtp, c);
       eat_separator (dtp);
       dtp->u.p.saved_type = BT_CHARACTER;
       free_line (dtp);
     }
-  else
+  else 
     {
       free_saved (dtp);
-      if (c == EOF)
-	{
-	  hit_eof (dtp);
-	  return;
-	}
       snprintf (message, MSGLEN, "Invalid string input in item %d",
 		  dtp->u.p.item_count);
       generate_error (&dtp->common, LIBERROR_READ_VALUE, message);
     }
+  return;
+
+ eof:
+  free_saved (dtp);
+  hit_eof (dtp);
 }
 
 

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

! { dg-do run }
! PR 49296 List formatted read of file without EOR marker (\n).
program read_list_eof_1
  implicit none
  integer, parameter :: strmx = 255
  character(len=strmx) :: s1, s2
  call genfil ()
  open (unit=20, file='read.dat', form='FORMATTED', action='READ', &
       status='OLD')
  read (20, fmt=*) s1, s2
  close (20, status='delete')
  if (trim(s1) /= "abcd" .or. trim(s2) /= "efgh") then
     call abort ()
  end if

contains
  subroutine genfil
    open(10, file='read.dat', form='unformatted', action='write', &
         status='replace', access='stream')
    write(10) 'abcd efgh'
    close(10)
  end subroutine genfil
end program read_list_eof_1

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Patch, libfortran] PR 49296 List read of file without EOR
  2011-06-11 10:22 [Patch, libfortran] PR 49296 List read of file without EOR Janne Blomqvist
@ 2011-06-17 19:24 ` Janne Blomqvist
  2011-06-18  1:29   ` jerry DeLisle
  0 siblings, 1 reply; 6+ messages in thread
From: Janne Blomqvist @ 2011-06-17 19:24 UTC (permalink / raw)
  To: Fortran List, GCC Patches

PING.

Also, here's a slightly simplfied testcase:

! { 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
  call genfil ()
  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

contains
  subroutine genfil
    open(10, file='read.dat', form='unformatted', action='write', &
         status='replace', access='stream')
    write(10) 'a'
    close(10)
  end subroutine genfil
end program read_list_eof_1


On Sat, Jun 11, 2011 at 13:05, Janne Blomqvist
<blomqvist.janne@gmail.com> wrote:
> Hi,
>
> attached patch fixes PR 49296. A new test for the testsuite is also included.
>
> Regtested on x86_64-unknown-linux-gnu, Ok for trunk?
>
> 2011-06-11  Janne Blomqvist  <jb@gcc.gnu.org>
>
>        PR libfortran/49296
>        * io/list_read.c (read_character): Accept EOF as a separator when
>        reading string.
>
>
> --
> Janne Blomqvist
>



-- 
Janne Blomqvist

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Patch, libfortran] PR 49296 List read of file without EOR
  2011-06-17 19:24 ` Janne Blomqvist
@ 2011-06-18  1:29   ` jerry DeLisle
  0 siblings, 0 replies; 6+ messages in thread
From: jerry DeLisle @ 2011-06-18  1:29 UTC (permalink / raw)
  To: Janne Blomqvist; +Cc: Fortran List, GCC Patches

On 06/17/2011 12:02 PM, Janne Blomqvist wrote:
> PING.
>
> Also, here's a slightly simplfied testcase:
>
Yes, OK

Jerry

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Patch, libfortran] PR 49296 List read of file without EOR
  2011-07-12  9:05 ` Janne Blomqvist
@ 2011-07-12 12:32   ` Jerry DeLisle
  0 siblings, 0 replies; 6+ messages in thread
From: Jerry DeLisle @ 2011-07-12 12:32 UTC (permalink / raw)
  To: Janne Blomqvist; +Cc: Fortran List, GCC Patches

On 07/12/2011 01:05 AM, Janne Blomqvist wrote:
> PING
>
> On Mon, Jul 4, 2011 at 00:57, Janne Blomqvist<blomqvist.janne@gmail.com>  wrote:
>> 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?
>>

Yes, OK.  I have been on vacation and missed this sooner.

Thanks for patch.

Jerry

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Patch, libfortran] PR 49296 List read of file without EOR
  2011-07-03 21:57 Janne Blomqvist
@ 2011-07-12  9:05 ` Janne Blomqvist
  2011-07-12 12:32   ` Jerry DeLisle
  0 siblings, 1 reply; 6+ messages in thread
From: Janne Blomqvist @ 2011-07-12  9:05 UTC (permalink / raw)
  To: Fortran List, GCC Patches

PING

On Mon, Jul 4, 2011 at 00:57, Janne Blomqvist <blomqvist.janne@gmail.com> wrote:
> 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
>



-- 
Janne Blomqvist

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Patch, libfortran] PR 49296 List read of file without EOR
@ 2011-07-03 21:57 Janne Blomqvist
  2011-07-12  9:05 ` Janne Blomqvist
  0 siblings, 1 reply; 6+ messages in thread
From: Janne Blomqvist @ 2011-07-03 21:57 UTC (permalink / raw)
  To: Fortran List, GCC Patches

[-- 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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-07-12 12:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-11 10:22 [Patch, libfortran] PR 49296 List read of file without EOR Janne Blomqvist
2011-06-17 19:24 ` Janne Blomqvist
2011-06-18  1:29   ` jerry DeLisle
2011-07-03 21:57 Janne Blomqvist
2011-07-12  9:05 ` Janne Blomqvist
2011-07-12 12:32   ` Jerry DeLisle

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