1 | /* 2 | * Copyright (c) 2007-2014, Lloyd Hilaiel <me@lloyd.io> 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 | * default memory allocation routines for yajl which use malloc(3), realloc(3), 19 | * and free(3) 20 | **/ 21 | 22 | #include "yajl_alloc.h" 23 | #include <stdlib.h> 24 | 25 | /*+ 26 | * a private wrapper around malloc(3) 27 | +*/ 28 | static void * yajl_internal_malloc(void *ctx, size_t sz) 29 | { 30 | (void)ctx; 31 | return malloc(sz); 32 | } 33 | 34 | /*+ 35 | * a private wrapper around realloc(3) 36 | +*/ 37 | static void * yajl_internal_realloc(void *ctx, void * previous, 38 | size_t sz) 39 | { 40 | (void)ctx; 41 | return realloc(previous, sz); 42 | } 43 | 44 | /*+ 45 | * a private wrapper around free(3) 46 | +*/ 47 | static void yajl_internal_free(void *ctx, void * ptr) 48 | { 49 | (void)ctx; 50 | free(ptr); 51 | } 52 | 53 | /*+ 54 | * Set the allocator function pointers in <yaf> to private functions which call 55 | * the default malloc(3), realloc(3), and free(3) functions. 56 | +*/ 57 | void yajl_set_default_alloc_funcs(yajl_alloc_funcs * yaf) 58 | { 59 | yaf->malloc = yajl_internal_malloc; 60 | yaf->free = yajl_internal_free; 61 | yaf->realloc = yajl_internal_realloc; 62 | yaf->ctx = NULL; 63 | } 64 |