deinit existing_cmds (not long lived)
This commit is contained in:
parent
80036c4c0d
commit
7cf16f9ffa
16
src/main.zig
16
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{
|
||||
|
|
Loading…
Reference in New Issue