Skip to content

Commit

Permalink
fix possibility of having no reallocate function (#954)
Browse files Browse the repository at this point in the history
Before, if a config was provided it was expected to have a reallocate function, now it can remain null and the default will be used.
  • Loading branch information
Orcolom authored Apr 4, 2021
1 parent a501fba commit 33ab8be
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/vm/wren_vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ WrenVM* wrenNewVM(WrenConfiguration* config)
WrenReallocateFn reallocate = defaultReallocate;
void* userData = NULL;
if (config != NULL) {
reallocate = config->reallocateFn;
userData = config->userData;
reallocate = config->reallocateFn ? config->reallocateFn : defaultReallocate;
}

WrenVM* vm = (WrenVM*)reallocate(NULL, sizeof(*vm), userData);
Expand All @@ -67,6 +67,10 @@ WrenVM* wrenNewVM(WrenConfiguration* config)
if (config != NULL)
{
memcpy(&vm->config, config, sizeof(WrenConfiguration));

// We choose to set this after copying,
// rather than modifying the user config pointer
vm->config.reallocateFn = reallocate;
}
else
{
Expand Down

0 comments on commit 33ab8be

Please sign in to comment.