From 7cf16f9ffa202ea68b669f27b7d8214cbff06bb5 Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 6 Oct 2019 15:12:19 -0300 Subject: [PATCH] deinit existing_cmds (not long lived) --- src/main.zig | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main.zig b/src/main.zig index 9e333f5..7a05be3 100644 --- a/src/main.zig +++ b/src/main.zig @@ -30,12 +30,6 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { var file_read = try std.fs.File.openRead(scri_path); const total_bytes = try file_read.getEndPos(); - // the thing here is that 'load :0' would load the scri_path, since we - // now have a 'repl' argument right before it. to counteract that, the - // initial repl buffer contains 'load :1' instead. - - // TODO load should -1 the index if its on repl - var cmds = langs.CommandList.init(allocator); defer cmds.deinit(); @@ -43,10 +37,15 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { defer lang.deinit(); if (total_bytes > 0) { - // those MUST BE long lived, we can't defer them here + // this MUST BE long lived (a reference to it is kept inside + // existing_cmds, and then passed along to cmds), + // we can't defer them here var scri_existing = try allocator.alloc(u8, total_bytes); _ = try file_read.read(scri_existing); + + // we can defer this because we copy the Command structs back to cmds var existing_cmds = try lang.parse(scri_existing); + defer existing_cmds.deinit(); // copy the existing command list into the repl's command list var it = existing_cmds.iterator(); @@ -56,8 +55,9 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { } else { // if there isn't any commands on the file, we load our default // 'load :1' command + + // TODO load should +1 the index if its on repl var loadargs = langs.ArgList.init(allocator); - // defer loadargs.deinit(); try loadargs.append(":1"); try cmds.append(langs.Command{