]> git.ipfire.org Git - thirdparty/json-c.git/blob - debug.h
Eliminate use of MC_ABORT in json-c code, and mark MC_ABORT/mc_abort deprecated.
[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 #ifndef _DEBUG_H_
14 #define _DEBUG_H_
15
16 #include <stdlib.h>
17
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21
22 extern void mc_set_debug(int debug);
23 extern int mc_get_debug(void);
24
25 extern void mc_set_syslog(int syslog);
26
27 /**
28 * @deprecated Use mc_error(), and return an appropriate error.
29 */
30 extern void mc_abort(const char *msg, ...);
31 extern void mc_debug(const char *msg, ...);
32 extern void mc_error(const char *msg, ...);
33 extern void mc_info(const char *msg, ...);
34
35 #ifndef __STRING
36 #define __STRING(x) #x
37 #endif
38
39 #ifndef PARSER_BROKEN_FIXED
40
41 #define JASSERT(cond) do {} while(0)
42
43 #else
44
45 #define JASSERT(cond) do { \
46 if (!(cond)) { \
47 mc_error("cjson assert failure %s:%d : cond \"" __STRING(cond) "failed\n", __FILE__, __LINE__); \
48 *(int *)0 = 1;\
49 abort(); \
50 }\
51 } while(0)
52
53 #endif
54
55 /**
56 * @deprecated Use MC_ERROR(), and return an appropriate error.
57 */
58 #define MC_ABORT(x, ...) mc_abort(x, ##__VA_ARGS__)
59 #define MC_ERROR(x, ...) mc_error(x, ##__VA_ARGS__)
60
61 #ifdef MC_MAINTAINER_MODE
62 #define MC_SET_DEBUG(x) mc_set_debug(x)
63 #define MC_GET_DEBUG() mc_get_debug()
64 #define MC_SET_SYSLOG(x) mc_set_syslog(x)
65 #define MC_DEBUG(x, ...) mc_debug(x, ##__VA_ARGS__)
66 #define MC_INFO(x, ...) mc_info(x, ##__VA_ARGS__)
67 #else
68 #define MC_SET_DEBUG(x) if (0) mc_set_debug(x)
69 #define MC_GET_DEBUG() (0)
70 #define MC_SET_SYSLOG(x) if (0) mc_set_syslog(x)
71 #define MC_DEBUG(x, ...) if (0) mc_debug(x, ##__VA_ARGS__)
72 #define MC_INFO(x, ...) if (0) mc_info(x, ##__VA_ARGS__)
73 #endif
74
75 #ifdef __cplusplus
76 }
77 #endif
78
79 #endif