[#19261] lstripped here-document (Re: comments and continuing strings on the next line) — nobu.nakada@...

なかだです。

29 messages 2003/01/01
[#19360] Re: lstripped here-document (Re: comments and continuing strings on the next line) — "K.Kosako" <kosako@...> 2003/01/15

nobu.nakada@nifty.ne.jpさんの

[#19361] Re: lstripped here-document (Re: comments and continuing strings on the next line) — "NAKAMURA, Hiroshi" <nakahiro@...> 2003/01/15

なひです。

[#19364] Re: lstripped here-document (Re: comments and continuing strings on the next line) — nobu.nakada@... 2003/01/17

なかだです。

[#19366] Re: lstripped here-document (Re: comments and continuing strings on the next line) — "NAKAMURA, Hiroshi" <nakahiro@...> 2003/01/17

なひです。

[#19299] [BUG] errno == 0 — Kazuhiro Yoshida <moriq@...>

もりきゅうです。win32だけかもしれません。

22 messages 2003/01/04
[#19301] Re: [BUG] errno == 0 — "U.Nakamura" <usa@...> 2003/01/04

こんにちは、なかむら(う)です。

[#19302] Re: [BUG] errno == 0 — "U.Nakamura" <usa@...> 2003/01/04

こんにちは、なかむら(う)です。

[#19303] Re: [BUG] errno == 0 — "U.Nakamura" <usa@...> 2003/01/04

こんにちは、なかむら(う)です。

[#19304] Re: [BUG] errno == 0 — "U.Nakamura" <usa@...> 2003/01/04

こんにちは、なかむら(う)です。

[#19306] Re: [BUG] errno == 0 — nobu.nakada@... 2003/01/05

なかだです。

[ruby-dev:19306] Re: [BUG] errno == 0

From: nobu.nakada@...
Date: 2003-01-05 00:29:15 UTC
List: ruby-dev #19306
なかだです。

At Sat, 4 Jan 2003 15:03:12 +0900,
U.Nakamura <usa@osb.att.ne.jp> wrote:
> > [ruby-dev:18426]と同じっぽいです。
> > この線で対策します。
> 
> 1.8のmswin32とmingw32は対処しました。
> 
> bccwin32はfflush()では救えなかったので対処してません。
> fseek(fp, SEEK_CUR, 0)はOKっぽいので、下記のパッチのような方
> 法でこの問題自体は潰せますが、なんか他にもいろいろありそうな
> 感じだったので深く踏み込んではいません。

そもそもR/Wの切り替えのときには、fflushではなくてfseekしたほう
がいいような気がして来ました。

それとどうもflush_before_seek()はread onlyのストリームに対して
もfflush()してそうです。


Index: configure.in
===================================================================
RCS file: /cvs/ruby/src/ruby/configure.in,v
retrieving revision 1.161
diff -u -2 -p -r1.161 configure.in
--- configure.in	4 Jan 2003 05:33:29 -0000	1.161
+++ configure.in	5 Jan 2003 00:22:06 -0000
@@ -266,5 +266,5 @@ human*)		ac_cv_func_getpgrp_void=yes;;
 beos*)		;;
 cygwin*)	rb_cv_have_daylight=no
-		rb_cv_need_io_flush_between_rw=no
+		rb_cv_need_io_seek_between_rw=no
 		rb_cv_need_io_flush_before_seek=no
 		ac_cv_var_tzname=no
@@ -273,5 +273,5 @@ cygwin*)	rb_cv_have_daylight=no
 		;;
 mingw*)		LIBS="-lwsock32 $LIBS"
-		rb_cv_need_io_flush_between_rw=yes
+		rb_cv_need_io_seek_between_rw=yes
 		rb_cv_need_io_flush_before_seek=no
 		ac_cv_header_a_out_h=no
@@ -560,8 +560,17 @@ else
 fi
 
-AC_DEFUN(RUBY_CHECK_IO_NEED_FLUSH,
-[AC_CACHE_CHECK(whether need to flush [$1], [$2],
+AC_DEFUN(RUBY_CHECK_IO_NEED,
+[AC_CACHE_CHECK(whether need to [$1], [$2],
     [AC_TRY_RUN([
 #include <stdio.h>
+#ifndef SEEK_SET
+#define SEEK_SET 0
+#endif
+#ifndef SEEK_CUR
+#define SEEK_CUR 1
+#endif
+#define before_seek(f) ]ifelse(index($2,flush_before_seek),-1,[fflush(f)],[(f,0)])[
+#define reset_rw(f) ]ifelse(index($2,seek_between_rw),-1,[do_seek(f,SEEK_CUR)],[(f,0)])[
+#define do_seek(f, w) (before_seek(f), fseek(f,0,w))
 
 char *fn = "conftest.dat";
@@ -577,12 +586,9 @@ int main()
     if (!(f = fopen(fn, "w+"))) return 1;
     fputs(wombat, f);
-    fflush(f);
-    fseek(f, 0, 0);
+    do_seek(f, SEEK_SET);
     if (!fgets(buf, BUFSIZ, f) || strcmp(buf, wombat)) goto fail;
-    ]ifelse(index($2,between_rw),-1,fflush(f);)[
+    reset_rw(f);
     fputs(koara, f);
-    ]ifelse(index($2,before_seek),-1,fflush(f);)[
-    fseek(f, 0, 0);
-    ]ifelse(index($2,between_rw),-1,fflush(f);)[
+    do_seek(f, SEEK_SET);
     if (!fgets(buf, BUFSIZ, f) || strcmp(buf, wombat)) goto fail;
     if (!fgets(buf, BUFSIZ, f) || strcmp(buf, koara)) goto fail;
@@ -594,12 +600,27 @@ int main()
 }
 ], [$2]=no, [$2]=yes, [$2]=yes)])])
-
-RUBY_CHECK_IO_NEED_FLUSH(between R/W, rb_cv_need_io_flush_between_rw)
-RUBY_CHECK_IO_NEED_FLUSH(before seek, rb_cv_need_io_flush_before_seek)
-if test "$rb_cv_need_io_flush_between_rw" = yes; then
-  AC_DEFINE(NEED_IO_FLUSH_BETWEEN_RW, 1)
+RUBY_CHECK_IO_NEED(seek between R/W, rb_cv_need_io_seek_between_rw)
+RUBY_CHECK_IO_NEED(flush before seek, rb_cv_need_io_flush_before_seek)
+check_do_something_else=no
+if test "$rb_cv_need_io_seek_between_rw" = yes; then
+  AC_DEFINE(NEED_IO_SEEK_BETWEEN_RW, 1)
+  check_do_something_else=yes
 fi
 if test "$rb_cv_need_io_flush_before_seek" = yes; then
   AC_DEFINE(NEED_IO_FLUSH_BEFORE_SEEK, 1)
+  check_do_something_else=yes
+fi
+if test "$cross_compiling" = no -a "$check_do_something_else" = yes; then
+  RUBY_CHECK_IO_NEED(do something else, unexpected_behavior)
+  if test "$unexpected_behavior" = yes; then
+    cat <<ABORT
+
+*** The behavior of your system's stdio apparently is something
+*** unexpected.  Please report to ruby-bugs@ruby-lang.org with
+*** config.log (except for \`Core tests' section).
+
+ABORT
+    exit 1
+  fi
 fi
 
Index: io.c
===================================================================
RCS file: /cvs/ruby/src/ruby/io.c,v
retrieving revision 1.175
diff -u -2 -p -r1.175 io.c
--- io.c	21 Dec 2002 18:02:00 -0000	1.175
+++ io.c	4 Jan 2003 13:30:04 -0000
@@ -196,10 +196,6 @@ flush_before_seek(fptr)
     OpenFile *fptr;
 {
-    int mode = fptr->mode;
-    if (mode & FMODE_RBUF) {
-	if (!fptr->f2) io_fflush(fptr->f, fptr);
-    }
-    if (mode & FMODE_WBUF) {
-	io_fflush((fptr->f2 ? fptr->f2 : fptr->f), fptr);
+    if (fptr->mode & FMODE_WBUF) {
+	io_fflush(GetWriteFile(fptr), fptr);
     }
     return fptr;
@@ -212,4 +208,10 @@ flush_before_seek(fptr)
 #define io_tell(fptr) ftello(flush_before_seek(fptr)->f)
 
+#ifndef SEEK_CUR
+# define SEEK_SET 0
+# define SEEK_CUR 1
+# define SEEK_END 2
+#endif
+
 void
 rb_io_check_readable(fptr)
@@ -219,7 +221,7 @@ rb_io_check_readable(fptr)
 	rb_raise(rb_eIOError, "not opened for reading");
     }
-#if NEED_IO_FLUSH_BETWEEN_RW
+#if NEED_IO_SEEK_BETWEEN_RW
     if ((fptr->mode & FMODE_WBUF) && !fptr->f2) {
-	io_fflush(fptr->f, fptr);
+	io_seek(fptr, 0, SEEK_CUR);
     }
     fptr->mode |= FMODE_RBUF;
@@ -234,7 +236,7 @@ rb_io_check_writable(fptr)
 	rb_raise(rb_eIOError, "not opened for writing");
     }
-#if NEED_IO_FLUSH_BETWEEN_RW
+#if NEED_IO_SEEK_BETWEEN_RW
     if ((fptr->mode & FMODE_RBUF) && !fptr->f2) {
-	io_fflush(fptr->f, fptr);
+	io_seek(fptr, 0, SEEK_CUR);
     }
 #endif
@@ -473,10 +475,4 @@ rb_io_tell(io)
 }
 
-#ifndef SEEK_CUR
-# define SEEK_SET 0
-# define SEEK_CUR 1
-# define SEEK_END 2
-#endif
-
 static VALUE
 rb_io_seek(io, offset, whence)
Index: bcc32/Makefile.sub
===================================================================
RCS file: /cvs/ruby/src/ruby/bcc32/Makefile.sub,v
retrieving revision 1.19
diff -u -2 -p -r1.19 Makefile.sub
--- bcc32/Makefile.sub	31 Dec 2002 12:31:12 -0000	1.19
+++ bcc32/Makefile.sub	4 Jan 2003 15:08:52 -0000
@@ -243,4 +243,5 @@ config.h: Makefile $(srcdir)bcc32/Makefi
 \#define HAVE_TANH 1
 
+\#define NEED_IO_SEEK_BETWEEN_RW 1
 \#define RSHIFT(x,y) ((x)>>y)
 \#define FILE_COUNT level
Index: win32/Makefile.sub
===================================================================
RCS file: /cvs/ruby/src/ruby/win32/Makefile.sub,v
retrieving revision 1.39
diff -u -2 -p -r1.39 Makefile.sub
--- win32/Makefile.sub	4 Jan 2003 05:33:29 -0000	1.39
+++ win32/Makefile.sub	4 Jan 2003 15:06:37 -0000
@@ -261,5 +261,5 @@ config.h: Makefile $(srcdir)/win32/Makef
 #define SETPGRP_VOID 1
 #define inline __inline
-#define NEED_IO_FLUSH_BETWEEN_RW 1
+#define NEED_IO_SEEK_BETWEEN_RW 1
 #define RSHIFT(x,y) ((x)>>(int)y)
 #define FILE_COUNT _cnt


-- 
--- 僕の前にBugはない。
--- 僕の後ろにBugはできる。
    中田 伸悦

In This Thread