Obsolete
/
libipc-old
Archived
3
0
Fork 0

Context uses an allocator, currently a simple c_allocator.

master
Philippe Pittoli 2023-01-16 21:58:22 +01:00
parent c5e3b7b901
commit a6cfa88f79
1 changed files with 6 additions and 7 deletions

View File

@ -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;
};