9 #include <CoreFoundation/CoreFoundation.h>
12 void MyDispatchAsync(dispatch_queue_t queue
, void(^block
)(void));
13 dispatch_queue_t
MyDispatchQueueCreate(const char* name
, dispatch_queue_attr_t attr
);
15 CFErrorRef
CreateGenericErrorRef(CFStringRef domain
, int errorCode
, const char* format
, ...);
16 CFErrorRef
CreateSecTransformErrorRef(int errorCode
, const char* format
, ...);
17 CFErrorRef
CreateSecTransformErrorRefWithCFType(int errorCode
, CFTypeRef errorMsg
);
19 CFTypeRef
DebugRetain(const void* owner
, CFTypeRef type
);
20 void DebugRelease(const void* owner
, CFTypeRef type
);
22 void transforms_bug(size_t line
, long val
) __attribute__((__noinline__
));
24 // Borrowed form libdispatch, fastpath's x should normally be true; slowpath's x should normally be false.
25 // The compiler will generate correct code in either case, but it is faster if you hint right. If you
26 // hint wrong it could be slower then no hints.
27 #define fastpath(x) ((typeof(x))__builtin_expect((long)(x), ~0l))
28 #define slowpath(x) ((typeof(x))__builtin_expect((long)(x), 0l))
31 * Borrowed (with minor changes) from libdispatch.
33 * For reporting bugs or impedance mismatches between SecTransform and external subsystems,
34 * and for internal consistency failures. These do NOT abort(), and are always compiled
37 * Libdispatch wraps all system-calls with assume() macros, and we ought to do the same
40 #define transforms_assume(e) ({ \
41 typeof(e) _e = fastpath(e); /* always eval 'e' */ \
43 if (__builtin_constant_p(e)) { \
44 char __compile_time_assert__[(e) ? 1 : -1]; \
45 (void)__compile_time_assert__; \
47 transforms_bug(__LINE__, (long)_e); \
52 /* A lot of API return zero upon success and not-zero on fail. Let's capture and log the non-zero value */
53 #define transforms_assume_zero(e) ({ \
54 typeof(e) _e = slowpath(e); /* always eval 'e' */ \
56 if (__builtin_constant_p(e)) { \
57 char __compile_time_assert__[(e) ? -1 : 1]; \
58 (void)__compile_time_assert__; \
60 transforms_bug(__LINE__, (long)_e); \