From d5babe9fd13735744a217f543ba1838d58fb9b12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Tue, 22 Jun 2021 23:26:46 +0200 Subject: [PATCH 1/5] Fix FileDescriptor#pos return Int64 on armv6 --- src/crystal/system/unix/file_descriptor.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/crystal/system/unix/file_descriptor.cr b/src/crystal/system/unix/file_descriptor.cr index 68a4fb2ce3b9..7fb97e33f818 100644 --- a/src/crystal/system/unix/file_descriptor.cr +++ b/src/crystal/system/unix/file_descriptor.cr @@ -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! raise IO::Error.from_errno "Unable to tell" if pos == -1 pos end From 6d3b506b53c64ce398915cdb146ff22d276db3a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Tue, 22 Jun 2021 23:27:03 +0200 Subject: [PATCH 2/5] Fix Dwarf use Int64 offset --- src/crystal/dwarf/info.cr | 4 ++-- src/crystal/dwarf/line_numbers.cr | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/crystal/dwarf/info.cr b/src/crystal/dwarf/info.cr index 771c3702eb07..b5dc0832579d 100644 --- a/src/crystal/dwarf/info.cr +++ b/src/crystal/dwarf/info.cr @@ -11,8 +11,8 @@ module Crystal property! abbreviations : Array(Abbrev) property dwarf64 : Bool - @offset : LibC::OffT - @ref_offset : LibC::OffT + @offset : Int64 + @ref_offset : Int64 def initialize(@io : IO::FileDescriptor, @offset) @ref_offset = offset diff --git a/src/crystal/dwarf/line_numbers.cr b/src/crystal/dwarf/line_numbers.cr index 6d303f3f88cd..1ad9d0d04ae0 100644 --- a/src/crystal/dwarf/line_numbers.cr +++ b/src/crystal/dwarf/line_numbers.cr @@ -123,7 +123,7 @@ module Crystal # # An individual compressed sequence. struct Sequence - property! offset : LibC::OffT + property! offset : Int64 property! unit_length : UInt32 property! version : UInt16 property! header_length : UInt32 # FIXME: UInt64 for DWARF64 (uncommon) @@ -166,7 +166,7 @@ module Crystal # reduce the memory usage of repeating a String many times. getter matrix : Array(Array(Row)) - @offset : LibC::OffT + @offset : Int64 def initialize(@io : IO::FileDescriptor, size, @base_address : LibC::SizeT = 0) @offset = @io.tell From 1509694b4943eb00193c8c3ce9c6e7d6655388c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Wed, 23 Jun 2021 12:08:50 +0200 Subject: [PATCH 3/5] Add return type restriction to File::PReader#unbuffered_read --- src/crystal/system/unix/file_descriptor.cr | 2 +- src/crystal/system/win32/file_descriptor.cr | 4 ++-- src/file/preader.cr | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/crystal/system/unix/file_descriptor.cr b/src/crystal/system/unix/file_descriptor.cr index 7fb97e33f818..7bbf48f24487 100644 --- a/src/crystal/system/unix/file_descriptor.cr +++ b/src/crystal/system/unix/file_descriptor.cr @@ -153,7 +153,7 @@ module Crystal::System::FileDescriptor end def self.pread(fd, buffer, offset) - bytes_read = LibC.pread(fd, buffer, buffer.size, offset) + bytes_read = LibC.pread(fd, buffer, buffer.size, offset).to_i64! if bytes_read == -1 raise IO::Error.from_errno "Error reading file" diff --git a/src/crystal/system/win32/file_descriptor.cr b/src/crystal/system/win32/file_descriptor.cr index 49dcec575188..d5d24ada9779 100644 --- a/src/crystal/system/win32/file_descriptor.cr +++ b/src/crystal/system/win32/file_descriptor.cr @@ -157,11 +157,11 @@ module Crystal::System::FileDescriptor overlapped.union.offset.offsetHigh = LibC::DWORD.new(offset >> 32) if LibC.ReadFile(handle, buffer, buffer.size, out bytes_read, pointerof(overlapped)) == 0 error = WinError.value - return 0 if error == WinError::ERROR_HANDLE_EOF + return 0_i64 if error == WinError::ERROR_HANDLE_EOF raise IO::Error.from_winerror "Error reading file", error end - bytes_read + bytes_read.to_i64! end def self.from_stdio(fd) diff --git a/src/file/preader.cr b/src/file/preader.cr index e036929f4fee..f44e75b45835 100644 --- a/src/file/preader.cr +++ b/src/file/preader.cr @@ -13,7 +13,7 @@ class File::PReader < IO @pos = 0 end - def unbuffered_read(slice : Bytes) + def unbuffered_read(slice : Bytes) : Int64 check_open count = slice.size From 0628a6a5d7f913c42db503b3235f053b45fcd97b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Wed, 23 Jun 2021 19:32:39 +0200 Subject: [PATCH 4/5] Restrict File::PRead@pos to Int64 --- src/file/preader.cr | 1 + 1 file changed, 1 insertion(+) diff --git a/src/file/preader.cr b/src/file/preader.cr index f44e75b45835..e4999e80df53 100644 --- a/src/file/preader.cr +++ b/src/file/preader.cr @@ -6,6 +6,7 @@ class File::PReader < IO @offset : Int64 @bytesize : Int64 + @pos : Int64 def initialize(@file : File, offset : Int, bytesize : Int) @offset = offset.to_i64 From bda94381494b42e5c759a737788fdaa626cb40ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Wed, 23 Jun 2021 19:33:56 +0200 Subject: [PATCH 5/5] Use to_i64 over to_i64! --- src/crystal/system/unix/file_descriptor.cr | 4 ++-- src/crystal/system/win32/file_descriptor.cr | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/crystal/system/unix/file_descriptor.cr b/src/crystal/system/unix/file_descriptor.cr index 7bbf48f24487..bc3576a2fe01 100644 --- a/src/crystal/system/unix/file_descriptor.cr +++ b/src/crystal/system/unix/file_descriptor.cr @@ -80,7 +80,7 @@ module Crystal::System::FileDescriptor end private def system_pos - pos = LibC.lseek(fd, 0, IO::Seek::Current).to_i64! + pos = LibC.lseek(fd, 0, IO::Seek::Current).to_i64 raise IO::Error.from_errno "Unable to tell" if pos == -1 pos end @@ -153,7 +153,7 @@ module Crystal::System::FileDescriptor end def self.pread(fd, buffer, offset) - bytes_read = LibC.pread(fd, buffer, buffer.size, offset).to_i64! + bytes_read = LibC.pread(fd, buffer, buffer.size, offset).to_i64 if bytes_read == -1 raise IO::Error.from_errno "Error reading file" diff --git a/src/crystal/system/win32/file_descriptor.cr b/src/crystal/system/win32/file_descriptor.cr index d5d24ada9779..8d32088e0fd9 100644 --- a/src/crystal/system/win32/file_descriptor.cr +++ b/src/crystal/system/win32/file_descriptor.cr @@ -161,7 +161,7 @@ module Crystal::System::FileDescriptor raise IO::Error.from_winerror "Error reading file", error end - bytes_read.to_i64! + bytes_read.to_i64 end def self.from_stdio(fd)