Compare commits

...

4 commits

Author SHA1 Message Date
6d8614e678 revert cloned runner using parsed cmd list 2020-06-02 17:25:03 -03:00
af0ea574e1 remove default value for Runner.repl field 2020-06-02 17:16:02 -03:00
1b59705eae cloned runners inherit repl flag from parent 2020-06-02 17:15:50 -03:00
a2ea8fb53e make args live through lifetime of runner
we just assign cloned runners the args of the parent runner and don't
free the parent's, maintaining okay memory usage.
2020-06-02 17:12:34 -03:00
2 changed files with 16 additions and 10 deletions

View file

@ -222,9 +222,9 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void {
// taking address is fine, because runqs_cmd lives in the lifetime
// of this function.
try cmds.append(&runqs_cmd.base);
try cmds_parsed.append(&runqs_cmd.base);
try runner_clone.runCommands(cmds, true);
try runner_clone.runCommands(cmds_parsed, true);
_ = try stdout.write("\n");
}
}

View file

@ -24,12 +24,15 @@ pub const Runner = struct {
image: ?*Image = null,
/// If the runner is in REPL mode
repl: bool = false,
repl: bool,
args: [][]u8,
pub fn init(allocator: *std.mem.Allocator, repl: bool) Runner {
return Runner{
.allocator = allocator,
.repl = repl,
.args = std.process.argsAlloc(allocator) catch unreachable,
};
}
@ -41,7 +44,12 @@ pub const Runner = struct {
pub fn clone(self: *Runner) !Runner {
var cloned_image = if (self.image) |image| try image.clone() else null;
return Runner{ .allocator = self.allocator, .image = cloned_image };
return Runner{
.allocator = self.allocator,
.image = cloned_image,
.repl = self.repl,
.args = self.args,
};
}
fn resolveArg(self: *Runner, load_path: []const u8) ![]const u8 {
@ -57,14 +65,12 @@ pub const Runner = struct {
// ':0' should ALWAYS point to the image.
if (self.repl) index += 3 else index += 2;
var args = try std.process.argsAlloc(self.allocator);
defer std.process.argsFree(self.allocator, args);
std.debug.warn("ARGS!! {} \n", .{args.len});
for (args) |arg, idx| {
std.debug.warn("ARGS!! {} \n", .{self.args.len});
for (self.args) |arg, idx| {
std.debug.warn("arg{} = {}\n", .{ idx, arg });
}
std.debug.warn("fetch arg idx={}, val={}\n", .{ index, args[index] });
return args[index];
std.debug.warn("fetch arg idx={}, val={}\n", .{ index, self.args[index] });
return self.args[index];
} else {
return load_path;
}