You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

debug.h 1.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. #ifndef _DEBUG_H_
  13. #define _DEBUG_H_
  14. #include <stdlib.h>
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. extern void mc_set_debug(int debug);
  19. extern int mc_get_debug(void);
  20. extern void mc_set_syslog(int syslog);
  21. extern void mc_abort(const char *msg, ...);
  22. extern void mc_debug(const char *msg, ...);
  23. extern void mc_error(const char *msg, ...);
  24. extern void mc_info(const char *msg, ...);
  25. #ifndef __STRING
  26. #define __STRING(x) #x
  27. #endif
  28. #ifndef PARSER_BROKEN_FIXED
  29. #define JASSERT(cond) do {} while(0)
  30. #else
  31. #define JASSERT(cond) do { \
  32. if (!(cond)) { \
  33. mc_error("cjson assert failure %s:%d : cond \"" __STRING(cond) "failed\n", __FILE__, __LINE__); \
  34. *(int *)0 = 1;\
  35. abort(); \
  36. }\
  37. } while(0)
  38. #endif
  39. #define MC_ABORT(x, ...) mc_abort(x, ##__VA_ARGS__)
  40. #define MC_ERROR(x, ...) mc_error(x, ##__VA_ARGS__)
  41. #ifdef MC_MAINTAINER_MODE
  42. #define MC_SET_DEBUG(x) mc_set_debug(x)
  43. #define MC_GET_DEBUG() mc_get_debug()
  44. #define MC_SET_SYSLOG(x) mc_set_syslog(x)
  45. #define MC_DEBUG(x, ...) mc_debug(x, ##__VA_ARGS__)
  46. #define MC_INFO(x, ...) mc_info(x, ##__VA_ARGS__)
  47. #else
  48. #define MC_SET_DEBUG(x) if (0) mc_set_debug(x)
  49. #define MC_GET_DEBUG() (0)
  50. #define MC_SET_SYSLOG(x) if (0) mc_set_syslog(x)
  51. #define MC_DEBUG(x, ...) if (0) mc_debug(x, ##__VA_ARGS__)
  52. #define MC_INFO(x, ...) if (0) mc_info(x, ##__VA_ARGS__)
  53. #endif
  54. #ifdef __cplusplus
  55. }
  56. #endif
  57. #endif