hbmap: fix iterator truncation when size_t < 32bit
[rofl0r-agsutils.git] / debug.h
blob8ee0bea6ba8e9d3647347d759fd602de4e153109
1 #ifndef DEBUG_H
2 #define DEBUG_H
4 #define empty_body do {} while(0)
5 #if defined(__x86_64) || defined(__x86_64__) || defined(_M_X64)
6 # define INTEL_CPU 64
7 #elif defined(__x86) || defined(__x86__) || defined(__i386) || defined(__i386__) || defined(_M_IX86)
8 # define INTEL_CPU 32
9 #endif
11 //#define NO_BREAKPOINTS
12 #ifdef NO_BREAKPOINTS
13 # define breakpoint() empty_body
14 #else
15 # ifdef INTEL_CPU
16 # ifdef __GNUC__
17 # define breakpoint() __asm__("int3")
18 # elif defined(__POCC__)
19 # define breakpoint() __asm { int3 }
20 # else
21 # define breakpoint() empty_body
22 # endif
23 # elif defined __unix__
24 # include <signal.h>
25 # include <unistd.h>
26 # define breakpoint() kill(getpid(), SIGTRAP)
27 # else
28 # define breakpoint() empty_body
29 # endif
30 #endif
32 #if !defined(__GNUC__) && (defined(__POCC__) || __STDC_VERSION__+0 >= 199901L)
33 #define __FUNCTION__ __func__
34 #endif
36 //#define NO_ASSERT
37 #ifdef NO_ASSERT
38 # define assert_dbg(exp) empty_body
39 # define assert_lt(exp) empty_body
40 # define assert_lte(exp) empty_body
41 # define assert(x) empty_body
42 #else
43 # include <stdio.h>
44 # define assert_dbg(exp) do { if (!(exp)) breakpoint(); } while(0)
45 # define assert_op(val, op, max) do { if(!((val) op (max))) { \
46 fprintf(stderr, "[%s:%d] %s: assert failed: %s < %s\n", \
47 __FILE__, __LINE__, __FUNCTION__, # val, # max); \
48 breakpoint();}} while(0)
50 # define assert_lt (val, max) assert_op(val, <, max)
51 # define assert_lte(val, max) assert_op(val, <= ,max)
52 #endif
54 #endif