| author | |
| committer | |
| log | b2b0bf0506e708e6b8c143eb438a84592310b5a9 |
| tree | 28b7a8997249dafa8b1171e789fbb0dfce2a9d56 |
| parent | bd7eab573a5e5f1366cd5dc3639fef28c4acb32a |
* std.fs.File.copyRange and copyRangeAll return u64 instead of usize -
the returned value is how much of the `len` is transferred, so the
types should match. This removes the need for an `@intCast`.
* fix typo that removed a subtraction
* Fix the size of codegen.AnyMCValue which gave me a compile error when
I tried to build self-hosted for i386-linux.
* restore the coercion to u64 of syms_sect.sh_info. We want to make
sure the multiplication happens with 64 bits and not the smaller type
used by the ELF format.
* fix another offset parameter in link/Elf.zig to be u64 instead of usize
* add a nice little TODO note to help out Jakub
* FmtError already has FileTooBig in it; we just need to return it.5 files changed, 16 insertions(+), 11 deletions(-)
lib/std/fs/file.zig+7-6| ... | @@ -652,25 +652,26 @@ pub const File = struct { | ... | @@ -652,25 +652,26 @@ pub const File = struct { |
| 652 | 652 | ||
| 653 | pub const CopyRangeError = os.CopyFileRangeError; | 653 | pub const CopyRangeError = os.CopyFileRangeError; |
| 654 | 654 | ||
| 655 | pub fn copyRange(in: File, in_offset: u64, out: File, out_offset: u64, len: u64) CopyRangeError!usize { | 655 | pub fn copyRange(in: File, in_offset: u64, out: File, out_offset: u64, len: u64) CopyRangeError!u64 { |
| 656 | const adjusted_len = math.cast(usize, len) catch math.maxInt(usize); | 656 | const adjusted_len = math.cast(usize, len) catch math.maxInt(usize); |
| 657 | return os.copy_file_range(in.handle, in_offset, out.handle, out_offset, adjusted_len, 0); | 657 | const result = try os.copy_file_range(in.handle, in_offset, out.handle, out_offset, adjusted_len, 0); |
| 658 | return result; | ||
| 658 | } | 659 | } |
| 659 | 660 | ||
| 660 | /// Returns the number of bytes copied. If the number read is smaller than `buffer.len`, it | 661 | /// Returns the number of bytes copied. If the number read is smaller than `buffer.len`, it |
| 661 | /// means the in file reached the end. Reaching the end of a file is not an error condition. | 662 | /// means the in file reached the end. Reaching the end of a file is not an error condition. |
| 662 | pub fn copyRangeAll(in: File, in_offset: u64, out: File, out_offset: u64, len: u64) CopyRangeError!usize { | 663 | pub fn copyRangeAll(in: File, in_offset: u64, out: File, out_offset: u64, len: u64) CopyRangeError!u64 { |
| 663 | var total_bytes_copied: u64 = 0; | 664 | var total_bytes_copied: u64 = 0; |
| 664 | var in_off = in_offset; | 665 | var in_off = in_offset; |
| 665 | var out_off = out_offset; | 666 | var out_off = out_offset; |
| 666 | while (total_bytes_copied < len) { | 667 | while (total_bytes_copied < len) { |
| 667 | const amt_copied = try copyRange(in, in_off, out, out_off, len); | 668 | const amt_copied = try copyRange(in, in_off, out, out_off, len - total_bytes_copied); |
| 668 | if (amt_copied == 0) return @intCast(usize, total_bytes_copied); | 669 | if (amt_copied == 0) return total_bytes_copied; |
| 669 | total_bytes_copied += amt_copied; | 670 | total_bytes_copied += amt_copied; |
| 670 | in_off += amt_copied; | 671 | in_off += amt_copied; |
| 671 | out_off += amt_copied; | 672 | out_off += amt_copied; |
| 672 | } | 673 | } |
| 673 | return @intCast(usize, total_bytes_copied); | 674 | return total_bytes_copied; |
| 674 | } | 675 | } |
| 675 | 676 | ||
| 676 | pub const WriteFileOptions = struct { | 677 | pub const WriteFileOptions = struct { |
src/codegen.zig+1-1| ... | @@ -32,7 +32,7 @@ pub const BlockData = struct { | ... | @@ -32,7 +32,7 @@ pub const BlockData = struct { |
| 32 | /// comptime assert that makes sure we guessed correctly about the size. This only | 32 | /// comptime assert that makes sure we guessed correctly about the size. This only |
| 33 | /// exists so that we can bitcast an arch-independent field to and from the real MCValue. | 33 | /// exists so that we can bitcast an arch-independent field to and from the real MCValue. |
| 34 | pub const AnyMCValue = extern struct { | 34 | pub const AnyMCValue = extern struct { |
| 35 | a: u64, | 35 | a: usize, |
| 36 | b: u64, | 36 | b: u64, |
| 37 | }; | 37 | }; |
| 38 | 38 |
src/link/Elf.zig+2-2| ... | @@ -2757,7 +2757,7 @@ fn writeSymbol(self: *Elf, index: usize) !void { | ... | @@ -2757,7 +2757,7 @@ fn writeSymbol(self: *Elf, index: usize) !void { |
| 2757 | if (needed_size > self.allocatedSize(syms_sect.sh_offset)) { | 2757 | if (needed_size > self.allocatedSize(syms_sect.sh_offset)) { |
| 2758 | // Move all the symbols to a new file location. | 2758 | // Move all the symbols to a new file location. |
| 2759 | const new_offset = self.findFreeSpace(needed_size, sym_align); | 2759 | const new_offset = self.findFreeSpace(needed_size, sym_align); |
| 2760 | const existing_size = syms_sect.sh_info * sym_size; | 2760 | const existing_size = @as(u64, syms_sect.sh_info) * sym_size; |
| 2761 | const amt = try self.base.file.?.copyRangeAll(syms_sect.sh_offset, self.base.file.?, new_offset, existing_size); | 2761 | const amt = try self.base.file.?.copyRangeAll(syms_sect.sh_offset, self.base.file.?, new_offset, existing_size); |
| 2762 | if (amt != existing_size) return error.InputOutput; | 2762 | if (amt != existing_size) return error.InputOutput; |
| 2763 | syms_sect.sh_offset = new_offset; | 2763 | syms_sect.sh_offset = new_offset; |
| ... | @@ -2990,7 +2990,7 @@ fn pwriteDbgInfoNops( | ... | @@ -2990,7 +2990,7 @@ fn pwriteDbgInfoNops( |
| 2990 | buf: []const u8, | 2990 | buf: []const u8, |
| 2991 | next_padding_size: usize, | 2991 | next_padding_size: usize, |
| 2992 | trailing_zero: bool, | 2992 | trailing_zero: bool, |
| 2993 | offset: usize, | 2993 | offset: u64, |
| 2994 | ) !void { | 2994 | ) !void { |
| 2995 | const tracy = trace(@src()); | 2995 | const tracy = trace(@src()); |
| 2996 | defer tracy.end(); | 2996 | defer tracy.end(); |
src/link/MachO.zig+4| ... | @@ -1264,6 +1264,10 @@ fn updateString(self: *MachO, old_str_off: u32, new_name: []const u8) !u32 { | ... | @@ -1264,6 +1264,10 @@ fn updateString(self: *MachO, old_str_off: u32, new_name: []const u8) !u32 { |
| 1264 | return self.makeString(new_name); | 1264 | return self.makeString(new_name); |
| 1265 | } | 1265 | } |
| 1266 | 1266 | ||
| 1267 | /// TODO This should not heap allocate, instead it should utilize a fixed size, statically allocated | ||
| 1268 | /// global const array. You could even use pwritev to write the same buffer multiple times with only | ||
| 1269 | /// 1 syscall if you needed to, for example, write 8192 bytes using a buffer of only 4096 bytes. | ||
| 1270 | /// This size parameter should probably be a usize not u64. | ||
| 1267 | fn addPadding(self: *MachO, size: u64, file_offset: u64) !void { | 1271 | fn addPadding(self: *MachO, size: u64, file_offset: u64) !void { |
| 1268 | if (size == 0) return; | 1272 | if (size == 0) return; |
| 1269 | 1273 |
src/main.zig+2-2| ... | @@ -2541,7 +2541,7 @@ fn fmtPathFile( | ... | @@ -2541,7 +2541,7 @@ fn fmtPathFile( |
| 2541 | check_mode: bool, | 2541 | check_mode: bool, |
| 2542 | dir: fs.Dir, | 2542 | dir: fs.Dir, |
| 2543 | sub_path: []const u8, | 2543 | sub_path: []const u8, |
| 2544 | ) (FmtError || error{Overflow})!void { | 2544 | ) FmtError!void { |
| 2545 | const source_file = try dir.openFile(sub_path, .{}); | 2545 | const source_file = try dir.openFile(sub_path, .{}); |
| 2546 | var file_closed = false; | 2546 | var file_closed = false; |
| 2547 | errdefer if (!file_closed) source_file.close(); | 2547 | errdefer if (!file_closed) source_file.close(); |
| ... | @@ -2554,7 +2554,7 @@ fn fmtPathFile( | ... | @@ -2554,7 +2554,7 @@ fn fmtPathFile( |
| 2554 | const source_code = source_file.readToEndAllocOptions( | 2554 | const source_code = source_file.readToEndAllocOptions( |
| 2555 | fmt.gpa, | 2555 | fmt.gpa, |
| 2556 | max_src_size, | 2556 | max_src_size, |
| 2557 | try std.math.cast(usize, stat.size), | 2557 | std.math.cast(usize, stat.size) catch return error.FileTooBig, |
| 2558 | @alignOf(u8), | 2558 | @alignOf(u8), |
| 2559 | null, | 2559 | null, |
| 2560 | ) catch |err| switch (err) { | 2560 | ) catch |err| switch (err) { |