From: nobu.nakada@... Date: 2002-09-22T13:15:50+09:00 Subject: [ruby-dev:18345] Re: rubicon on EWS4800 なかだです。 At Sun, 22 Sep 2002 03:03:31 +0900, Tanaka Akira wrote: > > 手抜きですが。 > > > > flushが必要かどうか、configureで見るようにしたほうがいいでしょ > > うか。 > > 動いているようです。 > > fflush のやりすぎによる効率低下を心配してたんですが、この実装なら > read/write が切り替わる時にしかやらないようですから問題ないでしょうね。 一応configure.inのテストも追加してみました。cf.sourceforgeの Solarisで試してみたんですが、scpがうまく行かない(昨夜はloginも できなかった)ので全体では試してません。 Index: configure.in =================================================================== RCS file: /cvs/ruby/src/ruby/configure.in,v retrieving revision 1.140 diff -u -2 -p -r1.140 configure.in --- configure.in 15 Sep 2002 12:57:20 -0000 1.140 +++ configure.in 22 Sep 2002 04:13:15 -0000 @@ -542,4 +542,38 @@ else fi +dnl +AC_CACHE_CHECK(whether need to flush between read and write, rb_cv_need_to_flush, + [AC_TRY_RUN([ +#include + +char *fn = "conftest.dat"; + +int main() +{ + char buf[BUFSIZ]; + FILE *f; + + if (!(f = fopen(fn, "w+"))) return 1; + fputs("foo\n", f); + fflush(f); + fseek(f, 0, 0); + fgets(buf, BUFSIZ, f); + fputs("bar\n", f); + fflush(f); + fseek(f, 0, 0); + fread(buf, 1, BUFSIZ, f); + fclose(f); + unlink(fn); + if (strcmp(buf, "foo\nbar\n")) return 1; + return 0; +} +], + rb_cv_need_to_flush=no, + rb_cv_need_to_flush=yes, + rb_cv_need_to_flush=yes)]) +if test "$rb_cv_need_to_flush" = yes; then + AC_DEFINE(NEED_TO_FLUSH, 1) +fi + dnl default value for $KANJI DEFAULT_KCODE="KCODE_NONE" Index: io.c =================================================================== RCS file: /cvs/ruby/src/ruby/io.c,v retrieving revision 1.159 diff -u -2 -p -r1.159 io.c --- io.c 17 Sep 2002 13:52:45 -0000 1.159 +++ io.c 22 Sep 2002 04:11:02 -0000 @@ -190,4 +190,11 @@ rb_io_check_readable(fptr) rb_raise(rb_eIOError, "not opened for reading"); } +#if NEED_TO_FLUSH + if ((fptr->mode & FMODE_WBUF) && !fptr->f2) { + fflush(fptr->f); + fptr->mode &= ~FMODE_WBUF; + } + fptr->mode |= FMODE_RBUF; +#endif } @@ -199,4 +206,10 @@ rb_io_check_writable(fptr) rb_raise(rb_eIOError, "not opened for writing"); } +#if NEED_TO_FLUSH + if ((fptr->mode & FMODE_RBUF) && !fptr->f2) { + fflush(fptr->f); + fptr->mode &= ~FMODE_RBUF; + } +#endif } Index: rubyio.h =================================================================== RCS file: /cvs/ruby/src/ruby/rubyio.h,v retrieving revision 1.18 diff -u -2 -p -r1.18 rubyio.h --- rubyio.h 16 Aug 2002 02:52:25 -0000 1.18 +++ rubyio.h 21 Sep 2002 17:35:51 -0000 @@ -33,4 +33,5 @@ typedef struct OpenFile { #define FMODE_SYNC 8 #define FMODE_WBUF 16 +#define FMODE_RBUF 32 #define GetOpenFile(obj,fp) rb_io_check_closed((fp) = RFILE(rb_io_taint_check(obj))->fptr) -- --- 僕の前にBugはない。 --- 僕の後ろにBugはできる。 中田 伸悦