* Copyright (c) 2014 Apple Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
- *
+ *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
- *
+ *
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
- *
+ *
* @APPLE_LICENSE_HEADER_END@
*/
/* CFArray.c
- Copyright (c) 1998-2013, Apple Inc. All rights reserved.
+ Copyright (c) 1998-2014, Apple Inc. All rights reserved.
Responsibility: Christopher Kane
*/
CF_INLINE bool hasBeenFinalized(CFTypeRef collection) {
return __CFBitfieldGetValue(((const CFRuntimeBase *)collection)->_cfinfo[CF_INFO_BITS], 5, 5) != 0;
}
-
+#if DEPLOYMENT_TARGET_MACOSX
CF_INLINE void markFinalized(CFTypeRef collection) {
__CFBitfieldSetValue(((CFRuntimeBase *)collection)->_cfinfo[CF_INFO_BITS], 5, 5, 1);
}
+#endif
CF_INLINE CFIndex __CFArrayGetType(CFArrayRef array) {
return __CFBitfieldGetValue(((const CFRuntimeBase *)array)->_cfinfo[CF_INFO_BITS], 1, 0);
__CFArrayCopyDescription
};
-CF_PRIVATE void __CFArrayInitialize(void) {
- __kCFArrayTypeID = _CFRuntimeRegisterClass(&__CFArrayClass);
-}
-
CFTypeID CFArrayGetTypeID(void) {
+ static dispatch_once_t initOnce;
+ dispatch_once(&initOnce, ^{ __kCFArrayTypeID = _CFRuntimeRegisterClass(&__CFArrayClass); });
return __kCFArrayTypeID;
}
case __kCFArrayDeque:
break;
}
- memory = (struct __CFArray*)_CFRuntimeCreateInstance(allocator, __kCFArrayTypeID, size, NULL);
+ memory = (struct __CFArray*)_CFRuntimeCreateInstance(allocator, CFArrayGetTypeID(), size, NULL);
if (NULL == memory) {
return NULL;
}
__CFBitfieldSetValue(flags, 3, 2, __kCFArrayHasCFTypeCallBacks);
UInt32 size = __CFArrayGetSizeOfType(flags) - sizeof(CFRuntimeBase);
size += numValues * sizeof(struct __CFArrayBucket);
- struct __CFArray *memory = (struct __CFArray*)_CFRuntimeCreateInstance(allocator, __kCFArrayTypeID, size, NULL);
+ struct __CFArray *memory = (struct __CFArray*)_CFRuntimeCreateInstance(allocator, CFArrayGetTypeID(), size, NULL);
if (NULL == memory) {
return NULL;
}
void* bucketsBase;
CFIndex numValues = CFArrayGetCount(array);
CFIndex idx;
- if (CF_IS_OBJC(__kCFArrayTypeID, array)) {
+ if (CF_IS_OBJC(CFArrayGetTypeID(), array)) {
cb = &kCFTypeArrayCallBacks;
} else {
cb = __CFArrayGetCallBacks(array);
const CFArrayCallBacks *cb;
CFIndex idx, numValues = CFArrayGetCount(array);
UInt32 flags;
- if (CF_IS_OBJC(__kCFArrayTypeID, array)) {
+ if (CF_IS_OBJC(CFArrayGetTypeID(), array)) {
cb = &kCFTypeArrayCallBacks;
}
else {
#endif
CFIndex CFArrayGetCount(CFArrayRef array) {
- CF_OBJC_FUNCDISPATCHV(__kCFArrayTypeID, CFIndex, (NSArray *)array, count);
- __CFGenericValidateType(array, __kCFArrayTypeID);
+ CF_OBJC_FUNCDISPATCHV(CFArrayGetTypeID(), CFIndex, (NSArray *)array, count);
+ __CFGenericValidateType(array, CFArrayGetTypeID());
CHECK_FOR_MUTATION(array);
return __CFArrayGetCount(array);
}
CFIndex CFArrayGetCountOfValue(CFArrayRef array, CFRange range, const void *value) {
CFIndex idx, count = 0;
- __CFGenericValidateType(array, __kCFArrayTypeID);
+ __CFGenericValidateType(array, CFArrayGetTypeID());
__CFArrayValidateRange(array, range, __PRETTY_FUNCTION__);
CHECK_FOR_MUTATION(array);
const CFArrayCallBacks *cb = CF_IS_OBJC(CFArrayGetTypeID(), array) ? &kCFTypeArrayCallBacks : __CFArrayGetCallBacks(array);
Boolean CFArrayContainsValue(CFArrayRef array, CFRange range, const void *value) {
CFIndex idx;
- __CFGenericValidateType(array, __kCFArrayTypeID);
+ __CFGenericValidateType(array, CFArrayGetTypeID());
__CFArrayValidateRange(array, range, __PRETTY_FUNCTION__);
CHECK_FOR_MUTATION(array);
const CFArrayCallBacks *cb = CF_IS_OBJC(CFArrayGetTypeID(), array) ? &kCFTypeArrayCallBacks : __CFArrayGetCallBacks(array);
}
const void *CFArrayGetValueAtIndex(CFArrayRef array, CFIndex idx) {
- CF_OBJC_FUNCDISPATCHV(__kCFArrayTypeID, const void *, (NSArray *)array, objectAtIndex:idx);
- __CFGenericValidateType(array, __kCFArrayTypeID);
+ CF_OBJC_FUNCDISPATCHV(CFArrayGetTypeID(), const void *, (NSArray *)array, objectAtIndex:idx);
+ __CFGenericValidateType(array, CFArrayGetTypeID());
CFAssert2(0 <= idx && idx < __CFArrayGetCount(array), __kCFLogAssertion, "%s(): index (%d) out of bounds", __PRETTY_FUNCTION__, idx);
CHECK_FOR_MUTATION(array);
return __CFArrayGetBucketAtIndex(array, idx)->_item;
void CFArrayGetValues(CFArrayRef array, CFRange range, const void **values) {
- CF_OBJC_FUNCDISPATCHV(__kCFArrayTypeID, void, (NSArray *)array, getObjects:(id *)values range:NSMakeRange(range.location, range.length));
- __CFGenericValidateType(array, __kCFArrayTypeID);
+ CF_OBJC_FUNCDISPATCHV(CFArrayGetTypeID(), void, (NSArray *)array, getObjects:(id *)values range:NSMakeRange(range.location, range.length));
+ __CFGenericValidateType(array, CFArrayGetTypeID());
__CFArrayValidateRange(array, range, __PRETTY_FUNCTION__);
CFAssert1(NULL != values, __kCFLogAssertion, "%s(): pointer to values may not be NULL", __PRETTY_FUNCTION__);
CHECK_FOR_MUTATION(array);
void CFArrayApplyFunction(CFArrayRef array, CFRange range, CFArrayApplierFunction applier, void *context) {
CFIndex idx;
FAULT_CALLBACK((void **)&(applier));
- __CFGenericValidateType(array, __kCFArrayTypeID);
+ __CFGenericValidateType(array, CFArrayGetTypeID());
__CFArrayValidateRange(array, range, __PRETTY_FUNCTION__);
CFAssert1(NULL != applier, __kCFLogAssertion, "%s(): pointer to applier function may not be NULL", __PRETTY_FUNCTION__);
CHECK_FOR_MUTATION(array);
CFIndex CFArrayGetFirstIndexOfValue(CFArrayRef array, CFRange range, const void *value) {
CFIndex idx;
- __CFGenericValidateType(array, __kCFArrayTypeID);
+ __CFGenericValidateType(array, CFArrayGetTypeID());
__CFArrayValidateRange(array, range, __PRETTY_FUNCTION__);
CHECK_FOR_MUTATION(array);
const CFArrayCallBacks *cb = CF_IS_OBJC(CFArrayGetTypeID(), array) ? &kCFTypeArrayCallBacks : __CFArrayGetCallBacks(array);
CFIndex CFArrayGetLastIndexOfValue(CFArrayRef array, CFRange range, const void *value) {
CFIndex idx;
- __CFGenericValidateType(array, __kCFArrayTypeID);
+ __CFGenericValidateType(array, CFArrayGetTypeID());
__CFArrayValidateRange(array, range, __PRETTY_FUNCTION__);
CHECK_FOR_MUTATION(array);
const CFArrayCallBacks *cb = CF_IS_OBJC(CFArrayGetTypeID(), array) ? &kCFTypeArrayCallBacks : __CFArrayGetCallBacks(array);
}
void CFArrayAppendValue(CFMutableArrayRef array, const void *value) {
- CF_OBJC_FUNCDISPATCHV(__kCFArrayTypeID, void, (NSMutableArray *)array, addObject:(id)value);
+ CF_OBJC_FUNCDISPATCHV(CFArrayGetTypeID(), void, (NSMutableArray *)array, addObject:(id)value);
- __CFGenericValidateType(array, __kCFArrayTypeID);
+ __CFGenericValidateType(array, CFArrayGetTypeID());
CFAssert1(__CFArrayGetType(array) != __kCFArrayImmutable, __kCFLogAssertion, "%s(): array is immutable", __PRETTY_FUNCTION__);
CHECK_FOR_MUTATION(array);
_CFArrayReplaceValues(array, CFRangeMake(__CFArrayGetCount(array), 0), &value, 1);
}
void CFArraySetValueAtIndex(CFMutableArrayRef array, CFIndex idx, const void *value) {
- CF_OBJC_FUNCDISPATCHV(__kCFArrayTypeID, void, (NSMutableArray *)array, setObject:(id)value atIndex:(NSUInteger)idx);
- __CFGenericValidateType(array, __kCFArrayTypeID);
+ CF_OBJC_FUNCDISPATCHV(CFArrayGetTypeID(), void, (NSMutableArray *)array, setObject:(id)value atIndex:(NSUInteger)idx);
+ __CFGenericValidateType(array, CFArrayGetTypeID());
CFAssert1(__CFArrayGetType(array) != __kCFArrayImmutable, __kCFLogAssertion, "%s(): array is immutable", __PRETTY_FUNCTION__);
CFAssert2(0 <= idx && idx <= __CFArrayGetCount(array), __kCFLogAssertion, "%s(): index (%d) out of bounds", __PRETTY_FUNCTION__, idx);
CHECK_FOR_MUTATION(array);
}
void CFArrayInsertValueAtIndex(CFMutableArrayRef array, CFIndex idx, const void *value) {
- CF_OBJC_FUNCDISPATCHV(__kCFArrayTypeID, void, (NSMutableArray *)array, insertObject:(id)value atIndex:(NSUInteger)idx);
- __CFGenericValidateType(array, __kCFArrayTypeID);
+ CF_OBJC_FUNCDISPATCHV(CFArrayGetTypeID(), void, (NSMutableArray *)array, insertObject:(id)value atIndex:(NSUInteger)idx);
+ __CFGenericValidateType(array, CFArrayGetTypeID());
CFAssert1(__CFArrayGetType(array) != __kCFArrayImmutable, __kCFLogAssertion, "%s(): array is immutable", __PRETTY_FUNCTION__);
CFAssert2(0 <= idx && idx <= __CFArrayGetCount(array), __kCFLogAssertion, "%s(): index (%d) out of bounds", __PRETTY_FUNCTION__, idx);
CHECK_FOR_MUTATION(array);
void CFArrayExchangeValuesAtIndices(CFMutableArrayRef array, CFIndex idx1, CFIndex idx2) {
const void *tmp;
struct __CFArrayBucket *bucket1, *bucket2;
- CF_OBJC_FUNCDISPATCHV(__kCFArrayTypeID, void, (NSMutableArray *)array, exchangeObjectAtIndex:(NSUInteger)idx1 withObjectAtIndex:(NSUInteger)idx2);
- __CFGenericValidateType(array, __kCFArrayTypeID);
+ CF_OBJC_FUNCDISPATCHV(CFArrayGetTypeID(), void, (NSMutableArray *)array, exchangeObjectAtIndex:(NSUInteger)idx1 withObjectAtIndex:(NSUInteger)idx2);
+ __CFGenericValidateType(array, CFArrayGetTypeID());
CFAssert2(0 <= idx1 && idx1 < __CFArrayGetCount(array), __kCFLogAssertion, "%s(): index #1 (%d) out of bounds", __PRETTY_FUNCTION__, idx1);
CFAssert2(0 <= idx2 && idx2 < __CFArrayGetCount(array), __kCFLogAssertion, "%s(): index #2 (%d) out of bounds", __PRETTY_FUNCTION__, idx2);
CFAssert1(__CFArrayGetType(array) != __kCFArrayImmutable, __kCFLogAssertion, "%s(): array is immutable", __PRETTY_FUNCTION__);
}
void CFArrayRemoveValueAtIndex(CFMutableArrayRef array, CFIndex idx) {
- CF_OBJC_FUNCDISPATCHV(__kCFArrayTypeID, void, (NSMutableArray *)array, removeObjectAtIndex:(NSUInteger)idx);
- __CFGenericValidateType(array, __kCFArrayTypeID);
+ CF_OBJC_FUNCDISPATCHV(CFArrayGetTypeID(), void, (NSMutableArray *)array, removeObjectAtIndex:(NSUInteger)idx);
+ __CFGenericValidateType(array, CFArrayGetTypeID());
CFAssert1(__CFArrayGetType(array) != __kCFArrayImmutable, __kCFLogAssertion, "%s(): array is immutable", __PRETTY_FUNCTION__);
CFAssert2(0 <= idx && idx < __CFArrayGetCount(array), __kCFLogAssertion, "%s(): index (%d) out of bounds", __PRETTY_FUNCTION__, idx);
CHECK_FOR_MUTATION(array);
}
void CFArrayRemoveAllValues(CFMutableArrayRef array) {
- CF_OBJC_FUNCDISPATCHV(__kCFArrayTypeID, void, (NSMutableArray *)array, removeAllObjects);
- __CFGenericValidateType(array, __kCFArrayTypeID);
+ CF_OBJC_FUNCDISPATCHV(CFArrayGetTypeID(), void, (NSMutableArray *)array, removeAllObjects);
+ __CFGenericValidateType(array, CFArrayGetTypeID());
CFAssert1(__CFArrayGetType(array) != __kCFArrayImmutable, __kCFLogAssertion, "%s(): array is immutable", __PRETTY_FUNCTION__);
CHECK_FOR_MUTATION(array);
BEGIN_MUTATION(array);
// This function is for Foundation's benefit; no one else should use it.
void _CFArraySetCapacity(CFMutableArrayRef array, CFIndex cap) {
- if (CF_IS_OBJC(__kCFArrayTypeID, array)) return;
- __CFGenericValidateType(array, __kCFArrayTypeID);
+ if (CF_IS_OBJC(CFArrayGetTypeID(), array)) return;
+ __CFGenericValidateType(array, CFArrayGetTypeID());
CFAssert1(__CFArrayGetType(array) != __kCFArrayImmutable, __kCFLogAssertion, "%s(): array is immutable", __PRETTY_FUNCTION__);
CFAssert3(__CFArrayGetCount(array) <= cap, __kCFLogAssertion, "%s(): desired capacity (%d) is less than count (%d)", __PRETTY_FUNCTION__, cap, __CFArrayGetCount(array));
CHECK_FOR_MUTATION(array);
void CFArrayReplaceValues(CFMutableArrayRef array, CFRange range, const void **newValues, CFIndex newCount) {
- CF_OBJC_FUNCDISPATCHV(__kCFArrayTypeID, void, (NSMutableArray *)array, replaceObjectsInRange:NSMakeRange(range.location, range.length) withObjects:(id *)newValues count:(NSUInteger)newCount);
- __CFGenericValidateType(array, __kCFArrayTypeID);
+ CF_OBJC_FUNCDISPATCHV(CFArrayGetTypeID(), void, (NSMutableArray *)array, replaceObjectsInRange:NSMakeRange(range.location, range.length) withObjects:(id *)newValues count:(NSUInteger)newCount);
+ __CFGenericValidateType(array, CFArrayGetTypeID());
__CFArrayValidateRange(array, range, __PRETTY_FUNCTION__);
CFAssert1(__CFArrayGetType(array) != __kCFArrayImmutable, __kCFLogAssertion, "%s(): array is immutable", __PRETTY_FUNCTION__);
CFAssert2(0 <= newCount, __kCFLogAssertion, "%s(): newCount (%d) cannot be less than zero", __PRETTY_FUNCTION__, newCount);
__CFArrayValidateRange(array, range, __PRETTY_FUNCTION__);
CFAssert1(NULL != comparator, __kCFLogAssertion, "%s(): pointer to comparator function may not be NULL", __PRETTY_FUNCTION__);
Boolean immutable = false;
- if (CF_IS_OBJC(__kCFArrayTypeID, array)) {
+ if (CF_IS_OBJC(CFArrayGetTypeID(), array)) {
BOOL result;
result = CF_OBJC_CALLV((NSMutableArray *)array, isKindOfClass:[NSMutableArray class]);
immutable = !result;
immutable = true;
}
const CFArrayCallBacks *cb = NULL;
- if (CF_IS_OBJC(__kCFArrayTypeID, array)) {
+ if (CF_IS_OBJC(CFArrayGetTypeID(), array)) {
cb = &kCFTypeArrayCallBacks;
} else {
cb = __CFArrayGetCallBacks(array);