From d3edac5aa43e0972cec52aa52c171a6c582bc432 Mon Sep 17 00:00:00 2001 From: Mahdi Sharifi Date: Fri, 31 May 2024 22:44:17 +0330 Subject: [PATCH] Update to the latest Zig --- .gitignore | 4 +- build.zig | 35 +-- build.zig.zon | 9 +- src/codegen/core.zig | 2 +- src/core/ByteMap.zig | 16 +- src/core/FreeListAlloc.zig | 107 ++++++++ src/core/Kivi.zig | 28 +-- src/core/Wyhash.zig | 233 ------------------ src/core/include/kivi.h | 2 +- .../js/runtimes/nodejs/functions/del.zig | 2 +- .../js/runtimes/nodejs/functions/set.zig | 6 +- 11 files changed, 149 insertions(+), 295 deletions(-) create mode 100644 src/core/FreeListAlloc.zig delete mode 100644 src/core/Wyhash.zig diff --git a/.gitignore b/.gitignore index c501269..0ed5f8a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -**/zig-cache +**/.zig-cache **/zig-out **/node_modules **/pnpm-lock.yaml @@ -6,4 +6,4 @@ bench/faker/data/* !bench/faker/data/README.md perf.data -perf.data.old \ No newline at end of file +perf.data.old diff --git a/build.zig b/build.zig index ce61fee..9bc2974 100644 --- a/build.zig +++ b/build.zig @@ -5,7 +5,7 @@ var target: std.Target = undefined; var optimize: std.builtin.OptimizeMode = undefined; var resolved_target: std.Build.ResolvedTarget = undefined; -var global_deps: [3]Dependency = undefined; +var global_deps: [2]Dependency = undefined; const Dependency = struct { name: []const u8, module: *std.Build.Module, @@ -29,15 +29,11 @@ const Dependency = struct { comptime name: []const u8, comptime source: []const u8, comptime n: comptime_int, - comptime link_module_to: ?comptime_int, ) void { global_deps[n] = .{ .name = name, - .module = b.createModule(.{ .root_source_file = .{ .path = source } }), + .module = b.createModule(.{ .root_source_file = .{ .src_path = .{ .sub_path = source, .owner = b } } }), }; - if (link_module_to) |link_module| { - global_deps[n].module.addImport(global_deps[link_module].name, global_deps[link_module].module); - } } }; @@ -51,7 +47,7 @@ const Libs = struct { strip = true; } - const shared = b.addSharedLibrary(.{ .name = name, .root_source_file = .{ .path = path }, .target = resolved_target, .optimize = optimize }); + const shared = b.addSharedLibrary(.{ .name = name, .root_source_file = .{ .src_path = .{ .sub_path = path, .owner = b } }, .target = resolved_target, .optimize = optimize }); shared.root_module.pic = true; shared.root_module.strip = strip; shared.linker_allow_shlib_undefined = true; @@ -61,7 +57,7 @@ const Libs = struct { var static: ?*std.Build.Step.Compile = null; if (with_static) { - static = b.addStaticLibrary(.{ .name = name, .root_source_file = .{ .path = path }, .target = resolved_target, .optimize = optimize }); + static = b.addStaticLibrary(.{ .name = name, .root_source_file = .{ .src_path = .{ .sub_path = path, .owner = b } }, .target = resolved_target, .optimize = optimize }); shared.root_module.pic = true; static.?.root_module.strip = strip; static.?.linker_allow_shlib_undefined = true; @@ -82,7 +78,7 @@ const Libs = struct { }; fn install_pnpm() !void { - const command_res = try std.ChildProcess.run(.{ .allocator = std.heap.page_allocator, .argv = &[_][]const u8{ "npm", "install", "-g", "pnpm@latest" } }); + const command_res = try std.process.Child.run(.{ .allocator = std.heap.page_allocator, .argv = &[_][]const u8{ "npm", "install", "-g", "pnpm@latest" } }); if (command_res.stderr.len > 0) { std.debug.print("{s}\n", .{command_res.stderr}); return error.PnpmNotFoundAndFailedToInstall; @@ -90,7 +86,7 @@ fn install_pnpm() !void { } // Checks if pnpm is installed on the machine and insatlls it if possible fn pnpm_check(allocator: std.mem.Allocator) !void { - const npm_version_command = std.ChildProcess.run(.{ .allocator = allocator, .argv = &[2][]const u8{ "pnpm", "--version" } }); + const npm_version_command = std.process.Child.run(.{ .allocator = allocator, .argv = &[2][]const u8{ "pnpm", "--version" } }); if (npm_version_command) |command_res| { if (command_res.stderr.len > 0) { return install_pnpm(); @@ -100,10 +96,6 @@ fn pnpm_check(allocator: std.mem.Allocator) !void { } } -fn get_lazypath(path: []const u8) std.Build.LazyPath { - return std.Build.LazyPath.relative(path); -} - inline fn run_npm_command( b: *std.Build, comptime dir: []const u8, @@ -115,7 +107,7 @@ inline fn run_npm_command( ) void { inline for (commands, 0..) |command, idx| { const syscommand = b.addSystemCommand(&[3][]const u8{ "pnpm", "run", command }); - syscommand.cwd = get_lazypath(dir); + syscommand.cwd = .{ .src_path = .{ .sub_path = dir, .owner = b } }; inline for (dependency_steps) |dependency_step| { syscommand.step.dependOn(dependency_step); @@ -146,21 +138,20 @@ pub fn build(b: *std.Build) !void { const tag = @tagName(target.os.tag); // Declares dependencies - Dependency.addExternal(b, "swiftzig", 0); - Dependency.addInternal(b, "Kivi", "src/core/Kivi.zig", 1, 0); - Dependency.addInternal(b, "core", "src/core/main.zig", 2, 0); + Dependency.addInternal(b, "Kivi", "src/core/Kivi.zig", 0); + Dependency.addInternal(b, "core", "src/core/main.zig", 1); // Executes codegens const codegen_step = b.step("codegen", "Generates bindings"); const core_codegen = b.addExecutable(.{ .name = "codegen_generate", - .root_source_file = .{ .path = "src/codegen/core.zig" }, + .root_source_file = .{ .src_path = .{ .sub_path = "src/codegen/core.zig", .owner = b } }, .optimize = optimize, .target = resolved_target, }); const js_driver_codegen = b.addExecutable(.{ .name = "codegen_generate", - .root_source_file = .{ .path = "src/codegen/js_driver.zig" }, + .root_source_file = .{ .src_path = .{ .sub_path = "src/codegen/core.zig", .owner = b } }, .optimize = optimize, .target = resolved_target, }); @@ -207,9 +198,9 @@ pub fn build(b: *std.Build) !void { const ffi_tests = b.addExecutable(.{ .name = "ffi-tests", .target = resolved_target, .optimize = optimize }); ffi_tests.linkLibC(); ffi_tests.linkLibrary(core_targets.shared); - ffi_tests.addSystemIncludePath(.{ .path = "src/core/include" }); + ffi_tests.addSystemIncludePath(.{ .src_path = .{ .sub_path = "src/core/include", .owner = b } }); ffi_tests.addCSourceFile(.{ - .file = .{ .path = "src/core/tests/ffi.c" }, + .file = .{ .src_path = .{ .sub_path = "src/core/tests/ffi.c", .owner = b } }, .flags = &.{"-std=c17"}, }); ffi_tests_step.dependOn(core_build_step); diff --git a/build.zig.zon b/build.zig.zon index 3618bc3..ed2742a 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,12 +1,7 @@ .{ .name = "kivi", .version = "0.0.0", - .minimum_zig_version = "0.11.0", + .dependencies = .{}, + .minimum_zig_version = "0.12.0", .paths = .{ "src", "build.zig", "build.zig.zon" }, - .dependencies = .{ - .swiftzig = .{ - .url = "https://github.com/devraymondsh/swiftzig/archive/refs/tags/v0.4.0.tar.gz", - .hash = "12208f395f60bbb782d91309c7b6d5d0da64a41db784e227f28dfd22ae996c05abaa", - }, - }, } diff --git a/src/codegen/core.zig b/src/codegen/core.zig index c21005e..24ce37d 100644 --- a/src/codegen/core.zig +++ b/src/codegen/core.zig @@ -1,7 +1,7 @@ const std = @import("std"); const core_mod = @import("core"); -const TypeMap = std.ComptimeStringMap([]const u8, .{ +const TypeMap = std.static_string_map.StaticStringMap([]const u8).initComptime(.{ .{ "void", "void" }, .{ "usize", "const size_t" }, .{ "*Kivi", "struct Kivi *const" }, diff --git a/src/core/ByteMap.zig b/src/core/ByteMap.zig index 3fe261b..626b52b 100644 --- a/src/core/ByteMap.zig +++ b/src/core/ByteMap.zig @@ -1,7 +1,6 @@ -/// This is Byte(u8) hashmap implementation that relies on the caller to handle allocations and lifetimes. +const std = @import("std"); const builtin = @import("builtin"); -const Wyhash = @import("./Wyhash.zig"); -const swiftzig = @import("swiftzig"); +const FreeListAlloc = @import("FreeListAlloc.zig"); const Entry = struct { key: []u8, @@ -68,10 +67,10 @@ table: []Group, table_metadata: []GroupMetadata, table_size: usize, -var hasher = Wyhash.init(0); +// var hasher = std.hash.Wyhash.init(0); -pub fn init(self: *ByteMap, allocator: swiftzig.mem.Allocator, size: usize) !void { - self.table_size = swiftzig.math.ceilPowerOfTwo(size); +pub fn init(self: *ByteMap, allocator: *FreeListAlloc, size: usize) !void { + self.table_size = try std.math.ceilPowerOfTwo(usize, size); self.table_metadata = try allocator.alloc(GroupMetadata, self.table_size); self.table = try allocator.alloc(Group, self.table_size); @@ -83,7 +82,8 @@ pub fn init(self: *ByteMap, allocator: swiftzig.mem.Allocator, size: usize) !voi } fn hash(key: []const u8) usize { - return hasher.reset_hash(@intCast(key.len), key); + // return hasher.reset_hash(@intCast(key.len), key); + return std.hash.Wyhash.hash(@intCast(key.len), key); } fn hash_to_groupidx(self: *ByteMap, hashed: usize) usize { return (hashed >> 7) % self.table_size; @@ -183,7 +183,7 @@ pub fn get(self: *ByteMap, key: []const u8) ?[]u8 { } return null; } -pub fn del(self: *ByteMap, allocator: swiftzig.mem.Allocator, key: []const u8) ?[]u8 { +pub fn del(self: *ByteMap, allocator: *FreeListAlloc, key: []const u8) ?[]u8 { const found_entity = self.find_index(key, true); if (found_entity) |entity| { const entry = &self.table[entity.group_idx].elements[entity.elem_idx]; diff --git a/src/core/FreeListAlloc.zig b/src/core/FreeListAlloc.zig new file mode 100644 index 0000000..6cb7f2b --- /dev/null +++ b/src/core/FreeListAlloc.zig @@ -0,0 +1,107 @@ +const std = @import("std"); +const builtin = @import("builtin"); + +const is_windows: bool = builtin.os.tag == .windows; + +const FreelistNode = packed struct { + len: usize, + next: ?*FreelistNode, +}; +var empty_freelist = FreelistNode{ .len = 0, .next = null }; + +cursor: usize, +freelist: *FreelistNode, +mem: []align(std.mem.page_size) u8, + +const FreeListAlloc = @This(); + +pub fn init(total_size: usize) !FreeListAlloc { + var mem: []align(std.mem.page_size) u8 = undefined; + const size = std.mem.alignForward(usize, total_size, std.mem.page_size); + if (!is_windows) { + mem = try std.posix.mmap( + null, + size, + std.posix.PROT.READ | std.posix.PROT.WRITE, + std.posix.MAP{ .ANONYMOUS = true, .TYPE = .PRIVATE }, + -1, + 0, + ); + } else { + const lpvoid = try std.os.windows.VirtualAlloc(null, size, std.os.windows.MEM_RESERVE, std.os.windows.PAGE_NOACCESS); + + mem.len = size; + mem.ptr = @alignCast(@ptrCast(lpvoid)); + } + + return FreeListAlloc{ .mem = mem, .cursor = 0, .freelist = &empty_freelist }; +} + +pub fn alloc_byte(self: *FreeListAlloc, size: usize) ![]u8 { + if (self.freelist.len != 0) { + if (self.freelist.len >= size) { + var freelist_slice: []u8 = undefined; + freelist_slice.len = self.freelist.len; + freelist_slice.ptr = @alignCast(@ptrCast(self.freelist)); + + if (self.freelist.len - size != 0) { + @memset(freelist_slice[size..self.freelist.len], 0); + } + + if (self.freelist.next) |_| { + self.freelist = self.freelist.next.?; + } else { + self.freelist = &empty_freelist; + } + + return freelist_slice[0..size]; + } + } + + const starting_pos = self.cursor; + var ending_pos: usize = starting_pos + 16; + if (size > 16) { + ending_pos += std.mem.alignForward(usize, size - 16, 8); + } + + if (ending_pos >= self.mem.len) { + return error.OutOfMemory; + } + + self.cursor = ending_pos; + + return self.mem[starting_pos .. starting_pos + size]; +} + +pub fn alloc(self: *FreeListAlloc, comptime T: type, n: usize) ![]T { + var allocated: []T = undefined; + allocated.ptr = @alignCast(@ptrCast(try self.alloc_byte(n * @sizeOf(T)))); + allocated.len = n; + return allocated; +} + +pub fn free(self: *FreeListAlloc, data: []u8) void { + const freelist = @as(*FreelistNode, @alignCast(@ptrCast(data.ptr))); + + if (data.len > 16) { + freelist.len = @intCast(std.mem.alignForward(usize, data.len, 8)); + } else { + freelist.len = 16; + } + + if (self.freelist.len != 0) { + freelist.next = self.freelist; + } else { + freelist.next = null; + } + + self.freelist = freelist; +} + +pub fn deinit(self: *FreeListAlloc) void { + if (!is_windows) { + std.posix.munmap(self.mem); + } else { + std.os.windows.VirtualFree(@alignCast(@ptrCast(self.mem.ptr)), 0, std.os.windows.MEM_RELEASE); + } +} diff --git a/src/core/Kivi.zig b/src/core/Kivi.zig index da62ccb..8eb4f18 100644 --- a/src/core/Kivi.zig +++ b/src/core/Kivi.zig @@ -1,5 +1,6 @@ +const std = @import("std"); const ByteMap = @import("ByteMap.zig"); -const swiftzig = @import("swiftzig"); +const FreeListAlloc = @import("FreeListAlloc.zig"); pub const Config = extern struct { // (2 ** 18) * 16 = 4194304 @@ -8,8 +9,7 @@ pub const Config = extern struct { }; map: ByteMap, -allocator: swiftzig.mem.Allocator, -freelist: swiftzig.mem.FreelistAllocator, +mem: FreeListAlloc, const Kivi = @This(); @@ -21,21 +21,17 @@ fn stringcpy(dest: []u8, src: []const u8) !void { } pub fn init(self: *Kivi, config: *const Config) !usize { - const pages = try swiftzig.mem.PageAllocator.init(config.mem_size / swiftzig.os.page_size); - - self.freelist = swiftzig.mem.FreelistAllocator.init(pages.mem); - self.allocator = self.freelist.allocator(); - - try self.map.init(self.allocator, config.group_size); + self.mem = try FreeListAlloc.init(config.mem_size); + try self.map.init(&self.mem, config.group_size); return @sizeOf(Kivi); } pub fn reserve_key(self: *Kivi, size: usize) ![]u8 { - return self.allocator.alloc(u8, size); + return self.mem.alloc(u8, size); } pub fn reserve_value(self: *Kivi, size: usize) ![]u8 { - return try self.allocator.alloc(u8, size); + return self.mem.alloc(u8, size); } pub fn put_entry(self: *Kivi, key: []u8, value: []u8) !void { return self.map.put(key, value); @@ -69,7 +65,7 @@ pub fn get_copy(self: *Kivi, key: []const u8, value: ?[]u8) !usize { } pub fn del(self: *Kivi, key: []const u8) ![]u8 { - if (self.map.del(self.allocator, key)) |value| { + if (self.map.del(&self.mem, key)) |value| { return value; } else { return error.NotFound; @@ -83,19 +79,17 @@ pub fn del_copy(self: *Kivi, key: []const u8, value: ?[]u8) !usize { try stringcpy(value.?, value_slice); } - self.allocator.free(value_slice); + self.mem.free(value_slice); return value_slice_len; } pub fn rm(self: *Kivi, key: []const u8) !void { const value_slice = try self.del(key); - self.allocator.free(value_slice); + self.mem.free(value_slice); } pub fn deinit(self: *Kivi) void { - var pages: swiftzig.mem.PageAllocator = .{ .mem = @alignCast(self.freelist.mem) }; - self.map.deinit(); - pages.deinit(); + self.mem.deinit(); } diff --git a/src/core/Wyhash.zig b/src/core/Wyhash.zig deleted file mode 100644 index 3c2e426..0000000 --- a/src/core/Wyhash.zig +++ /dev/null @@ -1,233 +0,0 @@ -const builtin = @import("builtin"); - -const Wyhash = @This(); - -const secret = [_]u64{ - 0xa0761d6478bd642f, - 0xe7037ed1a0b428db, - 0x8ebc6af09c88c6e3, - 0x589965cc75374cc3, -}; - -a: u64, -b: u64, -state: [3]u64, -total_len: usize, - -buf: [48]u8, -buf_len: usize, - -pub fn init(seed: u64) Wyhash { - var self = Wyhash{ - .a = undefined, - .b = undefined, - .state = undefined, - .total_len = 0, - .buf = undefined, - .buf_len = 0, - }; - - self.state[0] = seed ^ mix(seed ^ secret[0], secret[1]); - self.state[1] = self.state[0]; - self.state[2] = self.state[0]; - return self; -} - -// This is subtly different from other hash function update calls. Wyhash requires the last -// full 48-byte block to be run through final1 if is exactly aligned to 48-bytes. -pub fn update(self: *Wyhash, input: []const u8) void { - self.total_len += input.len; - - if (input.len <= 48 - self.buf_len) { - @memcpy(self.buf[self.buf_len..][0..input.len], input); - self.buf_len += input.len; - return; - } - - var i: usize = 0; - - if (self.buf_len > 0) { - i = 48 - self.buf_len; - @memcpy(self.buf[self.buf_len..][0..i], input[0..i]); - self.round(&self.buf); - self.buf_len = 0; - } - - while (i + 48 < input.len) : (i += 48) { - self.round(input[i..][0..48]); - } - - const remaining_bytes = input[i..]; - if (remaining_bytes.len < 16 and i >= 48) { - const rem = 16 - remaining_bytes.len; - @memcpy(self.buf[self.buf.len - rem ..], input[i - rem .. i]); - } - @memcpy(self.buf[0..remaining_bytes.len], remaining_bytes); - self.buf_len = remaining_bytes.len; -} - -pub fn final(self: *Wyhash) u64 { - var input: []const u8 = self.buf[0..self.buf_len]; - var newSelf = self.shallowCopy(); // ensure idempotency - - if (self.total_len <= 16) { - newSelf.smallKey(input); - } else { - var offset: usize = 0; - if (self.buf_len < 16) { - var scratch: [16]u8 = undefined; - const rem = 16 - self.buf_len; - @memcpy(scratch[0..rem], self.buf[self.buf.len - rem ..][0..rem]); - @memcpy(scratch[rem..][0..self.buf_len], self.buf[0..self.buf_len]); - - // Same as input but with additional bytes preceeding start in case of a short buffer - input = &scratch; - offset = rem; - } - - newSelf.final0(); - newSelf.final1(input, offset); - } - - return newSelf.final2(); -} - -// Copies the core wyhash state but not any internal buffers. -inline fn shallowCopy(self: *Wyhash) Wyhash { - return .{ - .a = self.a, - .b = self.b, - .state = self.state, - .total_len = self.total_len, - .buf = undefined, - .buf_len = undefined, - }; -} - -inline fn smallKey(self: *Wyhash, input: []const u8) void { - // TODO: Panic - // std.debug.assert(input.len <= 16); - - if (input.len >= 4) { - const end = input.len - 4; - const quarter = (input.len >> 3) << 2; - self.a = (read(4, input[0..]) << 32) | read(4, input[quarter..]); - self.b = (read(4, input[end..]) << 32) | read(4, input[end - quarter ..]); - } else if (input.len > 0) { - self.a = (@as(u64, input[0]) << 16) | (@as(u64, input[input.len >> 1]) << 8) | input[input.len - 1]; - self.b = 0; - } else { - self.a = 0; - self.b = 0; - } -} - -inline fn round(self: *Wyhash, input: *const [48]u8) void { - inline for (0..3) |i| { - const a = read(8, input[8 * (2 * i) ..]); - const b = read(8, input[8 * (2 * i + 1) ..]); - self.state[i] = mix(a ^ secret[i + 1], b ^ self.state[i]); - } -} - -pub const Endian = enum { - big, - little, -}; -const native_endian = builtin.cpu.arch.endian(); -pub inline fn readInt(comptime T: type, buffer: *const [@divExact(@typeInfo(T).Int.bits, 8)]u8, endian: Endian) T { - const value: T = @bitCast(buffer.*); - return if (@intFromEnum(endian) == @intFromEnum(native_endian)) value else @byteSwap(value); -} - -inline fn read(comptime bytes: usize, data: []const u8) u64 { - // TODO: Panic - // std.debug.assert(bytes <= 8); - - return @as(u64, readInt(@Type(.{ - .Int = .{ - .signedness = .unsigned, - .bits = 8 * bytes, - }, - }), data[0..bytes], .little)); -} - -inline fn mum(a: *u64, b: *u64) void { - const x = @as(u128, a.*) *% b.*; - a.* = @as(u64, @truncate(x)); - b.* = @as(u64, @truncate(x >> 64)); -} - -inline fn mix(a_: u64, b_: u64) u64 { - var a = a_; - var b = b_; - mum(&a, &b); - return a ^ b; -} - -inline fn final0(self: *Wyhash) void { - self.state[0] ^= self.state[1] ^ self.state[2]; -} - -// input_lb must be at least 16-bytes long (in shorter key cases the smallKey function will be -// used instead). We use an index into a slice to for comptime processing as opposed to if we -// used pointers. -inline fn final1(self: *Wyhash, input_lb: []const u8, start_pos: usize) void { - // TODO: Panic - // std.debug.assert(input_lb.len >= 16); - // std.debug.assert(input_lb.len - start_pos <= 48); - - const input = input_lb[start_pos..]; - - var i: usize = 0; - while (i + 16 < input.len) : (i += 16) { - self.state[0] = mix(read(8, input[i..]) ^ secret[1], read(8, input[i + 8 ..]) ^ self.state[0]); - } - - self.a = read(8, input_lb[input_lb.len - 16 ..][0..8]); - self.b = read(8, input_lb[input_lb.len - 8 ..][0..8]); -} - -inline fn final2(self: *Wyhash) u64 { - self.a ^= secret[1]; - self.b ^= self.state[0]; - mum(&self.a, &self.b); - return mix(self.a ^ secret[0] ^ self.total_len, self.b ^ secret[1]); -} - -pub fn hash(self: *Wyhash, input: []const u8) u64 { - if (input.len <= 16) { - self.smallKey(input); - } else { - var i: usize = 0; - if (input.len >= 48) { - while (i + 48 < input.len) : (i += 48) { - self.round(input[i..][0..48]); - } - self.final0(); - } - self.final1(input, i); - } - - self.total_len = input.len; - return self.final2(); -} - -pub fn reset_hash(self: *Wyhash, seed: u64, input: []const u8) u64 { - self.total_len = 0; - self.buf_len = 0; - - self.state[0] = seed ^ mix(seed ^ secret[0], secret[1]); - self.state[1] = self.state[0]; - self.state[2] = self.state[0]; - - return self.hash(input); -} - -pub fn reset(self: *Wyhash) void { - self.total_len = 0; - self.buf_len = 0; - self.a = undefined; - self.state = undefined; - self.buf = undefined; -} diff --git a/src/core/include/kivi.h b/src/core/include/kivi.h index b689701..951ec60 100644 --- a/src/core/include/kivi.h +++ b/src/core/include/kivi.h @@ -2,7 +2,7 @@ #include struct __attribute__((aligned(8))) Kivi { - char __opaque[88]; + char __opaque[72]; }; struct Config { diff --git a/src/drivers/js/runtimes/nodejs/functions/del.zig b/src/drivers/js/runtimes/nodejs/functions/del.zig index 0426e4e..717ffe4 100644 --- a/src/drivers/js/runtimes/nodejs/functions/del.zig +++ b/src/drivers/js/runtimes/nodejs/functions/del.zig @@ -19,7 +19,7 @@ pub export fn kivi_del_js(env: ntypes.napi_env, info: ntypes.napi_callback_info) return common.exception_ret(env, "Failed to create a buffer for the results!"); }; - self.allocator.free(value); + self.mem.free(value); return ret; } diff --git a/src/drivers/js/runtimes/nodejs/functions/set.zig b/src/drivers/js/runtimes/nodejs/functions/set.zig index 165eb0e..4558bac 100644 --- a/src/drivers/js/runtimes/nodejs/functions/set.zig +++ b/src/drivers/js/runtimes/nodejs/functions/set.zig @@ -20,14 +20,14 @@ pub export fn kivi_set_js(env: ntypes.napi_env, info: ntypes.napi_callback_info) return common.exception_ret(env, "Not enough memory to store the key!"); }; const reserved_value = self.reserve_value(value.len) catch { - self.allocator.free(reserved_key); + self.mem.free(reserved_key); return common.exception_ret(env, "Not enough memory to store the value!"); }; @memcpy(reserved_key, key); @memcpy(reserved_value, value); self.put_entry(reserved_key, reserved_value) catch { - self.allocator.free(reserved_key); - self.allocator.free(reserved_value); + self.mem.free(reserved_key); + self.mem.free(reserved_value); return common.exception_ret(env, "Not enough memory to fit the new key/value pair!"); };