| ... | ... | @@ -23,7 +23,10 @@ pub const VTable = struct { |
| 23 | 23 | /// |
| 24 | 24 | /// `ret_addr` is optionally provided as the first return address of the allocation call stack. |
| 25 | 25 | /// 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 | }, |
| 27 | 30 | |
| 28 | 31 | /// Attempt to expand or shrink memory in place. `buf.len` must equal the most recent |
| 29 | 32 | /// length returned by `alloc` or `resize`. `buf_align` must equal the same value |
| ... | ... | @@ -42,16 +45,26 @@ pub const VTable = struct { |
| 42 | 45 | /// |
| 43 | 46 | /// `ret_addr` is optionally provided as the first return address of the allocation call stack. |
| 44 | 47 | /// 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 | }, |
| 46 | 52 | |
| 47 | 53 | /// Free and invalidate a buffer. `buf.len` must equal the most recent length returned by `alloc` or `resize`. |
| 48 | 54 | /// `buf_align` must equal the same value that was passed as the `ptr_align` parameter to the original `alloc` call. |
| 49 | 55 | /// |
| 50 | 56 | /// `ret_addr` is optionally provided as the first return address of the allocation call stack. |
| 51 | 57 | /// 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 | }, |
| 53 | 62 | }; |
| 54 | 63 | |
| 64 | const allocProto = fn (ptr: *anyopaque, len: usize, ptr_align: u29, len_align: u29, ret_addr: usize) Error![]u8; |
| 65 | const resizeProto = fn (ptr: *anyopaque, buf: []u8, buf_align: u29, new_len: usize, len_align: u29, ret_addr: usize) ?usize; |
| 66 | const freeProto = fn (ptr: *anyopaque, buf: []u8, buf_align: u29, ret_addr: usize) void; |
| 67 | |
| 55 | 68 | pub fn init( |
| 56 | 69 | pointer: anytype, |
| 57 | 70 | comptime allocFn: fn (ptr: @TypeOf(pointer), len: usize, ptr_align: u29, len_align: u29, ret_addr: usize) Error![]u8, |