Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generalize factory patterns for use outside of NSValue #1095

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
165b89a
Generalize factory patterns for use outside of NSValue
phausler Jul 3, 2017
8dc8ad8
Remove the CF base from NSNumber
phausler Jul 3, 2017
2077ee2
refine the documentation on _NSFactory
phausler Jul 3, 2017
417c95c
Remove the _CFNumberInit family since it is no longer used
phausler Jul 3, 2017
f5a686f
Extract NSCFNumber into its own type and seperate bridges into their …
phausler Jul 3, 2017
6b3324d
add a placeholder for NSString to String initialization
phausler Jul 5, 2017
bc5e153
Refactor NSTimeZone to use factory patterns
phausler Jul 5, 2017
33c2dc3
Re-work bridging for InputStream/OutputStream to use factory patterns
phausler Jul 5, 2017
4996aa0
Rework NSCharacterSet to use factory patterns and re-import Character…
phausler Jul 7, 2017
1489cff
add bridge callouts for CFCharacterSet and CFStream
phausler Jul 7, 2017
81066e1
Convert NSString to factory patterns and corect a few outstanding bug…
phausler Jun 28, 2017
e95183d
Update NSData to use factory patterns and update bridging patterns to…
phausler Jul 9, 2017
1d9ddb7
Conditionalize _ObjectiveCBridgeable to non DEPLOYMENT_RUNTIME_SWIFT …
phausler Jul 10, 2017
78c5784
Correct copyright notices to swift.org attribution
phausler Jul 10, 2017
96b3fbc
Avoid as cast in CharacterSet
phausler Jul 10, 2017
6fbdc1c
Avoid a warning for nullability of array elements
phausler Jul 10, 2017
873f171
memset and memmove are nonnull on linux
phausler Jul 10, 2017
6235e2a
restore hasPrefix and hasSuffix (and add substring calls for it)
phausler Jul 10, 2017
c78d3a1
Correct NSCopyMemoryPages memmove optionality
phausler Jul 10, 2017
96d32ed
Correct linux code path for free in NSDeallocateMemoryPages
phausler Jul 10, 2017
240dd54
Additional linux compatability shims for CF enum types and some addit…
phausler Jul 11, 2017
a0f964a
Remove unimplemented AutoreleasingUnsafeMutablePointer using function…
phausler Jul 12, 2017
e646150
Update constants and bit fields for linux/darwin compatability
phausler Jul 27, 2017
c64924e
Additional fixes for linux targets
phausler Jul 31, 2017
560d826
Migrate for numeric truncation
phausler Jul 31, 2017
31742c1
Recover from some merge damage in TestNSCharacterSet
phausler Jul 31, 2017
f5efffd
Add back in Codable support for CharacterSet
phausler Jul 31, 2017
ea11e17
use unsafeBitCast instead of _unsafeReferenceCast (which does not wor…
phausler Jul 31, 2017
c51f3d0
Convert to bit cast from extracted NS from NSCharacterSet.copy() to C…
phausler Jul 31, 2017
18713a7
Copy UTF32BE and UTF32LE data files to test resources
phausler Jul 31, 2017
8b18ee1
restore the 32BE/LE BOM test for path initialization
phausler Jul 31, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion CoreFoundation/Base.subproj/CFInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ CF_PRIVATE CFIndex __CFActiveProcessorCount();
#if defined(DEBUG)
#define CFAssert(cond, prio, desc) do { if (!(cond)) { CFLog(prio, CFSTR(desc)); /* HALT; */ } } while (0)
#define CFAssert1(cond, prio, desc, a1) do { if (!(cond)) { CFLog(prio, CFSTR(desc), a1); /* HALT; */ } } while (0)
#define CFAssert2(cond, prio, desc, a1, a2) do { if (!(cond)) { CFLog(prio, CFSTR(desc), a1, a2); /* HALT; */ } } while (0)
#define CFAssert2(cond, prio, desc, a1, a2) do { if (!(cond)) { CFLog(prio, CFSTR(desc), a1, a2); HALT; } } while (0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the HALT uncommented here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was using it to catch some failures in bridge casts

#define CFAssert3(cond, prio, desc, a1, a2, a3) do { if (!(cond)) { CFLog(prio, CFSTR(desc), a1, a2, a3); /* HALT; */ } } while (0)
#define CFAssert4(cond, prio, desc, a1, a2, a3, a4) do { if (!(cond)) { CFLog(prio, CFSTR(desc), a1, a2, a3, a4); /* HALT; */ } } while (0)
#else
Expand Down
30 changes: 24 additions & 6 deletions CoreFoundation/Base.subproj/CFRuntime.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
OBJC_EXPORT void *objc_destructInstance(id obj);
#endif

#if DEPLOYMENT_RUNTIME_SWIFT
extern void swift_retain(void *);
extern void swift_release(void *);
#endif

#if DEPLOYMENT_TARGET_WINDOWS
#include <Shellapi.h>
Expand Down Expand Up @@ -578,7 +582,13 @@ CFTypeID CFGetTypeID(CFTypeRef cf) {
#endif
CFTYPE_OBJC_FUNCDISPATCH0(CFTypeID, cf, _cfTypeID);
CFTYPE_SWIFT_FUNCDISPATCH0(CFTypeID, cf, NSObject._cfTypeID);

#if DEPLOYMENT_RUNTIME_SWIFT
if (!(cf != NULL && (NULL != __CFRuntimeClassTable[__CFGenericTypeID_inline(cf)]) && (__kCFNotATypeTypeID != __CFGenericTypeID_inline(cf)) && (__kCFTypeTypeID != __CFGenericTypeID_inline(cf)))) {
if (__kCFNotATypeTypeID == __CFGenericTypeID_inline(cf)) {
return __CFSwiftBridge.NSObject._cfTypeID(cf);
}
}
#endif
__CFGenericAssertIsCF(cf);
return __CFGenericTypeID_inline(cf);
}
Expand All @@ -599,6 +609,11 @@ CFTypeRef _CFNonObjCRetain(CFTypeRef cf) {

CFTypeRef CFRetain(CFTypeRef cf) {
if (NULL == cf) { CRSetCrashLogMessage("*** CFRetain() called with NULL ***"); HALT; }
#if DEPLOYMENT_RUNTIME_SWIFT
// We always call through to swift_retain, since all CFTypeRefs are at least _NSCFType objects
swift_retain((void *)cf);
return cf;
#endif
if (cf) __CFGenericAssertIsCF(cf);
return _CFRetain(cf, false);
}
Expand All @@ -617,6 +632,11 @@ void _CFNonObjCRelease(CFTypeRef cf) {

void CFRelease(CFTypeRef cf) {
if (NULL == cf) { CRSetCrashLogMessage("*** CFRelease() called with NULL ***"); HALT; }
#if DEPLOYMENT_RUNTIME_SWIFT
// We always call through to swift_retain, since all CFTypeRefs are at least _NSCFType objects
swift_release((void *)cf);
return;
#endif
#if 0
void **addrs[2] = {&&start, &&end};
start:;
Expand Down Expand Up @@ -779,6 +799,9 @@ CFHashCode CFHash(CFTypeRef cf) {
CFStringRef CFCopyDescription(CFTypeRef cf) {
if (NULL == cf) return NULL;
// CFTYPE_OBJC_FUNCDISPATCH0(CFStringRef, cf, _copyDescription); // XXX returns 0 refcounted item under GC
#if DEPLOYMENT_RUNTIME_SWIFT
CFTYPE_SWIFT_FUNCDISPATCH0(CFStringRef, cf, NSObject._copyDescription);
#endif
__CFGenericAssertIsCF(cf);
if (NULL != __CFRuntimeClassTable[__CFGenericTypeID_inline(cf)]->copyDebugDesc) {
CFStringRef result = __CFRuntimeClassTable[__CFGenericTypeID_inline(cf)]->copyDebugDesc(cf);
Expand Down Expand Up @@ -1276,11 +1299,6 @@ static bool (*CAS64)(int64_t, int64_t, volatile int64_t *) = OSAtomicCompareAndS
static bool (*CAS32)(int32_t, int32_t, volatile int32_t *) = OSAtomicCompareAndSwap32Barrier;
#endif

#if DEPLOYMENT_RUNTIME_SWIFT
extern void swift_retain(void *);
extern void swift_release(void *);
#endif

// For "tryR==true", a return of NULL means "failed".
static CFTypeRef _CFRetain(CFTypeRef cf, Boolean tryR) {
#if DEPLOYMENT_RUNTIME_SWIFT
Expand Down
18 changes: 2 additions & 16 deletions CoreFoundation/Base.subproj/ForFoundationOnly.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ typedef struct {
CFTypeRef _Null_unspecified (*_Null_unspecified fetchValue)(CFTypeRef context, void *domain, CFStringRef key); // Caller releases
void (*_Null_unspecified writeValue)(CFTypeRef context, void *domain, CFStringRef key, CFTypeRef value);
Boolean (*_Null_unspecified synchronize)(CFTypeRef context, void *domain);
void (*_Null_unspecified getKeysAndValues)(CFAllocatorRef _Nullable alloc, CFTypeRef context, void *domain, void *_Null_unspecified * _Null_unspecified buf[], CFIndex *numKeyValuePairs);
void (*_Null_unspecified getKeysAndValues)(CFAllocatorRef _Nullable alloc, CFTypeRef context, void *domain, void *_Null_unspecified * _Null_unspecified buf[_Null_unspecified], CFIndex *numKeyValuePairs);
CFDictionaryRef _Null_unspecified (*_Null_unspecified copyDomainDictionary)(CFTypeRef context, void *domain);
/* HACK - see comment on _CFPreferencesDomainSetIsWorldReadable(), below */
void (*setIsWorldReadable)(CFTypeRef context, void *domain, Boolean isWorldReadable);
Expand Down Expand Up @@ -304,7 +304,7 @@ CF_EXPORT Boolean __CFStringDecodeByteStream3(const UInt8 *bytes, CFIndex len, C

/* Convert single byte to Unicode; assumes one-to-one correspondence (that is, can only be used with 1-byte encodings). You can use the function if it's not NULL.
*/
CF_EXPORT Boolean (*__CFCharToUniCharFunc)(UInt32 flags, UInt8 ch, UniChar *unicodeChar);
CF_EXPORT Boolean (*_Nullable __CFCharToUniCharFunc)(UInt32 flags, UInt8 ch, UniChar *unicodeChar);

/* Character class functions UnicodeData-2_1_5.txt
*/
Expand Down Expand Up @@ -538,20 +538,6 @@ CF_INLINE CFHashCode _CFHashDouble(double d) {
return (CFHashCode)(integralHash + (CFHashCode)((d - dInt) * ULONG_MAX));
}

CF_SWIFT_EXPORT void _CFNumberInitBool(CFNumberRef result, Boolean value);
CF_SWIFT_EXPORT void _CFNumberInitInt8(CFNumberRef result, int8_t value);
CF_SWIFT_EXPORT void _CFNumberInitUInt8(CFNumberRef result, uint8_t value);
CF_SWIFT_EXPORT void _CFNumberInitInt16(CFNumberRef result, int16_t value);
CF_SWIFT_EXPORT void _CFNumberInitUInt16(CFNumberRef result, uint16_t value);
CF_SWIFT_EXPORT void _CFNumberInitInt32(CFNumberRef result, int32_t value);
CF_SWIFT_EXPORT void _CFNumberInitUInt32(CFNumberRef result, uint32_t value);
CF_SWIFT_EXPORT void _CFNumberInitInt(CFNumberRef result, long value);
CF_SWIFT_EXPORT void _CFNumberInitUInt(CFNumberRef result, unsigned long value);
CF_SWIFT_EXPORT void _CFNumberInitInt64(CFNumberRef result, int64_t value);
CF_SWIFT_EXPORT void _CFNumberInitUInt64(CFNumberRef result, uint64_t value);
CF_SWIFT_EXPORT void _CFNumberInitFloat(CFNumberRef result, float value);
CF_SWIFT_EXPORT void _CFNumberInitDouble(CFNumberRef result, double value);

/* These four functions are used by NSError in formatting error descriptions. They take NS or CFError as arguments and return a retained CFString or NULL.
*/
CF_EXPORT CFStringRef _CFErrorCreateLocalizedDescription(CFErrorRef err);
Expand Down
53 changes: 52 additions & 1 deletion CoreFoundation/Base.subproj/ForSwiftFoundationOnly.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ struct _NSObjectBridge {
CFHashCode (*hash)(CFTypeRef object);
bool (*isEqual)(CFTypeRef object, CFTypeRef other);
_Nonnull CFTypeRef (*_Nonnull copyWithZone)(_Nonnull CFTypeRef object, _Nullable CFTypeRef zone);
_Nonnull CFStringRef (*_Nonnull _copyDescription)(_Nonnull CFTypeRef object);
};

struct _NSArrayBridge {
Expand Down Expand Up @@ -211,7 +212,7 @@ struct _NSCharacterSetBridge {
_Nonnull CFMutableCharacterSetRef (*_Nonnull mutableCopy)(CFTypeRef cset);
bool (*_Nonnull longCharacterIsMember)(CFTypeRef cset, UTF32Char ch);
bool (*_Nonnull hasMemberInPlane)(CFTypeRef cset, uint8_t thePlane);
_Nonnull CFCharacterSetRef (*_Nonnull invertedSet)(CFTypeRef cset);
_Nonnull CFCharacterSetRef (*_Nonnull createInvertedSet)(CFTypeRef cset);
};

struct _NSMutableCharacterSetBridge {
Expand All @@ -230,6 +231,49 @@ struct _NSNumberBridge {
bool (*_Nonnull _getValue)(CFTypeRef number, void *value, CFNumberType type);
};

struct _NSInputStreamBridge {
CFStreamStatus (*_Nonnull streamStatus)(CFTypeRef stream);
CFStreamError (*_Nonnull _cfStreamError)(CFTypeRef stream);
CFErrorRef _Nullable (*_Nonnull streamError)(CFTypeRef stream);
void (*_Nonnull open)(CFTypeRef stream);
void (*_Nonnull close)(CFTypeRef stream);
bool (*_Nonnull hasBytesAvailable)(CFTypeRef stream);
CFIndex (*_Nonnull read)(CFTypeRef stream, uint8_t *buffer, CFIndex maxLength);
bool (*_Nonnull getBuffer)(CFTypeRef stream, uint8_t *_Nullable*_Nonnull bufferPtr, CFIndex *length);
CFTypeRef _Nullable (*_Nonnull copyPropertyForKey)(CFTypeRef stream, CFStringRef key);
bool (*_Nonnull setPropertyForKey)(CFTypeRef stream, CFTypeRef _Nullable value, CFStringRef key);
void (*_Nonnull scheduleWithRunLoop)(CFTypeRef stream, CFRunLoopRef rl, CFStringRef mode);
void (*_Nonnull unscheduleWithRunLoop)(CFTypeRef stream, CFRunLoopRef rl, CFStringRef mode);
};

struct _NSOutputStreamBridge {
CFStreamStatus (*_Nonnull streamStatus)(CFTypeRef stream);
CFStreamError (*_Nonnull _cfStreamError)(CFTypeRef stream);
CFErrorRef _Nullable (*_Nonnull streamError)(CFTypeRef stream);
void (*_Nonnull open)(CFTypeRef stream);
void (*_Nonnull close)(CFTypeRef stream);
bool (*_Nonnull hasSpaceAvailable)(CFTypeRef stream);
CFIndex (*_Nonnull write)(CFTypeRef stream, const uint8_t *buffer, CFIndex maxLength);
CFTypeRef _Nullable (*_Nonnull copyPropertyForKey)(CFTypeRef stream, CFStringRef key);
bool (*_Nonnull setPropertyForKey)(CFTypeRef stream, CFTypeRef _Nullable value, CFStringRef key);
void (*_Nonnull scheduleWithRunLoop)(CFTypeRef stream, CFRunLoopRef rl, CFStringRef mode);
void (*_Nonnull unscheduleWithRunLoop)(CFTypeRef stream, CFRunLoopRef rl, CFStringRef mode);
};

struct _NSDataBridge {
CFIndex (*_Nonnull length)(CFTypeRef data);
const void *_Nullable (*_Nonnull bytes)(CFTypeRef data);
void (*_Nonnull getBytes)(CFTypeRef data, void *buffer, CFRange range);
};

struct _NSMutableDataBridge {
uint8_t *_Nullable (*_Nonnull mutableBytes)(CFTypeRef data);
void (*_Nonnull setLength)(CFTypeRef data, CFIndex newLength);
void (*_Nonnull increaseLengthBy)(CFTypeRef data, CFIndex extraLength);
void (*_Nonnull appendBytes)(CFTypeRef data, const uint8_t *bytes, CFIndex length);
void (*_Nonnull replaceBytesInRange)(CFTypeRef data, CFRange range, void *_Nullable newBytes, CFIndex newLength);
};

struct _CFSwiftBridge {
struct _NSObjectBridge NSObject;
struct _NSArrayBridge NSArray;
Expand All @@ -245,6 +289,10 @@ struct _CFSwiftBridge {
struct _NSCharacterSetBridge NSCharacterSet;
struct _NSMutableCharacterSetBridge NSMutableCharacterSet;
struct _NSNumberBridge NSNumber;
struct _NSInputStreamBridge NSInputStream;
struct _NSOutputStreamBridge NSOutputStream;
struct _NSDataBridge NSData;
struct _NSMutableDataBridge NSMutableData;
};

CF_EXPORT struct _CFSwiftBridge __CFSwiftBridge;
Expand Down Expand Up @@ -286,6 +334,9 @@ extern CFIndex __CFBinaryPlistWriteToStream(CFPropertyListRef plist, CFTypeRef s
extern CFDataRef _CFPropertyListCreateXMLDataWithExtras(CFAllocatorRef allocator, CFPropertyListRef propertyList);
extern CFWriteStreamRef _CFWriteStreamCreateFromFileDescriptor(CFAllocatorRef alloc, int fd);

CF_EXPORT void *_Nullable _CFReadStreamGetClient(CFReadStreamRef readStream);
CF_EXPORT void *_Nullable _CFWriteStreamGetClient(CFWriteStreamRef writeStream);

extern _Nullable CFDateRef CFCalendarCopyGregorianStartDate(CFCalendarRef calendar);
extern void CFCalendarSetGregorianStartDate(CFCalendarRef calendar, CFDateRef date);

Expand Down
9 changes: 9 additions & 0 deletions CoreFoundation/Collections.subproj/CFData.c
Original file line number Diff line number Diff line change
Expand Up @@ -458,26 +458,30 @@ CFMutableDataRef CFDataCreateMutableCopy(CFAllocatorRef allocator, CFIndex capac

CFIndex CFDataGetLength(CFDataRef data) {
CF_OBJC_FUNCDISPATCHV(CFDataGetTypeID(), CFIndex, (NSData *)data, length);
CF_SWIFT_FUNCDISPATCHV(CFDataGetTypeID(), CFIndex, (CFSwiftRef)data, NSData.length);
__CFGenericValidateType(data, CFDataGetTypeID());
return __CFDataLength(data);
}

const uint8_t *CFDataGetBytePtr(CFDataRef data) {
CF_OBJC_FUNCDISPATCHV(CFDataGetTypeID(), const uint8_t *, (NSData *)data, bytes);
CF_SWIFT_FUNCDISPATCHV(CFDataGetTypeID(), const uint8_t *, (CFSwiftRef)data, NSData.bytes);
__CFGenericValidateType(data, CFDataGetTypeID());
// compaction: if inline, always do the computation.
return __CFDataBytesInline(data) ? (uint8_t *)__CFDataInlineBytesPtr(data) : data->_bytes;
}

uint8_t *CFDataGetMutableBytePtr(CFMutableDataRef data) {
CF_OBJC_FUNCDISPATCHV(CFDataGetTypeID(), uint8_t *, (NSMutableData *)data, mutableBytes);
CF_SWIFT_FUNCDISPATCHV(CFDataGetTypeID(), uint8_t *, (CFSwiftRef)data, NSMutableData.mutableBytes);
CFAssert1(__CFDataIsMutable(data), __kCFLogAssertion, "%s(): data is immutable", __PRETTY_FUNCTION__);
// compaction: if inline, always do the computation.
return __CFDataBytesInline(data) ? (uint8_t *)__CFDataInlineBytesPtr(data) : data->_bytes;
}

void CFDataGetBytes(CFDataRef data, CFRange range, uint8_t *buffer) {
CF_OBJC_FUNCDISPATCHV(CFDataGetTypeID(), void, (NSData *)data, getBytes:(void *)buffer range:NSMakeRange(range.location, range.length));
CF_SWIFT_FUNCDISPATCHV(CFDataGetTypeID(), void, (CFSwiftRef)data, NSData.getBytes, buffer, range);
__CFDataValidateRange(data, range, __PRETTY_FUNCTION__);
memmove(buffer, CFDataGetBytePtr(data) + range.location, range.length);
}
Expand Down Expand Up @@ -523,6 +527,7 @@ void CFDataSetLength(CFMutableDataRef data, CFIndex newLength) {
CFIndex oldLength, capacity;
Boolean isGrowable;
CF_OBJC_FUNCDISPATCHV(CFDataGetTypeID(), void, (NSMutableData *)data, setLength:(NSUInteger)newLength);
CF_SWIFT_FUNCDISPATCHV(CFDataGetTypeID(), void, (CFSwiftRef)data, NSMutableData.setLength, newLength);
CFAssert1(__CFDataIsMutable(data), __kCFLogAssertion, "%s(): data is immutable", __PRETTY_FUNCTION__);
oldLength = __CFDataLength(data);
capacity = __CFDataCapacity(data);
Expand Down Expand Up @@ -554,25 +559,29 @@ void CFDataSetLength(CFMutableDataRef data, CFIndex newLength) {

void CFDataIncreaseLength(CFMutableDataRef data, CFIndex extraLength) {
CF_OBJC_FUNCDISPATCHV(CFDataGetTypeID(), void, (NSMutableData *)data, increaseLengthBy:(NSUInteger)extraLength);
CF_SWIFT_FUNCDISPATCHV(CFDataGetTypeID(), void, (CFSwiftRef)data, NSMutableData.increaseLengthBy, extraLength);
CFAssert1(__CFDataIsMutable(data), __kCFLogAssertion, "%s(): data is immutable", __PRETTY_FUNCTION__);
if (extraLength < 0) HALT; // Avoid integer overflow.
CFDataSetLength(data, __CFDataLength(data) + extraLength);
}

void CFDataAppendBytes(CFMutableDataRef data, const uint8_t *bytes, CFIndex length) {
CF_OBJC_FUNCDISPATCHV(CFDataGetTypeID(), void, (NSMutableData *)data, appendBytes:(const void *)bytes length:(NSUInteger)length);
CF_SWIFT_FUNCDISPATCHV(CFDataGetTypeID(), void, (CFSwiftRef)data, NSMutableData.appendBytes, bytes, length);
CFAssert1(__CFDataIsMutable(data), __kCFLogAssertion, "%s(): data is immutable", __PRETTY_FUNCTION__);
CFDataReplaceBytes(data, CFRangeMake(__CFDataLength(data), 0), bytes, length);
}

void CFDataDeleteBytes(CFMutableDataRef data, CFRange range) {
CF_OBJC_FUNCDISPATCHV(CFDataGetTypeID(), void, (NSMutableData *)data, replaceBytesInRange:NSMakeRange(range.location, range.length) withBytes:NULL length:0);
CF_SWIFT_FUNCDISPATCHV(CFDataGetTypeID(), void, (CFSwiftRef)data, NSMutableData.replaceBytesInRange, range, NULL, 0);
CFAssert1(__CFDataIsMutable(data), __kCFLogAssertion, "%s(): data is immutable", __PRETTY_FUNCTION__);
CFDataReplaceBytes(data, range, NULL, 0);
}

void CFDataReplaceBytes(CFMutableDataRef data, CFRange range, const uint8_t *newBytes, CFIndex newLength) {
CF_OBJC_FUNCDISPATCHV(CFDataGetTypeID(), void, (NSMutableData *)data, replaceBytesInRange:NSMakeRange(range.location, range.length) withBytes:(const void *)newBytes length:(NSUInteger)newLength);
CF_SWIFT_FUNCDISPATCHV(CFDataGetTypeID(), void, (CFSwiftRef)data, NSMutableData.replaceBytesInRange, range, (const void *)newBytes, newLength);
__CFGenericValidateType(data, CFDataGetTypeID());
__CFDataValidateRange(data, range, __PRETTY_FUNCTION__);
CFAssert1(__CFDataIsMutable(data), __kCFLogAssertion, "%s(): data is immutable", __PRETTY_FUNCTION__);
Expand Down
90 changes: 0 additions & 90 deletions CoreFoundation/NumberDate.subproj/CFNumber.c
Original file line number Diff line number Diff line change
Expand Up @@ -1107,96 +1107,6 @@ static inline void _CFNumberInit(CFNumberRef result, CFNumberType type, const vo
__CFBitfieldSetValue(((struct __CFNumber *)result)->_base._cfinfo[CF_INFO_BITS], 4, 0, (uint8_t)__CFNumberTypeTable[type].canonicalType);
}

void _CFNumberInitInt128(CFNumberRef result, int64_t value) {
CFSInt128Struct int128value;
int128value.high = 0;
int128value.low = value;
_CFNumberInit(result, kCFNumberSInt128Type, &int128value);
}

void _CFNumberInitBool(CFNumberRef result, Boolean value) {
_CFNumberInit(result, kCFNumberCharType, &value);
}

void _CFNumberInitInt8(CFNumberRef result, int8_t value) {
_CFNumberInit(result, kCFNumberCharType, &value);
}

void _CFNumberInitUInt8(CFNumberRef result, uint8_t value) {
if (value > INT8_MAX) {
_CFNumberInitInt16(result, value);
} else {
_CFNumberInit(result, kCFNumberCharType, &value);
}
}

void _CFNumberInitInt16(CFNumberRef result, int16_t value) {
_CFNumberInit(result, kCFNumberShortType, &value);
}

void _CFNumberInitUInt16(CFNumberRef result, uint16_t value) {
if (value > INT16_MAX) {
_CFNumberInitInt32(result, value);
} else {
_CFNumberInit(result, kCFNumberShortType, &value);
}
}

void _CFNumberInitInt32(CFNumberRef result, int32_t value) {
_CFNumberInit(result, kCFNumberIntType, &value);
}

void _CFNumberInitUInt32(CFNumberRef result, uint32_t value) {
if (value > INT32_MAX) {
_CFNumberInitInt64(result, value);
} else {
_CFNumberInit(result, kCFNumberIntType, &value);
}
}

void _CFNumberInitInt(CFNumberRef result, long value) {
_CFNumberInit(result, kCFNumberLongType, &value);
}

void _CFNumberInitUInt(CFNumberRef result, unsigned long value) {
if (value > LONG_MAX) {
switch (sizeof(unsigned long)) {
case 4:
_CFNumberInitInt64(result, value);
break;

case 8:
_CFNumberInitInt128(result, value);
break;

default:
CFAssert1(false, __kCFLogAssertion, "Unexpected unsigned long type size: %d", sizeof(unsigned long));
}
} else {
_CFNumberInit(result, kCFNumberLongType, &value);
}
}

void _CFNumberInitInt64(CFNumberRef result, int64_t value) {
_CFNumberInit(result, kCFNumberLongLongType, &value);
}

void _CFNumberInitUInt64(CFNumberRef result, uint64_t value) {
if (value > INT64_MAX) {
_CFNumberInitInt128(result, value);
} else {
_CFNumberInit(result, kCFNumberLongLongType, &value);
}
}

void _CFNumberInitFloat(CFNumberRef result, float value) {
_CFNumberInit(result, kCFNumberFloatType, &value);
}

void _CFNumberInitDouble(CFNumberRef result, double value) {
_CFNumberInit(result, kCFNumberDoubleType, &value);
}

CFNumberRef CFNumberCreate(CFAllocatorRef allocator, CFNumberType type, const void *valuePtr) {
__CFAssertIsValidNumberType(type);
//printf("+ [%p] CFNumberCreate(%p, %d, %p)\n", pthread_self(), allocator, type, valuePtr);
Expand Down