diff --git a/vlib/builtin/linux_bare/libc_impl.c.v b/vlib/builtin/linux_bare/libc_impl.v similarity index 85% rename from vlib/builtin/linux_bare/libc_impl.c.v rename to vlib/builtin/linux_bare/libc_impl.v index 3310ad032098f1..03eec7e573541f 100644 --- a/vlib/builtin/linux_bare/libc_impl.c.v +++ b/vlib/builtin/linux_bare/libc_impl.v @@ -5,7 +5,7 @@ import dlmalloc __global global_allocator dlmalloc.Dlmalloc [unsafe] -pub fn memcpy(dest &C.void, src &C.void, n usize) &C.void { +pub fn memcpy(dest voidptr, src voidptr, n usize) voidptr { dest_ := unsafe { &u8(dest) } src_ := unsafe { &u8(src) } unsafe { @@ -18,12 +18,12 @@ pub fn memcpy(dest &C.void, src &C.void, n usize) &C.void { [export: 'malloc'] [unsafe] -fn __malloc(n usize) &C.void { +fn __malloc(n usize) voidptr { return unsafe { global_allocator.malloc(n) } } [unsafe] -fn strlen(_s &C.void) usize { +fn strlen(_s voidptr) usize { s := unsafe { &u8(_s) } mut i := 0 for ; unsafe { s[i] } != 0; i++ {} @@ -31,7 +31,7 @@ fn strlen(_s &C.void) usize { } [unsafe] -fn realloc(old_area &C.void, new_size usize) &C.void { +fn realloc(old_area voidptr, new_size usize) voidptr { if old_area == 0 { return unsafe { malloc(int(new_size)) } } @@ -39,7 +39,7 @@ fn realloc(old_area &C.void, new_size usize) &C.void { unsafe { free(old_area) } return 0 } - old_size := unsafe { *(&u64(old_area - sizeof(u64))) } + old_size := unsafe { *(&u64(&u64(old_area) - sizeof(u64))) } if u64(new_size) <= old_size { return unsafe { old_area } } else { @@ -51,7 +51,7 @@ fn realloc(old_area &C.void, new_size usize) &C.void { } [unsafe] -fn memset(s &C.void, c int, n usize) &C.void { +fn memset(s voidptr, c int, n usize) voidptr { mut s_ := unsafe { &char(s) } for i in 0 .. int(n) { unsafe { @@ -62,7 +62,7 @@ fn memset(s &C.void, c int, n usize) &C.void { } [unsafe] -fn memmove(dest &C.void, src &C.void, n usize) &C.void { +fn memmove(dest voidptr, src voidptr, n usize) voidptr { dest_ := unsafe { &u8(dest) } src_ := unsafe { &u8(src) } mut temp_buf := unsafe { malloc(int(n)) } @@ -83,7 +83,7 @@ fn memmove(dest &C.void, src &C.void, n usize) &C.void { [export: 'calloc'] [unsafe] -fn __calloc(nmemb usize, size usize) &C.void { +fn __calloc(nmemb usize, size usize) voidptr { new_area := unsafe { malloc(int(nmemb) * int(size)) } unsafe { memset(new_area, 0, nmemb * size) } return new_area @@ -95,7 +95,7 @@ fn getchar() int { return int(x) } -fn memcmp(a &C.void, b &C.void, n usize) int { +fn memcmp(a voidptr, b voidptr, n usize) int { a_ := unsafe { &u8(a) } b_ := unsafe { &u8(b) } for i in 0 .. int(n) { @@ -110,7 +110,7 @@ fn memcmp(a &C.void, b &C.void, n usize) int { [export: 'free'] [unsafe] -fn __free(ptr &C.void) { +fn __free(ptr voidptr) { unsafe { global_allocator.free_(ptr) }