authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-01-26 19:58:40-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-01-26 20:02:01-07:00
logdb55f469c12c01831bd393c6701c26c15ffe726c
tree60a760bef0cf5288188bde6a5b8861e74b49208d
parent50accb757fb8514c3eac824fad5d09d569a6fdc9

std.mem.Allocator: upgrade to new function pointer semantics


1 files changed, 16 insertions(+), 3 deletions(-)

lib/std/mem/Allocator.zig+16-3
......@@ -23,7 +23,10 @@ pub const VTable = struct {
2323 ///
2424 /// `ret_addr` is optionally provided as the first return address of the allocation call stack.
2525 /// If the value is `0` it means no return address has been provided.
26 alloc: fn (ptr: *anyopaque, len: usize, ptr_align: u29, len_align: u29, ret_addr: usize) Error![]u8,
26 alloc: switch (builtin.zig_backend) {
27 .stage1 => allocProto, // temporary workaround until we replace stage1 with stage2
28 else => *const allocProto,
29 },
2730
2831 /// Attempt to expand or shrink memory in place. `buf.len` must equal the most recent
2932 /// length returned by `alloc` or `resize`. `buf_align` must equal the same value
......@@ -42,16 +45,26 @@ pub const VTable = struct {
4245 ///
4346 /// `ret_addr` is optionally provided as the first return address of the allocation call stack.
4447 /// If the value is `0` it means no return address has been provided.
45 resize: fn (ptr: *anyopaque, buf: []u8, buf_align: u29, new_len: usize, len_align: u29, ret_addr: usize) ?usize,
48 resize: switch (builtin.zig_backend) {
49 .stage1 => resizeProto, // temporary workaround until we replace stage1 with stage2
50 else => *const resizeProto,
51 },
4652
4753 /// Free and invalidate a buffer. `buf.len` must equal the most recent length returned by `alloc` or `resize`.
4854 /// `buf_align` must equal the same value that was passed as the `ptr_align` parameter to the original `alloc` call.
4955 ///
5056 /// `ret_addr` is optionally provided as the first return address of the allocation call stack.
5157 /// If the value is `0` it means no return address has been provided.
52 free: fn (ptr: *anyopaque, buf: []u8, buf_align: u29, ret_addr: usize) void,
58 free: switch (builtin.zig_backend) {
59 .stage1 => freeProto, // temporary workaround until we replace stage1 with stage2
60 else => *const freeProto,
61 },
5362};
5463
64const allocProto = fn (ptr: *anyopaque, len: usize, ptr_align: u29, len_align: u29, ret_addr: usize) Error![]u8;
65const resizeProto = fn (ptr: *anyopaque, buf: []u8, buf_align: u29, new_len: usize, len_align: u29, ret_addr: usize) ?usize;
66const freeProto = fn (ptr: *anyopaque, buf: []u8, buf_align: u29, ret_addr: usize) void;
67
5568pub fn init(
5669 pointer: anytype,
5770 comptime allocFn: fn (ptr: @TypeOf(pointer), len: usize, ptr_align: u29, len_align: u29, ret_addr: usize) Error![]u8,