| ... | @@ -23,7 +23,10 @@ pub const VTable = struct { | ... | @@ -23,7 +23,10 @@ pub const VTable = struct { |
| 23 | /// | 23 | /// |
| 24 | /// `ret_addr` is optionally provided as the first return address of the allocation call stack. | 24 | /// `ret_addr` is optionally provided as the first return address of the allocation call stack. |
| 25 | /// If the value is `0` it means no return address has been provided. | 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 | /// Attempt to expand or shrink memory in place. `buf.len` must equal the most recent | 31 | /// Attempt to expand or shrink memory in place. `buf.len` must equal the most recent |
| 29 | /// length returned by `alloc` or `resize`. `buf_align` must equal the same value | 32 | /// length returned by `alloc` or `resize`. `buf_align` must equal the same value |
| ... | @@ -42,16 +45,26 @@ pub const VTable = struct { | ... | @@ -42,16 +45,26 @@ pub const VTable = struct { |
| 42 | /// | 45 | /// |
| 43 | /// `ret_addr` is optionally provided as the first return address of the allocation call stack. | 46 | /// `ret_addr` is optionally provided as the first return address of the allocation call stack. |
| 44 | /// If the value is `0` it means no return address has been provided. | 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 | /// Free and invalidate a buffer. `buf.len` must equal the most recent length returned by `alloc` or `resize`. | 53 | /// Free and invalidate a buffer. `buf.len` must equal the most recent length returned by `alloc` or `resize`. |
| 48 | /// `buf_align` must equal the same value that was passed as the `ptr_align` parameter to the original `alloc` call. | 54 | /// `buf_align` must equal the same value that was passed as the `ptr_align` parameter to the original `alloc` call. |
| 49 | /// | 55 | /// |
| 50 | /// `ret_addr` is optionally provided as the first return address of the allocation call stack. | 56 | /// `ret_addr` is optionally provided as the first return address of the allocation call stack. |
| 51 | /// If the value is `0` it means no return address has been provided. | 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 | pub fn init( | 68 | pub fn init( |
| 56 | pointer: anytype, | 69 | pointer: anytype, |
| 57 | comptime allocFn: fn (ptr: @TypeOf(pointer), len: usize, ptr_align: u29, len_align: u29, ret_addr: usize) Error![]u8, | 70 | comptime allocFn: fn (ptr: @TypeOf(pointer), len: usize, ptr_align: u29, len_align: u29, ret_addr: usize) Error![]u8, |