Oolite 1.91.0.7645-241119-222d325
Loading...
Searching...
No Matches
OOFunctionAttributes.h
Go to the documentation of this file.
1#ifndef INCLUDED_OOFUNCTIONATTRIBUTES_h
2#define INCLUDED_OOFUNCTIONATTRIBUTES_h
3
4
5#ifndef GCC_ATTR
6 #ifdef __GNUC__
7 #define GCC_ATTR(x) __attribute__(x)
8 #else
9 #define GCC_ATTR(x)
10 #endif
11#endif
12
13
14// Clang feature testing extensions.
15#ifndef __has_feature
16 #define __has_feature(x) (0)
17#endif
18
19#ifndef __has_attribute
20 #define __has_attribute(x) (0)
21#endif
22
23#ifndef __has_extension
24 #define __has_extension(x) (0)
25#endif
26
27
28#if __cplusplus
29#define OOINLINE inline
30#else
31#define OOINLINE static inline
32#endif
33
34
35#if !OO_DEBUG
36#define ALWAYS_INLINE_FUNC GCC_ATTR((always_inline)) // Force inlining of function
37#else
38#define ALWAYS_INLINE_FUNC // Don't force inlining of function (because gdb is silly)
39#endif
40
41#define PURE_FUNC GCC_ATTR((pure)) // result dependent only on params and globals
42#define CONST_FUNC GCC_ATTR((const)) // pure + no pointer dereferences or globals
43#define NONNULL_FUNC GCC_ATTR((nonnull)) // Pointer parameters may not be NULL
44#define DEPRECATED_FUNC GCC_ATTR((deprecated)) // Warn if this function is used
45#define NO_RETURN_FUNC GCC_ATTR((noreturn)) // Function can never return
46#define NO_INLINE_FUNC GCC_ATTR((noinline)) // Function must never be inlined
47
48#define INLINE_PURE_FUNC ALWAYS_INLINE_FUNC PURE_FUNC
49#define INLINE_CONST_FUNC ALWAYS_INLINE_FUNC CONST_FUNC
50
51
52#if __has_extension(attribute_deprecated_with_message)
53#define DEPRECATED_MSG(msg) __attribute__((deprecated(msg)))
54#else
55#define DEPRECATED_MSG(msg) DEPRECATED_FUNC
56#endif
57
58
59#if __clang__
60#define DEPRECATED_METHOD(msg) DEPRECATED_MSG(msg)
61#else
62// GCC doesn't support attributes on Objective-C methods.
63#define DEPRECATED_METHOD(msg)
64#endif
65
66
67#ifdef __GNUC__
68 #define EXPECT(x) __builtin_expect((x), 1)
69 #define EXPECT_NOT(x) __builtin_expect((x), 0)
70#else
71 #define EXPECT(x) (x)
72 #define EXPECT_NOT(x) (x)
73#endif
74
75
76// OO_RETURNS_RETAINED: indicates the caller of a method owns a reference to the return value.
77#if __has_feature(attribute_ns_returns_retained)
78 #define OO_RETURNS_RETAINED __attribute__((ns_returns_retained))
79#else
80 #define OO_RETURNS_RETAINED
81#endif
82
83// OO_NS_CONSUMED: indicates that a reference to an object parameter is "consumed".
84#ifndef OO_NS_CONSUMED
85#if __has_feature(attribute_ns_consumed)
86#define OO_NS_CONSUMED __attribute__((ns_consumed))
87#else
88#define OO_NS_CONSUMED
89#endif
90#endif
91
92// OO_UNREACHABLE(): a statement that should never be executed (Clang optimization hint).
93#if __has_feature(__builtin_unreachable)
94 #define OO_UNREACHABLE() __builtin_unreachable()
95#else
96 #define OO_UNREACHABLE() do {} while (0)
97#endif
98
99
100/*
101 OO_TAKES_FORMAT_STRING(stringIndex, firstToCheck): marks a function that
102 applies [NSString stringWithFormat:]-type formatting to arguments.
103
104 According to the fine manuals, mainline GCC supports basic checking of
105 NSString format strings since 4.6, but doesn't validate the arguments.
106
107 Update: apparently GCC 4.6.3 doesn't recognize Objective-C string literals
108 as being string literals for this purpose, and errors out.
109 -- Ahruman 2012-10-06
110*/
111#if __has_attribute(format) /*|| (defined(OOLITE_GCC_VERSION) && OOLITE_GCC_VERSION >= 40600)*/
112 #define OO_TAKES_FORMAT_STRING(stringIndex, firstToCheck) __attribute__((format(NSString, stringIndex, firstToCheck)))
113#else
114 #define OO_TAKES_FORMAT_STRING(stringIndex, firstToCheck)
115#endif
116
117
118#if __OBJC__
119/* OOConsumeReference()
120 Decrements the Clang Static Analyzer's notion of an object's reference
121 count. This is used to work around cases where the analyzer claims an
122 object is being leaked but it actually isn't, due to a pattern the
123 analyzer doesn't understand (like singletons, or references being stored
124 in JavaScript objects' private field).
125 Do not use this blindly. If you aren't absolutely certain it's appropriate,
126 don't use it.
127 -- Ahruman 2011-01-28
128*/
129#if NDEBUG
132{
133 return value;
134}
135#else
136// Externed to work around analyzer being too "clever" and ignoring attributes
137// when it's inlined.
139#endif
140#endif
141
142#endif /* INCLUDED_OOFUNCTIONATTRIBUTES_h */
id OOConsumeReference(id OO_NS_CONSUMED value)
Definition OOCocoa.m:93
#define ALWAYS_INLINE_FUNC
#define OOINLINE
#define OO_NS_CONSUMED