From bd00f619777e4f37bba0b0a7017559aebc3a8335 Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 7 Jul 2019 15:04:25 -0300 Subject: [PATCH] add helpers for c string construction --- src/main.zig | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main.zig b/src/main.zig index 4e60afe..d66ecf5 100644 --- a/src/main.zig +++ b/src/main.zig @@ -43,6 +43,11 @@ fn Lv2Core(ns: []const u8) ![]const u8 { ); } +fn makeCStr(data: []const u8) ![]u8 { + var allocator = std.heap.direct_allocator; + return std.cstr.addNullByte(allocator, data); +} + /// Control port value set from the command line const Param = struct { /// Port symbol @@ -131,6 +136,10 @@ const LV2Apply = struct { self.params.deinit(); } + pub fn makeCStr(self: *LV2Apply, data: []const u8) ![]u8 { + return std.cstr.addNullByte(self.allocator, data); + } + pub fn createPorts(self: *LV2Apply) !i32 { var world = self.world; const n_ports: u32 = c.lilv_plugin_get_num_ports(self.plugin); @@ -327,9 +336,9 @@ pub fn main() !void { return; } - self.in_path = in_path.?; - self.out_path = out_path.?; - var plugin_uri = try std.cstr.addNullByte(self.allocator, plugin_uri_opt.?); + self.in_path = try self.makeCStr(in_path.?); + self.out_path = try self.makeCStr(out_path.?); + var plugin_uri = try self.makeCStr(plugin_uri_opt.?); self.world = c.lilv_world_new().?; var uri: *c.LilvNode = c.lilv_new_uri(self.world, plugin_uri.ptr) orelse blk: {