diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2017-11-06 22:41:12 -0500 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2017-11-06 22:41:12 -0500 |
| commit | 3a600297ca3f99ee57630c44900eec1fe7c92804 (patch) | |
| tree | 9642e53df266077c0ee76c1a045366f8f805fe95 /std | |
| parent | 4a82c2d124881512548254f5cdff3009b2f424df (diff) | |
| parent | 634e8713c394bacfe080d03256d1dd4f9a43dd8c (diff) | |
| download | zig-3a600297ca3f99ee57630c44900eec1fe7c92804.tar.gz zig-3a600297ca3f99ee57630c44900eec1fe7c92804.zip | |
Merge remote-tracking branch 'origin/master' into llvm6
Diffstat (limited to 'std')
| -rw-r--r-- | std/heap.zig | 16 | ||||
| -rw-r--r-- | std/io.zig | 4 |
2 files changed, 14 insertions, 6 deletions
diff --git a/std/heap.zig b/std/heap.zig index b654f28a74..d0bf8ab871 100644 --- a/std/heap.zig +++ b/std/heap.zig @@ -17,8 +17,8 @@ pub var c_allocator = Allocator { }; fn cAlloc(self: &Allocator, n: usize, alignment: usize) -> %[]u8 { - if (c.malloc(usize(n))) |mem| { - @ptrCast(&u8, mem)[0..n] + if (c.malloc(usize(n))) |buf| { + @ptrCast(&u8, buf)[0..n] } else { error.OutOfMemory } @@ -29,8 +29,8 @@ fn cRealloc(self: &Allocator, old_mem: []u8, new_size: usize, alignment: usize) old_mem[0..new_size] } else { const old_ptr = @ptrCast(&c_void, old_mem.ptr); - if (c.realloc(old_ptr, usize(new_size))) |mem| { - @ptrCast(&u8, mem)[0..new_size] + if (c.realloc(old_ptr, usize(new_size))) |buf| { + @ptrCast(&u8, buf)[0..new_size] } else { error.OutOfMemory } @@ -136,6 +136,14 @@ pub const IncrementingAllocator = struct { } }; +test "c_allocator" { + if (builtin.link_libc) { + var slice = c_allocator.alloc(u8, 50) %% return; + defer c_allocator.free(slice); + slice = c_allocator.realloc(u8, slice, 100) %% return; + } +} + test "IncrementingAllocator" { const total_bytes = 100 * 1024 * 1024; var inc_allocator = %%IncrementingAllocator.init(total_bytes); diff --git a/std/io.zig b/std/io.zig index 9778f38239..499ae95da9 100644 --- a/std/io.zig +++ b/std/io.zig @@ -308,7 +308,7 @@ pub const InStream = struct { readFn: fn(self: &InStream, buffer: []u8) -> %usize, /// Replaces `buffer` contents by reading from the stream until it is finished. - /// If `buffer.len()` woould exceed `max_size`, `error.StreamTooLong` is returned and + /// If `buffer.len()` would exceed `max_size`, `error.StreamTooLong` is returned and /// the contents read from the stream are lost. pub fn readAllBuffer(self: &InStream, buffer: &Buffer, max_size: usize) -> %void { %return buffer.resize(0); @@ -339,7 +339,7 @@ pub const InStream = struct { var buf = Buffer.initNull(allocator); defer buf.deinit(); - %return self.readAllBuffer(self, &buf, max_size); + %return self.readAllBuffer(&buf, max_size); return buf.toOwnedSlice(); } |
