Add json_get_alloc_funcs() to allow alloc function fetching

This is particularly useful in modular situations where the allocation
functions are either unknown or private. For instance, in such cases,
the caller of json_dumps() has no way to free the returned buffer.
This commit is contained in:
Nathaniel McCallum
2015-12-21 11:46:32 -05:00
parent e44b2231b5
commit 245e532934
5 changed files with 21 additions and 1 deletions

View File

@@ -36,10 +36,15 @@ static void my_free(void *ptr)
static void test_simple()
{
json_malloc_t mfunc = NULL;
json_free_t ffunc = NULL;
json_set_alloc_funcs(my_malloc, my_free);
json_get_alloc_funcs(&mfunc, &ffunc);
create_and_free_complex_object();
if(malloc_called != 1 || free_called != 1)
if (malloc_called != 1 || free_called != 1
|| mfunc != my_malloc || ffunc != my_free)
fail("Custom allocation failed");
}