Compare commits

...

2 Commits

Author SHA1 Message Date
Luna 4adf80e51a fix some memory leaks 2020-08-18 17:58:04 -03:00
Luna 353d8d6947 fix for latest zig 2020-08-18 17:49:23 -03:00
6 changed files with 22 additions and 21 deletions

View File

@ -97,7 +97,7 @@ pub fn temporaryName(allocator: *std.mem.Allocator) ![]u8 {
var tmp_file: std.fs.File = std.fs.cwd().openFile(
nam,
.{ .read = true, .write = false },
) catch |err| blk: {
) catch |err| {
if (err == error.FileNotFound) return nam else continue;
};
@ -321,7 +321,7 @@ pub const Image = struct {
defer self.allocator.free(sym_cstr);
var sym = c.lilv_new_string(ctx.world, sym_cstr.ptr);
const port = c.lilv_plugin_get_port_by_symbol(ctx.plugin, sym) orelse blk: {
const port = c.lilv_plugin_get_port_by_symbol(ctx.plugin, sym) orelse {
std.debug.warn("assert fail: symbol {} not found on port\n", .{param.sym});
return ImageError.InvalidSymbol;
};

View File

@ -135,8 +135,6 @@ pub const Command = struct {
.embed => Embed,
.rotate => Rotate,
else => @panic("TODO"),
};
}

View File

@ -81,20 +81,20 @@ pub fn setupPorts(ctx: *plugin.Context) ![]Port {
defer ctx.allocator.free(values);
c.lilv_plugin_get_port_ranges_float(ctx.plugin, null, null, values.ptr);
var lv2_InputPort = c.lilv_new_uri(world, LV2_CORE__InputPort.ptr);
defer std.heap.c_allocator.destroy(lv2_InputPort);
var lv2_InputPort = c.lilv_new_uri(world, LV2_CORE__InputPort.ptr).?;
//defer std.heap.c_allocator.destroy(lv2_InputPort);
var lv2_OutputPort = c.lilv_new_uri(world, LV2_CORE__OutputPort.ptr);
defer std.heap.c_allocator.destroy(lv2_OutputPort);
var lv2_OutputPort = c.lilv_new_uri(world, LV2_CORE__OutputPort.ptr).?;
//defer std.heap.c_allocator.destroy(lv2_OutputPort);
var lv2_AudioPort = c.lilv_new_uri(world, LV2_CORE__AudioPort.ptr);
defer std.heap.c_allocator.destroy(lv2_AudioPort);
var lv2_AudioPort = c.lilv_new_uri(world, LV2_CORE__AudioPort.ptr).?;
//defer std.heap.c_allocator.destroy(lv2_AudioPort);
var lv2_ControlPort = c.lilv_new_uri(world, LV2_CORE__ControlPort.ptr);
defer std.heap.c_allocator.destroy(lv2_ControlPort);
var lv2_ControlPort = c.lilv_new_uri(world, LV2_CORE__ControlPort.ptr).?;
//defer std.heap.c_allocator.destroy(lv2_ControlPort);
var lv2_connectionOptional = c.lilv_new_uri(world, LV2_CORE__connectionOptional.ptr);
defer std.heap.c_allocator.destroy(lv2_connectionOptional);
var lv2_connection_string = c.lilv_new_uri(world, LV2_CORE__connectionOptional.ptr).?;
//defer std.heap.c_allocator.destroy(lv2_connection_string);
var i: u32 = 0;
while (i < n_ports) : (i += 1) {
@ -111,7 +111,7 @@ pub fn setupPorts(ctx: *plugin.Context) ![]Port {
port.value = values[i];
}
port.optional = c.lilv_port_has_property(ctx.plugin, lport, lv2_connectionOptional);
port.optional = c.lilv_port_has_property(ctx.plugin, lport, lv2_connection_string);
if (c.lilv_port_is_a(ctx.plugin, lport, lv2_InputPort)) {
port.is_input = true;

View File

@ -104,7 +104,7 @@ pub const RunContext = struct {
switch (port.ptype) {
.Control => lv2.lilv_instance_connect_port(self.instance, p, &port.value),
.Audio => blk: {
.Audio => {
if (port.is_input) {
lv2.lilv_instance_connect_port(
self.instance,
@ -121,7 +121,7 @@ pub const RunContext = struct {
o += 1;
}
},
else => lv2.lilv_instance_connect_port(self.instance, p, null),
// else => lv2.lilv_instance_connect_port(self.instance, p, null),
}
}
}
@ -136,7 +136,7 @@ pub fn makeContext(allocator: *std.mem.Allocator, plugin_uri: []const u8) !Conte
c.lilv_world_load_all(world);
var uri: *c.LilvNode = c.lilv_new_uri(world, cstr_plugin_uri.ptr) orelse blk: {
var uri: *c.LilvNode = c.lilv_new_uri(world, cstr_plugin_uri.ptr) orelse {
std.debug.warn("Invalid plugin URI <{}>\n", .{plugin_uri});
return ImageError.InvalidPlugin;
};
@ -144,7 +144,7 @@ pub fn makeContext(allocator: *std.mem.Allocator, plugin_uri: []const u8) !Conte
const plugins: *const c.LilvPlugins = c.lilv_world_get_all_plugins(world).?;
var plugin: *const c.LilvPlugin = c.lilv_plugins_get_by_uri(plugins, uri) orelse blk: {
var plugin: *const c.LilvPlugin = c.lilv_plugins_get_by_uri(plugins, uri) orelse {
std.debug.warn("Plugin <{}> not found\n", .{plugin_uri});
return ImageError.UnknownPlugin;
};

View File

@ -27,7 +27,6 @@ fn printCommand(stream: anytype, cmd: *langs.Command, comptime tag: langs.Comman
switch (ctype) {
.lv2_command => try printCommandWithParams(stream, casted),
.custom_command => try printCommandWithParams(stream, casted),
else => @panic("TODO support command type"),
}
}

View File

@ -40,6 +40,8 @@ pub const Runner = struct {
if (self.image) |image| {
image.close();
}
std.process.argsFree(self.allocator, self.args);
}
pub fn clone(self: *Runner) !Runner {
@ -117,6 +119,7 @@ pub const Runner = struct {
}
}
/// Caller owns returned memory.
fn makeGlitchedPath(self: *Runner) ![]const u8 {
// we want to transform basename, if it is "x.bmp" to "x_gN.bmp", where
// N is the maximum non-used integer.
@ -180,6 +183,7 @@ pub const Runner = struct {
fn quicksaveCmd(self: *Runner) !void {
var image = try self.getImage();
const out_path = try self.makeGlitchedPath();
defer self.allocator.free(out_path);
try image.saveTo(out_path);
}
@ -187,6 +191,7 @@ pub const Runner = struct {
const runqs = cmd.cast(lang.Command.RunQS).?;
var image = try self.getImage();
const out_path = try self.makeGlitchedPath();
defer self.allocator.free(out_path);
try image.saveTo(out_path);
var proc = try std.ChildProcess.init(
@ -252,7 +257,6 @@ pub const Runner = struct {
switch (ctype) {
.lv2_command => try self.executeLV2Command(command.*),
.custom_command => try self.executeCustomCommand(command.*),
else => @panic("TODO support command type"),
}
}