2 * Copyright (c) 2012 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-2011, Apple Inc. All rights reserved.
28 #if !defined(__COREFOUNDATION_CFBASE__)
29 #define __COREFOUNDATION_CFBASE__ 1
31 #include <TargetConditionals.h>
33 #if (defined(__CYGWIN32__) || defined(_WIN32)) && !defined(__WIN32__)
37 #if defined(_MSC_VER) && defined(_M_IX86)
41 #if (defined(__i386__) || defined(__x86_64__)) && !defined(__LITTLE_ENDIAN__)
42 #define __LITTLE_ENDIAN__ 1
45 #if !defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__)
46 #error Do not know the endianess of this architecture
49 #if !__BIG_ENDIAN__ && !__LITTLE_ENDIAN__
50 #error Both __BIG_ENDIAN__ and __LITTLE_ENDIAN__ cannot be false
53 #if __BIG_ENDIAN__ && __LITTLE_ENDIAN__
54 #error Both __BIG_ENDIAN__ and __LITTLE_ENDIAN__ cannot be true
57 // Some compilers provide the capability to test if certain features are available. This macro provides a compatibility path for other compilers.
59 #define __has_feature(x) 0
62 #if defined(__GNUC__) || TARGET_OS_WIN32
71 // The arguments to these availability macros is a version number, e.g. 10_6, 3_0
72 #if TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE)
73 #include <AvailabilityMacros.h>
74 #include <Availability.h>
76 // Available on MacOS and iOS
77 #define CF_AVAILABLE(_mac, _ios) AVAILABLE_MAC_OS_X_VERSION_##_mac##_AND_LATER
79 // Available on MacOS only
80 #define CF_AVAILABLE_MAC(_mac) AVAILABLE_MAC_OS_X_VERSION_##_mac##_AND_LATER
82 // Available on iOS only
83 #define CF_AVAILABLE_IOS(_ios) __OSX_AVAILABLE_STARTING(__MAC_NA, __IPHONE_##_ios)
85 // Deprecated on either MacOS or iOS, or deprecated on both (check version numbers for details)
86 #define CF_DEPRECATED(_macIntro, _macDep, _iosIntro, _iosDep) AVAILABLE_MAC_OS_X_VERSION_##_macIntro##_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_##_macDep
88 // Deprecated on MacOS, unavailable on iOS
89 #define CF_DEPRECATED_MAC(_macIntro, _macDep) AVAILABLE_MAC_OS_X_VERSION_##_macIntro##_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_##_macDep
91 // Unavailable on MacOS, deprecated on iOS
92 #define CF_DEPRECATED_IOS(_iosIntro, _iosDep) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_NA, __MAC_NA, __IPHONE_##_iosIntro, __IPHONE_##_iosDep)
94 #elif (TARGET_OS_EMBEDDED || TARGET_OS_IPHONE)
95 #include <AvailabilityMacros.h>
96 #include <Availability.h>
98 #define CF_AVAILABLE(_mac, _ios) __OSX_AVAILABLE_STARTING(__MAC_##_mac, __IPHONE_##_ios)
99 #define CF_AVAILABLE_MAC(_mac) __OSX_AVAILABLE_STARTING(__MAC_##_mac, __IPHONE_NA)
100 #define CF_AVAILABLE_IOS(_ios) __OSX_AVAILABLE_STARTING(__MAC_NA, __IPHONE_##_ios)
101 #define CF_DEPRECATED(_macIntro, _macDep, _iosIntro, _iosDep) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_##_macIntro, __MAC_##_macDep, __IPHONE_##_iosIntro, __IPHONE_##_iosDep)
102 #define CF_DEPRECATED_MAC(_macIntro, _macDep) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_##_macIntro, __MAC_##_macDep, __IPHONE_NA, __IPHONE_NA)
103 #define CF_DEPRECATED_IOS(_iosIntro, _iosDep) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_NA, __MAC_NA, __IPHONE_##_iosIntro, __IPHONE_##_iosDep)
108 #include <AvailabilityMacros.h>
109 #include <Availability.h>
112 #define CF_AVAILABLE(_mac, _ios)
113 #define CF_AVAILABLE_MAC(_mac)
114 #define CF_AVAILABLE_IOS(_ios)
115 #define CF_DEPRECATED(_macIntro, _macDep, _iosIntro, _iosDep)
116 #define CF_DEPRECATED_MAC(_macIntro, _macDep)
117 #define CF_DEPRECATED_IOS(_iosIntro, _iosDep)
122 // Older versions of these macro; use IOS versions instead
123 #define CF_AVAILABLE_IPHONE(_ios) CF_AVAILABLE_IOS(_ios)
124 #define CF_DEPRECATED_IPHONE(_iosIntro, _iosDep) CF_DEPRECATED_IOS(_iosIntro, _iosDep)
126 #if (TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE)) || (TARGET_OS_EMBEDDED || TARGET_OS_IPHONE)
127 #include <libkern/OSTypes.h>
130 #if !defined(__MACTYPES__)
131 #if !defined(_OS_OSTYPES_H)
132 typedef unsigned char Boolean
;
133 typedef unsigned char UInt8
;
134 typedef signed char SInt8
;
135 typedef unsigned short UInt16
;
136 typedef signed short SInt16
;
137 typedef unsigned int UInt32
;
138 typedef signed int SInt32
;
139 typedef uint64_t UInt64
;
140 typedef int64_t SInt64
;
141 typedef SInt32 OSStatus
;
143 typedef float Float32
;
144 typedef double Float64
;
145 typedef unsigned short UniChar
;
146 typedef unsigned long UniCharCount
;
147 typedef unsigned char * StringPtr
;
148 typedef const unsigned char * ConstStringPtr
;
149 typedef unsigned char Str255
[256];
150 typedef const unsigned char * ConstStr255Param
;
151 typedef SInt16 OSErr
;
152 typedef SInt16 RegionCode
;
153 typedef SInt16 LangCode
;
154 typedef SInt16 ScriptCode
;
155 typedef UInt32 FourCharCode
;
156 typedef FourCharCode OSType
;
158 typedef SInt8 SignedByte
;
160 #if !defined(__MACTYPES__) || (defined(UNIVERSAL_INTERFACES_VERSION) && UNIVERSAL_INTERFACES_VERSION < 0x0340)
161 typedef UInt32 UTF32Char
;
162 typedef UInt16 UTF16Char
;
163 typedef UInt8 UTF8Char
;
166 #if !defined(CF_EXTERN_C_BEGIN)
167 #if defined(__cplusplus)
168 #define CF_EXTERN_C_BEGIN extern "C" {
169 #define CF_EXTERN_C_END }
171 #define CF_EXTERN_C_BEGIN
172 #define CF_EXTERN_C_END
178 #if !defined(CF_EXPORT)
179 #if defined(CF_BUILDING_CF) && defined(__cplusplus)
180 #define CF_EXPORT extern "C" __declspec(dllexport)
181 #elif defined(CF_BUILDING_CF) && !defined(__cplusplus)
182 #define CF_EXPORT extern __declspec(dllexport)
183 #elif defined(__cplusplus)
184 #define CF_EXPORT extern "C" __declspec(dllimport)
186 #define CF_EXPORT extern __declspec(dllimport)
191 #define CF_EXPORT extern
197 #if defined(__GNUG__)
199 #elif defined(__cplusplus)
202 #define NULL ((void *)0)
214 #if !defined(CF_INLINE)
215 #if defined(__GNUC__) && (__GNUC__ == 4) && !defined(DEBUG)
216 #define CF_INLINE static __inline__ __attribute__((always_inline))
217 #elif defined(__GNUC__)
218 #define CF_INLINE static __inline__
219 #elif defined(__MWERKS__) || defined(__cplusplus)
220 #define CF_INLINE static inline
221 #elif defined(_MSC_VER)
222 #define CF_INLINE static __inline
223 #elif TARGET_OS_WIN32
224 #define CF_INLINE static __inline__
228 // 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.
229 // This macro is ONLY to be used in exceptional circumstances, not to annotate functions which conform to the CoreFoundation naming rules.
230 #if __has_feature(attribute_cf_returns_retained)
231 #define CF_RETURNS_RETAINED __attribute__((cf_returns_retained))
233 #define CF_RETURNS_RETAINED
236 // 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.
237 // This macro is ONLY to be used in exceptional circumstances, not to annotate functions which conform to the CoreFoundation naming rules.
238 #if __has_feature(attribute_cf_returns_not_retained)
239 #define CF_RETURNS_NOT_RETAINED __attribute__((cf_returns_not_retained))
241 #define CF_RETURNS_NOT_RETAINED
244 // Marks functions which cannot be used when compiling in automatic reference counting mode.
245 #if __has_feature(objc_arc)
246 #define CF_AUTOMATED_REFCOUNT_UNAVAILABLE __attribute__((unavailable("not available in automatic reference counting mode")))
248 #define CF_AUTOMATED_REFCOUNT_UNAVAILABLE
251 CF_EXPORT
double kCFCoreFoundationVersionNumber
;
254 #define kCFCoreFoundationVersionNumber10_0 196.40
255 #define kCFCoreFoundationVersionNumber10_0_3 196.50
256 #define kCFCoreFoundationVersionNumber10_1 226.00
257 #define kCFCoreFoundationVersionNumber10_1_1 226.00
258 /* Note the next three do not follow the usual numbering policy from the base release */
259 #define kCFCoreFoundationVersionNumber10_1_2 227.20
260 #define kCFCoreFoundationVersionNumber10_1_3 227.20
261 #define kCFCoreFoundationVersionNumber10_1_4 227.30
262 #define kCFCoreFoundationVersionNumber10_2 263.00
263 #define kCFCoreFoundationVersionNumber10_2_1 263.10
264 #define kCFCoreFoundationVersionNumber10_2_2 263.10
265 #define kCFCoreFoundationVersionNumber10_2_3 263.30
266 #define kCFCoreFoundationVersionNumber10_2_4 263.30
267 #define kCFCoreFoundationVersionNumber10_2_5 263.50
268 #define kCFCoreFoundationVersionNumber10_2_6 263.50
269 #define kCFCoreFoundationVersionNumber10_2_7 263.50
270 #define kCFCoreFoundationVersionNumber10_2_8 263.50
271 #define kCFCoreFoundationVersionNumber10_3 299.00
272 #define kCFCoreFoundationVersionNumber10_3_1 299.00
273 #define kCFCoreFoundationVersionNumber10_3_2 299.00
274 #define kCFCoreFoundationVersionNumber10_3_3 299.30
275 #define kCFCoreFoundationVersionNumber10_3_4 299.31
276 #define kCFCoreFoundationVersionNumber10_3_5 299.31
277 #define kCFCoreFoundationVersionNumber10_3_6 299.32
278 #define kCFCoreFoundationVersionNumber10_3_7 299.33
279 #define kCFCoreFoundationVersionNumber10_3_8 299.33
280 #define kCFCoreFoundationVersionNumber10_3_9 299.35
281 #define kCFCoreFoundationVersionNumber10_4 368.00
282 #define kCFCoreFoundationVersionNumber10_4_1 368.10
283 #define kCFCoreFoundationVersionNumber10_4_2 368.11
284 #define kCFCoreFoundationVersionNumber10_4_3 368.18
285 #define kCFCoreFoundationVersionNumber10_4_4_Intel 368.26
286 #define kCFCoreFoundationVersionNumber10_4_4_PowerPC 368.25
287 #define kCFCoreFoundationVersionNumber10_4_5_Intel 368.26
288 #define kCFCoreFoundationVersionNumber10_4_5_PowerPC 368.25
289 #define kCFCoreFoundationVersionNumber10_4_6_Intel 368.26
290 #define kCFCoreFoundationVersionNumber10_4_6_PowerPC 368.25
291 #define kCFCoreFoundationVersionNumber10_4_7 368.27
292 #define kCFCoreFoundationVersionNumber10_4_8 368.27
293 #define kCFCoreFoundationVersionNumber10_4_9 368.28
294 #define kCFCoreFoundationVersionNumber10_4_10 368.28
295 #define kCFCoreFoundationVersionNumber10_4_11 368.31
296 #define kCFCoreFoundationVersionNumber10_5 476.00
297 #define kCFCoreFoundationVersionNumber10_5_1 476.00
298 #define kCFCoreFoundationVersionNumber10_5_2 476.10
299 #define kCFCoreFoundationVersionNumber10_5_3 476.13
300 #define kCFCoreFoundationVersionNumber10_5_4 476.14
301 #define kCFCoreFoundationVersionNumber10_5_5 476.15
302 #define kCFCoreFoundationVersionNumber10_5_6 476.17
303 #define kCFCoreFoundationVersionNumber10_5_7 476.18
304 #define kCFCoreFoundationVersionNumber10_5_8 476.19
305 #define kCFCoreFoundationVersionNumber10_6 550.00
306 #define kCFCoreFoundationVersionNumber10_6_1 550.00
307 #define kCFCoreFoundationVersionNumber10_6_2 550.13
308 #define kCFCoreFoundationVersionNumber10_6_3 550.19
309 #define kCFCoreFoundationVersionNumber10_6_4 550.29
310 #define kCFCoreFoundationVersionNumber10_6_5 550.42
314 #define kCFCoreFoundationVersionNumber_iPhoneOS_2_0 478.23
315 #define kCFCoreFoundationVersionNumber_iPhoneOS_2_1 478.26
316 #define kCFCoreFoundationVersionNumber_iPhoneOS_2_2 478.29
317 #define kCFCoreFoundationVersionNumber_iPhoneOS_3_0 478.47
318 #define kCFCoreFoundationVersionNumber_iPhoneOS_3_1 478.52
319 #define kCFCoreFoundationVersionNumber_iPhoneOS_3_2 478.61
320 #define kCFCoreFoundationVersionNumber_iOS_4_0 550.32
321 #define kCFCoreFoundationVersionNumber_iOS_4_1 550.38
322 #define kCFCoreFoundationVersionNumber_iOS_4_2 550.52
325 typedef unsigned long CFTypeID
;
326 typedef unsigned long CFOptionFlags
;
327 typedef unsigned long CFHashCode
;
328 typedef signed long CFIndex
;
330 /* Base "type" of all "CF objects", and polymorphic functions on them */
331 typedef const void * CFTypeRef
;
333 typedef const struct __CFString
* CFStringRef
;
334 typedef struct __CFString
* CFMutableStringRef
;
337 Type to mean any instance of a property list type;
338 currently, CFString, CFData, CFNumber, CFBoolean, CFDate,
339 CFArray, and CFDictionary.
341 typedef CFTypeRef CFPropertyListRef
;
343 /* Values returned from comparison functions */
345 kCFCompareLessThan
= -1,
346 kCFCompareEqualTo
= 0,
347 kCFCompareGreaterThan
= 1
349 typedef CFIndex CFComparisonResult
;
351 /* A standard comparison function */
352 typedef CFComparisonResult (*CFComparatorFunction
)(const void *val1
, const void *val2
, void *context
);
354 /* Constant used by some functions to indicate failed searches. */
355 /* This is of type CFIndex. */
367 #if defined(CF_INLINE)
368 CF_INLINE CFRange
CFRangeMake(CFIndex loc
, CFIndex len
) {
370 range
.location
= loc
;
375 #define CFRangeMake(LOC, LEN) __CFRangeMake(LOC, LEN)
378 /* Private; do not use */
380 CFRange
__CFRangeMake(CFIndex loc
, CFIndex len
);
383 /* Null representant */
385 typedef const struct __CFNull
* CFNullRef
;
388 CFTypeID
CFNullGetTypeID(void);
391 const CFNullRef kCFNull
; // the singleton null instance
396 Most of the time when specifying an allocator to Create functions, the NULL
397 argument indicates "use the default"; this is the same as using kCFAllocatorDefault
398 or the return value from CFAllocatorGetDefault(). This assures that you will use
399 the allocator in effect at that time.
401 You should rarely use kCFAllocatorSystemDefault, the default default allocator.
403 typedef const struct __CFAllocator
* CFAllocatorRef
;
405 /* This is a synonym for NULL, if you'd rather use a named constant. */
407 const CFAllocatorRef kCFAllocatorDefault
;
409 /* Default system allocator; you rarely need to use this. */
411 const CFAllocatorRef kCFAllocatorSystemDefault
;
413 /* This allocator uses malloc(), realloc(), and free(). This should not be
414 generally used; stick to kCFAllocatorDefault whenever possible. This
415 allocator is useful as the "bytesDeallocator" in CFData or
416 "contentsDeallocator" in CFString where the memory was obtained as a
417 result of malloc() type functions.
420 const CFAllocatorRef kCFAllocatorMalloc
;
422 /* This allocator explicitly uses the default malloc zone, returned by
423 malloc_default_zone(). It should only be used when an object is
424 safe to be allocated in non-scanned memory.
427 const CFAllocatorRef kCFAllocatorMallocZone
;
429 /* Null allocator which does nothing and allocates no memory. This allocator
430 is useful as the "bytesDeallocator" in CFData or "contentsDeallocator"
431 in CFString where the memory should not be freed.
434 const CFAllocatorRef kCFAllocatorNull
;
436 /* Special allocator argument to CFAllocatorCreate() which means
437 "use the functions given in the context to allocate the allocator
441 const CFAllocatorRef kCFAllocatorUseContext
;
443 typedef const void * (*CFAllocatorRetainCallBack
)(const void *info
);
444 typedef void (*CFAllocatorReleaseCallBack
)(const void *info
);
445 typedef CFStringRef (*CFAllocatorCopyDescriptionCallBack
)(const void *info
);
446 typedef void * (*CFAllocatorAllocateCallBack
)(CFIndex allocSize
, CFOptionFlags hint
, void *info
);
447 typedef void * (*CFAllocatorReallocateCallBack
)(void *ptr
, CFIndex newsize
, CFOptionFlags hint
, void *info
);
448 typedef void (*CFAllocatorDeallocateCallBack
)(void *ptr
, void *info
);
449 typedef CFIndex (*CFAllocatorPreferredSizeCallBack
)(CFIndex size
, CFOptionFlags hint
, void *info
);
453 CFAllocatorRetainCallBack retain
;
454 CFAllocatorReleaseCallBack release
;
455 CFAllocatorCopyDescriptionCallBack copyDescription
;
456 CFAllocatorAllocateCallBack allocate
;
457 CFAllocatorReallocateCallBack reallocate
;
458 CFAllocatorDeallocateCallBack deallocate
;
459 CFAllocatorPreferredSizeCallBack preferredSize
;
460 } CFAllocatorContext
;
463 CFTypeID
CFAllocatorGetTypeID(void);
466 CFAllocatorSetDefault() sets the allocator that is used in the current
467 thread whenever NULL is specified as an allocator argument. This means
468 that most, if not all allocations will go through this allocator. It
469 also means that any allocator set as the default needs to be ready to
470 deal with arbitrary memory allocation requests; in addition, the size
471 and number of requests will change between releases.
473 An allocator set as the default will never be released, even if later
474 another allocator replaces it as the default. Not only is it impractical
475 for it to be released (as there might be caches created under the covers
476 that refer to the allocator), in general it's also safer and more
477 efficient to keep it around.
479 If you wish to use a custom allocator in a context, it's best to provide
480 it as the argument to the various creation functions rather than setting
481 it as the default. Setting the default allocator is not encouraged.
483 If you do set an allocator as the default, either do it for all time in
484 your app, or do it in a nested fashion (by restoring the previous allocator
485 when you exit your context). The latter might be appropriate for plug-ins
486 or libraries that wish to set the default allocator.
489 void CFAllocatorSetDefault(CFAllocatorRef allocator
);
492 CFAllocatorRef
CFAllocatorGetDefault(void);
495 CFAllocatorRef
CFAllocatorCreate(CFAllocatorRef allocator
, CFAllocatorContext
*context
);
498 void *CFAllocatorAllocate(CFAllocatorRef allocator
, CFIndex size
, CFOptionFlags hint
);
501 void *CFAllocatorReallocate(CFAllocatorRef allocator
, void *ptr
, CFIndex newsize
, CFOptionFlags hint
);
504 void CFAllocatorDeallocate(CFAllocatorRef allocator
, void *ptr
);
507 CFIndex
CFAllocatorGetPreferredSizeForSize(CFAllocatorRef allocator
, CFIndex size
, CFOptionFlags hint
);
510 void CFAllocatorGetContext(CFAllocatorRef allocator
, CFAllocatorContext
*context
);
513 /* Polymorphic CF functions */
516 CFTypeID
CFGetTypeID(CFTypeRef cf
);
519 CFStringRef
CFCopyTypeIDDescription(CFTypeID type_id
);
522 CFTypeRef
CFRetain(CFTypeRef cf
);
525 void CFRelease(CFTypeRef cf
);
528 CFIndex
CFGetRetainCount(CFTypeRef cf
);
530 // This function is unavailable in ARC mode. Use CFBridgingRelease instead.
532 CFTypeRef
CFMakeCollectable(CFTypeRef cf
) CF_AUTOMATED_REFCOUNT_UNAVAILABLE
;
535 Boolean
CFEqual(CFTypeRef cf1
, CFTypeRef cf2
);
538 CFHashCode
CFHash(CFTypeRef cf
);
541 CFStringRef
CFCopyDescription(CFTypeRef cf
);
544 CFAllocatorRef
CFGetAllocator(CFTypeRef cf
);
548 #endif /* ! __COREFOUNDATION_CFBASE__ */