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:
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user