mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-18 13:49:59 +01:00
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:
committed by
GitHub
parent
a501fba4bb
commit
33ab8be7e3
@ -56,8 +56,8 @@ WrenVM* wrenNewVM(WrenConfiguration* config)
|
|||||||
WrenReallocateFn reallocate = defaultReallocate;
|
WrenReallocateFn reallocate = defaultReallocate;
|
||||||
void* userData = NULL;
|
void* userData = NULL;
|
||||||
if (config != NULL) {
|
if (config != NULL) {
|
||||||
reallocate = config->reallocateFn;
|
|
||||||
userData = config->userData;
|
userData = config->userData;
|
||||||
|
reallocate = config->reallocateFn ? config->reallocateFn : defaultReallocate;
|
||||||
}
|
}
|
||||||
|
|
||||||
WrenVM* vm = (WrenVM*)reallocate(NULL, sizeof(*vm), userData);
|
WrenVM* vm = (WrenVM*)reallocate(NULL, sizeof(*vm), userData);
|
||||||
@ -67,6 +67,10 @@ WrenVM* wrenNewVM(WrenConfiguration* config)
|
|||||||
if (config != NULL)
|
if (config != NULL)
|
||||||
{
|
{
|
||||||
memcpy(&vm->config, config, sizeof(WrenConfiguration));
|
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
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user