2 * Copyright (c) 2009-2016 Petri Lehtinen <petri@digip.org>
3 * Copyright (c) 2011-2012 Basile Starynkevitch <basile@starynkevitch.net>
5 * Jansson is free software; you can redistribute it and/or modify it
6 * under the terms of the MIT license. See LICENSE for details.
13 #include "jansson_private.h"
15 /* C89 allows these to be macros */
19 /* memory function pointers */
20 static json_malloc_t do_malloc
= malloc
;
21 static json_free_t do_free
= free
;
23 void *jsonp_malloc(size_t size
) {
27 return (*do_malloc
)(size
);
30 void jsonp_free(void *ptr
) {
37 char *jsonp_strdup(const char *str
) {
38 return jsonp_strndup(str
, strlen(str
));
41 char *jsonp_strndup(const char *str
, size_t len
) {
44 new_str
= jsonp_malloc(len
+ 1);
48 memcpy(new_str
, str
, len
);
53 void json_set_alloc_funcs(json_malloc_t malloc_fn
, json_free_t free_fn
) {
54 do_malloc
= malloc_fn
;
58 void json_get_alloc_funcs(json_malloc_t
*malloc_fn
, json_free_t
*free_fn
) {
60 *malloc_fn
= do_malloc
;