2 * Copyright (c) 2005 Apple Computer, 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-2005, 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 "CFRuntime.h"
47 #include <mach/thread_switch.h>
48 #include <mach/mach_time.h>
50 #if defined(__MACH__) || defined(__LINUX__) || defined(__FREEBSD__)
56 #include "auto_stubs.h"
57 #include <libkern/OSAtomic.h>
61 // This hack is in here because B&I kernel does not set up comm page with Tiger additions yet.
62 #define AtomicCompareAndSwap(mem, old, new) ({bool result; if (((void **)OSMemoryBarrier)[1] == 0x0) {result = ((*(mem) == (old)) ? (*(mem) = (new), 1) : 0);} else {result = OSAtomicCompareAndSwap32(old, new, (int32_t *)mem); OSMemoryBarrier();} result;})
63 #define AtomicAdd32(mem, val) ({if (((void **)OSMemoryBarrier)[1] == 0x0) {*(mem) += (val);} else {OSAtomicAdd32(val, mem); OSMemoryBarrier();} 0;})
65 #define AtomicCompareAndSwap(mem, old, new) ({bool result; result = OSAtomicCompareAndSwap32(old, new, (int32_t *)mem); OSMemoryBarrier(); result;})
66 #define AtomicAdd32(mem, val) ({OSAtomicAdd32(val, mem); OSMemoryBarrier(); 0;})
70 #include "ForFoundationOnly.h"
72 #if !defined(__MACH__)
73 #define __private_extern__
76 CF_EXPORT
char **_CFArgv(void);
77 CF_EXPORT
int _CFArgc(void);
79 CF_EXPORT
const char *_CFProcessName(void);
80 CF_EXPORT CFStringRef
_CFProcessNameString(void);
82 CF_EXPORT Boolean
_CFIsCFM(void);
84 CF_EXPORT Boolean
_CFGetCurrentDirectory(char *path
, int maxlen
);
86 CF_EXPORT CFStringRef
_CFGetUserName(void);
87 CF_EXPORT CFStringRef
_CFStringCreateHostName(void);
89 CF_EXPORT
void __CFSetNastyFile(CFTypeRef cf
);
91 CF_EXPORT
void _CFMachPortInstallNotifyPort(CFRunLoopRef rl
, CFStringRef mode
);
93 #if defined(__ppc__) || defined(__ppc64__)
94 #define HALT asm __volatile__("trap")
95 #elif defined(__i386__)
97 #define HALT asm __volatile__("int3")
98 #elif defined(_MSC_VER) || defined(__MWERKS__)
99 #define HALT __asm int 3;
101 #error Compiler not supported
106 #define __CFAssert(cond, prio, desc, a1, a2, a3, a4, a5) \
109 CFLog(prio, CFSTR(desc), a1, a2, a3, a4, a5); \
114 #define __CFAssert(cond, prio, desc, a1, a2, a3, a4, a5) \
118 #define CFAssert(condition, priority, description) \
119 __CFAssert((condition), (priority), description, 0, 0, 0, 0, 0)
120 #define CFAssert1(condition, priority, description, a1) \
121 __CFAssert((condition), (priority), description, (a1), 0, 0, 0, 0)
122 #define CFAssert2(condition, priority, description, a1, a2) \
123 __CFAssert((condition), (priority), description, (a1), (a2), 0, 0, 0)
124 #define CFAssert3(condition, priority, description, a1, a2, a3) \
125 __CFAssert((condition), (priority), description, (a1), (a2), (a3), 0, 0)
126 #define CFAssert4(condition, priority, description, a1, a2, a3, a4) \
127 __CFAssert((condition), (priority), description, (a1), (a2), (a3), (a4), 0)
129 #define __kCFLogAssertion 15
132 extern void __CFGenericValidateType_(CFTypeRef cf
, CFTypeID type
, const char *func
);
133 #define __CFGenericValidateType(cf, type) __CFGenericValidateType_(cf, type, __PRETTY_FUNCTION__)
135 #define __CFGenericValidateType(cf, type)
139 /* Bit manipulation macros */
140 /* Bits are numbered from 31 on left to 0 on right */
141 /* 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. */
142 /* In the following, N1 and N2 specify an inclusive range N2..N1 with N1 >= N2 */
143 #define __CFBitfieldMask(N1, N2) ((((UInt32)~0UL) << (31UL - (N1) + (N2))) >> (31UL - N1))
144 #define __CFBitfieldGetValue(V, N1, N2) (((V) & __CFBitfieldMask(N1, N2)) >> (N2))
145 #define __CFBitfieldSetValue(V, N1, N2, X) ((V) = ((V) & ~__CFBitfieldMask(N1, N2)) | (((X) << (N2)) & __CFBitfieldMask(N1, N2)))
146 #define __CFBitfieldMaxValue(N1, N2) __CFBitfieldGetValue(0xFFFFFFFFUL, (N1), (N2))
148 #define __CFBitIsSet(V, N) (((V) & (1UL << (N))) != 0)
149 #define __CFBitSet(V, N) ((V) |= (1UL << (N)))
150 #define __CFBitClear(V, N) ((V) &= ~(1UL << (N)))
152 typedef struct ___CFThreadSpecificData
{
157 // If you add things to this struct, add cleanup to __CFFinalizeThreadData()
158 } __CFThreadSpecificData
;
160 extern __CFThreadSpecificData
*__CFGetThreadSpecificData(void);
161 __private_extern__
void __CFFinalizeThreadData(void *arg
);
163 #if defined(__MACH__) || defined(__LINUX__) || defined(__FREEBSD__)
164 extern pthread_key_t __CFTSDKey
;
166 #if defined(__WIN32__)
167 extern DWORD __CFTSDKey
;
170 //extern void *pthread_getspecific(pthread_key_t key);
172 CF_INLINE __CFThreadSpecificData
*__CFGetThreadSpecificData_inline(void) {
173 #if defined(__MACH__) || defined(__LINUX__) || defined(__FREEBSD__)
174 __CFThreadSpecificData
*data
= pthread_getspecific(__CFTSDKey
);
175 return data
? data
: __CFGetThreadSpecificData();
176 #elif defined(__WIN32__)
177 __CFThreadSpecificData
*data
= TlsGetValue(__CFTSDKey
);
178 return data
? data
: __CFGetThreadSpecificData();
182 CF_EXPORT
void CFLog(int p
, CFStringRef str
, ...);
184 #define __kCFAllocatorTypeID_CONST 2
186 CF_INLINE CFAllocatorRef
__CFGetDefaultAllocator(void) {
187 CFAllocatorRef allocator
= __CFGetThreadSpecificData_inline()->_allocator
;
188 if (NULL
== allocator
) {
189 allocator
= kCFAllocatorSystemDefault
;
194 extern CFTypeID
__CFGenericTypeID(const void *cf
);
196 // This should only be used in CF types, not toll-free bridged objects!
197 // It should not be used with CFAllocator arguments!
198 // Use CFGetAllocator() in the general case, and this inline function in a few limited (but often called) situations.
199 CF_INLINE CFAllocatorRef
__CFGetAllocator(CFTypeRef cf
) { // !!! Use with CF types only, and NOT WITH CFAllocator!
200 CFAssert1(__kCFAllocatorTypeID_CONST
!= __CFGenericTypeID(cf
), __kCFLogAssertion
, "__CFGetAllocator(): CFAllocator argument", cf
);
201 if (__builtin_expect(__CFBitfieldGetValue(((const CFRuntimeBase
*)cf
)->_info
, 7, 7), 1)) {
202 return kCFAllocatorSystemDefault
;
204 return *(CFAllocatorRef
*)((char *)cf
- sizeof(CFAllocatorRef
));
207 // Don't define a __CFGetCurrentRunLoop(), because even internal clients should go through the real one
210 #if !defined(LLONG_MAX)
211 #if defined(_I64_MAX)
212 #define LLONG_MAX _I64_MAX
214 #warning Arbitrarily defining LLONG_MAX
215 #define LLONG_MAX (int64_t)9223372036854775807
217 #endif /* !defined(LLONG_MAX) */
219 #if !defined(LLONG_MIN)
220 #if defined(_I64_MIN)
221 #define LLONG_MIN _I64_MIN
223 #warning Arbitrarily defining LLONG_MIN
224 #define LLONG_MIN (-LLONG_MAX - (int64_t)1)
226 #endif /* !defined(LLONG_MIN) */
228 #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
229 #define __CFMin(A,B) ({__typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __a : __b; })
230 #define __CFMax(A,B) ({__typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __b : __a; })
232 #define __CFMin(A,B) ((A) < (B) ? (A) : (B))
233 #define __CFMax(A,B) ((A) > (B) ? (A) : (B))
234 #endif /* __GNUC__ */
236 /* Secret CFAllocator hint bits */
237 #define __kCFAllocatorTempMemory 0x2
238 #define __kCFAllocatorNoPointers 0x10
239 #define __kCFAllocatorDoNotRecordEvent 0x100
241 CF_EXPORT CFAllocatorRef
_CFTemporaryMemoryAllocator(void);
243 extern SInt64
__CFTimeIntervalToTSR(CFTimeInterval ti
);
244 extern CFTimeInterval
__CFTSRToTimeInterval(SInt64 tsr
);
246 extern CFStringRef
__CFCopyFormattingDescription(CFTypeRef cf
, CFDictionaryRef formatOptions
);
248 /* result is long long or int, depending on doLonglong
250 extern Boolean
__CFStringScanInteger(CFStringInlineBuffer
*buf
, CFDictionaryRef locale
, SInt32
*indexPtr
, Boolean doLonglong
, void *result
);
251 extern Boolean
__CFStringScanDouble(CFStringInlineBuffer
*buf
, CFDictionaryRef locale
, SInt32
*indexPtr
, double *resultPtr
);
252 extern Boolean
__CFStringScanHex(CFStringInlineBuffer
*buf
, SInt32
*indexPtr
, unsigned *result
);
255 #ifdef __CONSTANT_CFSTRINGS__
256 #define CONST_STRING_DECL(S, V) const CFStringRef S = __builtin___CFStringMakeConstantString(V);
259 struct CF_CONST_STRING
{
265 extern int __CFConstantStringClassReference
[];
267 /* 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 */
268 #if defined(__ppc__) || defined(__ppc64__)
269 #define CONST_STRING_DECL(S, V) \
270 static struct CF_CONST_STRING __ ## S ## __ = {{&__CFConstantStringClassReference, 0x0000, 0x07c8}, V, sizeof(V) - 1}; \
271 const CFStringRef S = (CFStringRef) & __ ## S ## __;
272 #elif defined(__i386__)
273 #define CONST_STRING_DECL(S, V) \
274 static struct CF_CONST_STRING __ ## S ## __ = {{&__CFConstantStringClassReference, 0x07c8, 0x0000}, V, sizeof(V) - 1}; \
275 const CFStringRef S = (CFStringRef) & __ ## S ## __;
277 #error undefined architecture
281 #if defined(__MACH__)
282 #define __kCFCharacterSetDir "/System/Library/CoreServices"
283 #elif defined(__LINUX__) || defined(__FREEBSD__)
284 #define __kCFCharacterSetDir "/usr/local/share/CoreFoundation"
285 #elif defined(__WIN32__)
286 #define __kCFCharacterSetDir "\\Windows\\CoreFoundation"
290 /* Buffer size for file pathname */
291 #if defined(__WIN32__)
292 #define CFMaxPathSize ((CFIndex)262)
293 #define CFMaxPathLength ((CFIndex)260)
295 #define CFMaxPathSize ((CFIndex)1026)
296 #define CFMaxPathLength ((CFIndex)1024)
299 #if defined(__MACH__)
300 extern bool __CFOASafe
;
301 extern void __CFSetLastAllocationEventName(void *ptr
, const char *classname
);
304 #define __CFSetLastAllocationEventName(a, b)
308 CF_EXPORT CFStringRef
_CFCreateLimitedUniqueString(void);
310 extern CFStringRef
__CFCopyEthernetAddrString(void);
312 /* Comparators are passed the address of the values; this is somewhat different than CFComparatorFunction is used in public API usually. */
313 CF_EXPORT CFIndex
CFBSearch(const void *element
, CFIndex elementSize
, const void *list
, CFIndex count
, CFComparatorFunction comparator
, void *context
);
315 CF_EXPORT CFHashCode
CFHashBytes(UInt8
*bytes
, CFIndex length
);
317 CF_EXPORT CFStringEncoding
CFStringFileSystemEncoding(void);
319 CF_EXPORT 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
);
321 extern const void *__CFTypeCollectionRetain(CFAllocatorRef allocator
, const void *ptr
);
322 extern void __CFTypeCollectionRelease(CFAllocatorRef allocator
, const void *ptr
);
325 #if defined(__MACH__)
327 typedef OSSpinLock CFSpinLock_t
;
329 #define CFSpinLockInit OS_SPINLOCK_INIT
331 #if defined(__i386__)
332 extern void _spin_lock(CFSpinLock_t
*lockp
);
333 extern void _spin_unlock(CFSpinLock_t
*lockp
);
334 #define OSSpinLockLock(p) _spin_lock(p)
335 #define OSSpinLockUnlock(p) _spin_unlock(p)
338 CF_INLINE
void __CFSpinLock(CFSpinLock_t
*lockp
) {
339 OSSpinLockLock(lockp
);
342 CF_INLINE
void __CFSpinUnlock(CFSpinLock_t
*lockp
) {
343 OSSpinLockUnlock(lockp
);
346 #elif defined(__WIN32__)
348 typedef LONG CFSpinLock_t
;
350 CF_INLINE
void __CFSpinLock(CFSpinLock_t
*slock
) {
351 while (InterlockedExchange(slock
, 1) != 0) {
356 CF_INLINE
void __CFSpinUnlock(CFSpinLock_t
*lock
) {
362 #warning CF spin locks not defined for this platform -- CF is not thread-safe
363 #define __CFSpinLock(A) do {} while (0)
364 #define __CFSpinUnlock(A) do {} while (0)
368 #if defined(__svr4__) || defined(__hpux__) || defined(__WIN32__)
370 #elif defined(__MACH__) || defined(__LINUX__) || defined(__FREEBSD__)
371 #include <sys/errno.h>
374 #define thread_errno() errno
375 #define thread_set_errno(V) do {errno = (V);} while (0)
377 extern void *__CFStartSimpleThread(void *func
, void *arg
);
379 /* ==================== Simple file access ==================== */
380 /* For dealing with abstract types. MF:!!! These ought to be somewhere else and public. */
382 CF_EXPORT CFStringRef
_CFCopyExtensionForAbstractType(CFStringRef abstractType
);
384 /* ==================== Simple file access ==================== */
385 /* These functions all act on a c-strings which must be in the file system encoding. */
387 CF_EXPORT Boolean
_CFCreateDirectory(const char *path
);
388 CF_EXPORT Boolean
_CFRemoveDirectory(const char *path
);
389 CF_EXPORT Boolean
_CFDeleteFile(const char *path
);
391 CF_EXPORT Boolean
_CFReadBytesFromFile(CFAllocatorRef alloc
, CFURLRef url
, void **bytes
, CFIndex
*length
, CFIndex maxLength
);
392 /* resulting bytes are allocated from alloc which MUST be non-NULL. */
393 /* maxLength of zero means the whole file. Otherwise it sets a limit on the number of bytes read. */
395 CF_EXPORT Boolean
_CFWriteBytesToFile(CFURLRef url
, const void *bytes
, CFIndex length
);
396 #if defined(__MACH__)
397 CF_EXPORT Boolean
_CFWriteBytesToFileWithAtomicity(CFURLRef url
, const void *bytes
, unsigned int length
, SInt32 mode
, Boolean atomic
);
400 CF_EXPORT CFMutableArrayRef
_CFContentsOfDirectory(CFAllocatorRef alloc
, char *dirPath
, void *dirSpec
, CFURLRef dirURL
, CFStringRef matchingAbstractType
);
401 /* On Mac OS 8/9, one of dirSpec, dirPath and dirURL must be non-NULL */
402 /* On all other platforms, one of path and dirURL must be non-NULL */
403 /* If both are present, they are assumed to be in-synch; that is, they both refer to the same directory. */
404 /* alloc may be NULL */
405 /* return value is CFArray of CFURLs */
407 CF_EXPORT SInt32
_CFGetFileProperties(CFAllocatorRef alloc
, CFURLRef pathURL
, Boolean
*exists
, SInt32
*posixMode
, SInt64
*size
, CFDateRef
*modTime
, SInt32
*ownerID
, CFArrayRef
*dirContents
);
408 /* alloc may be NULL */
409 /* 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. */
412 /* ==================== Simple path manipulation ==================== */
413 /* These functions all act on a UniChar buffers. */
415 CF_EXPORT Boolean
_CFIsAbsolutePath(UniChar
*unichars
, CFIndex length
);
416 CF_EXPORT Boolean
_CFStripTrailingPathSlashes(UniChar
*unichars
, CFIndex
*length
);
417 CF_EXPORT Boolean
_CFAppendPathComponent(UniChar
*unichars
, CFIndex
*length
, CFIndex maxLength
, UniChar
*component
, CFIndex componentLength
);
418 CF_EXPORT Boolean
_CFAppendPathExtension(UniChar
*unichars
, CFIndex
*length
, CFIndex maxLength
, UniChar
*extension
, CFIndex extensionLength
);
419 CF_EXPORT Boolean
_CFTransmutePathSlashes(UniChar
*unichars
, CFIndex
*length
, UniChar replSlash
);
420 CF_EXPORT CFIndex
_CFStartOfLastPathComponent(UniChar
*unichars
, CFIndex length
);
421 CF_EXPORT CFIndex
_CFLengthAfterDeletingLastPathComponent(UniChar
*unichars
, CFIndex length
);
422 CF_EXPORT CFIndex
_CFStartOfPathExtension(UniChar
*unichars
, CFIndex length
);
423 CF_EXPORT CFIndex
_CFLengthAfterDeletingPathExtension(UniChar
*unichars
, CFIndex length
);
425 #if !defined(__MACH__)
427 #define CF_IS_OBJC(typeID, obj) (false)
429 #define CF_OBJC_VOIDCALL0(obj, sel)
430 #define CF_OBJC_VOIDCALL1(obj, sel, a1)
431 #define CF_OBJC_VOIDCALL2(obj, sel, a1, a2)
433 #define CF_OBJC_CALL0(rettype, retvar, obj, sel)
434 #define CF_OBJC_CALL1(rettype, retvar, obj, sel, a1)
435 #define CF_OBJC_CALL2(rettype, retvar, obj, sel, a1, a2)
437 #define CF_OBJC_FUNCDISPATCH0(typeID, rettype, obj, sel)
438 #define CF_OBJC_FUNCDISPATCH1(typeID, rettype, obj, sel, a1)
439 #define CF_OBJC_FUNCDISPATCH2(typeID, rettype, obj, sel, a1, a2)
440 #define CF_OBJC_FUNCDISPATCH3(typeID, rettype, obj, sel, a1, a2, a3)
441 #define CF_OBJC_FUNCDISPATCH4(typeID, rettype, obj, sel, a1, a2, a3, a4)
442 #define CF_OBJC_FUNCDISPATCH5(typeID, rettype, obj, sel, a1, a2, a3, a4, a5)
446 #if defined(__LINUX__) || defined(__FREEBSD__) || defined(__WIN32__)
447 #define __CFISAForTypeID(x) (NULL)
450 #define __CFMaxRuntimeTypes 256
452 #if defined(__MACH__)
454 #include <objc/objc-class.h>
456 extern struct objc_class
*__CFRuntimeObjCClassTable
[];
457 CF_INLINE
void *__CFISAForTypeID(CFTypeID typeID
) {
458 return (void *)(__CFRuntimeObjCClassTable
[typeID
]);
462 #define __CFSendObjCMsg 0xfffeff00
464 extern void * (*__CFSendObjCMsg
)(const void *, SEL
, ...);
468 // Although it might seem to make better performance to check for NULL
469 // first, doing the other check first is better.
470 CF_INLINE
int CF_IS_OBJC(CFTypeID typeID
, const void *obj
) {
471 return (((CFRuntimeBase
*)obj
)->_isa
!= __CFISAForTypeID(typeID
) && ((CFRuntimeBase
*)obj
)->_isa
> (void *)0xFFF);
474 #define CF_IS_OBJC(typeID, obj) (false)
477 // Invoke an ObjC method that returns void.
478 // Assumes CF_IS_OBJC has already been checked.
479 #define CF_OBJC_VOIDCALL0(obj, sel) \
480 {void (*func)(const void *, SEL) = (void *)__CFSendObjCMsg; \
481 static SEL s = NULL; if (!s) s = sel_registerName(sel); \
482 func((const void *)obj, s);}
483 #define CF_OBJC_VOIDCALL1(obj, sel, a1) \
484 {void (*func)(const void *, SEL, ...) = (void *)__CFSendObjCMsg; \
485 static SEL s = NULL; if (!s) s = sel_registerName(sel); \
486 func((const void *)obj, s, (a1));}
487 #define CF_OBJC_VOIDCALL2(obj, sel, a1, a2) \
488 {void (*func)(const void *, SEL, ...) = (void *)__CFSendObjCMsg; \
489 static SEL s = NULL; if (!s) s = sel_registerName(sel); \
490 func((const void *)obj, s, (a1), (a2));}
493 // Invoke an ObjC method, leaving the result in "retvar".
494 // Assumes CF_IS_OBJC has already been checked.
495 #define CF_OBJC_CALL0(rettype, retvar, obj, sel) \
496 {rettype (*func)(const void *, SEL) = (void *)__CFSendObjCMsg; \
497 static SEL s = NULL; if (!s) s = sel_registerName(sel); \
498 retvar = func((const void *)obj, s);}
499 #define CF_OBJC_CALL1(rettype, retvar, obj, sel, a1) \
500 {rettype (*func)(const void *, SEL, ...) = (void *)__CFSendObjCMsg; \
501 static SEL s = NULL; if (!s) s = sel_registerName(sel); \
502 retvar = func((const void *)obj, s, (a1));}
503 #define CF_OBJC_CALL2(rettype, retvar, obj, sel, a1, a2) \
504 {rettype (*func)(const void *, SEL, ...) = (void *)__CFSendObjCMsg; \
505 static SEL s = NULL; if (!s) s = sel_registerName(sel); \
506 retvar = func((const void *)obj, s, (a1), (a2));}
508 // Invoke an ObjC method, return the result
509 #define CF_OBJC_FUNCDISPATCH0(typeID, rettype, obj, sel) \
510 if (__builtin_expect(CF_IS_OBJC(typeID, obj), 0)) \
511 {rettype (*func)(const void *, SEL) = (void *)__CFSendObjCMsg; \
512 static SEL s = NULL; if (!s) s = sel_registerName(sel); \
513 return func((const void *)obj, s);}
514 #define CF_OBJC_FUNCDISPATCH1(typeID, rettype, obj, sel, a1) \
515 if (__builtin_expect(CF_IS_OBJC(typeID, obj), 0)) \
516 {rettype (*func)(const void *, SEL, ...) = (void *)__CFSendObjCMsg; \
517 static SEL s = NULL; if (!s) s = sel_registerName(sel); \
518 return func((const void *)obj, s, (a1));}
519 #define CF_OBJC_FUNCDISPATCH2(typeID, rettype, obj, sel, a1, a2) \
520 if (__builtin_expect(CF_IS_OBJC(typeID, obj), 0)) \
521 {rettype (*func)(const void *, SEL, ...) = (void *)__CFSendObjCMsg; \
522 static SEL s = NULL; if (!s) s = sel_registerName(sel); \
523 return func((const void *)obj, s, (a1), (a2));}
524 #define CF_OBJC_FUNCDISPATCH3(typeID, rettype, obj, sel, a1, a2, a3) \
525 if (__builtin_expect(CF_IS_OBJC(typeID, obj), 0)) \
526 {rettype (*func)(const void *, SEL, ...) = (void *)__CFSendObjCMsg; \
527 static SEL s = NULL; if (!s) s = sel_registerName(sel); \
528 return func((const void *)obj, s, (a1), (a2), (a3));}
529 #define CF_OBJC_FUNCDISPATCH4(typeID, rettype, obj, sel, a1, a2, a3, a4) \
530 if (__builtin_expect(CF_IS_OBJC(typeID, obj), 0)) \
531 {rettype (*func)(const void *, SEL, ...) = (void *)__CFSendObjCMsg; \
532 static SEL s = NULL; if (!s) s = sel_registerName(sel); \
533 return func((const void *)obj, s, (a1), (a2), (a3), (a4));}
534 #define CF_OBJC_FUNCDISPATCH5(typeID, rettype, obj, sel, a1, a2, a3, a4, a5) \
535 if (__builtin_expect(CF_IS_OBJC(typeID, obj), 0)) \
536 {rettype (*func)(const void *, SEL, ...) = (void *)__CFSendObjCMsg; \
537 static SEL s = NULL; if (!s) s = sel_registerName(sel); \
538 return func((const void *)obj, s, (a1), (a2), (a3), (a4), (a5));}
542 /* See comments in CFBase.c
544 #if defined(__ppc__) && defined(__MACH__)
545 extern void __CF_FAULT_CALLBACK(void **ptr
);
546 extern void *__CF_INVOKE_CALLBACK(void *, ...);
548 #define FAULT_CALLBACK(V) __CF_FAULT_CALLBACK(V)
549 #define INVOKE_CALLBACK1(P, A) (((uintptr_t)(P) & 0x2) ? __CF_INVOKE_CALLBACK(P, A) : (P)(A))
550 #define INVOKE_CALLBACK2(P, A, B) (((uintptr_t)(P) & 0x2) ? __CF_INVOKE_CALLBACK(P, A, B) : (P)(A, B))
551 #define INVOKE_CALLBACK3(P, A, B, C) (((uintptr_t)(P) & 0x2) ? __CF_INVOKE_CALLBACK(P, A, B, C) : (P)(A, B, C))
552 #define INVOKE_CALLBACK4(P, A, B, C, D) (((uintptr_t)(P) & 0x2) ? __CF_INVOKE_CALLBACK(P, A, B, C, D) : (P)(A, B, C, D))
553 #define INVOKE_CALLBACK5(P, A, B, C, D, E) (((uintptr_t)(P) & 0x2) ? __CF_INVOKE_CALLBACK(P, A, B, C, D, E) : (P)(A, B, C, D, E))
555 #define FAULT_CALLBACK(V)
556 #define INVOKE_CALLBACK1(P, A) (P)(A)
557 #define INVOKE_CALLBACK2(P, A, B) (P)(A, B)
558 #define INVOKE_CALLBACK3(P, A, B, C) (P)(A, B, C)
559 #define INVOKE_CALLBACK4(P, A, B, C, D) (P)(A, B, C, D)
560 #define INVOKE_CALLBACK5(P, A, B, C, D, E) (P)(A, B, C, D, E)
563 #if defined(__MACH__)
565 /* For the support of functionality which needs CarbonCore or other frameworks */
566 extern void *__CFLookupCarbonCoreFunction(const char *name
);
567 extern void *__CFLookupCFNetworkFunction(const char *name
);
569 // These macros define an upcall or weak "symbol-lookup" wrapper function.
570 // The parameters are:
571 // R : the return type of the function
572 // N : the name of the function (in the other library)
573 // P : the parenthesized parameter list of the function
574 // A : the parenthesized actual argument list to be passed
575 // opt: a fifth optional argument can be passed in which is the
576 // return value of the wrapper when the function cannot be
577 // found; should be of type R, & can be a function call
578 // The name of the resulting wrapper function is:
579 // __CFCarbonCore_N (where N is the second parameter)
580 // __CFNetwork_N (where N is the second parameter)
583 // DEFINE_WEAK_CARBONCORE_FUNC(void, DisposeHandle, (Handle h), (h))
586 #define DEFINE_WEAK_CARBONCORE_FUNC(R, N, P, A, ...) \
587 static R __CFCarbonCore_ ## N P { \
588 static R (*dyfunc) P = (void *)(~(uintptr_t)0); \
589 if ((void *)(~(uintptr_t)0) == dyfunc) { \
590 dyfunc = __CFLookupCarbonCoreFunction(#N); } \
591 return dyfunc ? dyfunc A : (R)(0 , ## __VA_ARGS__); \
594 #define DEFINE_WEAK_CFNETWORK_FUNC(R, N, P, A, ...) \
595 static R __CFNetwork_ ## N P { \
596 static R (*dyfunc) P = (void *)(~(uintptr_t)0); \
597 if ((void *)(~(uintptr_t)0) == dyfunc) { \
598 dyfunc = __CFLookupCFNetworkFunction(#N); } \
599 return dyfunc ? dyfunc A : (R)(0 , ## __VA_ARGS__); \
604 #define DEFINE_WEAK_CARBONCORE_FUNC(R, N, P, A, ...)
605 #define DEFINE_WEAK_CFNETWORK_FUNC(R, N, P, A, ...)
610 __private_extern__ CFArrayRef
_CFBundleCopyUserLanguages(Boolean useBackstops
);
612 /* GC related internal SPIs. */
613 extern malloc_zone_t
*__CFCollectableZone
;
614 __private_extern__
void _CFStorageSetWeak(struct __CFStorage
*storage
);
616 #if defined(__WIN32__)
617 __private_extern__
const char *_CFDLLPath(void);
618 __private_extern__
void __CFStringCleanup(void);
619 __private_extern__
void __CFSocketCleanup(void);
620 __private_extern__
void __CFUniCharCleanup(void);
621 __private_extern__
void __CFStreamCleanup(void);
622 // We should export this as SPI or API to clients - 3514284
623 CF_EXPORT CFAbsoluteTime
_CFAbsoluteTimeFromFileTime(const FILETIME
*ft
);
626 #endif /* ! __COREFOUNDATION_CFINTERNAL__ */