From 99628bf1f0f401ef2ad877675321432ebb9a7586 Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 9 Jan 2003 08:05:32 +0000 Subject: * configure.in (RUBY_CHECK_IO_NEED): check whether fseek() and fflush() are needed. * io.c (flush_before_seek): flush write stream only. * io.c (rb_io_check_readable): seek instead of flush if the last operation was write. * io.c (rb_io_check_writable): seek instead of flush if the last operation was read. * bcc32/Makefile.sub, win32/Makefile.sub: needs to seek between R/W. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3318 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 16 ++++++++++++++++ bcc32/Makefile.sub | 1 + configure.in | 44 +++++++++++++++++++++++++++++--------------- io.c | 28 ++++++++++++---------------- win32/Makefile.sub | 2 +- 5 files changed, 59 insertions(+), 32 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1c50f840ce..6286a7dbdc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +Thu Jan 09 17:05:24 2003 Nobuyoshi Nakada + + * configure.in (RUBY_CHECK_IO_NEED): check whether fseek() and + fflush() are needed. + + * io.c (flush_before_seek): flush write stream only. + + * io.c (rb_io_check_readable): seek instead of flush if the last + operation was write. + + * io.c (rb_io_check_writable): seek instead of flush if the last + operation was read. + + * bcc32/Makefile.sub, win32/Makefile.sub: needs to seek between + R/W. + Thu Jan 9 16:31:51 2003 Yukihiro Matsumoto * eval.c (rb_eval): should not discard nested NODE_BLOCK. diff --git a/bcc32/Makefile.sub b/bcc32/Makefile.sub index 965f564ce8..025eebbc0c 100644 --- a/bcc32/Makefile.sub +++ b/bcc32/Makefile.sub @@ -242,6 +242,7 @@ config.h: \#define HAVE_SINH 1 \#define HAVE_TANH 1 +\#define NEED_IO_SEEK_BETWEEN_RW 1 \#define RSHIFT(x,y) ((x)>>y) \#define FILE_COUNT level \#define FILE_READPTR curp diff --git a/configure.in b/configure.in index b6bc0a03d4..1619b798df 100644 --- a/configure.in +++ b/configure.in @@ -265,14 +265,14 @@ darwin*) LIBS="-lobjc $LIBS";; 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 ac_cv_func__setjmp=no ac_cv_func_setitimer=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 ac_cv_header_pwd_h=no @@ -559,10 +559,19 @@ else fi 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 +#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"; char *wombat = "wombat\n"; @@ -576,14 +585,11 @@ 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; r = 0; @@ -593,14 +599,22 @@ int main() return r; } ], [$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_to_do_something_else=no +if test "$rb_cv_need_io_seek_between_rw" = yes; then + AC_DEFINE(NEED_IO_SEEK_BETWEEN_RW, 1) + check_to_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_to_do_something_else=yes +fi +if test "$cross_compiling" = no -a "$check_to_do_something_else" = yes; then + RUBY_CHECK_IO_NEED(do something else, unexpected_stdio_behavior) + if test "$unexpected_stdio_behavior" = yes; then + AC_MSG_FAILURE([unexpected stdio behavior]) + fi fi dnl default value for $KANJI diff --git a/io.c b/io.c index 0c2ba4d0af..fd612ddcce 100644 --- a/io.c +++ b/io.c @@ -195,12 +195,8 @@ static OpenFile * 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; } @@ -211,6 +207,12 @@ flush_before_seek(fptr) #define io_seek(fptr, ofs, whence) fseeko(flush_before_seek(fptr)->f, ofs, whence) #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) OpenFile *fptr; @@ -218,9 +220,9 @@ rb_io_check_readable(fptr) if (!(fptr->mode & FMODE_READABLE)) { 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; #endif @@ -233,9 +235,9 @@ rb_io_check_writable(fptr) if (!(fptr->mode & FMODE_WRITABLE)) { 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 } @@ -472,12 +474,6 @@ rb_io_tell(io) return OFFT2NUM(pos); } -#ifndef SEEK_CUR -# define SEEK_SET 0 -# define SEEK_CUR 1 -# define SEEK_END 2 -#endif - static VALUE rb_io_seek(io, offset, whence) VALUE io, offset; diff --git a/win32/Makefile.sub b/win32/Makefile.sub index 57add88df7..5ba33b1830 100644 --- a/win32/Makefile.sub +++ b/win32/Makefile.sub @@ -260,7 +260,7 @@ config.h: #define HAVE_DAYLIGHT 1 #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 #define FILE_READPTR _ptr -- cgit v1.2.3