mirror of
https://github.com/vlang/v.git
synced 2025-09-14 06:52:36 +03:00
builtin.wasm_bare: use walloc as malloc/free implementation (#13731)
This commit is contained in:
parent
4d99157cd5
commit
c8b0f51c13
4 changed files with 553 additions and 84 deletions
|
@ -1,8 +1,13 @@
|
|||
module builtin
|
||||
|
||||
import dlmalloc
|
||||
//__global global_allocator dlmalloc.Dlmalloc
|
||||
|
||||
__global global_allocator dlmalloc.Dlmalloc
|
||||
[unsafe]
|
||||
pub fn __malloc(size usize) voidptr {
|
||||
unsafe {
|
||||
return malloc(int(size))
|
||||
}
|
||||
}
|
||||
|
||||
[unsafe]
|
||||
pub fn memcpy(dest &C.void, src &C.void, n usize) &C.void {
|
||||
|
@ -16,12 +21,6 @@ pub fn memcpy(dest &C.void, src &C.void, n usize) &C.void {
|
|||
return unsafe { dest }
|
||||
}
|
||||
|
||||
[export: 'malloc']
|
||||
[unsafe]
|
||||
fn __malloc(n usize) &C.void {
|
||||
return unsafe { global_allocator.malloc(n) }
|
||||
}
|
||||
|
||||
[unsafe]
|
||||
fn strlen(_s &C.void) usize {
|
||||
s := unsafe { &byte(_s) }
|
||||
|
@ -106,14 +105,6 @@ fn memcmp(a &C.void, b &C.void, n usize) int {
|
|||
return 0
|
||||
}
|
||||
|
||||
[export: 'free']
|
||||
[unsafe]
|
||||
fn __free(ptr &C.void) {
|
||||
unsafe {
|
||||
global_allocator.free_(ptr)
|
||||
}
|
||||
}
|
||||
|
||||
fn vsprintf(str &char, format &char, ap &byte) int {
|
||||
panic('vsprintf(): string interpolation is not supported in `-freestanding`')
|
||||
}
|
||||
|
@ -169,5 +160,5 @@ fn __qsort(base voidptr, nmemb usize, size usize, sort_cb FnSortCB) {
|
|||
}
|
||||
|
||||
fn init_global_allocator() {
|
||||
global_allocator = dlmalloc.new(get_wasm_allocator())
|
||||
// global_allocator = dlmalloc.new(get_wasm_allocator())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue