Commit b612512bb5

LemonBoy <thatlemon@gmail.com>
2019-05-03 13:11:53
std: Remove some assumptions about the host platform
The stdlib is now 32-bit friendly.
1 parent fca3e3a
Changed files (5)
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) {
std/os/linux.zig
@@ -1100,8 +1100,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,
std/os/time.zig
@@ -31,8 +31,8 @@ pub fn sleep(nanoseconds: u64) void {
 
 pub fn posixSleep(seconds: u63, nanoseconds: u63) void {
     var req = posix.timespec{
-        .tv_sec = seconds,
-        .tv_nsec = nanoseconds,
+        .tv_sec = @intCast(isize, seconds),
+        .tv_nsec = @intCast(isize, nanoseconds),
     };
     var rem: posix.timespec = undefined;
     while (true) {
std/heap.zig
@@ -601,7 +601,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..]);
 
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;
     }