Oh yes, thanks, that was silly of me.  Calls to IO.read with no length
argument also failed for the same reason.

This brings up the question of what the behavior should be when one
(accidentally) does this on a 32-bit platform:

    s = File.open("some_large_file").read

If we can rely on the stat structure always having its st_size member
initialized to a reasonable value for streams and stuff, then I'd be
inclined to put something like this in read_all:

	    if (st.st_size > pos && pos >= 0) {
		siz = st.st_size - pos + 1;
+               if (siz > LONG_MAX) {
+                   rb_raise(rb_eIOError, "file too big for single
read")
+               }
	    }

with a cast later on:

	n = io_fread(RSTRING(str)->ptr+bytes, (long)siz-bytes, fptr->f);

and leave the declaration of io_fread as is, since you can't address
anything bigger anyway.

  --Jonathan



nobu.nokada / softhome.net wrote in message news:<20020308100600.CD46516F / sharui.nakada.kanuma.tochigi.jp>...
> Hi,
> 
> At Fri, 8 Mar 2002 18:19:40 +0900,
> Jonathan Baker wrote:
> > Discovered that the patch for large files caused a nasty side effect:
> > any use of backquotes (%x) results in a seg fault.  :(  The fix is
> > simple, but very strange: just include a prototype declaration for
> > io_fread in io.c:
> > 
> >   static long io_fread _((char *, long, FILE *));
> > 
> > and all is well.  I've updated the patch to include this, see
> > http://www.jonathanbaker.org/software/ruby/ruby.html.
> > 
> > Without the prototype, just before this call in read_all in io.c:
> > 
> >   n = io_fread(RSTRING(str)->ptr+bytes, siz-bytes, fptr->f);
> 
> Because you changed siz to off_t, 64bit integer is passed to
> read_all() without the prototype.
> 
> > the fptr->f is fine, but somehow it mysteriously becomes NULL
> > immediately after entering io_fread.  Seems rather like a compiler
> > bug, unless I'm overlooking something silly.  I get the same behavior
> > on multiple platforms using gcc 2.96.  Anyone understand this?
> 
> And you must use little-endian system, thus higher 32bit is
> used as FILE*.
> 
> I guess it's better to change 2nd argument of io_fread() to
> off_t.