|
24 | 24 | #ifndef ___CDEFS_H_ |
25 | 25 | #define ___CDEFS_H_ |
26 | 26 |
|
27 | | -// Version information. |
28 | | -#define __cloudlibc__ 1 |
29 | | -#define __cloudlibc_major__ 0 |
30 | | -#define __cloudlibc_minor__ 102 |
31 | | - |
32 | | -#ifdef __cplusplus |
33 | | -#define __BEGIN_DECLS extern "C" { |
34 | | -#define __END_DECLS } |
35 | | -#else |
36 | | -#define __BEGIN_DECLS |
37 | | -#define __END_DECLS |
38 | | -#endif |
39 | | - |
40 | | -// Whether we should provide inline versions of functions. Due to C++'s |
41 | | -// support for namespaces, it is generally a bad idea to declare |
42 | | -// function macros. |
43 | | -#ifdef __cplusplus |
44 | | -#define _CLOUDLIBC_INLINE_FUNCTIONS 0 |
45 | | -#else |
46 | | -#define _CLOUDLIBC_INLINE_FUNCTIONS 1 |
47 | | -#endif |
48 | | - |
49 | 27 | // Compiler-independent annotations. |
50 | 28 |
|
51 | | -#ifndef __has_builtin |
52 | | -#define __has_builtin(x) 0 |
53 | | -#endif |
54 | | -#ifndef __has_extension |
55 | | -#define __has_extension(x) __has_feature(x) |
56 | | -#endif |
57 | | -#ifndef __has_feature |
58 | | -#define __has_feature(x) 0 |
59 | | -#endif |
60 | | - |
61 | | -#define __offsetof(type, member) __builtin_offsetof(type, member) |
62 | | -#define __containerof(ptr, type, member) \ |
63 | | - ((type *)((char *)(ptr)-__offsetof(type, member))) |
64 | | - |
65 | | -#define __extname(x) __asm__(x) |
66 | | -#define __malloc_like __attribute__((__malloc__)) |
67 | | -#define __pure2 __attribute__((__const__)) |
68 | | -#define __pure __attribute__((__pure__)) |
69 | | -#define __section(x) __attribute__((__section__(x))) |
70 | | -#define __unused __attribute__((__unused__)) |
71 | | -#define __used __attribute__((__used__)) |
72 | | -#define __weak_symbol __attribute__((__weak__)) |
73 | | - |
74 | | -// Format string argument type checking. |
75 | | -#define __printflike(format, va) \ |
76 | | - __attribute__((__format__(__printf__, format, va))) |
77 | | -#define __scanflike(format, va) \ |
78 | | - __attribute__((__format__(__scanf__, format, va))) |
79 | | -// TODO(ed): Enable this once supported by LLVM: |
80 | | -// https://llvm.org/bugs/show_bug.cgi?id=16810 |
81 | | -#define __wprintflike(format, va) |
82 | | -#define __wscanflike(format, va) |
83 | | - |
84 | 29 | #define __strong_reference(oldsym, newsym) \ |
85 | 30 | extern __typeof__(oldsym) newsym __attribute__((__alias__(#oldsym))) |
86 | 31 |
|
87 | 32 | // Convenience macros. |
88 | 33 |
|
89 | 34 | #define __arraycount(x) (sizeof(x) / sizeof((x)[0])) |
90 | | -#define __howmany(x, y) (((x) + (y)-1) / (y)) |
91 | | -#define __rounddown(x, y) (((x) / (y)) * (y)) |
92 | | -#define __roundup(x, y) ((((x) + (y)-1) / (y)) * (y)) |
93 | | - |
94 | | -// Lock annotations. |
95 | | - |
96 | | -#if __has_extension(c_thread_safety_attributes) |
97 | | -#define __lock_annotate(x) __attribute__((x)) |
98 | | -#else |
99 | | -#define __lock_annotate(x) |
100 | | -#endif |
101 | | - |
102 | | -#define __lockable __lock_annotate(lockable) |
103 | | - |
104 | | -#define __locks_exclusive(...) \ |
105 | | - __lock_annotate(exclusive_lock_function(__VA_ARGS__)) |
106 | | -#define __locks_shared(...) __lock_annotate(shared_lock_function(__VA_ARGS__)) |
107 | | - |
108 | | -#define __trylocks_exclusive(...) \ |
109 | | - __lock_annotate(exclusive_trylock_function(__VA_ARGS__)) |
110 | | -#define __trylocks_shared(...) \ |
111 | | - __lock_annotate(shared_trylock_function(__VA_ARGS__)) |
112 | | - |
113 | | -#define __unlocks(...) __lock_annotate(unlock_function(__VA_ARGS__)) |
114 | | - |
115 | | -#define __asserts_exclusive(...) \ |
116 | | - __lock_annotate(assert_exclusive_lock(__VA_ARGS__)) |
117 | | -#define __asserts_shared(...) __lock_annotate(assert_shared_lock(__VA_ARGS__)) |
118 | | - |
119 | | -#define __requires_exclusive(...) \ |
120 | | - __lock_annotate(exclusive_locks_required(__VA_ARGS__)) |
121 | | -#define __requires_shared(...) \ |
122 | | - __lock_annotate(shared_locks_required(__VA_ARGS__)) |
123 | | -#define __requires_unlocked(...) __lock_annotate(locks_excluded(__VA_ARGS__)) |
124 | | - |
125 | | -#define __no_lock_analysis __lock_annotate(no_thread_safety_analysis) |
126 | | - |
127 | | -#define __guarded_by(x) __lock_annotate(guarded_by(x)) |
128 | | -#define __pt_guarded_by(x) __lock_annotate(pt_guarded_by(x)) |
129 | | - |
130 | | -// Const preservation. |
131 | | -// |
132 | | -// Functions like strchr() allow you to silently discard a const |
133 | | -// qualifier from a string. This macro can be used to wrap such |
134 | | -// functions to propagate the const keyword where possible. |
135 | | -// |
136 | | -// This macro has many limitations, such as only being able to detect |
137 | | -// constness for void, char and wchar_t. For Clang, it also doesn't seem |
138 | | -// to work on string literals. |
139 | | - |
140 | | -#define __preserve_const(type, name, arg, ...) \ |
141 | | - _Generic(arg, \ |
142 | | - const void *: (const type *)name(__VA_ARGS__), \ |
143 | | - const char *: (const type *)name(__VA_ARGS__), \ |
144 | | - const signed char *: (const type *)name(__VA_ARGS__), \ |
145 | | - const unsigned char *: (const type *)name(__VA_ARGS__), \ |
146 | | - const __wchar_t *: (const type *)name(__VA_ARGS__), \ |
147 | | - default: name(__VA_ARGS__)) |
148 | 35 |
|
149 | 36 | #endif |
0 commit comments