1/* struct::stack - critcl - layer 0 declarations 2 * API general utilities 3 */ 4 5#ifndef _UTIL_H 6#define _UTIL_H 1 7 8#include <tcl.h> 9 10/* Allocation macros for common situations. 11 */ 12 13#define ALLOC(type) (type *) ckalloc (sizeof (type)) 14#define NALLOC(n,type) (type *) ckalloc ((n) * sizeof (type)) 15 16/* Assertions in general, and asserting the proper range of an array index. 17 */ 18 19#undef STACK_DEBUG 20#define STACK_DEBUG 1 21 22#ifdef STACK_DEBUG 23#define XSTR(x) #x 24#define STR(x) XSTR(x) 25#define RANGEOK(i,n) ((0 <= (i)) && (i < (n))) 26#define ASSERT(x,msg) if (!(x)) { Tcl_Panic (msg " (" #x "), in file " __FILE__ " @line " STR(__LINE__));} 27#define ASSERT_BOUNDS(i,n) ASSERT (RANGEOK(i,n),"array index out of bounds: " STR(i) " > " STR(n)) 28#else 29#define ASSERT(x,msg) 30#define ASSERT_BOUNDS(i,n) 31#endif 32 33#endif /* _UTIL_H */ 34 35/* 36 * Local Variables: 37 * mode: c 38 * c-basic-offset: 4 39 * fill-column: 78 40 * End: 41 */ 42