-
Notifications
You must be signed in to change notification settings - Fork 1.6k
SeekFrom
with different inner types is confusing (and non-POSIX)
#1889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
We are not going to break backwards compatibility and change the type in this field. Do you work with seekable structures that are over 9.2 exabytes? How would point 2 be improved if |
The current form implies that `pos` and `size` in a file should be `u64`.
This is not very useful (over `i64`), because no real structure needs this.
But if someone implemented some case where this could happen, an object
whose "real" size is not related to its "API" size (ex. sparesly allocated
memory buf with prespecified size), they are likely to make the same
mistake, and then when someone (else) does somehow use the full `u64` (just
because they can - in the example above it makes sense), things will break.
On the other hand, if `Start` were to hold `i64`, it would be implied that
`pos`, as well as `size`, should be `i64`, no usability will really get
hurt (the user from above will use the maximal `i64` and will be fine), but
no trouble will ensue.
In my usecase I get the effective size from outside. It shouldn't be
greater than `i64`, but if I don't check this (and why should I?), it might.
On Feb 8, 2017 1:17 AM, "Steven Fackler" <[email protected]> wrote:
We are not going to break backwards compatibility and change the type in
this field.
Do you work with seekable structures that are over 9.2 exabytes? How would
point 2 be improved if Start and End stored an i64?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#1889 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AC_zrQBmtW6B3clxgSAcL6Er-kkIa6_qks5raQmIgaJpZM4L6Nm8>
.
|
What I mean is that if an edge case doesn't matter, it's better to forbid
it than to let it break.
…On Feb 8, 2017 1:36 AM, "Amos Onn" ***@***.***> wrote:
The current form implies that `pos` and `size` in a file should be `u64`.
This is not very useful (over `i64`), because no real structure needs this.
But if someone implemented some case where this could happen, an object
whose "real" size is not related to its "API" size (ex. sparesly allocated
memory buf with prespecified size), they are likely to make the same
mistake, and then when someone (else) does somehow use the full `u64` (just
because they can - in the example above it makes sense), things will break.
On the other hand, if `Start` were to hold `i64`, it would be implied that
`pos`, as well as `size`, should be `i64`, no usability will really get
hurt (the user from above will use the maximal `i64` and will be fine), but
no trouble will ensue.
In my usecase I get the effective size from outside. It shouldn't be
greater than `i64`, but if I don't check this (and why should I?), it might.
On Feb 8, 2017 1:17 AM, "Steven Fackler" ***@***.***> wrote:
We are not going to break backwards compatibility and change the type in
this field.
Do you work with seekable structures that are over 9.2 exabytes? How would
point 2 be improved if Start and End stored an i64?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#1889 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AC_zrQBmtW6B3clxgSAcL6Er-kkIa6_qks5raQmIgaJpZM4L6Nm8>
.
|
Again, it is a year and a half too late to make that change.
I don't think that would be the case - |
Well, "Too late" is definitely a good argument. |
It uses lseek64. |
Seems this was resolved and the libs team is not inclined to do anything here so I'll close this. |
Currently,
SeekFrom
has different "inner" type depending on whether we seek from theStart
(u64
) or from theCurrent
orEnd
position (i64
). This of course only makes sense, if we assume thatSeek
objects can (and should) support au64
size. This has a few problems (in rising order of importance, IMO):SeekFrom
-s.Current
orEnd
, which kinda sucks. Not necessarily terrible, but also not the best API.Seek
for a custom type (which is not a wrapper of an inner,Seek
type) will encounter this problem. That's how I found it - I was at loss how to properly do the arithmetic, looked for a stdlib example, and found it was buggy. The other place I found in stdlib implementing a customSeek
type was intest_buffered_reader_seek_underflow()
inlibstd/io/buffered.rs
, and there they overcame the problem by making the type a "circular" reader. I presume this is because implementing proper arithmetic considering the two different types was too much work (and irrelevant for the test), but of course isn't applicable for many real-life cases.Generally speaking, I think that it is better to change an API that pushes people to have buggy implementations, especially when the ramifications are quite measly. The reason the bug above is still in stdlib is because nobody cares, because we never really have objects that are this big, which means we might as well use
i64
to store our position. For files, this also the standard, so no trouble with the OS interface there.The text was updated successfully, but these errors were encountered: