]> git.saurik.com Git - apple/libc.git/blame - gen/assumes.h
Libc-763.12.tar.gz
[apple/libc.git] / gen / assumes.h
CommitLineData
1f2f436a
A
1#ifndef __OSX_ASSUMES_H__
2#define __OSX_ASSUMES_H__
3
4#include <sys/cdefs.h>
5
6__BEGIN_DECLS
7
8#include <Availability.h>
9#include <stdlib.h>
10#include <stdint.h>
11#include <stdarg.h>
12#include <stdbool.h>
13#include <asl.h>
14
15#if __GNUC__
16#define osx_fastpath(x) ((typeof(x))__builtin_expect((long)(x), ~0l))
17#define osx_slowpath(x) ((typeof(x))__builtin_expect((long)(x), 0l))
18#define osx_constant(x) __builtin_constant_p((x))
19
20#define __OSX_COMPILETIME_ASSERT__(e) ({ \
21 char __compile_time_assert__[(e) ? 1 : -1]; \
22 (void)__compile_time_assert__; \
23})
24#else
25#define osx_fastpath(x) (x)
26#define osx_slowpath(x) (x)
27#define osx_constant(x) ((long)0)
28
29#define __OSX_COMPILETIME_ASSERT__(e) (e)
30#endif /* __GNUC__ */
31
32#define osx_assumes(e) ({ \
33 typeof(e) _e = osx_fastpath(e); /* Force evaluation of 'e' */ \
34 if (!_e) { \
35 if (osx_constant(e)) { \
36 __OSX_COMPILETIME_ASSERT__(e); \
37 } \
38 _osx_assumes_log((uintptr_t)_e); \
39 } \
40 _e; \
41})
42
43#define osx_assumes_zero(e) ({ \
44 typeof(e) _e = osx_slowpath(e); /* Force evaluation of 'e' */ \
45 if (_e) { \
46 if (osx_constant(e)) { \
47 __OSX_COMPILETIME_ASSERT__(!e); \
48 } \
49 _osx_assumes_log((uintptr_t)_e); \
50 } \
51 _e; \
52})
53
54__OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_4_3)
55extern void
56_osx_assumes_log(uint64_t code);
57
58__END_DECLS
59
60#endif /* __OSX_ASSUMES_H__ */