fix possibility of having no reallocate function (#954)

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.
This commit is contained in:
Joram Vandemoortele
2021-04-04 20:24:48 +02:00
committed by GitHub
parent a501fba4bb
commit 33ab8be7e3

View File

@ -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);
@ -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
{