mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-10 14:03:39 +00:00
Added realloc implementation to GCs
When using the latest wasi-libc I experienced a panic on an attempt to call realloc. My first attempt to add it to arch_tinygowasm.go was obviously not good (PR #2194). So here is another suggestion.
This commit is contained in:
committed by
Ron Evans
parent
ef8c1a187d
commit
0f69d016a0
@@ -35,6 +35,18 @@ func alloc(size uintptr, layout unsafe.Pointer) unsafe.Pointer {
|
||||
return unsafe.Pointer(addr)
|
||||
}
|
||||
|
||||
func realloc(ptr unsafe.Pointer, size uintptr) unsafe.Pointer {
|
||||
newAlloc := alloc(size, nil)
|
||||
if ptr == nil {
|
||||
return newAlloc
|
||||
}
|
||||
// according to POSIX everything beyond the previous pointer's
|
||||
// size will have indeterminate values so we can just copy garbage
|
||||
memcpy(newAlloc, ptr, size)
|
||||
|
||||
return newAlloc
|
||||
}
|
||||
|
||||
func free(ptr unsafe.Pointer) {
|
||||
// Memory is never freed.
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user