]> git.saurik.com Git - apple/cf.git/blame - CFBase.h
CF-1151.16.tar.gz
[apple/cf.git] / CFBase.h
CommitLineData
9ce05555 1/*
d8b101a4 2 * Copyright (c) 2014 Apple Inc. All rights reserved.
9ce05555
A
3 *
4 * @APPLE_LICENSE_HEADER_START@
d7384798 5 *
9ce05555
A
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
11 * file.
d7384798 12 *
9ce05555
A
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.
d7384798 20 *
9ce05555
A
21 * @APPLE_LICENSE_HEADER_END@
22 */
f64f9b69 23
9ce05555 24/* CFBase.h
d7384798 25 Copyright (c) 1998-2014, Apple Inc. All rights reserved.
9ce05555
A
26*/
27
28#if !defined(__COREFOUNDATION_CFBASE__)
29#define __COREFOUNDATION_CFBASE__ 1
30
cf7d2af9 31#include <TargetConditionals.h>
a48904a4 32#include <CoreFoundation/CFAvailability.h>
cf7d2af9
A
33
34#if (defined(__CYGWIN32__) || defined(_WIN32)) && !defined(__WIN32__)
d8925383
A
35#define __WIN32__ 1
36#endif
37
856091c5
A
38#if defined(_WIN64) && !defined(__WIN64__)
39#define __WIN64__ 1
40#endif
41
42#if defined(__WIN64__) && !defined(__LLP64__)
43#define __LLP64__ 1
44#endif
45
d8925383
A
46#if defined(_MSC_VER) && defined(_M_IX86)
47#define __i386__ 1
48#endif
49
bd5b749c 50#if (defined(__i386__) || defined(__x86_64__)) && !defined(__LITTLE_ENDIAN__)
cf7d2af9 51#define __LITTLE_ENDIAN__ 1
bd5b749c
A
52#endif
53
54#if !defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__)
55#error Do not know the endianess of this architecture
56#endif
57
58#if !__BIG_ENDIAN__ && !__LITTLE_ENDIAN__
59#error Both __BIG_ENDIAN__ and __LITTLE_ENDIAN__ cannot be false
60#endif
61
62#if __BIG_ENDIAN__ && __LITTLE_ENDIAN__
63#error Both __BIG_ENDIAN__ and __LITTLE_ENDIAN__ cannot be true
9ce05555
A
64#endif
65
8ca704e1
A
66// Some compilers provide the capability to test if certain features are available. This macro provides a compatibility path for other compilers.
67#ifndef __has_feature
68#define __has_feature(x) 0
69#endif
70
856091c5
A
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
74#endif
75
76#ifndef __has_extension
77#define __has_extension(x) 0
78#endif
79
8ca704e1 80#if defined(__GNUC__) || TARGET_OS_WIN32
9ce05555
A
81#include <stdint.h>
82#include <stdbool.h>
d8925383 83#endif
8ca704e1
A
84
85#if __BLOCKS__
86#include <Block.h>
87#endif
88
8ca704e1
A
89 #if (TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE)) || (TARGET_OS_EMBEDDED || TARGET_OS_IPHONE)
90 #include <libkern/OSTypes.h>
91 #endif
92
d8925383 93#if !defined(__MACTYPES__)
bd5b749c 94#if !defined(_OS_OSTYPES_H)
9ce05555
A
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;
bd5b749c
A
100 typedef unsigned int UInt32;
101 typedef signed int SInt32;
9ce05555
A
102 typedef uint64_t UInt64;
103 typedef int64_t SInt64;
bd5b749c
A
104 typedef SInt32 OSStatus;
105#endif
9ce05555
A
106 typedef float Float32;
107 typedef double Float64;
108 typedef unsigned short UniChar;
cf7d2af9 109 typedef unsigned long UniCharCount;
9ce05555
A
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;
bd5b749c
A
115 typedef SInt16 RegionCode;
116 typedef SInt16 LangCode;
cf7d2af9
A
117 typedef SInt16 ScriptCode;
118 typedef UInt32 FourCharCode;
119 typedef FourCharCode OSType;
120 typedef UInt8 Byte;
121 typedef SInt8 SignedByte;
d8925383
A
122#endif
123#if !defined(__MACTYPES__) || (defined(UNIVERSAL_INTERFACES_VERSION) && UNIVERSAL_INTERFACES_VERSION < 0x0340)
9ce05555
A
124 typedef UInt32 UTF32Char;
125 typedef UInt16 UTF16Char;
126 typedef UInt8 UTF8Char;
127#endif
128
bd5b749c 129#if !defined(CF_EXTERN_C_BEGIN)
9ce05555 130#if defined(__cplusplus)
bd5b749c
A
131#define CF_EXTERN_C_BEGIN extern "C" {
132#define CF_EXTERN_C_END }
133#else
134#define CF_EXTERN_C_BEGIN
135#define CF_EXTERN_C_END
136#endif
9ce05555
A
137#endif
138
8ca704e1
A
139#if TARGET_OS_WIN32
140
141#if !defined(CF_EXPORT)
142#if defined(CF_BUILDING_CF) && defined(__cplusplus)
cf7d2af9 143#define CF_EXPORT extern "C" __declspec(dllexport)
8ca704e1 144#elif defined(CF_BUILDING_CF) && !defined(__cplusplus)
cf7d2af9 145#define CF_EXPORT extern __declspec(dllexport)
8ca704e1 146#elif defined(__cplusplus)
cf7d2af9 147#define CF_EXPORT extern "C" __declspec(dllimport)
8ca704e1 148#else
cf7d2af9 149#define CF_EXPORT extern __declspec(dllimport)
8ca704e1
A
150#endif
151#endif
152
cf7d2af9
A
153#else
154#define CF_EXPORT extern
155#endif
156
bd5b749c
A
157CF_EXTERN_C_BEGIN
158
159#if !defined(NULL)
160#if defined(__GNUG__)
161 #define NULL __null
162#elif defined(__cplusplus)
163 #define NULL 0
164#else
165 #define NULL ((void *)0)
166#endif
167#endif
9ce05555
A
168
169#if !defined(TRUE)
170 #define TRUE 1
171#endif
172
173#if !defined(FALSE)
174 #define FALSE 0
175#endif
176
9ce05555 177#if !defined(CF_INLINE)
60beada3 178 #if defined(__GNUC__) && (__GNUC__ == 4) && !defined(DEBUG)
bd5b749c 179 #define CF_INLINE static __inline__ __attribute__((always_inline))
4c91a73d 180 #elif defined(__GNUC__)
bd5b749c 181 #define CF_INLINE static __inline__
856091c5 182 #elif defined(__cplusplus)
9ce05555 183 #define CF_INLINE static inline
d8925383
A
184 #elif defined(_MSC_VER)
185 #define CF_INLINE static __inline
cf7d2af9 186 #elif TARGET_OS_WIN32
9ce05555
A
187 #define CF_INLINE static __inline__
188 #endif
189#endif
190
8ca704e1
A
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.
856091c5 193#ifndef CF_RETURNS_RETAINED
8ca704e1 194#if __has_feature(attribute_cf_returns_retained)
cf7d2af9
A
195#define CF_RETURNS_RETAINED __attribute__((cf_returns_retained))
196#else
197#define CF_RETURNS_RETAINED
198#endif
856091c5 199#endif
cf7d2af9 200
8ca704e1
A
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.
856091c5 203#ifndef CF_RETURNS_NOT_RETAINED
8ca704e1
A
204#if __has_feature(attribute_cf_returns_not_retained)
205#define CF_RETURNS_NOT_RETAINED __attribute__((cf_returns_not_retained))
206#else
207#define CF_RETURNS_NOT_RETAINED
208#endif
856091c5
A
209#endif
210
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))
215#else
216#define CF_RELEASES_ARGUMENT
217#endif
218#endif
219
220// Compatibility
221#ifndef CF_CONSUMED
222#if __has_feature(attribute_cf_consumed)
223#define CF_CONSUMED __attribute__((cf_consumed))
224#else
225#define CF_CONSUMED
226#endif
227#endif
8ca704e1
A
228
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")))
232#else
233#define CF_AUTOMATED_REFCOUNT_UNAVAILABLE
234#endif
9ce05555 235
856091c5
A
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")
239#else
240#define CF_IMPLICIT_BRIDGING_ENABLED
241#endif
242#endif
243
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")
247#else
248#define CF_IMPLICIT_BRIDGING_DISABLED
249#endif
250#endif
251
d7384798
A
252#if __has_attribute(objc_bridge)
253
254#ifdef __OBJC__
255@class NSArray;
256@class NSAttributedString;
257@class NSString;
258@class NSNull;
259@class NSCharacterSet;
260@class NSData;
261@class NSDate;
262@class NSTimeZone;
263@class NSDictionary;
264@class NSError;
265@class NSLocale;
266@class NSNumber;
267@class NSNumber;
268@class NSSet;
269@class NSURL;
270#endif
271
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)))
275#else
276#define CF_BRIDGED_TYPE(T)
277#define CF_BRIDGED_MUTABLE_TYPE(T)
278#define CF_RELATED_TYPE(T,C,I)
279#endif
280
856091c5 281
9ce05555
A
282CF_EXPORT double kCFCoreFoundationVersionNumber;
283
cf7d2af9 284#if TARGET_OS_MAC
bd5b749c
A
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
cf7d2af9
A
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
7c97c3e0
A
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
8ca704e1
A
340#define kCFCoreFoundationVersionNumber10_6_4 550.29
341#define kCFCoreFoundationVersionNumber10_6_5 550.42
856091c5
A
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
a48904a4
A
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
d7384798
A
356#define kCFCoreFoundationVersionNumber10_9 855.11
357#define kCFCoreFoundationVersionNumber10_9_1 855.11
358#define kCFCoreFoundationVersionNumber10_9_2 855.14
cf7d2af9
A
359#endif
360
361#if TARGET_OS_IPHONE
d7384798 362#define kCFCoreFoundationVersionNumber_iPhoneOS_2_0 478.23
cf7d2af9
A
363#define kCFCoreFoundationVersionNumber_iPhoneOS_2_1 478.26
364#define kCFCoreFoundationVersionNumber_iPhoneOS_2_2 478.29
7c97c3e0
A
365#define kCFCoreFoundationVersionNumber_iPhoneOS_3_0 478.47
366#define kCFCoreFoundationVersionNumber_iPhoneOS_3_1 478.52
367#define kCFCoreFoundationVersionNumber_iPhoneOS_3_2 478.61
8ca704e1
A
368#define kCFCoreFoundationVersionNumber_iOS_4_0 550.32
369#define kCFCoreFoundationVersionNumber_iOS_4_1 550.38
370#define kCFCoreFoundationVersionNumber_iOS_4_2 550.52
856091c5 371#define kCFCoreFoundationVersionNumber_iOS_4_3 550.52
a48904a4
A
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
d7384798
A
376#define kCFCoreFoundationVersionNumber_iOS_7_0 847.20
377#define kCFCoreFoundationVersionNumber_iOS_7_1 847.24
cf7d2af9 378#endif
bd5b749c 379
856091c5
A
380#if __LLP64__
381typedef unsigned long long CFTypeID;
382typedef unsigned long long CFOptionFlags;
383typedef unsigned long long CFHashCode;
384typedef signed long long CFIndex;
385#else
bd5b749c
A
386typedef unsigned long CFTypeID;
387typedef unsigned long CFOptionFlags;
388typedef unsigned long CFHashCode;
389typedef signed long CFIndex;
856091c5 390#endif
9ce05555
A
391
392/* Base "type" of all "CF objects", and polymorphic functions on them */
393typedef const void * CFTypeRef;
394
d7384798
A
395typedef const struct CF_BRIDGED_TYPE(NSString) __CFString * CFStringRef;
396typedef struct CF_BRIDGED_MUTABLE_TYPE(NSMutableString) __CFString * CFMutableStringRef;
9ce05555
A
397
398/*
399 Type to mean any instance of a property list type;
400 currently, CFString, CFData, CFNumber, CFBoolean, CFDate,
401 CFArray, and CFDictionary.
402*/
403typedef CFTypeRef CFPropertyListRef;
404
405/* Values returned from comparison functions */
856091c5
A
406typedef CF_ENUM(CFIndex, CFComparisonResult) {
407 kCFCompareLessThan = -1L,
9ce05555
A
408 kCFCompareEqualTo = 0,
409 kCFCompareGreaterThan = 1
bd5b749c 410};
9ce05555
A
411
412/* A standard comparison function */
413typedef CFComparisonResult (*CFComparatorFunction)(const void *val1, const void *val2, void *context);
414
415/* Constant used by some functions to indicate failed searches. */
416/* This is of type CFIndex. */
417enum {
418 kCFNotFound = -1
419};
420
421
422/* Range type */
423typedef struct {
424 CFIndex location;
425 CFIndex length;
426} CFRange;
427
428#if defined(CF_INLINE)
429CF_INLINE CFRange CFRangeMake(CFIndex loc, CFIndex len) {
430 CFRange range;
431 range.location = loc;
432 range.length = len;
433 return range;
434}
435#else
436#define CFRangeMake(LOC, LEN) __CFRangeMake(LOC, LEN)
437#endif
438
439/* Private; do not use */
440CF_EXPORT
441CFRange __CFRangeMake(CFIndex loc, CFIndex len);
442
443
9ce05555
A
444/* Null representant */
445
d7384798 446typedef const struct CF_BRIDGED_TYPE(NSNull) __CFNull * CFNullRef;
9ce05555
A
447
448CF_EXPORT
449CFTypeID CFNullGetTypeID(void);
450
451CF_EXPORT
452const CFNullRef kCFNull; // the singleton null instance
453
9ce05555
A
454
455/* Allocator API
456
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.
9ce05555
A
461*/
462typedef const struct __CFAllocator * CFAllocatorRef;
463
464/* This is a synonym for NULL, if you'd rather use a named constant. */
465CF_EXPORT
466const CFAllocatorRef kCFAllocatorDefault;
467
468/* Default system allocator; you rarely need to use this. */
469CF_EXPORT
470const CFAllocatorRef kCFAllocatorSystemDefault;
471
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.
477*/
478CF_EXPORT
479const CFAllocatorRef kCFAllocatorMalloc;
480
d8925383
A
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.
484 */
485CF_EXPORT
8ca704e1 486const CFAllocatorRef kCFAllocatorMallocZone;
d8925383 487
9ce05555
A
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.
491*/
492CF_EXPORT
493const CFAllocatorRef kCFAllocatorNull;
494
495/* Special allocator argument to CFAllocatorCreate() which means
496 "use the functions given in the context to allocate the allocator
497 itself as well".
498*/
499CF_EXPORT
500const CFAllocatorRef kCFAllocatorUseContext;
501
502typedef const void * (*CFAllocatorRetainCallBack)(const void *info);
503typedef void (*CFAllocatorReleaseCallBack)(const void *info);
504typedef CFStringRef (*CFAllocatorCopyDescriptionCallBack)(const void *info);
505typedef void * (*CFAllocatorAllocateCallBack)(CFIndex allocSize, CFOptionFlags hint, void *info);
506typedef void * (*CFAllocatorReallocateCallBack)(void *ptr, CFIndex newsize, CFOptionFlags hint, void *info);
507typedef void (*CFAllocatorDeallocateCallBack)(void *ptr, void *info);
508typedef CFIndex (*CFAllocatorPreferredSizeCallBack)(CFIndex size, CFOptionFlags hint, void *info);
509typedef struct {
510 CFIndex version;
511 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;
520
521CF_EXPORT
522CFTypeID CFAllocatorGetTypeID(void);
523
524/*
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.
531
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.
537
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.
541
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.
546*/
547CF_EXPORT
548void CFAllocatorSetDefault(CFAllocatorRef allocator);
549
550CF_EXPORT
551CFAllocatorRef CFAllocatorGetDefault(void);
552
553CF_EXPORT
554CFAllocatorRef CFAllocatorCreate(CFAllocatorRef allocator, CFAllocatorContext *context);
555
556CF_EXPORT
557void *CFAllocatorAllocate(CFAllocatorRef allocator, CFIndex size, CFOptionFlags hint);
558
559CF_EXPORT
560void *CFAllocatorReallocate(CFAllocatorRef allocator, void *ptr, CFIndex newsize, CFOptionFlags hint);
561
562CF_EXPORT
563void CFAllocatorDeallocate(CFAllocatorRef allocator, void *ptr);
564
565CF_EXPORT
566CFIndex CFAllocatorGetPreferredSizeForSize(CFAllocatorRef allocator, CFIndex size, CFOptionFlags hint);
567
568CF_EXPORT
569void CFAllocatorGetContext(CFAllocatorRef allocator, CFAllocatorContext *context);
570
571
572/* Polymorphic CF functions */
573
a48904a4
A
574CF_IMPLICIT_BRIDGING_ENABLED
575
9ce05555
A
576CF_EXPORT
577CFTypeID CFGetTypeID(CFTypeRef cf);
578
579CF_EXPORT
580CFStringRef CFCopyTypeIDDescription(CFTypeID type_id);
581
582CF_EXPORT
583CFTypeRef CFRetain(CFTypeRef cf);
584
585CF_EXPORT
586void CFRelease(CFTypeRef cf);
587
588CF_EXPORT
a48904a4 589CFTypeRef CFAutorelease(CFTypeRef CF_RELEASES_ARGUMENT arg) CF_AVAILABLE(10_9, 7_0);
9ce05555 590
d8925383 591CF_EXPORT
a48904a4 592CFIndex CFGetRetainCount(CFTypeRef cf);
d8925383 593
9ce05555
A
594CF_EXPORT
595Boolean CFEqual(CFTypeRef cf1, CFTypeRef cf2);
596
597CF_EXPORT
598CFHashCode CFHash(CFTypeRef cf);
599
600CF_EXPORT
601CFStringRef CFCopyDescription(CFTypeRef cf);
602
603CF_EXPORT
604CFAllocatorRef CFGetAllocator(CFTypeRef cf);
605
a48904a4
A
606CF_IMPLICIT_BRIDGING_DISABLED
607
608// This function is unavailable in ARC mode.
609CF_EXPORT
610CFTypeRef CFMakeCollectable(CFTypeRef cf) CF_AUTOMATED_REFCOUNT_UNAVAILABLE;
611
bd5b749c 612CF_EXTERN_C_END
9ce05555
A
613
614#endif /* ! __COREFOUNDATION_CFBASE__ */
615