1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

compiler: more memory logic + replace "cur_fn &Fn" with "cur_fn Fn"

This commit is contained in:
Alexander Medvednikov
2019-09-09 16:22:39 +03:00
parent f3a74e7d80
commit 9dd86f6fb8
8 changed files with 114 additions and 78 deletions

View File

@ -99,14 +99,14 @@ pub fn print(s string) {
}
__global total_m i64 = 0
//__global nr_mallocs int = 0
//__global nr_mallocs int = 0
pub fn malloc(n int) byteptr {
if n < 0 {
panic('malloc(<0)')
}
//nr_mallocs++
/*
TODO
//nr_mallocs++
/*
TODO
#ifdef VPLAY
if n > 10000 {
panic('allocating more than 10 KB is not allowed in the playground')
@ -117,7 +117,7 @@ TODO
println('\n\n\nmalloc($n) total=$total_m')
print_backtrace()
#endif
*/
*/
ptr := C.malloc(n)
if isnil(ptr) {
panic('malloc($n) failed')
@ -141,5 +141,9 @@ fn memdup(src voidptr, sz int) voidptr {
return C.memcpy(mem, src, sz)
}
fn v_ptr_free(ptr voidptr) {
C.free(ptr)
}

View File

@ -236,7 +236,24 @@ pub fn (m map) print() {
println('>>>>>>>>>>')
}
pub fn (m map) free() {
fn (n mut mapnode) free() {
if n.val != 0 {
free(n.val)
}
if n.left != 0 {
n.left.free()
}
if n.right != 0 {
n.right.free()
}
free(n)
}
pub fn (m mut map) free() {
if m.root == 0 {
return
}
m.root.free()
// C.free(m.table)
// C.free(m.keys_table)
}

View File

@ -156,7 +156,7 @@ pub fn (s string) u64() u64 {
// ==
fn (s string) eq(a string) bool {
if isnil(s.str) {
if isnil(s.str) { // should never happen
panic('string.eq(): nil string')
}
if s.len != a.len {

View File

@ -289,8 +289,7 @@ pub fn (f File) close() {
}
// system starts the specified command, waits for it to complete, and returns its code.
fn popen(path string) &FILE {
fn popen(path string) *C.FILE {
$if windows {
mode := 'rb'
wpath := path.to_wide()
@ -302,7 +301,7 @@ fn popen(path string) &FILE {
}
}
fn pclose(f &FILE) int {
fn pclose(f *C.FILE) int {
$if windows {
return C._pclose(f)
}