summaryrefslogtreecommitdiff
path: root/src/os/wasm.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/os/wasm.zig')
-rw-r--r--src/os/wasm.zig24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/os/wasm.zig b/src/os/wasm.zig
index d496e404e..5d3c65830 100644
--- a/src/os/wasm.zig
+++ b/src/os/wasm.zig
@@ -37,6 +37,18 @@ pub export fn malloc(len: usize) ?[*]u8 {
return alloc_(len) catch return null;
}
+fn alloc_(len: usize) ![*]u8 {
+ // Create the allocation
+ const slice = try alloc.alloc(u8, len);
+ errdefer alloc.free(slice);
+
+ // Store the size so we can deallocate later
+ try allocs.putNoClobber(alloc, slice.ptr, slice.len);
+ errdefer _ = allocs.remove(slice.ptr);
+
+ return slice.ptr;
+}
+
/// Free an allocation from malloc.
pub export fn free(ptr: ?[*]u8) void {
if (ptr) |v| {
@@ -79,18 +91,6 @@ pub fn toModuleOwned(ptr: anytype) void {
_ = allocs.remove(casted);
}
-fn alloc_(len: usize) ![*]u8 {
- // Create the allocation
- const slice = try alloc.alloc(u8, len);
- errdefer alloc.free(slice);
-
- // Store the size so we can deallocate later
- try allocs.putNoClobber(alloc, slice.ptr, slice.len);
- errdefer _ = allocs.remove(slice.ptr);
-
- return slice.ptr;
-}
-
test "basics" {
const testing = std.testing;
var buf = malloc(32).?;