00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #pragma once
00025 #ifndef ASSUME_H
00026 #define ASSUME_H
00027
00028 #include <stdio.h>
00029 #include <stdlib.h>
00030 #include "util.h"
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061 #define __LB(l, ...) l
00062 #define __RB(l, ...) __VA_ARGS__
00063 #define __emitmsg_fp stderr
00064
00065
00066
00067
00068
00069
00070 #define __atomic_emitmsg(...) \
00071 do { \
00072 if (ftrylockfile(__emitmsg_fp) == 0) { \
00073 fprintf (stderr, __VA_ARGS__); \
00074 funlockfile(__emitmsg_fp); \
00075 } \
00076 } while (0)
00077
00078 #ifndef NDEBUG
00079 # define __terminate(retval) abort()
00080 # define __emitmsg(...) __atomic_emitmsg (__VA_ARGS__)
00081 #else
00082 # define __terminate(retval) return retval
00083 # ifdef ASSUME_VERBOSE
00084 # define __emitmsg(...) __atomic_emitmsg (__VA_ARGS__)
00085 # else
00086 # define __emitmsg(...) while(0)
00087 # endif
00088 #endif
00089
00090 #define __assume(expr, exprstr, retval, ...) \
00091 do { \
00092 int OSCAP_CONCAT(__cont, __LINE__) = 1; \
00093 if (!(expr)) { \
00094 __emitmsg ("%s:%d (%s): Assumption `%s' not fulfilled!\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, exprstr); \
00095 do {__LB(__VA_ARGS__)} while((OSCAP_CONCAT(__cont, __LINE__) = 0)); \
00096 if (OSCAP_CONCAT(__cont, __LINE__) == 0) __terminate(retval); \
00097 } else { \
00098 do {__RB(__VA_ARGS__)} while(0); \
00099 } \
00100 } while (0)
00101
00102 #if defined(__GNUC__)
00103 # define assume(expr, retval, ...) __assume(__builtin_expect(expr, 1), #expr, retval, __VA_ARGS__)
00104 #else
00105 # define assume(expr, retval, ...) __assume(expr, #expr, retval, __VA_ARGS__)
00106 #endif
00107
00111 #define assume_r(...) assume(__VA_ARGS__)
00112
00116 #ifndef NDEBUG
00117 # define assume_d(...) assume(__VA_ARGS__)
00118 #else
00119 # define assume_d(...) while(0)
00120 #endif
00121
00122 #endif