1 /*
2  * Copyright (c) 2007-2011, Lloyd Hilaiel <lloyd@hilaiel.com>
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 /**
18  * \file yajl_alloc.h
19  * default memory allocation routines for yajl which use malloc/realloc and
20  * free
21  */
22 
23 #include "yajl_alloc.h"
24 #include <stdlib.h>
25 
yajl_internal_malloc(void *ctx, size_t sz)26 static void * yajl_internal_malloc(void *ctx, size_t sz)
27 {
28     return malloc(sz);
29 }
30 
yajl_internal_realloc(void *ctx, void * previous, size_t sz)31 static void * yajl_internal_realloc(void *ctx, void * previous,
32                                     size_t sz)
33 {
34     return realloc(previous, sz);
35 }
36 
yajl_internal_free(void *ctx, void * ptr)37 static void yajl_internal_free(void *ctx, void * ptr)
38 {
39     free(ptr);
40 }
41 
yajl_set_default_alloc_funcs(yajl_alloc_funcs * yaf)42 void yajl_set_default_alloc_funcs(yajl_alloc_funcs * yaf)
43 {
44     yaf->malloc = yajl_internal_malloc;
45     yaf->free = yajl_internal_free;
46     yaf->realloc = yajl_internal_realloc;
47     yaf->ctx = NULL;
48 }
49 
50