diff --git a/zig-impl/drop/src/main.zig b/zig-impl/drop/src/main.zig index 2fa8b1d..08bcf21 100644 --- a/zig-impl/drop/src/main.zig +++ b/zig-impl/drop/src/main.zig @@ -1,28 +1,27 @@ const std = @import("std"); const fmt = std.fmt; -const heap = std.heap; -const testing = std.testing; const print = std.debug.print; pub const Context = struct { rundir: [] u8, + allocator: std.mem.Allocator, const Self = @This(); - pub fn init() !Self { - var rundir = try std.heap.c_allocator.dupeZ(u8, "/tmp/libipc-run/"); - return Self { .rundir = rundir }; + pub fn init(allocator: std.mem.Allocator) !Self { + var rundir = try allocator.dupeZ(u8, "/tmp/libipc-run/"); + return Self { .rundir = rundir, .allocator = allocator }; } pub fn deinit(self: *Self) void { - std.heap.c_allocator.free(self.rundir); + self.allocator.free(self.rundir); } }; export fn ipc_context_init (ptr: **Context) callconv(.C) i32 { ptr.* = std.heap.c_allocator.create(Context) catch return 1; - ptr.*.* = Context.init() catch |err| { + ptr.*.* = Context.init(std.heap.c_allocator) catch |err| { print ("libipc: error while init context: {}\n", .{err}); return 1; };