public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch, libfortran] PR 30162 pipe I/O regression with 4.7/4.8
@ 2013-02-19 22:40 Janne Blomqvist
  2013-02-21  1:28 ` Jerry DeLisle
  0 siblings, 1 reply; 2+ messages in thread
From: Janne Blomqvist @ 2013-02-19 22:40 UTC (permalink / raw)
  To: Fortran List, GCC Patches

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

Hi,

attached is an attempt to fix writing formatted sequential I/O to a
pipe (The PR was reopened in comment #22, which refers to formatted
I/O so the PR title is incorrect). I think the underlying reason was
that the introduction of the ssize() member function led to a change
in semantics (size of a non-seekable fd is now 0 rather than -1), and
thus in io/open.c test_endfile() we incorrectly concluded that the
file was not positioned at the end, and thus we try to truncate after
writing, leading to the failure.

At the same time, the patch reverts the previous fix; Unformatted
sequential requires seeking due to updating the record markers, I
think that issue can be closed as WONTFIX.

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

2013-02-19  Janne Blomqvist  <jb@gcc.gnu.org>

	PR libfortran/30162
	* io/open.c (test_endfile): Call stell only if size != 0.
	* io/unix.c (raw_tell): Revert r194679.
	(raw_size): Return size field only for regular files, otherwise 0.


-- 
Janne Blomqvist

[-- Attachment #2: pipe2.diff --]
[-- Type: application/octet-stream, Size: 1294 bytes --]

diff --git a/libgfortran/io/open.c b/libgfortran/io/open.c
index 2895767..d9cfde8 100644
--- a/libgfortran/io/open.c
+++ b/libgfortran/io/open.c
@@ -152,8 +152,12 @@ static const st_option async_opt[] =
 static void
 test_endfile (gfc_unit * u)
 {
-  if (u->endfile == NO_ENDFILE && ssize (u->s) == stell (u->s))
-    u->endfile = AT_ENDFILE;
+  if (u->endfile == NO_ENDFILE)
+    { 
+      gfc_offset sz = ssize (u->s);
+      if (sz == 0 || sz == stell (u->s))
+	u->endfile = AT_ENDFILE;
+    }
 }
 
 
diff --git a/libgfortran/io/unix.c b/libgfortran/io/unix.c
index ba8392d..8b9d7a7 100644
--- a/libgfortran/io/unix.c
+++ b/libgfortran/io/unix.c
@@ -342,15 +342,7 @@ raw_seek (unix_stream * s, gfc_offset offset, int whence)
 static gfc_offset
 raw_tell (unix_stream * s)
 {
-  gfc_offset x;
-  x = lseek (s->fd, 0, SEEK_CUR);
-
-  /* Non-seekable files should always be assumed to be at
-     current position.  */
-  if (x == -1 && errno == ESPIPE)
-    x = 0;
-
-  return x;
+  return lseek (s->fd, 0, SEEK_CUR);
 }
 
 static gfc_offset
@@ -360,7 +352,10 @@ raw_size (unix_stream * s)
   int ret = fstat (s->fd, &statbuf);
   if (ret == -1)
     return ret;
-  return statbuf.st_size;
+  if (S_ISREG (statbuf.st_mode))
+    return statbuf.st_size;
+  else
+    return 0;
 }
 
 static int

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

* Re: [Patch, libfortran] PR 30162 pipe I/O regression with 4.7/4.8
  2013-02-19 22:40 [Patch, libfortran] PR 30162 pipe I/O regression with 4.7/4.8 Janne Blomqvist
@ 2013-02-21  1:28 ` Jerry DeLisle
  0 siblings, 0 replies; 2+ messages in thread
From: Jerry DeLisle @ 2013-02-21  1:28 UTC (permalink / raw)
  To: Janne Blomqvist; +Cc: Fortran List, GCC Patches

On 02/19/2013 02:40 PM, Janne Blomqvist wrote:
> Hi,
>
> attached is an attempt to fix writing formatted sequential I/O to a
> pipe (The PR was reopened in comment #22, which refers to formatted
> I/O so the PR title is incorrect). I think the underlying reason was
> that the introduction of the ssize() member function led to a change
> in semantics (size of a non-seekable fd is now 0 rather than -1), and
> thus in io/open.c test_endfile() we incorrectly concluded that the
> file was not positioned at the end, and thus we try to truncate after
> writing, leading to the failure.
>
> At the same time, the patch reverts the previous fix; Unformatted
> sequential requires seeking due to updating the record markers, I
> think that issue can be closed as WONTFIX.
>
> Regtested on x86_64-unknown-linux-gnu, Ok for trunk/4.7?
>
Patch is OK.

Jerry

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

end of thread, other threads:[~2013-02-21  1:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-19 22:40 [Patch, libfortran] PR 30162 pipe I/O regression with 4.7/4.8 Janne Blomqvist
2013-02-21  1:28 ` 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).