debug.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * $Id: debug.h,v 1.5 2006/01/30 23:07:57 mclark Exp $
  3. *
  4. * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd.
  5. * Michael Clark <michael@metaparadigm.com>
  6. * Copyright (c) 2009 Hewlett-Packard Development Company, L.P.
  7. *
  8. * This library is free software; you can redistribute it and/or modify
  9. * it under the terms of the MIT license. See COPYING for details.
  10. *
  11. */
  12. /**
  13. * @file
  14. * @brief Do not use, json-c internal, may be changed or removed at any time.
  15. */
  16. #ifndef _DEBUG_H_
  17. #define _DEBUG_H_
  18. #include <stdlib.h>
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. extern void mc_set_debug(int debug);
  23. extern int mc_get_debug(void);
  24. extern void mc_set_syslog(int syslog);
  25. extern void mc_debug(const char *msg, ...);
  26. extern void mc_error(const char *msg, ...);
  27. extern void mc_info(const char *msg, ...);
  28. #ifndef __STRING
  29. #define __STRING(x) #x
  30. #endif
  31. #ifndef PARSER_BROKEN_FIXED
  32. #define JASSERT(cond) do {} while(0)
  33. #else
  34. #define JASSERT(cond) do { \
  35. if (!(cond)) { \
  36. mc_error("cjson assert failure %s:%d : cond \"" __STRING(cond) "failed\n", __FILE__, __LINE__); \
  37. *(int *)0 = 1;\
  38. abort(); \
  39. }\
  40. } while(0)
  41. #endif
  42. #define MC_ERROR(x, ...) mc_error(x, ##__VA_ARGS__)
  43. #ifdef MC_MAINTAINER_MODE
  44. #define MC_SET_DEBUG(x) mc_set_debug(x)
  45. #define MC_GET_DEBUG() mc_get_debug()
  46. #define MC_SET_SYSLOG(x) mc_set_syslog(x)
  47. #define MC_DEBUG(x, ...) mc_debug(x, ##__VA_ARGS__)
  48. #define MC_INFO(x, ...) mc_info(x, ##__VA_ARGS__)
  49. #else
  50. #define MC_SET_DEBUG(x) if (0) mc_set_debug(x)
  51. #define MC_GET_DEBUG() (0)
  52. #define MC_SET_SYSLOG(x) if (0) mc_set_syslog(x)
  53. #define MC_DEBUG(x, ...) if (0) mc_debug(x, ##__VA_ARGS__)
  54. #define MC_INFO(x, ...) if (0) mc_info(x, ##__VA_ARGS__)
  55. #endif
  56. #ifdef __cplusplus
  57. }
  58. #endif
  59. #endif