Hook checks

FossilOrigin-Name: bddc30618d746725122fa5620c971ced3f8a6ca065e12c06208a7117b936d54c
This commit is contained in:
nekobit 2022-10-15 20:55:04 +00:00
parent 7647698b31
commit 28d69a286f

View file

@ -14,6 +14,7 @@
*/
#include <stdlib.h>
#include <assert.h>
#include <cjson/cJSON.h>
#include <mastodont_hooks.h>
@ -26,12 +27,20 @@ struct mstdnt_hooks _mstdnt_hooks_def = {
void mstdnt_set_hooks(struct mstdnt_hooks* hooks)
{
assert(hooks != NULL);
cJSON_Hooks cjson_hooks = {
.malloc_fn = hooks->malloc,
.free_fn = hooks->free,
};
cJSON_InitHooks(&cjson_hooks);
_mstdnt_hooks_def = *hooks;
if (hooks->malloc)
_mstdnt_hooks_def.malloc = hooks->malloc;
if (hooks->free)
_mstdnt_hooks_def.free = hooks->free;
if (hooks->calloc)
_mstdnt_hooks_def.calloc = hooks->calloc;
if (hooks->realloc)
_mstdnt_hooks_def.realloc = hooks->realloc;
}