#include <os/base.h>
os/base.h
<sys/_types/_os_inline.h>
macroOS_NORETURN
#define OS_NORETURN __attribute__((__noreturn__))
macroOS_NOTHROW
#define OS_NOTHROW __attribute__((__nothrow__))
macroOS_NONNULL1
#define OS_NONNULL1 __attribute__((__nonnull__(1)))
macroOS_NONNULL2
#define OS_NONNULL2 __attribute__((__nonnull__(2)))
macroOS_NONNULL3
#define OS_NONNULL3 __attribute__((__nonnull__(3)))
macroOS_NONNULL4
#define OS_NONNULL4 __attribute__((__nonnull__(4)))
macroOS_NONNULL5
#define OS_NONNULL5 __attribute__((__nonnull__(5)))
macroOS_NONNULL6
#define OS_NONNULL6 __attribute__((__nonnull__(6)))
macroOS_NONNULL7
#define OS_NONNULL7 __attribute__((__nonnull__(7)))
macroOS_NONNULL8
#define OS_NONNULL8 __attribute__((__nonnull__(8)))
macroOS_NONNULL9
#define OS_NONNULL9 __attribute__((__nonnull__(9)))
macroOS_NONNULL10
#define OS_NONNULL10 __attribute__((__nonnull__(10)))
macroOS_NONNULL11
#define OS_NONNULL11 __attribute__((__nonnull__(11)))
macroOS_NONNULL12
#define OS_NONNULL12 __attribute__((__nonnull__(12)))
macroOS_NONNULL13
#define OS_NONNULL13 __attribute__((__nonnull__(13)))
macroOS_NONNULL14
#define OS_NONNULL14 __attribute__((__nonnull__(14)))
macroOS_NONNULL15
#define OS_NONNULL15 __attribute__((__nonnull__(15)))
macroOS_NONNULL_ALL
#define OS_NONNULL_ALL __attribute__((__nonnull__))
macroOS_SENTINEL
#define OS_SENTINEL __attribute__((__sentinel__))
macroOS_PURE
#define OS_PURE __attribute__((__pure__))
macroOS_CONST
#define OS_CONST __attribute__((__const__))
macroOS_WARN_RESULT
#define OS_WARN_RESULT __attribute__((__warn_unused_result__))
macroOS_MALLOC
#define OS_MALLOC __attribute__((__malloc__))
macroOS_USED
#define OS_USED __attribute__((__used__))
macroOS_UNUSED
#define OS_UNUSED __attribute__((__unused__))
macroOS_COLD
#define OS_COLD __attribute__((__cold__))
macroOS_WEAK
#define OS_WEAK __attribute__((__weak__))
macroOS_WEAK_IMPORT
#define OS_WEAK_IMPORT __attribute__((__weak_import__))
macroOS_NOINLINE
#define OS_NOINLINE __attribute__((__noinline__))
macroOS_ALWAYS_INLINE
#define OS_ALWAYS_INLINE __attribute__((__always_inline__))
macroOS_TRANSPARENT_UNION
#define OS_TRANSPARENT_UNION __attribute__((__transparent_union__))
macroOS_ALIGNED
#define OS_ALIGNED(n) __attribute__((__aligned__((n))))
macroOS_FORMAT_PRINTF
#define OS_FORMAT_PRINTF(x, y) __attribute__((__format__(printf,x,y)))
macroOS_EXPORT
#define OS_EXPORT extern __attribute__((__visibility__("default")))macroOS_INLINE
#define OS_INLINE static __inline__
macroOS_EXPECT
#define OS_EXPECT(x, v) __builtin_expect((x), (v))
macroOS_NOESCAPE
#define OS_NOESCAPE __attribute__((__noescape__))
macroOS_FALLTHROUGH
#define OS_FALLTHROUGH __attribute__((__fallthrough__))
macroOS_ASSUME_NONNULL_BEGIN
#define OS_ASSUME_NONNULL_BEGIN _Pragma("clang assume_nonnull begin")macroOS_ASSUME_NONNULL_END
#define OS_ASSUME_NONNULL_END _Pragma("clang assume_nonnull end")macroOS_COMPILER_CAN_ASSUME
#define OS_COMPILER_CAN_ASSUME(expr) __builtin_assume(expr)
macroOS_OVERLOADABLE
#define OS_OVERLOADABLE __attribute__((__overloadable__))
macroOS_ANALYZER_SUPPRESS
#define OS_ANALYZER_SUPPRESS(RADAR)
macroOS_ENUM
#define OS_ENUM(_name, _type, ...) typedef enum : _type { __VA_ARGS__ } _name##_tmacroOS_CLOSED_ENUM
#define OS_CLOSED_ENUM(_name, _type, ...) typedef enum : _type { __VA_ARGS__ } __OS_ENUM_ATTR_CLOSED _name##_tmacroOS_OPTIONS
#define OS_OPTIONS(_name, _type, ...) typedef enum : _type { __VA_ARGS__ } __OS_ENUM_ATTR __OS_OPTIONS_ATTR _name##_tmacroOS_CLOSED_OPTIONS
#define OS_CLOSED_OPTIONS(_name, _type, ...) typedef enum : _type { __VA_ARGS__ } __OS_ENUM_ATTR_CLOSED __OS_OPTIONS_ATTR _name##_tmacroOS_SWIFT_UNAVAILABLE
equivalent to __SWIFT_UNAVAILABLE from Availability.h
#define OS_SWIFT_UNAVAILABLE(_msg) __attribute__((__availability__(swift, unavailable, message=_msg)))
macroOS_SWIFT_UNAVAILABLE_FROM_ASYNC
#define OS_SWIFT_UNAVAILABLE_FROM_ASYNC(msg) __attribute__((__swift_attr__("@_unavailableFromAsync(message: \"" msg "\")")))macroOS_SWIFT_NONISOLATED
#define OS_SWIFT_NONISOLATED __attribute__((__swift_attr__("nonisolated")))macroOS_SWIFT_NONISOLATED_UNSAFE
#define OS_SWIFT_NONISOLATED_UNSAFE __attribute__((__swift_attr__("nonisolated(unsafe)")))macroOS_REFINED_FOR_SWIFT
#define OS_REFINED_FOR_SWIFT __attribute__((__swift_private__))
macroOS_SWIFT_NAME
#define OS_SWIFT_NAME(_name) __attribute__((__swift_name__(#_name)))
macroOS_STRINGIFY
#define OS_STRINGIFY(s) __OS_STRINGIFY(s)
macroOS_CONCAT
#define OS_CONCAT(x, y) __OS_CONCAT(x, y)
macroos_prevent_tail_call_optimization
#define os_prevent_tail_call_optimization() __asm__("")macroos_is_compile_time_constant
#define os_is_compile_time_constant(expr) __builtin_constant_p(expr)
macroos_compiler_barrier
#define os_compiler_barrier() __asm__ __volatile__("" ::: "memory")macroOS_NOT_TAIL_CALLED
#define OS_NOT_TAIL_CALLED __attribute__((__not_tail_called__))
typedefos_function_t
typedef void (*os_function_t)(void *_Nullable)
typedefos_block_t
@typedef os_block_t
@abstract Generic type for a block taking no arguments and returning no value.
@discussion When not building with Objective-C ARC, a block object allocated on or
copied to the heap must be released with a -[release] message or the
Block_release() function.
The declaration of a block literal allocates storage on the stack.
Therefore, this is an invalid construct:
<code>
os_block_t block;
if (x) {
block = ^{ printf("true\n"); };
} else {
block = ^{ printf("false\n"); };
}
block(); // unsafe!!!
</code>
What is happening behind the scenes:
<code>
if (x) {
struct Block __tmp_1 = ...; // setup details
block = &__tmp_1;
} else {
struct Block __tmp_2 = ...; // setup details
block = &__tmp_2;
}
</code>
As the example demonstrates, the address of a stack variable is escaping the
scope in which it is allocated. That is a classic C bug.
Instead, the block literal must be copied to the heap with the Block_copy()
function or by sending it a -[copy] message.
typedef void (^os_block_t)(void)
macroOS_ASSUME_PTR_ABI_SINGLE_BEGIN
#define OS_ASSUME_PTR_ABI_SINGLE_BEGIN __ASSUME_PTR_ABI_SINGLE_BEGIN
macroOS_ASSUME_PTR_ABI_SINGLE_END
#define OS_ASSUME_PTR_ABI_SINGLE_END __ASSUME_PTR_ABI_SINGLE_END
macroOS_UNSAFE_INDEXABLE
#define OS_UNSAFE_INDEXABLE __unsafe_indexable
macroOS_HEADER_INDEXABLE
#define OS_HEADER_INDEXABLE __header_indexable
macroOS_COUNTED_BY
#define OS_COUNTED_BY(N) __counted_by(N)
macroOS_SIZED_BY
#define OS_SIZED_BY(N) __sized_by(N)