yajl_common.h 2.5 KB

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