caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Re: [Caml-list] in_channel_length fails for files longer than max_int
  2001-05-14 16:55 ` [Caml-list] in_channel_length fails for files longer than max_int David Fox
@ 2001-05-13  6:24   ` Chris Hecker
  2001-05-28 13:13   ` Xavier Leroy
  1 sibling, 0 replies; 3+ messages in thread
From: Chris Hecker @ 2001-05-13  6:24 UTC (permalink / raw)
  To: David Fox, caml-list


>The pervasive function in_channel_length fails when the file size is
>too large for an int, but it doesn't raise an exception.  The code in
>io.c just checks for lseek errors.  Would a check for end > max_int be
>worthwhile?

Shouldn't all of the file size stuff be converted to int64s now anyway?

Chris


-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Caml-list] in_channel_length fails for files longer than max_int
@ 2001-05-14 16:55 ` David Fox
  2001-05-13  6:24   ` Chris Hecker
  2001-05-28 13:13   ` Xavier Leroy
  0 siblings, 2 replies; 3+ messages in thread
From: David Fox @ 2001-05-14 16:55 UTC (permalink / raw)
  To: caml-list

The pervasive function in_channel_length fails when the file size is
too large for an int, but it doesn't raise an exception.  The code in
io.c just checks for lseek errors.  Would a check for end > max_int be
worthwhile?

long channel_size(struct channel *channel)
{
  long end;

  end = lseek(channel->fd, 0, SEEK_END);
  if (end == -1 ||
      lseek(channel->fd, channel->offset, SEEK_SET) != channel->offset) {
    sys_error(NO_ARG);
  }
  return end;
}
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] in_channel_length fails for files longer than max_int
  2001-05-14 16:55 ` [Caml-list] in_channel_length fails for files longer than max_int David Fox
  2001-05-13  6:24   ` Chris Hecker
@ 2001-05-28 13:13   ` Xavier Leroy
  1 sibling, 0 replies; 3+ messages in thread
From: Xavier Leroy @ 2001-05-28 13:13 UTC (permalink / raw)
  To: David Fox; +Cc: caml-list

> The pervasive function in_channel_length fails when the file size is
> too large for an int, but it doesn't raise an exception.  The code in
> io.c just checks for lseek errors.  Would a check for end > max_int be
> worthwhile?

That's one possibility.  The code for channel_size is already less
portable than it ought to be:

> long channel_size(struct channel *channel)
> {
>   long end;
>   end = lseek(channel->fd, 0, SEEK_END);

The return type of "lseek" is actually off_t, which is specified to be
"an extended signed integral type".  So, there is no guarantee that a
"long" can hold a file offset without losing bits, although it happens
to work on most Unix systems.  The check you suggest would handle this
case as well.

Then, the conversion of the long into an OCaml "int" loses one more
bit of precision.  Since off_t is signed, we don't actually lose bits,
but may end up with a negative file size, which is tolerable for
printing, but will cause an error if it is passed to "seek".

Chris Hecker suggests:

> Shouldn't all of the file size stuff be converted to int64s now anyway?

That's another option, especially since it would allow "lseek64" or
"llseek" to be used internally instead of "lseek" when available, thus
making it possible to work with files bigger than 2Gb on a 32-bit
platform.  However, we can't break backward compatibility, so we'd
have to add new functions "long_seek" and "long_{in,out}_channel_length"
to the OCaml API.

- Xavier Leroy
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2001-05-28 13:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <William Chesters's message of "Sun, 13 May 2001 23:29:24 +0200 (CEST)">
2001-05-14 16:55 ` [Caml-list] in_channel_length fails for files longer than max_int David Fox
2001-05-13  6:24   ` Chris Hecker
2001-05-28 13:13   ` Xavier Leroy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).