* 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
This commit is contained in:
nobu 2003-01-09 08:05:32 +00:00
parent 639ec76858
commit 99628bf1f0
5 changed files with 59 additions and 32 deletions

View File

@ -1,3 +1,19 @@
Thu Jan 09 17:05:24 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net>
* 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 <matz@ruby-lang.org>
* eval.c (rb_eval): should not discard nested NODE_BLOCK.

View File

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

View File

@ -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 <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";
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

28
io.c
View File

@ -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;

View File

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