]> git.ipfire.org Git - thirdparty/json-c.git/blob - debug.h
Merge pull request #501 from andy5995/iss_406-2
[thirdparty/json-c.git] / debug.h
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 /**
14 * @file
15 * @brief Do not use, json-c internal, may be changed or removed at any time.
16 */
17 #ifndef _DEBUG_H_
18 #define _DEBUG_H_
19
20 #include <stdlib.h>
21
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25
26 #ifndef JSON_EXPORT
27 #if defined(_MSC_VER)
28 #define JSON_EXPORT __declspec(dllexport)
29 #else
30 #define JSON_EXPORT extern
31 #endif
32 #endif
33
34 JSON_EXPORT void mc_set_debug(int debug);
35 JSON_EXPORT int mc_get_debug(void);
36
37 JSON_EXPORT void mc_set_syslog(int syslog);
38
39 JSON_EXPORT void mc_debug(const char *msg, ...);
40 JSON_EXPORT void mc_error(const char *msg, ...);
41 JSON_EXPORT void mc_info(const char *msg, ...);
42
43 #ifndef __STRING
44 #define __STRING(x) #x
45 #endif
46
47 #ifndef PARSER_BROKEN_FIXED
48
49 #define JASSERT(cond) do {} while(0)
50
51 #else
52
53 #define JASSERT(cond) do { \
54 if (!(cond)) { \
55 mc_error("cjson assert failure %s:%d : cond \"" __STRING(cond) "failed\n", __FILE__, __LINE__); \
56 *(int *)0 = 1;\
57 abort(); \
58 }\
59 } while(0)
60
61 #endif
62
63 #define MC_ERROR(x, ...) mc_error(x, ##__VA_ARGS__)
64
65 #ifdef MC_MAINTAINER_MODE
66 #define MC_SET_DEBUG(x) mc_set_debug(x)
67 #define MC_GET_DEBUG() mc_get_debug()
68 #define MC_SET_SYSLOG(x) mc_set_syslog(x)
69 #define MC_DEBUG(x, ...) mc_debug(x, ##__VA_ARGS__)
70 #define MC_INFO(x, ...) mc_info(x, ##__VA_ARGS__)
71 #else
72 #define MC_SET_DEBUG(x) if (0) mc_set_debug(x)
73 #define MC_GET_DEBUG() (0)
74 #define MC_SET_SYSLOG(x) if (0) mc_set_syslog(x)
75 #define MC_DEBUG(x, ...) if (0) mc_debug(x, ##__VA_ARGS__)
76 #define MC_INFO(x, ...) if (0) mc_info(x, ##__VA_ARGS__)
77 #endif
78
79 #ifdef __cplusplus
80 }
81 #endif
82
83 #endif