2 * Copyright (c) 2014 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
25 Copyright (c) 1998-2013, Apple Inc. All rights reserved.
28 #if !defined(__COREFOUNDATION_CFBASE__)
29 #define __COREFOUNDATION_CFBASE__ 1
31 #include <TargetConditionals.h>
32 #include <CoreFoundation/CFAvailability.h>
34 #if (defined(__CYGWIN32__) || defined(_WIN32)) && !defined(__WIN32__)
38 #if defined(_WIN64) && !defined(__WIN64__)
42 #if defined(__WIN64__) && !defined(__LLP64__)
46 #if defined(_MSC_VER) && defined(_M_IX86)
50 #if (defined(__i386__) || defined(__x86_64__)) && !defined(__LITTLE_ENDIAN__)
51 #define __LITTLE_ENDIAN__ 1
54 #if !defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__)
55 #error Do not know the endianess of this architecture
58 #if !__BIG_ENDIAN__ && !__LITTLE_ENDIAN__
59 #error Both __BIG_ENDIAN__ and __LITTLE_ENDIAN__ cannot be false
62 #if __BIG_ENDIAN__ && __LITTLE_ENDIAN__
63 #error Both __BIG_ENDIAN__ and __LITTLE_ENDIAN__ cannot be true
66 // Some compilers provide the capability to test if certain features are available. This macro provides a compatibility path for other compilers.
68 #define __has_feature(x) 0
71 // Some compilers provide the capability to test if certain attributes are available. This macro provides a compatibility path for other compilers.
72 #ifndef __has_attribute
73 #define __has_attribute(x) 0
76 #ifndef __has_extension
77 #define __has_extension(x) 0
80 #if defined(__GNUC__) || TARGET_OS_WIN32
89 #if (TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE)) || (TARGET_OS_EMBEDDED || TARGET_OS_IPHONE)
90 #include <libkern/OSTypes.h>
93 #if !defined(__MACTYPES__)
94 #if !defined(_OS_OSTYPES_H)
95 typedef unsigned char Boolean
;
96 typedef unsigned char UInt8
;
97 typedef signed char SInt8
;
98 typedef unsigned short UInt16
;
99 typedef signed short SInt16
;
100 typedef unsigned int UInt32
;
101 typedef signed int SInt32
;
102 typedef uint64_t UInt64
;
103 typedef int64_t SInt64
;
104 typedef SInt32 OSStatus
;
106 typedef float Float32
;
107 typedef double Float64
;
108 typedef unsigned short UniChar
;
109 typedef unsigned long UniCharCount
;
110 typedef unsigned char * StringPtr
;
111 typedef const unsigned char * ConstStringPtr
;
112 typedef unsigned char Str255
[256];
113 typedef const unsigned char * ConstStr255Param
;
114 typedef SInt16 OSErr
;
115 typedef SInt16 RegionCode
;
116 typedef SInt16 LangCode
;
117 typedef SInt16 ScriptCode
;
118 typedef UInt32 FourCharCode
;
119 typedef FourCharCode OSType
;
121 typedef SInt8 SignedByte
;
123 #if !defined(__MACTYPES__) || (defined(UNIVERSAL_INTERFACES_VERSION) && UNIVERSAL_INTERFACES_VERSION < 0x0340)
124 typedef UInt32 UTF32Char
;
125 typedef UInt16 UTF16Char
;
126 typedef UInt8 UTF8Char
;
129 #if !defined(CF_EXTERN_C_BEGIN)
130 #if defined(__cplusplus)
131 #define CF_EXTERN_C_BEGIN extern "C" {
132 #define CF_EXTERN_C_END }
134 #define CF_EXTERN_C_BEGIN
135 #define CF_EXTERN_C_END
141 #if !defined(CF_EXPORT)
142 #if defined(CF_BUILDING_CF) && defined(__cplusplus)
143 #define CF_EXPORT extern "C" __declspec(dllexport)
144 #elif defined(CF_BUILDING_CF) && !defined(__cplusplus)
145 #define CF_EXPORT extern __declspec(dllexport)
146 #elif defined(__cplusplus)
147 #define CF_EXPORT extern "C" __declspec(dllimport)
149 #define CF_EXPORT extern __declspec(dllimport)
154 #define CF_EXPORT extern
160 #if defined(__GNUG__)
162 #elif defined(__cplusplus)
165 #define NULL ((void *)0)
177 #if !defined(CF_INLINE)
178 #if defined(__GNUC__) && (__GNUC__ == 4) && !defined(DEBUG)
179 #define CF_INLINE static __inline__ __attribute__((always_inline))
180 #elif defined(__GNUC__)
181 #define CF_INLINE static __inline__
182 #elif defined(__cplusplus)
183 #define CF_INLINE static inline
184 #elif defined(_MSC_VER)
185 #define CF_INLINE static __inline
186 #elif TARGET_OS_WIN32
187 #define CF_INLINE static __inline__
191 // Marks functions which return a CF type that needs to be released by the caller but whose names are not consistent with CoreFoundation naming rules. The recommended fix to this is to rename the functions, but this macro can be used to let the clang static analyzer know of any exceptions that cannot be fixed.
192 // This macro is ONLY to be used in exceptional circumstances, not to annotate functions which conform to the CoreFoundation naming rules.
193 #ifndef CF_RETURNS_RETAINED
194 #if __has_feature(attribute_cf_returns_retained)
195 #define CF_RETURNS_RETAINED __attribute__((cf_returns_retained))
197 #define CF_RETURNS_RETAINED
201 // Marks functions which return a CF type that may need to be retained by the caller but whose names are not consistent with CoreFoundation naming rules. The recommended fix to this is to rename the functions, but this macro can be used to let the clang static analyzer know of any exceptions that cannot be fixed.
202 // This macro is ONLY to be used in exceptional circumstances, not to annotate functions which conform to the CoreFoundation naming rules.
203 #ifndef CF_RETURNS_NOT_RETAINED
204 #if __has_feature(attribute_cf_returns_not_retained)
205 #define CF_RETURNS_NOT_RETAINED __attribute__((cf_returns_not_retained))
207 #define CF_RETURNS_NOT_RETAINED
211 // Marks function arguments which are released by the callee.
212 #ifndef CF_RELEASES_ARGUMENT
213 #if __has_feature(attribute_cf_consumed)
214 #define CF_RELEASES_ARGUMENT __attribute__((cf_consumed))
216 #define CF_RELEASES_ARGUMENT
222 #if __has_feature(attribute_cf_consumed)
223 #define CF_CONSUMED __attribute__((cf_consumed))
229 // Marks functions which cannot be used when compiling in automatic reference counting mode.
230 #if __has_feature(objc_arc)
231 #define CF_AUTOMATED_REFCOUNT_UNAVAILABLE __attribute__((unavailable("not available in automatic reference counting mode")))
233 #define CF_AUTOMATED_REFCOUNT_UNAVAILABLE
236 #ifndef CF_IMPLICIT_BRIDGING_ENABLED
237 #if __has_feature(arc_cf_code_audited)
238 #define CF_IMPLICIT_BRIDGING_ENABLED _Pragma("clang arc_cf_code_audited begin")
240 #define CF_IMPLICIT_BRIDGING_ENABLED
244 #ifndef CF_IMPLICIT_BRIDGING_DISABLED
245 #if __has_feature(arc_cf_code_audited)
246 #define CF_IMPLICIT_BRIDGING_DISABLED _Pragma("clang arc_cf_code_audited end")
248 #define CF_IMPLICIT_BRIDGING_DISABLED
253 CF_EXPORT
double kCFCoreFoundationVersionNumber
;
256 #define kCFCoreFoundationVersionNumber10_0 196.40
257 #define kCFCoreFoundationVersionNumber10_0_3 196.50
258 #define kCFCoreFoundationVersionNumber10_1 226.00
259 #define kCFCoreFoundationVersionNumber10_1_1 226.00
260 /* Note the next three do not follow the usual numbering policy from the base release */
261 #define kCFCoreFoundationVersionNumber10_1_2 227.20
262 #define kCFCoreFoundationVersionNumber10_1_3 227.20
263 #define kCFCoreFoundationVersionNumber10_1_4 227.30
264 #define kCFCoreFoundationVersionNumber10_2 263.00
265 #define kCFCoreFoundationVersionNumber10_2_1 263.10
266 #define kCFCoreFoundationVersionNumber10_2_2 263.10
267 #define kCFCoreFoundationVersionNumber10_2_3 263.30
268 #define kCFCoreFoundationVersionNumber10_2_4 263.30
269 #define kCFCoreFoundationVersionNumber10_2_5 263.50
270 #define kCFCoreFoundationVersionNumber10_2_6 263.50
271 #define kCFCoreFoundationVersionNumber10_2_7 263.50
272 #define kCFCoreFoundationVersionNumber10_2_8 263.50
273 #define kCFCoreFoundationVersionNumber10_3 299.00
274 #define kCFCoreFoundationVersionNumber10_3_1 299.00
275 #define kCFCoreFoundationVersionNumber10_3_2 299.00
276 #define kCFCoreFoundationVersionNumber10_3_3 299.30
277 #define kCFCoreFoundationVersionNumber10_3_4 299.31
278 #define kCFCoreFoundationVersionNumber10_3_5 299.31
279 #define kCFCoreFoundationVersionNumber10_3_6 299.32
280 #define kCFCoreFoundationVersionNumber10_3_7 299.33
281 #define kCFCoreFoundationVersionNumber10_3_8 299.33
282 #define kCFCoreFoundationVersionNumber10_3_9 299.35
283 #define kCFCoreFoundationVersionNumber10_4 368.00
284 #define kCFCoreFoundationVersionNumber10_4_1 368.10
285 #define kCFCoreFoundationVersionNumber10_4_2 368.11
286 #define kCFCoreFoundationVersionNumber10_4_3 368.18
287 #define kCFCoreFoundationVersionNumber10_4_4_Intel 368.26
288 #define kCFCoreFoundationVersionNumber10_4_4_PowerPC 368.25
289 #define kCFCoreFoundationVersionNumber10_4_5_Intel 368.26
290 #define kCFCoreFoundationVersionNumber10_4_5_PowerPC 368.25
291 #define kCFCoreFoundationVersionNumber10_4_6_Intel 368.26
292 #define kCFCoreFoundationVersionNumber10_4_6_PowerPC 368.25
293 #define kCFCoreFoundationVersionNumber10_4_7 368.27
294 #define kCFCoreFoundationVersionNumber10_4_8 368.27
295 #define kCFCoreFoundationVersionNumber10_4_9 368.28
296 #define kCFCoreFoundationVersionNumber10_4_10 368.28
297 #define kCFCoreFoundationVersionNumber10_4_11 368.31
298 #define kCFCoreFoundationVersionNumber10_5 476.00
299 #define kCFCoreFoundationVersionNumber10_5_1 476.00
300 #define kCFCoreFoundationVersionNumber10_5_2 476.10
301 #define kCFCoreFoundationVersionNumber10_5_3 476.13
302 #define kCFCoreFoundationVersionNumber10_5_4 476.14
303 #define kCFCoreFoundationVersionNumber10_5_5 476.15
304 #define kCFCoreFoundationVersionNumber10_5_6 476.17
305 #define kCFCoreFoundationVersionNumber10_5_7 476.18
306 #define kCFCoreFoundationVersionNumber10_5_8 476.19
307 #define kCFCoreFoundationVersionNumber10_6 550.00
308 #define kCFCoreFoundationVersionNumber10_6_1 550.00
309 #define kCFCoreFoundationVersionNumber10_6_2 550.13
310 #define kCFCoreFoundationVersionNumber10_6_3 550.19
311 #define kCFCoreFoundationVersionNumber10_6_4 550.29
312 #define kCFCoreFoundationVersionNumber10_6_5 550.42
313 #define kCFCoreFoundationVersionNumber10_6_6 550.42
314 #define kCFCoreFoundationVersionNumber10_6_7 550.42
315 #define kCFCoreFoundationVersionNumber10_6_8 550.43
316 #define kCFCoreFoundationVersionNumber10_7 635.00
317 #define kCFCoreFoundationVersionNumber10_7_1 635.00
318 #define kCFCoreFoundationVersionNumber10_7_2 635.15
319 #define kCFCoreFoundationVersionNumber10_7_3 635.19
320 #define kCFCoreFoundationVersionNumber10_7_4 635.21
321 #define kCFCoreFoundationVersionNumber10_7_5 635.21
322 #define kCFCoreFoundationVersionNumber10_8 744.00
323 #define kCFCoreFoundationVersionNumber10_8_1 744.00
324 #define kCFCoreFoundationVersionNumber10_8_2 744.12
325 #define kCFCoreFoundationVersionNumber10_8_3 744.18
326 #define kCFCoreFoundationVersionNumber10_8_4 744.19
330 #define kCFCoreFoundationVersionNumber_iPhoneOS_2_0 478.23
331 #define kCFCoreFoundationVersionNumber_iPhoneOS_2_1 478.26
332 #define kCFCoreFoundationVersionNumber_iPhoneOS_2_2 478.29
333 #define kCFCoreFoundationVersionNumber_iPhoneOS_3_0 478.47
334 #define kCFCoreFoundationVersionNumber_iPhoneOS_3_1 478.52
335 #define kCFCoreFoundationVersionNumber_iPhoneOS_3_2 478.61
336 #define kCFCoreFoundationVersionNumber_iOS_4_0 550.32
337 #define kCFCoreFoundationVersionNumber_iOS_4_1 550.38
338 #define kCFCoreFoundationVersionNumber_iOS_4_2 550.52
339 #define kCFCoreFoundationVersionNumber_iOS_4_3 550.52
340 #define kCFCoreFoundationVersionNumber_iOS_5_0 675.00
341 #define kCFCoreFoundationVersionNumber_iOS_5_1 690.10
342 #define kCFCoreFoundationVersionNumber_iOS_6_0 793.00
343 #define kCFCoreFoundationVersionNumber_iOS_6_1 793.00
347 typedef unsigned long long CFTypeID
;
348 typedef unsigned long long CFOptionFlags
;
349 typedef unsigned long long CFHashCode
;
350 typedef signed long long CFIndex
;
352 typedef unsigned long CFTypeID
;
353 typedef unsigned long CFOptionFlags
;
354 typedef unsigned long CFHashCode
;
355 typedef signed long CFIndex
;
358 /* Base "type" of all "CF objects", and polymorphic functions on them */
359 typedef const void * CFTypeRef
;
361 typedef const struct __CFString
* CFStringRef
;
362 typedef struct __CFString
* CFMutableStringRef
;
365 Type to mean any instance of a property list type;
366 currently, CFString, CFData, CFNumber, CFBoolean, CFDate,
367 CFArray, and CFDictionary.
369 typedef CFTypeRef CFPropertyListRef
;
371 /* Values returned from comparison functions */
372 typedef CF_ENUM(CFIndex
, CFComparisonResult
) {
373 kCFCompareLessThan
= -1L,
374 kCFCompareEqualTo
= 0,
375 kCFCompareGreaterThan
= 1
378 /* A standard comparison function */
379 typedef CFComparisonResult (*CFComparatorFunction
)(const void *val1
, const void *val2
, void *context
);
381 /* Constant used by some functions to indicate failed searches. */
382 /* This is of type CFIndex. */
394 #if defined(CF_INLINE)
395 CF_INLINE CFRange
CFRangeMake(CFIndex loc
, CFIndex len
) {
397 range
.location
= loc
;
402 #define CFRangeMake(LOC, LEN) __CFRangeMake(LOC, LEN)
405 /* Private; do not use */
407 CFRange
__CFRangeMake(CFIndex loc
, CFIndex len
);
410 /* Null representant */
412 typedef const struct __CFNull
* CFNullRef
;
415 CFTypeID
CFNullGetTypeID(void);
418 const CFNullRef kCFNull
; // the singleton null instance
423 Most of the time when specifying an allocator to Create functions, the NULL
424 argument indicates "use the default"; this is the same as using kCFAllocatorDefault
425 or the return value from CFAllocatorGetDefault(). This assures that you will use
426 the allocator in effect at that time.
428 typedef const struct __CFAllocator
* CFAllocatorRef
;
430 /* This is a synonym for NULL, if you'd rather use a named constant. */
432 const CFAllocatorRef kCFAllocatorDefault
;
434 /* Default system allocator; you rarely need to use this. */
436 const CFAllocatorRef kCFAllocatorSystemDefault
;
438 /* This allocator uses malloc(), realloc(), and free(). This should not be
439 generally used; stick to kCFAllocatorDefault whenever possible. This
440 allocator is useful as the "bytesDeallocator" in CFData or
441 "contentsDeallocator" in CFString where the memory was obtained as a
442 result of malloc() type functions.
445 const CFAllocatorRef kCFAllocatorMalloc
;
447 /* This allocator explicitly uses the default malloc zone, returned by
448 malloc_default_zone(). It should only be used when an object is
449 safe to be allocated in non-scanned memory.
452 const CFAllocatorRef kCFAllocatorMallocZone
;
454 /* Null allocator which does nothing and allocates no memory. This allocator
455 is useful as the "bytesDeallocator" in CFData or "contentsDeallocator"
456 in CFString where the memory should not be freed.
459 const CFAllocatorRef kCFAllocatorNull
;
461 /* Special allocator argument to CFAllocatorCreate() which means
462 "use the functions given in the context to allocate the allocator
466 const CFAllocatorRef kCFAllocatorUseContext
;
468 typedef const void * (*CFAllocatorRetainCallBack
)(const void *info
);
469 typedef void (*CFAllocatorReleaseCallBack
)(const void *info
);
470 typedef CFStringRef (*CFAllocatorCopyDescriptionCallBack
)(const void *info
);
471 typedef void * (*CFAllocatorAllocateCallBack
)(CFIndex allocSize
, CFOptionFlags hint
, void *info
);
472 typedef void * (*CFAllocatorReallocateCallBack
)(void *ptr
, CFIndex newsize
, CFOptionFlags hint
, void *info
);
473 typedef void (*CFAllocatorDeallocateCallBack
)(void *ptr
, void *info
);
474 typedef CFIndex (*CFAllocatorPreferredSizeCallBack
)(CFIndex size
, CFOptionFlags hint
, void *info
);
478 CFAllocatorRetainCallBack retain
;
479 CFAllocatorReleaseCallBack release
;
480 CFAllocatorCopyDescriptionCallBack copyDescription
;
481 CFAllocatorAllocateCallBack allocate
;
482 CFAllocatorReallocateCallBack reallocate
;
483 CFAllocatorDeallocateCallBack deallocate
;
484 CFAllocatorPreferredSizeCallBack preferredSize
;
485 } CFAllocatorContext
;
488 CFTypeID
CFAllocatorGetTypeID(void);
491 CFAllocatorSetDefault() sets the allocator that is used in the current
492 thread whenever NULL is specified as an allocator argument. This means
493 that most, if not all allocations will go through this allocator. It
494 also means that any allocator set as the default needs to be ready to
495 deal with arbitrary memory allocation requests; in addition, the size
496 and number of requests will change between releases.
498 An allocator set as the default will never be released, even if later
499 another allocator replaces it as the default. Not only is it impractical
500 for it to be released (as there might be caches created under the covers
501 that refer to the allocator), in general it's also safer and more
502 efficient to keep it around.
504 If you wish to use a custom allocator in a context, it's best to provide
505 it as the argument to the various creation functions rather than setting
506 it as the default. Setting the default allocator is not encouraged.
508 If you do set an allocator as the default, either do it for all time in
509 your app, or do it in a nested fashion (by restoring the previous allocator
510 when you exit your context). The latter might be appropriate for plug-ins
511 or libraries that wish to set the default allocator.
514 void CFAllocatorSetDefault(CFAllocatorRef allocator
);
517 CFAllocatorRef
CFAllocatorGetDefault(void);
520 CFAllocatorRef
CFAllocatorCreate(CFAllocatorRef allocator
, CFAllocatorContext
*context
);
523 void *CFAllocatorAllocate(CFAllocatorRef allocator
, CFIndex size
, CFOptionFlags hint
);
526 void *CFAllocatorReallocate(CFAllocatorRef allocator
, void *ptr
, CFIndex newsize
, CFOptionFlags hint
);
529 void CFAllocatorDeallocate(CFAllocatorRef allocator
, void *ptr
);
532 CFIndex
CFAllocatorGetPreferredSizeForSize(CFAllocatorRef allocator
, CFIndex size
, CFOptionFlags hint
);
535 void CFAllocatorGetContext(CFAllocatorRef allocator
, CFAllocatorContext
*context
);
538 /* Polymorphic CF functions */
540 CF_IMPLICIT_BRIDGING_ENABLED
543 CFTypeID
CFGetTypeID(CFTypeRef cf
);
546 CFStringRef
CFCopyTypeIDDescription(CFTypeID type_id
);
549 CFTypeRef
CFRetain(CFTypeRef cf
);
552 void CFRelease(CFTypeRef cf
);
555 CFTypeRef
CFAutorelease(CFTypeRef CF_RELEASES_ARGUMENT arg
) CF_AVAILABLE(10_9
, 7_0
);
558 CFIndex
CFGetRetainCount(CFTypeRef cf
);
561 Boolean
CFEqual(CFTypeRef cf1
, CFTypeRef cf2
);
564 CFHashCode
CFHash(CFTypeRef cf
);
567 CFStringRef
CFCopyDescription(CFTypeRef cf
);
570 CFAllocatorRef
CFGetAllocator(CFTypeRef cf
);
572 CF_IMPLICIT_BRIDGING_DISABLED
574 // This function is unavailable in ARC mode.
576 CFTypeRef
CFMakeCollectable(CFTypeRef cf
) CF_AUTOMATED_REFCOUNT_UNAVAILABLE
;
580 #endif /* ! __COREFOUNDATION_CFBASE__ */