Merge branch 'FireFox317-fix-32-bit-target'

This commit is contained in:
Andrew Kelley 2020-10-07 00:42:58 -07:00
commit f2d374e846
6 changed files with 19 additions and 13 deletions

View File

@ -615,7 +615,7 @@ pub const File = struct {
}
}
pub fn pwritev(self: File, iovecs: []os.iovec_const, offset: usize) PWriteError!usize {
pub fn pwritev(self: File, iovecs: []os.iovec_const, offset: u64) PWriteError!usize {
if (is_windows) {
// TODO improve this to use WriteFileScatter
if (iovecs.len == 0) return @as(usize, 0);
@ -632,11 +632,11 @@ pub const File = struct {
/// The `iovecs` parameter is mutable because this function needs to mutate the fields in
/// order to handle partial writes from the underlying OS layer.
pub fn pwritevAll(self: File, iovecs: []os.iovec_const, offset: usize) PWriteError!void {
pub fn pwritevAll(self: File, iovecs: []os.iovec_const, offset: u64) PWriteError!void {
if (iovecs.len == 0) return;
var i: usize = 0;
var off: usize = 0;
var off: u64 = 0;
while (true) {
var amt = try self.pwritev(iovecs[i..], offset + off);
off += amt;
@ -652,14 +652,16 @@ pub const File = struct {
pub const CopyRangeError = os.CopyFileRangeError;
pub fn copyRange(in: File, in_offset: u64, out: File, out_offset: u64, len: usize) CopyRangeError!usize {
return os.copy_file_range(in.handle, in_offset, out.handle, out_offset, len, 0);
pub fn copyRange(in: File, in_offset: u64, out: File, out_offset: u64, len: u64) CopyRangeError!u64 {
const adjusted_len = math.cast(usize, len) catch math.maxInt(usize);
const result = try os.copy_file_range(in.handle, in_offset, out.handle, out_offset, adjusted_len, 0);
return result;
}
/// Returns the number of bytes copied. If the number read is smaller than `buffer.len`, it
/// means the in file reached the end. Reaching the end of a file is not an error condition.
pub fn copyRangeAll(in: File, in_offset: u64, out: File, out_offset: u64, len: usize) CopyRangeError!usize {
var total_bytes_copied: usize = 0;
pub fn copyRangeAll(in: File, in_offset: u64, out: File, out_offset: u64, len: u64) CopyRangeError!u64 {
var total_bytes_copied: u64 = 0;
var in_off = in_offset;
var out_off = out_offset;
while (total_bytes_copied < len) {

View File

@ -32,7 +32,7 @@ pub const BlockData = struct {
/// comptime assert that makes sure we guessed correctly about the size. This only
/// exists so that we can bitcast an arch-independent field to and from the real MCValue.
pub const AnyMCValue = extern struct {
a: u64,
a: usize,
b: u64,
};

View File

@ -2911,7 +2911,7 @@ fn pwriteDbgLineNops(
prev_padding_size: usize,
buf: []const u8,
next_padding_size: usize,
offset: usize,
offset: u64,
) !void {
const tracy = trace(@src());
defer tracy.end();
@ -2990,7 +2990,7 @@ fn pwriteDbgInfoNops(
buf: []const u8,
next_padding_size: usize,
trailing_zero: bool,
offset: usize,
offset: u64,
) !void {
const tracy = trace(@src());
defer tracy.end();

View File

@ -1264,10 +1264,14 @@ fn updateString(self: *MachO, old_str_off: u32, new_name: []const u8) !u32 {
return self.makeString(new_name);
}
/// TODO This should not heap allocate, instead it should utilize a fixed size, statically allocated
/// global const array. You could even use pwritev to write the same buffer multiple times with only
/// 1 syscall if you needed to, for example, write 8192 bytes using a buffer of only 4096 bytes.
/// This size parameter should probably be a usize not u64.
fn addPadding(self: *MachO, size: u64, file_offset: u64) !void {
if (size == 0) return;
const buf = try self.base.allocator.alloc(u8, size);
const buf = try self.base.allocator.alloc(u8, @intCast(usize, size));
defer self.base.allocator.free(buf);
mem.set(u8, buf[0..], 0);

View File

@ -2554,7 +2554,7 @@ fn fmtPathFile(
const source_code = source_file.readToEndAllocOptions(
fmt.gpa,
max_src_size,
stat.size,
std.math.cast(usize, stat.size) catch return error.FileTooBig,
@alignOf(u8),
null,
) catch |err| switch (err) {

View File

@ -842,7 +842,7 @@ pub const Value = extern union {
.int_u64 => {
const x = self.cast(Payload.Int_u64).?.int;
if (x == 0) return 0;
return std.math.log2(x) + 1;
return @intCast(usize, std.math.log2(x) + 1);
},
.int_i64 => {
@panic("TODO implement i64 intBitCountTwosComp");