2 * Copyright (c) 2008 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@
24 Copyright (c) 1998-2007, Apple Inc. All rights reserved.
28 NOT TO BE USED OUTSIDE CF!
32 #error The header file CFInternal.h is for the exclusive use of CoreFoundation. No other project should include it.
35 #if !defined(__COREFOUNDATION_CFINTERNAL__)
36 #define __COREFOUNDATION_CFINTERNAL__ 1
38 #include <CoreFoundation/CFBase.h>
39 #include <CoreFoundation/CFURL.h>
40 #include <CoreFoundation/CFString.h>
41 #include <CoreFoundation/CFDate.h>
42 #include <CoreFoundation/CFArray.h>
43 #include <CoreFoundation/CFRunLoop.h>
44 #include <CoreFoundation/CFStorage.h>
45 #include "CFLogUtilities.h"
46 #include "CFRuntime.h"
47 #if DEPLOYMENT_TARGET_MACOSX
49 #include <mach/mach_time.h>
51 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_LINUX || DEPLOYMENT_TARGET_FREEBSD
56 #include "auto_stubs.h"
57 #if !defined (__WIN32__)
61 #include <libkern/OSAtomic.h>
64 #if defined(__BIG_ENDIAN__)
65 #define __CF_BIG_ENDIAN__ 1
66 #define __CF_LITTLE_ENDIAN__ 0
69 #if defined(__LITTLE_ENDIAN__)
70 #define __CF_LITTLE_ENDIAN__ 1
71 #define __CF_BIG_ENDIAN__ 0
75 #include "ForFoundationOnly.h"
77 CF_EXPORT
const char *_CFProcessName(void);
78 CF_EXPORT CFStringRef
_CFProcessNameString(void);
80 CF_EXPORT Boolean
_CFIsCFM(void);
82 CF_EXPORT Boolean
_CFGetCurrentDirectory(char *path
, int maxlen
);
84 CF_EXPORT CFStringRef
_CFGetUserName(void);
86 CF_EXPORT CFArrayRef
_CFGetWindowsBinaryDirectories(void);
88 CF_EXPORT CFStringRef
_CFStringCreateHostName(void);
90 CF_EXPORT
void _CFMachPortInstallNotifyPort(CFRunLoopRef rl
, CFStringRef mode
);
92 #if defined(__ppc__) || defined(__ppc64__)
93 #define HALT asm __volatile__("trap")
94 #elif defined(__i386__) || defined(__x86_64__)
96 #define HALT asm __volatile__("int3")
97 #elif defined(_MSC_VER)
98 #define HALT __asm int 3;
100 #error Compiler not supported
105 #define __CFAssert(cond, prio, desc, a1, a2, a3, a4, a5) \
108 CFLog(prio, CFSTR(desc), a1, a2, a3, a4, a5); \
113 #define __CFAssert(cond, prio, desc, a1, a2, a3, a4, a5) \
117 #define CFAssert(condition, priority, description) \
118 __CFAssert((condition), (priority), description, 0, 0, 0, 0, 0)
119 #define CFAssert1(condition, priority, description, a1) \
120 __CFAssert((condition), (priority), description, (a1), 0, 0, 0, 0)
121 #define CFAssert2(condition, priority, description, a1, a2) \
122 __CFAssert((condition), (priority), description, (a1), (a2), 0, 0, 0)
123 #define CFAssert3(condition, priority, description, a1, a2, a3) \
124 __CFAssert((condition), (priority), description, (a1), (a2), (a3), 0, 0)
125 #define CFAssert4(condition, priority, description, a1, a2, a3, a4) \
126 __CFAssert((condition), (priority), description, (a1), (a2), (a3), (a4), 0)
128 #define __kCFLogAssertion 3
131 extern void __CFGenericValidateType_(CFTypeRef cf
, CFTypeID type
, const char *func
);
132 #define __CFGenericValidateType(cf, type) __CFGenericValidateType_(cf, type, __PRETTY_FUNCTION__)
134 #define __CFGenericValidateType(cf, type) ((void)0)
137 #define CF_INFO_BITS (!!(__CF_BIG_ENDIAN__) * 3)
138 #define CF_RC_BITS (!!(__CF_LITTLE_ENDIAN__) * 3)
140 /* Bit manipulation macros */
141 /* Bits are numbered from 31 on left to 0 on right */
142 /* May or may not work if you use them on bitfields in types other than UInt32, bitfields the full width of a UInt32, or anything else for which they were not designed. */
143 /* In the following, N1 and N2 specify an inclusive range N2..N1 with N1 >= N2 */
144 #define __CFBitfieldMask(N1, N2) ((((UInt32)~0UL) << (31UL - (N1) + (N2))) >> (31UL - N1))
145 #define __CFBitfieldGetValue(V, N1, N2) (((V) & __CFBitfieldMask(N1, N2)) >> (N2))
146 #define __CFBitfieldSetValue(V, N1, N2, X) ((V) = ((V) & ~__CFBitfieldMask(N1, N2)) | (((X) << (N2)) & __CFBitfieldMask(N1, N2)))
147 #define __CFBitfieldMaxValue(N1, N2) __CFBitfieldGetValue(0xFFFFFFFFUL, (N1), (N2))
149 #define __CFBitIsSet(V, N) (((V) & (1UL << (N))) != 0)
150 #define __CFBitSet(V, N) ((V) |= (1UL << (N)))
151 #define __CFBitClear(V, N) ((V) &= ~(1UL << (N)))
153 typedef struct ___CFThreadSpecificData
{
156 // If you add things to this struct, add cleanup to __CFFinalizeThreadData()
157 } __CFThreadSpecificData
;
159 extern __CFThreadSpecificData
*__CFGetThreadSpecificData(void);
160 __private_extern__
void __CFFinalizeThreadData(void *arg
);
162 #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_LINUX || DEPLOYMENT_TARGET_FREEBSD
163 extern pthread_key_t __CFTSDKey
;
166 //extern void *pthread_getspecific(pthread_key_t key);
168 CF_INLINE __CFThreadSpecificData
*__CFGetThreadSpecificData_inline(void) {
169 #if DEPLOYMENT_TARGET_MACOSX|| DEPLOYMENT_TARGET_LINUX || DEPLOYMENT_TARGET_FREEBSD
170 __CFThreadSpecificData
*data
= pthread_getspecific(__CFTSDKey
);
171 return data
? data
: __CFGetThreadSpecificData();
172 #elif defined(__WIN32__)
173 __CFThreadSpecificData
*data
= (__CFThreadSpecificData
*)TlsGetValue(__CFTSDKey
);
174 return data
? data
: __CFGetThreadSpecificData();
178 #define __kCFAllocatorTypeID_CONST 2
180 CF_INLINE CFAllocatorRef
__CFGetDefaultAllocator(void) {
181 CFAllocatorRef allocator
= (CFAllocatorRef
)__CFGetThreadSpecificData_inline()->_allocator
;
182 if (NULL
== allocator
) {
183 allocator
= kCFAllocatorSystemDefault
;
188 extern CFTypeID
__CFGenericTypeID(const void *cf
);
190 // This should only be used in CF types, not toll-free bridged objects!
191 // It should not be used with CFAllocator arguments!
192 // Use CFGetAllocator() in the general case, and this inline function in a few limited (but often called) situations.
193 CF_INLINE CFAllocatorRef
__CFGetAllocator(CFTypeRef cf
) { // !!! Use with CF types only, and NOT WITH CFAllocator!
194 CFAssert1(__kCFAllocatorTypeID_CONST
!= __CFGenericTypeID(cf
), __kCFLogAssertion
, "__CFGetAllocator(): CFAllocator argument", cf
);
195 if (__builtin_expect(__CFBitfieldGetValue(((const CFRuntimeBase
*)cf
)->_cfinfo
[CF_INFO_BITS
], 7, 7), 1)) {
196 return kCFAllocatorSystemDefault
;
198 return *(CFAllocatorRef
*)((char *)cf
- sizeof(CFAllocatorRef
));
201 // Don't define a __CFGetCurrentRunLoop(), because even internal clients should go through the real one
204 #if !defined(LLONG_MAX)
205 #if defined(_I64_MAX)
206 #define LLONG_MAX _I64_MAX
208 #warning Arbitrarily defining LLONG_MAX
209 #define LLONG_MAX (int64_t)9223372036854775807
211 #endif /* !defined(LLONG_MAX) */
213 #if !defined(LLONG_MIN)
214 #if defined(_I64_MIN)
215 #define LLONG_MIN _I64_MIN
217 #warning Arbitrarily defining LLONG_MIN
218 #define LLONG_MIN (-LLONG_MAX - (int64_t)1)
220 #endif /* !defined(LLONG_MIN) */
222 #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
223 #define __CFMin(A,B) ({__typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __a : __b; })
224 #define __CFMax(A,B) ({__typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __b : __a; })
226 #define __CFMin(A,B) ((A) < (B) ? (A) : (B))
227 #define __CFMax(A,B) ((A) > (B) ? (A) : (B))
228 #endif /* __GNUC__ */
230 /* Secret CFAllocator hint bits */
231 #define __kCFAllocatorTempMemory 0x2
232 #define __kCFAllocatorNoPointers 0x10
233 #define __kCFAllocatorDoNotRecordEvent 0x100
234 #define __kCFAllocatorGCScannedMemory 0x200 /* GC: memory should be scanned. */
235 #define __kCFAllocatorGCObjectMemory 0x400 /* GC: memory needs to be finalized. */
237 CF_INLINE auto_memory_type_t
CF_GET_GC_MEMORY_TYPE(CFOptionFlags flags
) {
238 auto_memory_type_t type
= (flags
& __kCFAllocatorGCScannedMemory
? 0 : AUTO_UNSCANNED
) | (flags
& __kCFAllocatorGCObjectMemory
? AUTO_OBJECT
: 0);
242 CF_EXPORT CFAllocatorRef
_CFTemporaryMemoryAllocator(void);
244 extern SInt64
__CFTimeIntervalToTSR(CFTimeInterval ti
);
245 extern CFTimeInterval
__CFTSRToTimeInterval(SInt64 tsr
);
247 extern CFStringRef
__CFCopyFormattingDescription(CFTypeRef cf
, CFDictionaryRef formatOptions
);
249 /* result is long long or int, depending on doLonglong
251 extern Boolean
__CFStringScanInteger(CFStringInlineBuffer
*buf
, CFTypeRef locale
, SInt32
*indexPtr
, Boolean doLonglong
, void *result
);
252 extern Boolean
__CFStringScanDouble(CFStringInlineBuffer
*buf
, CFTypeRef locale
, SInt32
*indexPtr
, double *resultPtr
);
253 extern Boolean
__CFStringScanHex(CFStringInlineBuffer
*buf
, SInt32
*indexPtr
, unsigned *result
);
256 #define STACK_BUFFER_DECL(T, N, C) T N[C];
258 #ifdef __CONSTANT_CFSTRINGS__
259 #define CONST_STRING_DECL(S, V) const CFStringRef S = (const CFStringRef)__builtin___CFStringMakeConstantString(V);
262 struct CF_CONST_STRING
{
268 extern int __CFConstantStringClassReference
[];
270 /* CFNetwork also has a copy of the CONST_STRING_DECL macro (for use on platforms without constant string support in cc); please warn cfnetwork-core@group.apple.com of any necessary changes to this macro. -- REW, 1/28/2002 */
272 #define ___WindowsConstantStringClassReference &__CFConstantStringClassReference
274 #define ___WindowsConstantStringClassReference NULL
277 #if __CF_BIG_ENDIAN__
278 #define CONST_STRING_DECL(S, V) \
279 static struct CF_CONST_STRING __ ## S ## __ = {{&__CFConstantStringClassReference, {0x0000, 0x07c8}}, V, sizeof(V) - 1}; \
280 const CFStringRef S = (CFStringRef) & __ ## S ## __;
281 #elif !defined (__WIN32__)
282 #define CONST_STRING_DECL(S, V) \
283 static struct CF_CONST_STRING __ ## S ## __ = {{&__CFConstantStringClassReference, {0x07c8, 0x0000}}, V, sizeof(V) - 1}; \
284 const CFStringRef S = (CFStringRef) & __ ## S ## __;
286 #define CONST_STRING_DECL(S, V) \
287 static struct CF_CONST_STRING __ ## S ## __ = {{___WindowsConstantStringClassReference, {0xc8, 0x07, 0x00, 0x00}},(uint8_t *) V, sizeof(V) - 1}; \
288 const CFStringRef S = (CFStringRef) & __ ## S ## __;
290 #define CONST_STRING_DECL_EXPORT(S, V) \
291 struct CF_CONST_STRING __ ## S ## __ = {{___WindowsConstantStringClassReference, {0xc8, 0x07, 0x00, 0x00}}, (uint8_t *)V, sizeof(V) - 1}; \
292 CF_EXPORT const CFStringRef S = (CFStringRef) & __ ## S ## __;
295 #define CONST_STRING_DECL(S, V) \
296 static struct CF_CONST_STRING __ ## S ## __ = {{NULL, {0xc8, 0x07, 0x00, 0x00}},(uint8_t *) V, sizeof(V) - 1}; \
297 const CFStringRef S = (CFStringRef) & __ ## S ## __;
299 #define CONST_STRING_DECL_EXPORT(S, V) \
300 struct CF_CONST_STRING __ ## S ## __ = {{NULL, {0xc8, 0x07, 0x00, 0x00}}, (uint8_t *)V, sizeof(V) - 1}; \
301 CF_EXPORT const CFStringRef S = (CFStringRef) & __ ## S ## __;
304 #endif // __BIG_ENDIAN__
306 #undef ___WindowsConstantStringClassReference
308 /* Buffer size for file pathname */
310 #define CFMaxPathSize ((CFIndex)262)
311 #define CFMaxPathLength ((CFIndex)260)
313 #define CFMaxPathSize ((CFIndex)1026)
314 #define CFMaxPathLength ((CFIndex)1024)
318 #define __CFSetLastAllocationEventName(a, b) ((void) 0)
320 CF_EXPORT CFStringRef
_CFCreateLimitedUniqueString(void);
322 /* Comparators are passed the address of the values; this is somewhat different than CFComparatorFunction is used in public API usually. */
323 CF_EXPORT CFIndex
CFBSearch(const void *element
, CFIndex elementSize
, const void *list
, CFIndex count
, CFComparatorFunction comparator
, void *context
);
325 CF_EXPORT CFHashCode
CFHashBytes(UInt8
*bytes
, CFIndex length
);
327 CF_EXPORT CFStringEncoding
CFStringFileSystemEncoding(void);
329 __private_extern__ CFStringRef
__CFStringCreateImmutableFunnel3(CFAllocatorRef alloc
, const void *bytes
, CFIndex numBytes
, CFStringEncoding encoding
, Boolean possiblyExternalFormat
, Boolean tryToReduceUnicode
, Boolean hasLengthByte
, Boolean hasNullByte
, Boolean noCopy
, CFAllocatorRef contentsDeallocator
, UInt32 converterFlags
);
331 extern const void *__CFStringCollectionCopy(CFAllocatorRef allocator
, const void *ptr
);
332 extern const void *__CFTypeCollectionRetain(CFAllocatorRef allocator
, const void *ptr
);
333 extern void __CFTypeCollectionRelease(CFAllocatorRef allocator
, const void *ptr
);
336 #if DEPLOYMENT_TARGET_MACOSX
338 typedef OSSpinLock CFSpinLock_t
;
340 #define CFSpinLockInit OS_SPINLOCK_INIT
341 #define CF_SPINLOCK_INIT_FOR_STRUCTS(X) (X = CFSpinLockInit)
343 CF_INLINE
void __CFSpinLock(CFSpinLock_t
*lockp
) {
344 OSSpinLockLock(lockp
);
347 CF_INLINE
void __CFSpinUnlock(CFSpinLock_t
*lockp
) {
348 OSSpinLockUnlock(lockp
);
351 #elif defined(__WIN32__)
353 typedef CRITICAL_SECTION CFSpinLock_t
;
355 #define CFSpinLockInit {0}
357 // For some reason, the {0} initializer does not work when the spinlock is a member of a structure; hence this macro
358 #define CF_SPINLOCK_INIT_FOR_STRUCTS(X) InitializeCriticalSection(&X)
359 extern CFSpinLock_t
*theLock
;
360 CF_INLINE
void __CFSpinLock(CFSpinLock_t
*slock
) {
361 if (NULL
== slock
->DebugInfo
) {
362 InitializeCriticalSection(slock
);
364 EnterCriticalSection(slock
);
367 CF_INLINE
void __CFSpinUnlock(CFSpinLock_t
*lock
) {
368 LeaveCriticalSection(lock
);
373 #warning CF spin locks not defined for this platform -- CF is not thread-safe
374 #define __CFSpinLock(A) do {} while (0)
375 #define __CFSpinUnlock(A) do {} while (0)
379 #if !defined(CHECK_FOR_FORK)
380 #define CHECK_FOR_FORK() do { } while (0)
383 #if !defined(HAS_FORKED)
384 #define HAS_FORKED() 0
387 #if defined(__svr4__) || defined(__hpux__) || defined(__WIN32__)
389 #elif DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_LINUX || DEPLOYMENT_TARGET_FREEBSD
390 #include <sys/errno.h>
393 #define thread_errno() errno
394 #define thread_set_errno(V) do {errno = (V);} while (0)
396 extern void *__CFStartSimpleThread(void *func
, void *arg
);
398 /* ==================== Simple file access ==================== */
399 /* For dealing with abstract types. MF:!!! These ought to be somewhere else and public. */
401 CF_EXPORT CFStringRef
_CFCopyExtensionForAbstractType(CFStringRef abstractType
);
403 /* ==================== Simple file access ==================== */
404 /* These functions all act on a c-strings which must be in the file system encoding. */
406 CF_EXPORT Boolean
_CFCreateDirectory(const char *path
);
407 CF_EXPORT Boolean
_CFRemoveDirectory(const char *path
);
408 CF_EXPORT Boolean
_CFDeleteFile(const char *path
);
410 CF_EXPORT Boolean
_CFReadBytesFromFile(CFAllocatorRef alloc
, CFURLRef url
, void **bytes
, CFIndex
*length
, CFIndex maxLength
);
411 /* resulting bytes are allocated from alloc which MUST be non-NULL. */
412 /* maxLength of zero means the whole file. Otherwise it sets a limit on the number of bytes read. */
414 CF_EXPORT Boolean
_CFWriteBytesToFile(CFURLRef url
, const void *bytes
, CFIndex length
);
415 #if DEPLOYMENT_TARGET_MACOSX
416 CF_EXPORT Boolean
_CFWriteBytesToFileWithAtomicity(CFURLRef url
, const void *bytes
, unsigned int length
, SInt32 mode
, Boolean atomic
);
419 CF_EXPORT CFMutableArrayRef
_CFContentsOfDirectory(CFAllocatorRef alloc
, char *dirPath
, void *dirSpec
, CFURLRef dirURL
, CFStringRef matchingAbstractType
);
420 /* On Mac OS 8/9, one of dirSpec, dirPath and dirURL must be non-NULL */
421 /* On all other platforms, one of path and dirURL must be non-NULL */
422 /* If both are present, they are assumed to be in-synch; that is, they both refer to the same directory. */
423 /* alloc may be NULL */
424 /* return value is CFArray of CFURLs */
426 CF_EXPORT SInt32
_CFGetFileProperties(CFAllocatorRef alloc
, CFURLRef pathURL
, Boolean
*exists
, SInt32
*posixMode
, SInt64
*size
, CFDateRef
*modTime
, SInt32
*ownerID
, CFArrayRef
*dirContents
);
427 /* alloc may be NULL */
428 /* any of exists, posixMode, size, modTime, and dirContents can be NULL. Usually it is not a good idea to pass NULL for exists, since interpretting the other values sometimes requires that you know whether the file existed or not. Except for dirContents, it is pretty cheap to compute any of these things as loing as one of them must be computed. */
431 /* ==================== Simple path manipulation ==================== */
432 /* These functions all act on a UniChar buffers. */
434 CF_EXPORT Boolean
_CFIsAbsolutePath(UniChar
*unichars
, CFIndex length
);
435 CF_EXPORT Boolean
_CFStripTrailingPathSlashes(UniChar
*unichars
, CFIndex
*length
);
436 CF_EXPORT Boolean
_CFAppendPathComponent(UniChar
*unichars
, CFIndex
*length
, CFIndex maxLength
, UniChar
*component
, CFIndex componentLength
);
437 CF_EXPORT Boolean
_CFAppendPathExtension(UniChar
*unichars
, CFIndex
*length
, CFIndex maxLength
, UniChar
*extension
, CFIndex extensionLength
);
438 CF_EXPORT Boolean
_CFTransmutePathSlashes(UniChar
*unichars
, CFIndex
*length
, UniChar replSlash
);
439 CF_EXPORT CFIndex
_CFStartOfLastPathComponent(UniChar
*unichars
, CFIndex length
);
440 CF_EXPORT CFIndex
_CFLengthAfterDeletingLastPathComponent(UniChar
*unichars
, CFIndex length
);
441 CF_EXPORT CFIndex
_CFStartOfPathExtension(UniChar
*unichars
, CFIndex length
);
442 CF_EXPORT CFIndex
_CFLengthAfterDeletingPathExtension(UniChar
*unichars
, CFIndex length
);
444 #define CF_IS_OBJC(typeID, obj) (false)
446 #define CF_OBJC_VOIDCALL0(obj, sel)
447 #define CF_OBJC_VOIDCALL1(obj, sel, a1)
448 #define CF_OBJC_VOIDCALL2(obj, sel, a1, a2)
450 #define CF_OBJC_CALL0(rettype, retvar, obj, sel)
451 #define CF_OBJC_CALL1(rettype, retvar, obj, sel, a1)
452 #define CF_OBJC_CALL2(rettype, retvar, obj, sel, a1, a2)
454 #if defined (__WIN32__)
455 #define CF_OBJC_FUNCDISPATCH0(typeID, rettype, obj, sel) ((void)0)
456 #define CF_OBJC_FUNCDISPATCH1(typeID, rettype, obj, sel, a1) ((void)0)
457 #define CF_OBJC_FUNCDISPATCH2(typeID, rettype, obj, sel, a1, a2) ((void)0)
458 #define CF_OBJC_FUNCDISPATCH3(typeID, rettype, obj, sel, a1, a2, a3) ((void)0)
459 #define CF_OBJC_FUNCDISPATCH4(typeID, rettype, obj, sel, a1, a2, a3, a4) ((void)0)
460 #define CF_OBJC_FUNCDISPATCH5(typeID, rettype, obj, sel, a1, a2, a3, a4, a5) ((void)0)
462 #define CF_OBJC_FUNCDISPATCH0(typeID, rettype, obj, sel)
463 #define CF_OBJC_FUNCDISPATCH1(typeID, rettype, obj, sel, a1)
464 #define CF_OBJC_FUNCDISPATCH2(typeID, rettype, obj, sel, a1, a2)
465 #define CF_OBJC_FUNCDISPATCH3(typeID, rettype, obj, sel, a1, a2, a3)
466 #define CF_OBJC_FUNCDISPATCH4(typeID, rettype, obj, sel, a1, a2, a3, a4)
467 #define CF_OBJC_FUNCDISPATCH5(typeID, rettype, obj, sel, a1, a2, a3, a4, a5)
470 #define __CFISAForTypeID(x) (0)
472 #define __CFMaxRuntimeTypes 65535
474 /* See comments in CFBase.c
476 #if DEPLOYMENT_TARGET_MACOSX && defined(__ppc__)
477 extern void __CF_FAULT_CALLBACK(void **ptr
);
478 extern void *__CF_INVOKE_CALLBACK(void *, ...);
479 #define FAULT_CALLBACK(V) __CF_FAULT_CALLBACK(V)
480 #define INVOKE_CALLBACK1(P, A) (__CF_INVOKE_CALLBACK(P, A))
481 #define INVOKE_CALLBACK2(P, A, B) (__CF_INVOKE_CALLBACK(P, A, B))
482 #define INVOKE_CALLBACK3(P, A, B, C) (__CF_INVOKE_CALLBACK(P, A, B, C))
483 #define INVOKE_CALLBACK4(P, A, B, C, D) (__CF_INVOKE_CALLBACK(P, A, B, C, D))
484 #define INVOKE_CALLBACK5(P, A, B, C, D, E) (__CF_INVOKE_CALLBACK(P, A, B, C, D, E))
485 #define UNFAULT_CALLBACK(V) do { V = (void *)((uintptr_t)V & ~0x3); } while (0)
487 #define FAULT_CALLBACK(V)
488 #define INVOKE_CALLBACK1(P, A) (P)(A)
489 #define INVOKE_CALLBACK2(P, A, B) (P)(A, B)
490 #define INVOKE_CALLBACK3(P, A, B, C) (P)(A, B, C)
491 #define INVOKE_CALLBACK4(P, A, B, C, D) (P)(A, B, C, D)
492 #define INVOKE_CALLBACK5(P, A, B, C, D, E) (P)(A, B, C, D, E)
493 #define UNFAULT_CALLBACK(V) do { } while (0)
496 /* For the support of functionality which needs CarbonCore or other frameworks */
497 // These macros define an upcall or weak "symbol-lookup" wrapper function.
498 // The parameters are:
499 // R : the return type of the function
500 // N : the name of the function (in the other library)
501 // P : the parenthesized parameter list of the function
502 // A : the parenthesized actual argument list to be passed
503 // opt: a fifth optional argument can be passed in which is the
504 // return value of the wrapper when the function cannot be
505 // found; should be of type R, & can be a function call
506 // The name of the resulting wrapper function is:
507 // __CFCarbonCore_N (where N is the second parameter)
508 // __CFNetwork_N (where N is the second parameter)
511 // DEFINE_WEAK_CARBONCORE_FUNC(void, DisposeHandle, (Handle h), (h))
514 #if DEPLOYMENT_TARGET_MACOSX
516 extern void *__CFLookupCFNetworkFunction(const char *name
);
518 #define DEFINE_WEAK_CFNETWORK_FUNC(R, N, P, A, ...) \
519 static R __CFNetwork_ ## N P { \
520 static R (*dyfunc) P = (void *)(~(uintptr_t)0); \
521 if ((void *)(~(uintptr_t)0) == dyfunc) { \
522 dyfunc = __CFLookupCFNetworkFunction(#N); } \
523 if (dyfunc) { return dyfunc A ; } \
524 return __VA_ARGS__ ; \
529 #define DEFINE_WEAK_CFNETWORK_FUNC(R, N, P, A, ...)
534 #if !defined(DEFINE_WEAK_CARBONCORE_FUNC)
535 #define DEFINE_WEAK_CARBONCORE_FUNC(R, N, P, A, ...)
539 __private_extern__ CFArrayRef
_CFBundleCopyUserLanguages(Boolean useBackstops
);
541 /* GC related internal SPIs. */
542 extern malloc_zone_t
*__CFCollectableZone
;
544 /* !!! Avoid #importing objc.h; e.g. converting this to a .m file */
545 struct __objcFastEnumerationStateEquivalent
{
547 unsigned long *itemsPtr
;
548 unsigned long *mutationsPtr
;
549 unsigned long extra
[5];
552 unsigned long _CFStorageFastEnumeration(CFStorageRef storage
, struct __objcFastEnumerationStateEquivalent
*state
, void *stackbuffer
, unsigned long count
);
555 // Allocate an id[count], new slots are nil
556 extern void *__CFAllocateObjectArray(unsigned long count
);
557 extern void *__CFReallocateObjectArray(id
*array
, unsigned long count
);
558 extern void __CFFreeObjectArray(id
*array
);
560 // check against LONG_MAX to catch negative numbers
561 #define new_id_array(N, C) \
562 size_t N ## _count__ = (C); \
563 if (N ## _count__ > LONG_MAX) { \
564 id rr = [objc_lookUpClass("NSString") stringWithFormat:@"*** attempt to create a temporary id buffer which is too large or with a negative count (%lu) -- possibly data is corrupt", N ## _count__]; \
565 @throw [NSException exceptionWithName:NSGenericException reason:rr userInfo:nil]; \
567 NSInteger N ## _is_stack__ = (N ## _count__ <= 256); \
568 id N ## _buffer__[N ## _is_stack__ ? N ## _count__ : 0]; \
569 if (N ## _is_stack__) memset(N ## _buffer__, 0, sizeof(N ## _buffer__)); \
570 id * N = N ## _is_stack__ ? N ## _buffer__ : __CFAllocateObjectArray(N ## _count__); \
572 id rr = [objc_lookUpClass("NSString") stringWithFormat:@"*** attempt to create a temporary id buffer of length (%lu) failed", N ## _count__]; \
573 @throw [NSException exceptionWithName:NSMallocException reason:rr userInfo:nil]; \
577 #define free_id_array(N) \
578 if (! N ## _is_stack__) __CFFreeObjectArray(N)
580 extern void *__CFFullMethodName(Class cls
, id obj
, SEL sel
);
581 extern void *__CFExceptionProem(id obj
, SEL sel
);
582 extern void __CFRequireConcreteImplementation(Class absClass
, id obj
, SEL sel
);
585 #endif /* ! __COREFOUNDATION_CFINTERNAL__ */