1/* 2 * = = == === ===== ======== ============= ===================== 3 * == pt::rde (critcl) - General utilities 4 */ 5 6#ifndef _RDE_UTIL_H 7#define _RDE_UTIL_H 1 8 9#include <tcl.h> 10 11/* 12 * Default scope, global 13 */ 14 15#ifndef SCOPE 16#define SCOPE 17#endif 18 19/* 20 * Allocation macros for common situations. 21 */ 22 23#define ALLOC(type) (type *) ckalloc (sizeof (type)) 24#define NALLOC(n,type) (type *) ckalloc ((n) * sizeof (type)) 25 26/* 27 * General assertions, and asserting the proper range of an array index. 28 */ 29 30#undef RDE_DEBUG 31#define RDE_DEBUG 1 32 33#undef RDE_TRACE 34/* #define RDE_TRACE 1 */ 35 36/* 37 * = = == === ===== ======== ============= ===================== 38 */ 39 40#ifdef RDE_DEBUG 41#define STOPAFTER(x) { static int count = (x); count --; if (!count) { Tcl_Panic ("stop"); } } 42#define XSTR(x) #x 43#define STR(x) XSTR(x) 44#define RANGEOK(i,n) ((0 <= (i)) && (i < (n))) 45#define ASSERT(x,msg) if (!(x)) { Tcl_Panic (msg " (" #x "), in file " __FILE__ " @line " STR(__LINE__));} 46#define ASSERT_BOUNDS(i,n) ASSERT (RANGEOK(i,n),"array index out of bounds: " STR(i) " >= " STR(n)) 47#else 48#define STOPAFTER(x) 49#define ASSERT(x,msg) 50#define ASSERT_BOUNDS(i,n) 51#endif 52 53#ifdef RDE_TRACE 54SCOPE void trace_enter (const char* fun); 55SCOPE void trace_return (const char *pat, ...); 56SCOPE void trace_printf (const char *pat, ...); 57 58#define ENTER(fun) trace_enter (fun) 59#define RETURN(format,x) trace_return (format,x) ; return x 60#define RETURNVOID trace_return ("%s","(void)") ; return 61#define TRACE0(x) trace_printf0 x 62#define TRACE(x) trace_printf x 63#else 64#define ENTER(fun) 65#define RETURN(f,x) return x 66#define RETURNVOID return 67#define TRACE0(x) 68#define TRACE(x) 69#endif 70 71#endif /* _RDE_UTIL_H */ 72 73/* 74 * Local Variables: 75 * mode: c 76 * c-basic-offset: 4 77 * fill-column: 78 78 * End: 79 */ 80