w.deng | e87b500 | 2025-08-20 10:43:03 +0800 | [diff] [blame] | 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 _JSON_C_DEBUG_H_ |
| 18 | #define _JSON_C_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) && defined(JSON_C_DLL) |
| 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) \ |
| 50 | do \ |
| 51 | { \ |
| 52 | } while (0) |
| 53 | |
| 54 | #else |
| 55 | |
| 56 | #define JASSERT(cond) \ |
| 57 | do \ |
| 58 | { \ |
| 59 | if (!(cond)) \ |
| 60 | { \ |
| 61 | mc_error("cjson assert failure %s:%d : cond \"" __STRING(cond) "failed\n", \ |
| 62 | __FILE__, __LINE__); \ |
| 63 | *(int *)0 = 1; \ |
| 64 | abort(); \ |
| 65 | } \ |
| 66 | } while (0) |
| 67 | |
| 68 | #endif |
| 69 | |
| 70 | #define MC_ERROR(x, ...) mc_error(x, ##__VA_ARGS__) |
| 71 | |
| 72 | #ifdef MC_MAINTAINER_MODE |
| 73 | #define MC_SET_DEBUG(x) mc_set_debug(x) |
| 74 | #define MC_GET_DEBUG() mc_get_debug() |
| 75 | #define MC_SET_SYSLOG(x) mc_set_syslog(x) |
| 76 | #define MC_DEBUG(x, ...) mc_debug(x, ##__VA_ARGS__) |
| 77 | #define MC_INFO(x, ...) mc_info(x, ##__VA_ARGS__) |
| 78 | #else |
| 79 | #define MC_SET_DEBUG(x) \ |
| 80 | if (0) \ |
| 81 | mc_set_debug(x) |
| 82 | #define MC_GET_DEBUG() (0) |
| 83 | #define MC_SET_SYSLOG(x) \ |
| 84 | if (0) \ |
| 85 | mc_set_syslog(x) |
| 86 | #define MC_DEBUG(x, ...) \ |
| 87 | if (0) \ |
| 88 | mc_debug(x, ##__VA_ARGS__) |
| 89 | #define MC_INFO(x, ...) \ |
| 90 | if (0) \ |
| 91 | mc_info(x, ##__VA_ARGS__) |
| 92 | #endif |
| 93 | |
| 94 | #ifdef __cplusplus |
| 95 | } |
| 96 | #endif |
| 97 | |
| 98 | #endif |