commit 70a9ee3dd68d8ed28a9fd2dc29f6c88fee5d789e (tree)
parent 6f0aa801c80a434b7cc931e879d234a8de501e38
Author: Andrew Kelley <andrew@ziglang.org>
Date: Sat, 4 May 2019 14:46:35 -0400
Merge branch 'stdlib-32b' of https://github.com/LemonBoy/zig into LemonBoy-stdlib-32b
Diffstat:
5 files changed, 26 insertions(+), 13 deletions(-)
diff --git a/std/crypto/chacha20.zig b/std/crypto/chacha20.zig
@@ -142,7 +142,7 @@ pub fn chaCha20With64BitNonce(out: []u8, in: []const u8, counter: u64, key: [32]
assert(in.len >= out.len);
assert(counter +% (in.len >> 6) >= counter);
- var cursor: u64 = 0;
+ var cursor: usize = 0;
var k: [8]u32 = undefined;
var c: [4]u32 = undefined;
@@ -161,7 +161,8 @@ pub fn chaCha20With64BitNonce(out: []u8, in: []const u8, counter: u64, key: [32]
c[3] = mem.readIntSliceLittle(u32, nonce[4..8]);
const block_size = (1 << 6);
- const big_block = (block_size << 32);
+ // The full block size is greater than the address space on a 32bit machine
+ const big_block = if (@sizeOf(usize) > 4) (block_size << 32) else maxInt(usize);
// first partial big block
if (((@intCast(u64, maxInt(u32) - @truncate(u32, counter)) + 1) << 6) < in.len) {
diff --git a/std/heap.zig b/std/heap.zig
@@ -603,7 +603,7 @@ test "ArenaAllocator" {
try testAllocatorAlignedShrink(&arena_allocator.allocator);
}
-var test_fixed_buffer_allocator_memory: [40000 * @sizeOf(usize)]u8 = undefined;
+var test_fixed_buffer_allocator_memory: [40000 * @sizeOf(u64)]u8 = undefined;
test "FixedBufferAllocator" {
var fixed_buffer_allocator = FixedBufferAllocator.init(test_fixed_buffer_allocator_memory[0..]);
diff --git a/std/os/linux.zig b/std/os/linux.zig
@@ -1101,8 +1101,8 @@ pub fn sigaction(sig: u6, noalias act: *const Sigaction, noalias oact: ?*Sigacti
const NSIG = 65;
const sigset_t = [128 / @sizeOf(usize)]usize;
-const all_mask = []usize{maxInt(usize)};
-const app_mask = []usize{0xfffffffc7fffffff};
+const all_mask = []u32{0xffffffff, 0xffffffff};
+const app_mask = []u32{0xfffffffc, 0x7fffffff};
const k_sigaction = extern struct {
handler: extern fn (i32) void,
diff --git a/std/os/time.zig b/std/os/time.zig
@@ -3,6 +3,7 @@ const builtin = @import("builtin");
const Os = builtin.Os;
const debug = std.debug;
const testing = std.testing;
+const math = std.math;
const windows = std.os.windows;
const linux = std.os.linux;
@@ -30,16 +31,26 @@ pub fn sleep(nanoseconds: u64) void {
}
pub fn posixSleep(seconds: u63, nanoseconds: u63) void {
- var req = posix.timespec{
- .tv_sec = seconds,
- .tv_nsec = nanoseconds,
- };
+ var req: posix.timespec = undefined;
var rem: posix.timespec = undefined;
+
+ var req_sec = seconds;
+ var req_nsec = nanoseconds;
+
while (true) {
+ req.tv_sec = math.min(math.maxInt(isize), req_sec);
+ req.tv_nsec = @intCast(isize, req_nsec);
+
+ req_sec -= @intCast(u63, req.tv_sec);
+ req_nsec = 0;
+
const ret_val = posix.nanosleep(&req, &rem);
const err = posix.getErrno(ret_val);
- if (err == 0) return;
switch (err) {
+ 0 => {
+ // If there's still time to wait keep running the loop
+ if (req_sec == 0 and req_nsec == 0) return;
+ },
posix.EFAULT => unreachable,
posix.EINVAL => {
// Sometimes Darwin returns EINVAL for no reason.
@@ -47,7 +58,8 @@ pub fn posixSleep(seconds: u63, nanoseconds: u63) void {
return;
},
posix.EINTR => {
- req = rem;
+ req_sec += @intCast(u63, rem.tv_sec);
+ req_nsec = @intCast(u63, rem.tv_nsec);
continue;
},
else => return,
diff --git a/std/rand.zig b/std/rand.zig
@@ -768,10 +768,10 @@ pub const Isaac64 = struct {
const x = self.m[base + m1];
self.a = mix +% self.m[base + m2];
- const y = self.a +% self.b +% self.m[(x >> 3) % self.m.len];
+ const y = self.a +% self.b +% self.m[@intCast(usize, (x >> 3) % self.m.len)];
self.m[base + m1] = y;
- self.b = x +% self.m[(y >> 11) % self.m.len];
+ self.b = x +% self.m[@intCast(usize, (y >> 11) % self.m.len)];
self.r[self.r.len - 1 - base - m1] = self.b;
}