aboutsummaryrefslogtreecommitdiff
path: root/lib/std
diff options
context:
space:
mode:
Diffstat (limited to 'lib/std')
-rw-r--r--lib/std/mem/Allocator.zig19
1 files changed, 16 insertions, 3 deletions
diff --git a/lib/std/mem/Allocator.zig b/lib/std/mem/Allocator.zig
index db2da5599b..59e93480ba 100644
--- a/lib/std/mem/Allocator.zig
+++ b/lib/std/mem/Allocator.zig
@@ -23,7 +23,10 @@ pub const VTable = struct {
///
/// `ret_addr` is optionally provided as the first return address of the allocation call stack.
/// If the value is `0` it means no return address has been provided.
- alloc: fn (ptr: *anyopaque, len: usize, ptr_align: u29, len_align: u29, ret_addr: usize) Error![]u8,
+ alloc: switch (builtin.zig_backend) {
+ .stage1 => allocProto, // temporary workaround until we replace stage1 with stage2
+ else => *const allocProto,
+ },
/// Attempt to expand or shrink memory in place. `buf.len` must equal the most recent
/// length returned by `alloc` or `resize`. `buf_align` must equal the same value
@@ -42,16 +45,26 @@ pub const VTable = struct {
///
/// `ret_addr` is optionally provided as the first return address of the allocation call stack.
/// If the value is `0` it means no return address has been provided.
- resize: fn (ptr: *anyopaque, buf: []u8, buf_align: u29, new_len: usize, len_align: u29, ret_addr: usize) ?usize,
+ resize: switch (builtin.zig_backend) {
+ .stage1 => resizeProto, // temporary workaround until we replace stage1 with stage2
+ else => *const resizeProto,
+ },
/// Free and invalidate a buffer. `buf.len` must equal the most recent length returned by `alloc` or `resize`.
/// `buf_align` must equal the same value that was passed as the `ptr_align` parameter to the original `alloc` call.
///
/// `ret_addr` is optionally provided as the first return address of the allocation call stack.
/// If the value is `0` it means no return address has been provided.
- free: fn (ptr: *anyopaque, buf: []u8, buf_align: u29, ret_addr: usize) void,
+ free: switch (builtin.zig_backend) {
+ .stage1 => freeProto, // temporary workaround until we replace stage1 with stage2
+ else => *const freeProto,
+ },
};
+const allocProto = fn (ptr: *anyopaque, len: usize, ptr_align: u29, len_align: u29, ret_addr: usize) Error![]u8;
+const resizeProto = fn (ptr: *anyopaque, buf: []u8, buf_align: u29, new_len: usize, len_align: u29, ret_addr: usize) ?usize;
+const freeProto = fn (ptr: *anyopaque, buf: []u8, buf_align: u29, ret_addr: usize) void;
+
pub fn init(
pointer: anytype,
comptime allocFn: fn (ptr: @TypeOf(pointer), len: usize, ptr_align: u29, len_align: u29, ret_addr: usize) Error![]u8,