clsync
macros.h
Go to the documentation of this file.
1 #ifndef __CLSYNC_MACROS_H
2 #define __CLSYNC_MACROS_H
3 
4 #ifdef _DEBUG
5 # define DEBUGV(...) __VA_ARGS__
6 #else
7 # define DEBUGV(...)
8 #endif
9 
10 #ifdef PARANOID
11 # define PARANOIDV(...) __VA_ARGS__
12 #else
13 # define PARANOIDV(...)
14 #endif
15 
16 // gcc, clang and lcc support __builtin_expect and define __GNUC__
17 #ifdef __GNUC__
18 # ifndef likely
19 # define likely(x) __builtin_expect(!!(x), 1)
20 # endif
21 # ifndef unlikely
22 # define unlikely(x) __builtin_expect(!!(x), 0)
23 # endif
24 #else
25 # ifndef likely
26 # define likely(x) (x)
27 # endif
28 # ifndef unlikely
29 # define unlikely(x) (x)
30 # endif
31 #endif
32 
33 #ifndef offsetof
34 # define offsetof(a, b) __builtin_offsetof(a, b)
35 #endif
36 
37 // clang defines "__GNUC__", but not compatible with gnuc. Fixing.
38 #ifdef __clang__
39 # ifdef __GNUC__
40 # undef __GNUC__
41 # endif
42 #endif
43 
44 #define TOSTR(a) # a
45 #define XTOSTR(a) TOSTR(a)
46 
47 #define COLLECTDELAY_INSTANT ((unsigned int)~0)
48 
49 
50 #define MSG_SECURITY_PROBLEM(a) "Security problem: "a". Don't use this application until the bug will be fixed. Report about the problem to: "AUTHOR
51 
52 #define require_strlen_le(str, limit) \
53  if (unlikely( strlen(str) >= limit ))\
54  critical("length of "TOSTR(str)" (\"%s\") >= "TOSTR(limit));\
55 
56 #define SAFE(code, onfail) __extension__({\
57  long _SAFE_rc;\
58  if (unlikely((_SAFE_rc = code))) {\
59  error("Got error while "TOSTR(code));\
60  onfail;\
61  } \
62  _SAFE_rc;\
63  })
64 
65 #endif