| 1 | /* |
| 2 | * Copyright (c) 2007-2014, Lloyd Hilaiel <[email protected]> |
| 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 | #ifndef __YAJL_COMMON_H__ |
| 18 | #define __YAJL_COMMON_H__ |
| 19 | |
| 20 | #include <stddef.h> |
| 21 | |
| 22 | #ifdef __cplusplus |
| 23 | extern "C" { |
| 24 | #endif |
| 25 | |
| 26 | #define YAJL_MAX_DEPTH 128 |
| 27 | |
| 28 | /* msft dll export gunk. To build a DLL on windows, you |
| 29 | * must define WIN32, YAJL_SHARED, and YAJL_BUILD. To use a shared |
| 30 | * DLL, you must define YAJL_SHARED and WIN32 */ |
| 31 | #if (defined(_WIN32) || defined(WIN32)) && defined(YAJL_SHARED) |
| 32 | # ifdef YAJL_BUILD |
| 33 | # define YAJL_API __declspec(dllexport) |
| 34 | # else |
| 35 | # define YAJL_API __declspec(dllimport) |
| 36 | # endif |
| 37 | #else |
| 38 | # if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 303 |
| 39 | # define YAJL_API __attribute__ ((visibility("default"))) |
| 40 | # else |
| 41 | # define YAJL_API |
| 42 | # endif |
| 43 | #endif |
| 44 | |
| 45 | /** pointer to a malloc function, supporting client overriding memory |
| 46 | * allocation routines */ |
| 47 | typedef void * (*yajl_malloc_func)(void *ctx, size_t sz); |
| 48 | |
| 49 | /** pointer to a free function, supporting client overriding memory |
| 50 | * allocation routines */ |
| 51 | typedef void (*yajl_free_func)(void *ctx, void * ptr); |
| 52 | |
| 53 | /** pointer to a realloc function which can resize an allocation. */ |
| 54 | typedef void * (*yajl_realloc_func)(void *ctx, void * ptr, size_t sz); |
| 55 | |
| 56 | /** A structure which can be passed to yajl_*_alloc routines to allow the |
| 57 | * client to specify memory allocation functions to be used. */ |
| 58 | typedef struct |
| 59 | { |
| 60 | /** pointer to a function that can allocate uninitialized memory */ |
| 61 | yajl_malloc_func malloc; |
| 62 | /** pointer to a function that can resize memory allocations */ |
| 63 | yajl_realloc_func realloc; |
| 64 | /** pointer to a function that can free memory allocated using |
| 65 | * reallocFunction or mallocFunction */ |
| 66 | yajl_free_func free; |
| 67 | /** a context pointer that will be passed to above allocation routines */ |
| 68 | void * ctx; |
| 69 | } yajl_alloc_funcs; |
| 70 | |
| 71 | #ifdef __cplusplus |
| 72 | } |
| 73 | #endif |
| 74 | |
| 75 | #endif |