Skip to content
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

Fix FileDescriptor#pos return Int64 on armv6 #10845

Merged

Conversation

straight-shoota
Copy link
Member

Since #10580, the return type of IO::FileDescriptor#pos is restricted to Int64. This means it's actually broken on armv6.

Similarly, IO::FileDescriptor#pread was missing a type restriction and returned different types depending on the target platform. This is getting unified.

This resolves the initial reports of #10645, but there may be more (#10645 (comment)).

@straight-shoota straight-shoota added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib:files platform:arm labels Jun 23, 2021
@@ -80,7 +80,7 @@ module Crystal::System::FileDescriptor
end

private def system_pos
pos = LibC.lseek(fd, 0, IO::Seek::Current)
pos = LibC.lseek(fd, 0, IO::Seek::Current).to_i64!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does it need to_i64! if to_i64 already introduces no additional runtime checks for types <= 64

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I accociate the exclamation mark method when I know the cast is safe and doesn't need any check. But we can use #to_i64 as well. I'm not sure I care either way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We happen to live in a world where we can say that this will never be Int128. But why rely on that instead of just writing the expression that's always correct? I think those ! methods need a high bar for acceptance.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, on the other hand maybe even if it was Int128 we'd prefer to assume that there are never such huge files. Whatever :D

@@ -13,7 +13,7 @@ class File::PReader < IO
@pos = 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not directly related, but pos really should be Int64

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added it anyways. It's in a similar mood.

@straight-shoota straight-shoota added this to the 1.1.0 milestone Jun 29, 2021
@straight-shoota straight-shoota changed the title Fix FileDescriptor#pos return Int64 on armv6 Fix FileDescriptor#pos return Int64 on armv6 Jul 2, 2021
@straight-shoota straight-shoota merged commit 849d1d1 into crystal-lang:master Jul 3, 2021
@straight-shoota straight-shoota deleted the fix/file-pos-armv6 branch July 3, 2021 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. platform:arm topic:stdlib:files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants