diff --git a/vlib/builtin/array.v b/vlib/builtin/array.v index b5084a5565..5520dc16ca 100644 --- a/vlib/builtin/array.v +++ b/vlib/builtin/array.v @@ -685,8 +685,12 @@ pub fn (a1 []string) eq(a2 []string) bool { if a1.len != a2.len { return false } + size_of_string := int(sizeof(string)) for i in 0 .. a1.len { - if a1[i] != a2[i] { + offset := i * size_of_string + s1 := &string(unsafe { byteptr(a1.data) + offset }) + s2 := &string(unsafe { byteptr(a2.data) + offset }) + if *s1 != *s2 { return false } } diff --git a/vlib/os/os_nix.c.v b/vlib/os/os_nix.c.v index a19e12d21b..3f86217fb0 100644 --- a/vlib/os/os_nix.c.v +++ b/vlib/os/os_nix.c.v @@ -157,6 +157,7 @@ pub fn mkdir(path string) ?bool { } // execute starts the specified command, waits for it to complete, and returns its output. +[manualfree] pub fn execute(cmd string) Result { // if cmd.contains(';') || cmd.contains('&&') || cmd.contains('||') || cmd.contains('\n') { // return Result{ exit_code: -1, output: ';, &&, || and \\n are not allowed in shell commands' } @@ -171,6 +172,9 @@ pub fn execute(cmd string) Result { } buf := [4096]byte{} mut res := strings.new_builder(1024) + defer { + unsafe { res.free() } + } unsafe { bufbp := &buf[0] for C.fgets(charptr(bufbp), 4096, f) != 0 { @@ -178,7 +182,6 @@ pub fn execute(cmd string) Result { } } soutput := res.str() - // res.free() exit_code := vpclose(f) return Result{ exit_code: exit_code @@ -196,19 +199,25 @@ pub: redirect_stdout bool } -// pub fn command(cmd Command) Command { -//} +[manualfree] pub fn (mut c Command) start() ? { - pcmd := '$c.path 2>&1' + pcmd := c.path + ' 2>&1' + defer { + unsafe { pcmd.free() } + } c.f = vpopen(pcmd) if isnil(c.f) { return error('exec("$c.path") failed') } } +[manualfree] pub fn (mut c Command) read_line() string { buf := [4096]byte{} mut res := strings.new_builder(1024) + defer { + unsafe { res.free() } + } unsafe { bufbp := &buf[0] for C.fgets(charptr(bufbp), 4096, c.f) != 0 { @@ -216,14 +225,16 @@ pub fn (mut c Command) read_line() string { for i in 0 .. len { if bufbp[i] == `\n` { res.write_ptr(bufbp, i) - return res.str() + final := res.str() + return final } } res.write_ptr(bufbp, len) } } c.eof = true - return res.str() + final := res.str() + return final } pub fn (c &Command) close() ? {