add helpers for c string construction

This commit is contained in:
Luna 2019-07-07 15:04:25 -03:00
parent 846faafc92
commit bd00f61977
1 changed files with 12 additions and 3 deletions

View File

@ -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: {