[1022] | 1 | /* Copyright 2009, UCAR/Unidata and OPeNDAP, Inc. |
---|
| 2 | See the COPYRIGHT file for more information. */ |
---|
| 3 | |
---|
| 4 | #ifndef OCOCDBG_H |
---|
| 5 | #define OCOCDBG_H |
---|
| 6 | |
---|
| 7 | #include <stdarg.h> |
---|
| 8 | |
---|
| 9 | #if 0 |
---|
| 10 | #define OCDEBUG |
---|
| 11 | #define DAPDEBUG 1 |
---|
| 12 | #endif |
---|
| 13 | |
---|
| 14 | #ifdef OCDEBUG |
---|
| 15 | #define OCVERBOSE |
---|
| 16 | #endif |
---|
| 17 | |
---|
| 18 | /* OCCATCHERROR is used to detect errors as close |
---|
| 19 | to their point of origin as possible. When |
---|
| 20 | enabled, one can set a breakpoint in ocbreakpoint() |
---|
| 21 | to catch the failure. Turing it on incurs a significant |
---|
| 22 | performance penalty, so it is off by default.*/ |
---|
| 23 | |
---|
| 24 | #define OCCATCHERROR |
---|
| 25 | |
---|
| 26 | #define OCPANIC(msg) assert(ocpanic(msg)) |
---|
| 27 | #define OCPANIC1(msg,arg) assert(ocpanic(msg,arg)) |
---|
| 28 | #define OCPANIC2(msg,arg1,arg2) assert(ocpanic(msg,arg1,arg2)) |
---|
| 29 | |
---|
| 30 | /* Make it possible to catch assertion failures by breakpointing ocpanic*/ |
---|
| 31 | #define OCASSERT(expr) if(!(expr)) {OCPANIC((#expr));} else {} |
---|
| 32 | |
---|
| 33 | /* Need some syntactic trickery to make these macros work*/ |
---|
| 34 | #ifdef OCDEBUG |
---|
| 35 | #define OCDBG(l,msg) {oc_log(LOGDBG,msg);} |
---|
| 36 | #define OCDBG1(l,msg,arg) {oc_log(LOGDBG,msg,arg);} |
---|
| 37 | #define OCDBG2(l,msg,arg1,arg2) {oc_log(LOGDBG,msg,arg1,arg2);} |
---|
| 38 | #define OCDBGTEXT(l,text) {oc_logtext(LOGNOTE,text);} else {} |
---|
| 39 | #define OCDBGCODE(l,code) {code;} |
---|
| 40 | |
---|
| 41 | #else |
---|
| 42 | #define OCDBG(l,msg) |
---|
| 43 | #define OCDBG1(l,msg,arg) |
---|
| 44 | #define OCDBG2(l,msg,arg1,arg2) |
---|
| 45 | #define OCDBGTEXT(l,text) |
---|
| 46 | #define OCDBGCODE(l,code) |
---|
| 47 | #endif |
---|
| 48 | |
---|
| 49 | |
---|
| 50 | /* |
---|
| 51 | OCPROGRESS attempts to provide some info |
---|
| 52 | about how IO is getting along. |
---|
| 53 | */ |
---|
| 54 | #undef OCPROGRESS |
---|
| 55 | |
---|
| 56 | extern int ocdebug; |
---|
| 57 | extern int cedebug; |
---|
| 58 | |
---|
| 59 | /*extern char* dent2(int n);*/ |
---|
| 60 | /*/extern char* dent(int n);*/ |
---|
| 61 | extern int ocpanic(const char* fmt, ...); |
---|
| 62 | |
---|
| 63 | extern int xdrerror(void); |
---|
| 64 | |
---|
| 65 | /* |
---|
| 66 | Provide wrapped versions of calloc and malloc. |
---|
| 67 | The wrapped version panics if memory |
---|
| 68 | is exhausted. It also guarantees that the |
---|
| 69 | memory has been zero'd. |
---|
| 70 | */ |
---|
| 71 | |
---|
| 72 | extern void* occalloc(size_t size, size_t nelems); |
---|
| 73 | extern void* ocmalloc(size_t size); |
---|
| 74 | extern void ocfree(void*); |
---|
| 75 | |
---|
| 76 | #define MEMCHECK(var,throw) {if((var)==NULL) return (throw);} |
---|
| 77 | |
---|
| 78 | #ifdef OCCATCHERROR |
---|
| 79 | /* Place breakpoint on ocbreakpoint to catch errors close to where they occur*/ |
---|
| 80 | #define OCTHROW(e) octhrow(e) |
---|
| 81 | #define OCTHROWCHK(e) (void)octhrow(e) |
---|
| 82 | #define OCGOTO(label) {ocbreakpoint(-1); goto label;} |
---|
| 83 | extern int ocbreakpoint(int err); |
---|
| 84 | extern int octhrow(int err); |
---|
| 85 | #else |
---|
| 86 | #define OCTHROW(e) (e) |
---|
| 87 | #define OCTHROWCHK(e) |
---|
| 88 | #define OCGOTO(label) goto label |
---|
| 89 | #endif |
---|
| 90 | |
---|
| 91 | |
---|
| 92 | #endif /*OCOCDBG_H*/ |
---|
| 93 | |
---|