diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2018-06-05 18:03:21 -0400 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2018-06-05 18:03:21 -0400 |
| commit | 652f4bdf6242462182005f4c7149f13beaaa3259 (patch) | |
| tree | e8b131095700c37604ebad9934f836e51538aabe /std/heap.zig | |
| parent | 7a0948253636080e5abe59b938761ee7348a7025 (diff) | |
| download | zig-652f4bdf6242462182005f4c7149f13beaaa3259.tar.gz zig-652f4bdf6242462182005f4c7149f13beaaa3259.zip | |
disallow unknown-length pointer to opaque
This also means that translate-c has to detect when a pointer to
opaque is happening, and use `*` instead of `[*]`.
See #1059
Diffstat (limited to 'std/heap.zig')
| -rw-r--r-- | std/heap.zig | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/std/heap.zig b/std/heap.zig index 4444a2307a..5d430bc761 100644 --- a/std/heap.zig +++ b/std/heap.zig @@ -22,7 +22,7 @@ fn cAlloc(self: *Allocator, n: usize, alignment: u29) ![]u8 { } fn cRealloc(self: *Allocator, old_mem: []u8, new_size: usize, alignment: u29) ![]u8 { - const old_ptr = @ptrCast([*]c_void, old_mem.ptr); + const old_ptr = @ptrCast(*c_void, old_mem.ptr); if (c.realloc(old_ptr, new_size)) |buf| { return @ptrCast([*]u8, buf)[0..new_size]; } else if (new_size <= old_mem.len) { @@ -33,7 +33,7 @@ fn cRealloc(self: *Allocator, old_mem: []u8, new_size: usize, alignment: u29) ![ } fn cFree(self: *Allocator, old_mem: []u8) void { - const old_ptr = @ptrCast([*]c_void, old_mem.ptr); + const old_ptr = @ptrCast(*c_void, old_mem.ptr); c.free(old_ptr); } @@ -140,7 +140,7 @@ pub const DirectAllocator = struct { const old_adjusted_addr = @ptrToInt(old_mem.ptr); const old_record_addr = old_adjusted_addr + old_mem.len; const root_addr = @intToPtr(*align(1) usize, old_record_addr).*; - const old_ptr = @intToPtr([*]c_void, root_addr); + const old_ptr = @intToPtr(*c_void, root_addr); const amt = new_size + alignment + @sizeOf(usize); const new_ptr = os.windows.HeapReAlloc(??self.heap_handle, 0, old_ptr, amt) ?? blk: { if (new_size > old_mem.len) return error.OutOfMemory; @@ -170,7 +170,7 @@ pub const DirectAllocator = struct { Os.windows => { const record_addr = @ptrToInt(bytes.ptr) + bytes.len; const root_addr = @intToPtr(*align(1) usize, record_addr).*; - const ptr = @intToPtr([*]c_void, root_addr); + const ptr = @intToPtr(*c_void, root_addr); _ = os.windows.HeapFree(??self.heap_handle, 0, ptr); }, else => @compileError("Unsupported OS"), |
