2 * Copyright (c) 2015 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-2014, 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
252 #if __has_attribute(objc_bridge)
256 @
class NSAttributedString
;
259 @
class NSCharacterSet
;
272 #define CF_BRIDGED_TYPE(T) __attribute__((objc_bridge(T)))
273 #define CF_BRIDGED_MUTABLE_TYPE(T) __attribute__((objc_bridge_mutable(T)))
274 #define CF_RELATED_TYPE(T,C,I) __attribute__((objc_bridge_related(T,C,I)))
276 #define CF_BRIDGED_TYPE(T)
277 #define CF_BRIDGED_MUTABLE_TYPE(T)
278 #define CF_RELATED_TYPE(T,C,I)
282 CF_EXPORT
double kCFCoreFoundationVersionNumber
;
285 #define kCFCoreFoundationVersionNumber10_0 196.40
286 #define kCFCoreFoundationVersionNumber10_0_3 196.50
287 #define kCFCoreFoundationVersionNumber10_1 226.00
288 #define kCFCoreFoundationVersionNumber10_1_1 226.00
289 /* Note the next three do not follow the usual numbering policy from the base release */
290 #define kCFCoreFoundationVersionNumber10_1_2 227.20
291 #define kCFCoreFoundationVersionNumber10_1_3 227.20
292 #define kCFCoreFoundationVersionNumber10_1_4 227.30
293 #define kCFCoreFoundationVersionNumber10_2 263.00
294 #define kCFCoreFoundationVersionNumber10_2_1 263.10
295 #define kCFCoreFoundationVersionNumber10_2_2 263.10
296 #define kCFCoreFoundationVersionNumber10_2_3 263.30
297 #define kCFCoreFoundationVersionNumber10_2_4 263.30
298 #define kCFCoreFoundationVersionNumber10_2_5 263.50
299 #define kCFCoreFoundationVersionNumber10_2_6 263.50
300 #define kCFCoreFoundationVersionNumber10_2_7 263.50
301 #define kCFCoreFoundationVersionNumber10_2_8 263.50
302 #define kCFCoreFoundationVersionNumber10_3 299.00
303 #define kCFCoreFoundationVersionNumber10_3_1 299.00
304 #define kCFCoreFoundationVersionNumber10_3_2 299.00
305 #define kCFCoreFoundationVersionNumber10_3_3 299.30
306 #define kCFCoreFoundationVersionNumber10_3_4 299.31
307 #define kCFCoreFoundationVersionNumber10_3_5 299.31
308 #define kCFCoreFoundationVersionNumber10_3_6 299.32
309 #define kCFCoreFoundationVersionNumber10_3_7 299.33
310 #define kCFCoreFoundationVersionNumber10_3_8 299.33
311 #define kCFCoreFoundationVersionNumber10_3_9 299.35
312 #define kCFCoreFoundationVersionNumber10_4 368.00
313 #define kCFCoreFoundationVersionNumber10_4_1 368.10
314 #define kCFCoreFoundationVersionNumber10_4_2 368.11
315 #define kCFCoreFoundationVersionNumber10_4_3 368.18
316 #define kCFCoreFoundationVersionNumber10_4_4_Intel 368.26
317 #define kCFCoreFoundationVersionNumber10_4_4_PowerPC 368.25
318 #define kCFCoreFoundationVersionNumber10_4_5_Intel 368.26
319 #define kCFCoreFoundationVersionNumber10_4_5_PowerPC 368.25
320 #define kCFCoreFoundationVersionNumber10_4_6_Intel 368.26
321 #define kCFCoreFoundationVersionNumber10_4_6_PowerPC 368.25
322 #define kCFCoreFoundationVersionNumber10_4_7 368.27
323 #define kCFCoreFoundationVersionNumber10_4_8 368.27
324 #define kCFCoreFoundationVersionNumber10_4_9 368.28
325 #define kCFCoreFoundationVersionNumber10_4_10 368.28
326 #define kCFCoreFoundationVersionNumber10_4_11 368.31
327 #define kCFCoreFoundationVersionNumber10_5 476.00
328 #define kCFCoreFoundationVersionNumber10_5_1 476.00
329 #define kCFCoreFoundationVersionNumber10_5_2 476.10
330 #define kCFCoreFoundationVersionNumber10_5_3 476.13
331 #define kCFCoreFoundationVersionNumber10_5_4 476.14
332 #define kCFCoreFoundationVersionNumber10_5_5 476.15
333 #define kCFCoreFoundationVersionNumber10_5_6 476.17
334 #define kCFCoreFoundationVersionNumber10_5_7 476.18
335 #define kCFCoreFoundationVersionNumber10_5_8 476.19
336 #define kCFCoreFoundationVersionNumber10_6 550.00
337 #define kCFCoreFoundationVersionNumber10_6_1 550.00
338 #define kCFCoreFoundationVersionNumber10_6_2 550.13
339 #define kCFCoreFoundationVersionNumber10_6_3 550.19
340 #define kCFCoreFoundationVersionNumber10_6_4 550.29
341 #define kCFCoreFoundationVersionNumber10_6_5 550.42
342 #define kCFCoreFoundationVersionNumber10_6_6 550.42
343 #define kCFCoreFoundationVersionNumber10_6_7 550.42
344 #define kCFCoreFoundationVersionNumber10_6_8 550.43
345 #define kCFCoreFoundationVersionNumber10_7 635.00
346 #define kCFCoreFoundationVersionNumber10_7_1 635.00
347 #define kCFCoreFoundationVersionNumber10_7_2 635.15
348 #define kCFCoreFoundationVersionNumber10_7_3 635.19
349 #define kCFCoreFoundationVersionNumber10_7_4 635.21
350 #define kCFCoreFoundationVersionNumber10_7_5 635.21
351 #define kCFCoreFoundationVersionNumber10_8 744.00
352 #define kCFCoreFoundationVersionNumber10_8_1 744.00
353 #define kCFCoreFoundationVersionNumber10_8_2 744.12
354 #define kCFCoreFoundationVersionNumber10_8_3 744.18
355 #define kCFCoreFoundationVersionNumber10_8_4 744.19
356 #define kCFCoreFoundationVersionNumber10_9 855.11
357 #define kCFCoreFoundationVersionNumber10_9_1 855.11
358 #define kCFCoreFoundationVersionNumber10_9_2 855.14
362 #define kCFCoreFoundationVersionNumber_iPhoneOS_2_0 478.23
363 #define kCFCoreFoundationVersionNumber_iPhoneOS_2_1 478.26
364 #define kCFCoreFoundationVersionNumber_iPhoneOS_2_2 478.29
365 #define kCFCoreFoundationVersionNumber_iPhoneOS_3_0 478.47
366 #define kCFCoreFoundationVersionNumber_iPhoneOS_3_1 478.52
367 #define kCFCoreFoundationVersionNumber_iPhoneOS_3_2 478.61
368 #define kCFCoreFoundationVersionNumber_iOS_4_0 550.32
369 #define kCFCoreFoundationVersionNumber_iOS_4_1 550.38
370 #define kCFCoreFoundationVersionNumber_iOS_4_2 550.52
371 #define kCFCoreFoundationVersionNumber_iOS_4_3 550.52
372 #define kCFCoreFoundationVersionNumber_iOS_5_0 675.00
373 #define kCFCoreFoundationVersionNumber_iOS_5_1 690.10
374 #define kCFCoreFoundationVersionNumber_iOS_6_0 793.00
375 #define kCFCoreFoundationVersionNumber_iOS_6_1 793.00
376 #define kCFCoreFoundationVersionNumber_iOS_7_0 847.20
377 #define kCFCoreFoundationVersionNumber_iOS_7_1 847.24
381 typedef unsigned long long CFTypeID
;
382 typedef unsigned long long CFOptionFlags
;
383 typedef unsigned long long CFHashCode
;
384 typedef signed long long CFIndex
;
386 typedef unsigned long CFTypeID
;
387 typedef unsigned long CFOptionFlags
;
388 typedef unsigned long CFHashCode
;
389 typedef signed long CFIndex
;
392 /* Base "type" of all "CF objects", and polymorphic functions on them */
393 typedef const void * CFTypeRef
;
395 typedef const struct CF_BRIDGED_TYPE(NSString
) __CFString
* CFStringRef
;
396 typedef struct CF_BRIDGED_MUTABLE_TYPE(NSMutableString
) __CFString
* CFMutableStringRef
;
399 Type to mean any instance of a property list type;
400 currently, CFString, CFData, CFNumber, CFBoolean, CFDate,
401 CFArray, and CFDictionary.
403 typedef CFTypeRef CFPropertyListRef
;
405 /* Values returned from comparison functions */
406 typedef CF_ENUM(CFIndex
, CFComparisonResult
) {
407 kCFCompareLessThan
= -1L,
408 kCFCompareEqualTo
= 0,
409 kCFCompareGreaterThan
= 1
412 /* A standard comparison function */
413 typedef CFComparisonResult (*CFComparatorFunction
)(const void *val1
, const void *val2
, void *context
);
415 /* Constant used by some functions to indicate failed searches. */
416 /* This is of type CFIndex. */
428 #if defined(CF_INLINE)
429 CF_INLINE CFRange
CFRangeMake(CFIndex loc
, CFIndex len
) {
431 range
.location
= loc
;
436 #define CFRangeMake(LOC, LEN) __CFRangeMake(LOC, LEN)
439 /* Private; do not use */
441 CFRange
__CFRangeMake(CFIndex loc
, CFIndex len
);
444 /* Null representant */
446 typedef const struct CF_BRIDGED_TYPE(NSNull
) __CFNull
* CFNullRef
;
449 CFTypeID
CFNullGetTypeID(void);
452 const CFNullRef kCFNull
; // the singleton null instance
457 Most of the time when specifying an allocator to Create functions, the NULL
458 argument indicates "use the default"; this is the same as using kCFAllocatorDefault
459 or the return value from CFAllocatorGetDefault(). This assures that you will use
460 the allocator in effect at that time.
462 typedef const struct __CFAllocator
* CFAllocatorRef
;
464 /* This is a synonym for NULL, if you'd rather use a named constant. */
466 const CFAllocatorRef kCFAllocatorDefault
;
468 /* Default system allocator; you rarely need to use this. */
470 const CFAllocatorRef kCFAllocatorSystemDefault
;
472 /* This allocator uses malloc(), realloc(), and free(). This should not be
473 generally used; stick to kCFAllocatorDefault whenever possible. This
474 allocator is useful as the "bytesDeallocator" in CFData or
475 "contentsDeallocator" in CFString where the memory was obtained as a
476 result of malloc() type functions.
479 const CFAllocatorRef kCFAllocatorMalloc
;
481 /* This allocator explicitly uses the default malloc zone, returned by
482 malloc_default_zone(). It should only be used when an object is
483 safe to be allocated in non-scanned memory.
486 const CFAllocatorRef kCFAllocatorMallocZone
;
488 /* Null allocator which does nothing and allocates no memory. This allocator
489 is useful as the "bytesDeallocator" in CFData or "contentsDeallocator"
490 in CFString where the memory should not be freed.
493 const CFAllocatorRef kCFAllocatorNull
;
495 /* Special allocator argument to CFAllocatorCreate() which means
496 "use the functions given in the context to allocate the allocator
500 const CFAllocatorRef kCFAllocatorUseContext
;
502 typedef const void * (*CFAllocatorRetainCallBack
)(const void *info
);
503 typedef void (*CFAllocatorReleaseCallBack
)(const void *info
);
504 typedef CFStringRef (*CFAllocatorCopyDescriptionCallBack
)(const void *info
);
505 typedef void * (*CFAllocatorAllocateCallBack
)(CFIndex allocSize
, CFOptionFlags hint
, void *info
);
506 typedef void * (*CFAllocatorReallocateCallBack
)(void *ptr
, CFIndex newsize
, CFOptionFlags hint
, void *info
);
507 typedef void (*CFAllocatorDeallocateCallBack
)(void *ptr
, void *info
);
508 typedef CFIndex (*CFAllocatorPreferredSizeCallBack
)(CFIndex size
, CFOptionFlags hint
, void *info
);
512 CFAllocatorRetainCallBack retain
;
513 CFAllocatorReleaseCallBack release
;
514 CFAllocatorCopyDescriptionCallBack copyDescription
;
515 CFAllocatorAllocateCallBack allocate
;
516 CFAllocatorReallocateCallBack reallocate
;
517 CFAllocatorDeallocateCallBack deallocate
;
518 CFAllocatorPreferredSizeCallBack preferredSize
;
519 } CFAllocatorContext
;
522 CFTypeID
CFAllocatorGetTypeID(void);
525 CFAllocatorSetDefault() sets the allocator that is used in the current
526 thread whenever NULL is specified as an allocator argument. This means
527 that most, if not all allocations will go through this allocator. It
528 also means that any allocator set as the default needs to be ready to
529 deal with arbitrary memory allocation requests; in addition, the size
530 and number of requests will change between releases.
532 An allocator set as the default will never be released, even if later
533 another allocator replaces it as the default. Not only is it impractical
534 for it to be released (as there might be caches created under the covers
535 that refer to the allocator), in general it's also safer and more
536 efficient to keep it around.
538 If you wish to use a custom allocator in a context, it's best to provide
539 it as the argument to the various creation functions rather than setting
540 it as the default. Setting the default allocator is not encouraged.
542 If you do set an allocator as the default, either do it for all time in
543 your app, or do it in a nested fashion (by restoring the previous allocator
544 when you exit your context). The latter might be appropriate for plug-ins
545 or libraries that wish to set the default allocator.
548 void CFAllocatorSetDefault(CFAllocatorRef allocator
);
551 CFAllocatorRef
CFAllocatorGetDefault(void);
554 CFAllocatorRef
CFAllocatorCreate(CFAllocatorRef allocator
, CFAllocatorContext
*context
);
557 void *CFAllocatorAllocate(CFAllocatorRef allocator
, CFIndex size
, CFOptionFlags hint
);
560 void *CFAllocatorReallocate(CFAllocatorRef allocator
, void *ptr
, CFIndex newsize
, CFOptionFlags hint
);
563 void CFAllocatorDeallocate(CFAllocatorRef allocator
, void *ptr
);
566 CFIndex
CFAllocatorGetPreferredSizeForSize(CFAllocatorRef allocator
, CFIndex size
, CFOptionFlags hint
);
569 void CFAllocatorGetContext(CFAllocatorRef allocator
, CFAllocatorContext
*context
);
572 /* Polymorphic CF functions */
574 CF_IMPLICIT_BRIDGING_ENABLED
577 CFTypeID
CFGetTypeID(CFTypeRef cf
);
580 CFStringRef
CFCopyTypeIDDescription(CFTypeID type_id
);
583 CFTypeRef
CFRetain(CFTypeRef cf
);
586 void CFRelease(CFTypeRef cf
);
589 CFTypeRef
CFAutorelease(CFTypeRef CF_RELEASES_ARGUMENT arg
) CF_AVAILABLE(10_9
, 7_0
);
592 CFIndex
CFGetRetainCount(CFTypeRef cf
);
595 Boolean
CFEqual(CFTypeRef cf1
, CFTypeRef cf2
);
598 CFHashCode
CFHash(CFTypeRef cf
);
601 CFStringRef
CFCopyDescription(CFTypeRef cf
);
604 CFAllocatorRef
CFGetAllocator(CFTypeRef cf
);
606 CF_IMPLICIT_BRIDGING_DISABLED
608 // This function is unavailable in ARC mode.
610 CFTypeRef
CFMakeCollectable(CFTypeRef cf
) CF_AUTOMATED_REFCOUNT_UNAVAILABLE
;
614 #endif /* ! __COREFOUNDATION_CFBASE__ */