Skip to content

Commit f84993a

Browse files
authored
Fix allocator for zig 0.14 (#7)
1 parent d5254e6 commit f84993a

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/zemscripten.zig

+15-4
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ pub const EmmalocAllocator = struct {
8686
.vtable = &.{
8787
.alloc = &alloc,
8888
.resize = &resize,
89+
.remap = &remap,
8990
.free = &free,
9091
},
9192
};
@@ -94,12 +95,12 @@ pub const EmmalocAllocator = struct {
9495
fn alloc(
9596
ctx: *anyopaque,
9697
len: usize,
97-
ptr_align_log2: u8,
98+
ptr_align_log2: std.mem.Alignment,
9899
return_address: usize,
99100
) ?[*]u8 {
100101
_ = ctx;
101102
_ = return_address;
102-
const ptr_align: u32 = @as(u32, 1) << @as(u5, @intCast(ptr_align_log2));
103+
const ptr_align: u32 = @as(u32, 1) << @as(u5, @intFromEnum(ptr_align_log2));
103104
if (!std.math.isPowerOfTwo(ptr_align)) unreachable;
104105
const ptr = emmalloc_memalign(ptr_align, len) orelse return null;
105106
return @ptrCast(ptr);
@@ -108,7 +109,7 @@ pub const EmmalocAllocator = struct {
108109
fn resize(
109110
ctx: *anyopaque,
110111
buf: []u8,
111-
buf_align_log2: u8,
112+
buf_align_log2: std.mem.Alignment,
112113
new_len: usize,
113114
return_address: usize,
114115
) bool {
@@ -118,10 +119,20 @@ pub const EmmalocAllocator = struct {
118119
return emmalloc_realloc_try(buf.ptr, new_len) != null;
119120
}
120121

122+
fn remap(
123+
ctx: *anyopaque,
124+
buf: []u8,
125+
buf_align_log2: std.mem.Alignment,
126+
new_len: usize,
127+
return_address: usize,
128+
) ?[*]u8 {
129+
return if (resize(ctx, buf, buf_align_log2, new_len, return_address)) buf.ptr else null;
130+
}
131+
121132
fn free(
122133
ctx: *anyopaque,
123134
buf: []u8,
124-
buf_align_log2: u8,
135+
buf_align_log2: std.mem.Alignment,
125136
return_address: usize,
126137
) void {
127138
_ = ctx;

0 commit comments

Comments
 (0)