aboutsummaryrefslogtreecommitdiff
path: root/std
diff options
context:
space:
mode:
authorLemonBoy <thatlemon@gmail.com>2019-05-03 13:11:53 +0200
committerLemonBoy <thatlemon@gmail.com>2019-05-04 08:44:26 +0200
commitb612512bb500defd399a11dfa47c83cefe4d87b5 (patch)
tree814da7387441ee9d5ee7498b7dd40c14492db3ab /std
parentfca3e3a73f157d93ae3d57f90c13512acfbe9aa4 (diff)
downloadzig-b612512bb500defd399a11dfa47c83cefe4d87b5.tar.gz
zig-b612512bb500defd399a11dfa47c83cefe4d87b5.zip
std: Remove some assumptions about the host platform
The stdlib is now 32-bit friendly.
Diffstat (limited to 'std')
-rw-r--r--std/crypto/chacha20.zig5
-rw-r--r--std/heap.zig2
-rw-r--r--std/os/linux.zig4
-rw-r--r--std/os/time.zig4
-rw-r--r--std/rand.zig4
5 files changed, 10 insertions, 9 deletions
diff --git a/std/crypto/chacha20.zig b/std/crypto/chacha20.zig
index 78ef700bdf..796b5c6e4f 100644
--- 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
index 65d346262b..c365fa0306 100644
--- a/std/heap.zig
+++ b/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..]);
diff --git a/std/os/linux.zig b/std/os/linux.zig
index e7f822185b..abfed410cc 100644
--- a/std/os/linux.zig
+++ b/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,
diff --git a/std/os/time.zig b/std/os/time.zig
index d742c5d03b..fb39fda1de 100644
--- a/std/os/time.zig
+++ b/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) {
diff --git a/std/rand.zig b/std/rand.zig
index a2fdfed6fd..4a6563f65a 100644
--- 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;
}