Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions source/m3_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,28 +105,34 @@ void * m3_Realloc (void * i_ptr, size_t i_newSize, size_t i_oldSize)

#else

static void*
_c_realloc(void* ptr, size_t old, size_t new)
{
return realloc(ptr, new);
}

M3AllocationFunctionStruct m3_alloc_funcs = {
calloc,
free,
realloc
_c_realloc
};

M3AllocationFunctionStruct m3_alloc_transient_funcs = {
calloc,
free,
realloc
_c_realloc
};

M3AllocationFunctionStruct m3_alloc_memory_funcs = {
calloc,
free,
realloc
_c_realloc
};

M3Result m3_SetAllocators (
void* (*calloc_fn) (size_t, size_t),
void (*free_fn) (void*),
void* (*realloc_fn) (void*, size_t)
void* (*realloc_fn) (void*, size_t, size_t)
)
{
if ( (calloc_fn == NULL) || (free_fn == NULL) || (realloc_fn == NULL) ) {
Expand All @@ -144,7 +150,7 @@ M3Result m3_SetAllocators (
M3Result m3_SetTransientAllocators (
void* (*calloc_fn) (size_t, size_t),
void (*free_fn) (void*),
void* (*realloc_fn) (void*, size_t)
void* (*realloc_fn) (void*, size_t, size_t)
)
{
if ( (calloc_fn == NULL) || (free_fn == NULL) || (realloc_fn == NULL) ) {
Expand All @@ -159,7 +165,7 @@ M3Result m3_SetTransientAllocators (
M3Result m3_SetMemoryAllocators (
void* (*calloc_fn) (size_t, size_t),
void (*free_fn) (void*),
void* (*realloc_fn) (void*, size_t)
void* (*realloc_fn) (void*, size_t, size_t)
)
{
if ( (calloc_fn == NULL) || (free_fn == NULL) || (realloc_fn == NULL) ) {
Expand Down Expand Up @@ -189,8 +195,8 @@ void m3_FreeImpl (void * io_ptr)
void * m3_Realloc (void * i_ptr, size_t i_newSize, size_t i_oldSize)
{
if (UNLIKELY(i_newSize == i_oldSize)) return i_ptr;

void * newPtr = m3_alloc_funcs.realloc_fn (i_ptr, i_newSize);
// NB: different order of new/old
void * newPtr = m3_alloc_funcs.realloc_fn (i_ptr, i_oldSize, i_newSize);

if (LIKELY(newPtr))
{
Expand Down Expand Up @@ -220,8 +226,8 @@ void m3_FreeTransientImpl (void * io_ptr)
void * m3_ReallocTransient (void * i_ptr, size_t i_newSize, size_t i_oldSize)
{
if (UNLIKELY(i_newSize == i_oldSize)) return i_ptr;

void * newPtr = m3_alloc_transient_funcs.realloc_fn (i_ptr, i_newSize);
// NB: different order of new/old
void * newPtr = m3_alloc_transient_funcs.realloc_fn (i_ptr, i_oldSize, i_newSize);

if (LIKELY(newPtr))
{
Expand All @@ -247,8 +253,8 @@ void m3_FreeMemoryImpl (void * io_ptr)
void * m3_ReallocMemory (void * i_ptr, size_t i_newSize, size_t i_oldSize)
{
if (UNLIKELY(i_newSize == i_oldSize)) return i_ptr;

void * newPtr = m3_alloc_memory_funcs.realloc_fn (i_ptr, i_newSize);
// NB: different order of new/old
void * newPtr = m3_alloc_memory_funcs.realloc_fn (i_ptr, i_oldSize, i_newSize);

if (LIKELY(newPtr))
{
Expand Down
2 changes: 1 addition & 1 deletion source/m3_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ typedef struct M3AllocationFunctionStruct
{
void* (* calloc_fn)(size_t, size_t);
void (* free_fn)(void*);
void* (* realloc_fn)(void*, size_t);
void* (* realloc_fn)(void*, size_t, size_t);
}
M3AllocationFunctionStruct;

Expand Down
6 changes: 3 additions & 3 deletions source/wasm3.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,15 @@ d_m3ErrorConst (SuspensionError, "error during suspension")

M3Result m3_SetAllocators (void* (* calloc_fn)(size_t, size_t),
void (* free_fn)(void*),
void* (* realloc_fn)(void*, size_t));
void* (* realloc_fn)(void*, size_t, size_t)); // first old, then new

M3Result m3_SetTransientAllocators (void* (* calloc_fn)(size_t, size_t),
void (* free_fn)(void*),
void* (* realloc_fn)(void*, size_t));
void* (* realloc_fn)(void*, size_t, size_t)); // first old, then new

M3Result m3_SetMemoryAllocators (void* (* calloc_fn)(size_t, size_t),
void (* free_fn)(void*),
void* (* realloc_fn)(void*, size_t));
void* (* realloc_fn)(void*, size_t, size_t)); // first old, then new

void m3_RewritePointersRuntime (IM3Runtime runtime,
uint8_t* base,
Expand Down