1767de84eSFilipe David Borba Manana/*
2767de84eSFilipe David Borba Manana * Copyright (c) 2007-2011, Lloyd Hilaiel <lloyd@hilaiel.com>
3767de84eSFilipe David Borba Manana *
4767de84eSFilipe David Borba Manana * Permission to use, copy, modify, and/or distribute this software for any
5767de84eSFilipe David Borba Manana * purpose with or without fee is hereby granted, provided that the above
6767de84eSFilipe David Borba Manana * copyright notice and this permission notice appear in all copies.
7767de84eSFilipe David Borba Manana *
8767de84eSFilipe David Borba Manana * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9767de84eSFilipe David Borba Manana * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10767de84eSFilipe David Borba Manana * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11767de84eSFilipe David Borba Manana * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12767de84eSFilipe David Borba Manana * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13767de84eSFilipe David Borba Manana * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14767de84eSFilipe David Borba Manana * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15767de84eSFilipe David Borba Manana */
16767de84eSFilipe David Borba Manana
17767de84eSFilipe David Borba Manana#ifndef __YAJL_COMMON_H__
18767de84eSFilipe David Borba Manana#define __YAJL_COMMON_H__
19767de84eSFilipe David Borba Manana
20767de84eSFilipe David Borba Manana#include <stddef.h>
21767de84eSFilipe David Borba Manana
22767de84eSFilipe David Borba Manana#ifdef __cplusplus
23767de84eSFilipe David Borba Mananaextern "C" {
24767de84eSFilipe David Borba Manana#endif
25767de84eSFilipe David Borba Manana
26767de84eSFilipe David Borba Manana#define YAJL_MAX_DEPTH 128
27767de84eSFilipe David Borba Manana
28767de84eSFilipe David Borba Manana/* msft dll export gunk.  To build a DLL on windows, you
29767de84eSFilipe David Borba Manana * must define WIN32, YAJL_SHARED, and YAJL_BUILD.  To use a shared
30767de84eSFilipe David Borba Manana * DLL, you must define YAJL_SHARED and WIN32 */
31767de84eSFilipe David Borba Manana#if (defined(_WIN32) || defined(WIN32)) && defined(YAJL_SHARED)
32767de84eSFilipe David Borba Manana#  ifdef YAJL_BUILD
33767de84eSFilipe David Borba Manana#    define YAJL_API __declspec(dllexport)
34767de84eSFilipe David Borba Manana#  else
35767de84eSFilipe David Borba Manana#    define YAJL_API __declspec(dllimport)
36767de84eSFilipe David Borba Manana#  endif
37767de84eSFilipe David Borba Manana#else
38767de84eSFilipe David Borba Manana#  if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 303
39767de84eSFilipe David Borba Manana#    define YAJL_API __attribute__ ((visibility("default")))
40767de84eSFilipe David Borba Manana#  else
41767de84eSFilipe David Borba Manana#    define YAJL_API
42767de84eSFilipe David Borba Manana#  endif
43767de84eSFilipe David Borba Manana#endif
44767de84eSFilipe David Borba Manana
45767de84eSFilipe David Borba Manana/** pointer to a malloc function, supporting client overriding memory
46767de84eSFilipe David Borba Manana *  allocation routines */
47767de84eSFilipe David Borba Mananatypedef void * (*yajl_malloc_func)(void *ctx, size_t sz);
48767de84eSFilipe David Borba Manana
49767de84eSFilipe David Borba Manana/** pointer to a free function, supporting client overriding memory
50767de84eSFilipe David Borba Manana *  allocation routines */
51767de84eSFilipe David Borba Mananatypedef void (*yajl_free_func)(void *ctx, void * ptr);
52767de84eSFilipe David Borba Manana
53767de84eSFilipe David Borba Manana/** pointer to a realloc function which can resize an allocation. */
54767de84eSFilipe David Borba Mananatypedef void * (*yajl_realloc_func)(void *ctx, void * ptr, size_t sz);
55767de84eSFilipe David Borba Manana
56767de84eSFilipe David Borba Manana/** A structure which can be passed to yajl_*_alloc routines to allow the
57767de84eSFilipe David Borba Manana *  client to specify memory allocation functions to be used. */
58767de84eSFilipe David Borba Mananatypedef struct
59767de84eSFilipe David Borba Manana{
60767de84eSFilipe David Borba Manana    /** pointer to a function that can allocate uninitialized memory */
61767de84eSFilipe David Borba Manana    yajl_malloc_func malloc;
62767de84eSFilipe David Borba Manana    /** pointer to a function that can resize memory allocations */
63767de84eSFilipe David Borba Manana    yajl_realloc_func realloc;
64767de84eSFilipe David Borba Manana    /** pointer to a function that can free memory allocated using
65767de84eSFilipe David Borba Manana     *  reallocFunction or mallocFunction */
66767de84eSFilipe David Borba Manana    yajl_free_func free;
67767de84eSFilipe David Borba Manana    /** a context pointer that will be passed to above allocation routines */
68767de84eSFilipe David Borba Manana    void * ctx;
69767de84eSFilipe David Borba Manana} yajl_alloc_funcs;
70767de84eSFilipe David Borba Manana
71767de84eSFilipe David Borba Manana#ifdef __cplusplus
72767de84eSFilipe David Borba Manana}
73767de84eSFilipe David Borba Manana#endif
74767de84eSFilipe David Borba Manana
75767de84eSFilipe David Borba Manana#endif
76