Skip to content

Commit 249fb16

Browse files
committed
Revert "Update for SE-0055: Making pointer nullability explicit." (#312)
Temporarily reverting while we sort out plans.
1 parent f5d35ed commit 249fb16

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+489
-376
lines changed

CoreFoundation/Base.subproj/ForFoundationOnly.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ enum {
588588
// This is for NSNumberFormatter use only!
589589
CF_EXPORT void *_CFNumberFormatterGetFormatter(CFNumberFormatterRef formatter);
590590

591-
CF_EXPORT void _CFDataInit(CFMutableDataRef memory, CFOptionFlags flags, CFIndex capacity, const uint8_t * _Nullable bytes, CFIndex length, Boolean noCopy);
591+
CF_EXPORT void _CFDataInit(CFMutableDataRef memory, CFOptionFlags flags, CFIndex capacity, const uint8_t *bytes, CFIndex length, Boolean noCopy);
592592
CF_EXPORT CFRange _CFDataFindBytes(CFDataRef data, CFDataRef dataToFind, CFRange searchRange, CFDataSearchFlags compareOptions);
593593

594594

CoreFoundation/Base.subproj/ForSwiftFoundationOnly.h

+11-11
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ struct _NSObjectBridge {
5454
struct _NSArrayBridge {
5555
CFIndex (*_Nonnull count)(CFTypeRef obj);
5656
_Nonnull CFTypeRef (*_Nonnull objectAtIndex)(CFTypeRef obj, CFIndex index);
57-
void (*_Nonnull getObjects)(CFTypeRef array, CFRange range, CFTypeRef _Nullable *_Nonnull values);
57+
void (*_Nonnull getObjects)(CFTypeRef array, CFRange range, CFTypeRef _Nonnull * _Nonnull values);
5858
};
5959

6060
struct _NSMutableArrayBridge {
@@ -73,11 +73,11 @@ struct _NSDictionaryBridge {
7373
CFIndex (*countForKey)(CFTypeRef dictionary, CFTypeRef key);
7474
bool (*containsKey)(CFTypeRef dictionary, CFTypeRef key);
7575
_Nullable CFTypeRef (*_Nonnull objectForKey)(CFTypeRef dictionary, CFTypeRef key);
76-
bool (*_getValueIfPresent)(CFTypeRef dictionary, CFTypeRef key, CFTypeRef _Nullable *_Nullable value);
76+
bool (*_getValueIfPresent)(CFTypeRef dictionary, CFTypeRef key, CFTypeRef _Nonnull * _Nullable value);
7777
CFIndex (*__getValue)(CFTypeRef dictionary, CFTypeRef value, CFTypeRef key);
7878
bool (*containsObject)(CFTypeRef dictionary, CFTypeRef value);
7979
CFIndex (*countForObject)(CFTypeRef dictionary, CFTypeRef value);
80-
void (*getObjects)(CFTypeRef dictionary, CFTypeRef _Nullable *_Nullable valuebuf, CFTypeRef _Nullable *_Nullable keybuf);
80+
void (*getObjects)(CFTypeRef dictionary, CFTypeRef _Nonnull * _Nonnull valuebuf, CFTypeRef _Nonnull * _Nonnull keybuf);
8181
void (*__apply)(CFTypeRef dictionary, void (*applier)(CFTypeRef key, CFTypeRef value, void *context), void *context);
8282
};
8383

@@ -104,7 +104,7 @@ struct _NSStringBridge {
104104
CFIndex (*length)(CFTypeRef str);
105105
UniChar (*characterAtIndex)(CFTypeRef str, CFIndex idx);
106106
void (*getCharacters)(CFTypeRef str, CFRange range, UniChar *buffer);
107-
CFIndex (*__getBytes)(CFTypeRef str, CFStringEncoding encoding, CFRange range, uint8_t *_Nullable buffer, CFIndex maxBufLen, CFIndex *_Nullable usedBufLen);
107+
CFIndex (*__getBytes)(CFTypeRef str, CFStringEncoding encoding, CFRange range, uint8_t *buffer, CFIndex maxBufLen, CFIndex *usedBufLen);
108108
const char *_Nullable (*_Nonnull _fastCStringContents)(CFTypeRef str);
109109
const UniChar *_Nullable (*_Nonnull _fastCharacterContents)(CFTypeRef str);
110110
bool (*_getCString)(CFTypeRef str, char *buffer, size_t len, UInt32 encoding);
@@ -123,15 +123,15 @@ struct _NSMutableStringBridge {
123123

124124
struct _NSXMLParserBridge {
125125
_CFXMLInterface _Nullable (*_Nonnull currentParser)();
126-
_CFXMLInterfaceParserInput _Nullable (*_Nonnull _xmlExternalEntityWithURL)(_CFXMLInterface interface, const char *url, const char * identifier, _CFXMLInterfaceParserContext context, _CFXMLInterfaceExternalEntityLoader originalLoaderFunction);
126+
_CFXMLInterfaceParserInput _Nonnull (*_Nonnull _xmlExternalEntityWithURL)(_CFXMLInterface interface, const char *url, const char * identifier, _CFXMLInterfaceParserContext context, _CFXMLInterfaceExternalEntityLoader originalLoaderFunction);
127127

128128
_CFXMLInterfaceParserContext _Nonnull (*_Nonnull getContext)(_CFXMLInterface ctx);
129129

130130
void (*internalSubset)(_CFXMLInterface ctx, const unsigned char *name, const unsigned char *ExternalID, const unsigned char *SystemID);
131131
int (*isStandalone)(_CFXMLInterface ctx);
132132
int (*hasInternalSubset)(_CFXMLInterface ctx);
133133
int (*hasExternalSubset)(_CFXMLInterface ctx);
134-
_CFXMLInterfaceEntity _Nullable (*_Nonnull getEntity)(_CFXMLInterface ctx, const unsigned char *name);
134+
_CFXMLInterfaceEntity _Nonnull (*_Nonnull getEntity)(_CFXMLInterface ctx, const unsigned char *name);
135135
void (*notationDecl)(_CFXMLInterface ctx,
136136
const unsigned char *name,
137137
const unsigned char *publicId,
@@ -156,16 +156,16 @@ struct _NSXMLParserBridge {
156156
void (*endDocument)(_CFXMLInterface ctx);
157157
void (*startElementNs)(_CFXMLInterface ctx,
158158
const unsigned char *localname,
159-
const unsigned char *_Nullable prefix,
159+
const unsigned char *prefix,
160160
const unsigned char *URI,
161161
int nb_namespaces,
162-
const unsigned char *_Nullable *_Nonnull namespaces,
162+
const unsigned char *_Nonnull *_Nonnull namespaces,
163163
int nb_attributes,
164164
int nb_defaulted,
165-
const unsigned char *_Nullable *_Nonnull attributes);
165+
const unsigned char *_Nonnull *_Nonnull attributes);
166166
void (*endElementNs)(_CFXMLInterface ctx,
167167
const unsigned char *localname,
168-
const unsigned char *_Nullable prefix,
168+
const unsigned char *prefix,
169169
const unsigned char *URI);
170170
void (*characters)(_CFXMLInterface ctx,
171171
const unsigned char *ch,
@@ -239,7 +239,7 @@ extern CFWriteStreamRef _CFWriteStreamCreateFromFileDescriptor(CFAllocatorRef al
239239
extern _Nullable CFDateRef CFCalendarCopyGregorianStartDate(CFCalendarRef calendar);
240240
extern void CFCalendarSetGregorianStartDate(CFCalendarRef calendar, CFDateRef date);
241241

242-
CF_PRIVATE CF_EXPORT char *_Nullable *_Nonnull _CFEnviron(void);
242+
CF_PRIVATE CF_EXPORT char *_Nonnull*_Nonnull _CFEnviron(void);
243243

244244
CF_EXPORT void CFLog1(CFLogLevel lev, CFStringRef message);
245245

CoreFoundation/Parsing.subproj/CFXMLInterface.h

+11-11
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ typedef void* _CFXMLEntityPtr;
136136
typedef void* _CFXMLDTDPtr;
137137
typedef void* _CFXMLDTDNodePtr;
138138

139-
_CFXMLNodePtr _CFXMLNewNode(_CFXMLNamespacePtr _Nullable namespace, const char* name);
139+
_CFXMLNodePtr _CFXMLNewNode(_CFXMLNamespacePtr namespace, const char* name);
140140
_CFXMLNodePtr _CFXMLCopyNode(_CFXMLNodePtr node, bool recursive);
141141

142142
_CFXMLDocPtr _CFXMLNewDoc(const unsigned char* version);
@@ -147,7 +147,7 @@ _CFXMLNodePtr _CFXMLNewProperty(_CFXMLNodePtr _Nullable node, const unsigned cha
147147
_CFXMLNamespacePtr _CFXMLNewNamespace(_CFXMLNodePtr _Nullable node, const unsigned char* uri, const unsigned char* prefix);
148148

149149
CF_RETURNS_RETAINED CFStringRef _Nullable _CFXMLNodeURI(_CFXMLNodePtr node);
150-
void _CFXMLNodeSetURI(_CFXMLNodePtr node, const unsigned char* _Nullable URI);
150+
void _CFXMLNodeSetURI(_CFXMLNodePtr node, const unsigned char* URI);
151151

152152
void _CFXMLNodeSetPrivateData(_CFXMLNodePtr node, void* data);
153153
void* _Nullable _CFXMLNodeGetPrivateData(_CFXMLNodePtr node);
@@ -156,7 +156,7 @@ CFIndex _CFXMLNodeGetType(_CFXMLNodePtr node);
156156
const char* _CFXMLNodeGetName(_CFXMLNodePtr node);
157157
void _CFXMLNodeSetName(_CFXMLNodePtr node, const char* name);
158158
CF_RETURNS_RETAINED CFStringRef _Nullable _CFXMLNodeGetContent(_CFXMLNodePtr node);
159-
void _CFXMLNodeSetContent(_CFXMLNodePtr node, const unsigned char* _Nullable content);
159+
void _CFXMLNodeSetContent(_CFXMLNodePtr node, const unsigned char* _Nullable content);
160160
void _CFXMLUnlinkNode(_CFXMLNodePtr node);
161161

162162
_CFXMLNodePtr _Nullable _CFXMLNodeGetFirstChild(_CFXMLNodePtr node);
@@ -179,13 +179,13 @@ void _CFXMLDocSetRootElement(_CFXMLDocPtr doc, _CFXMLNodePtr node);
179179
CF_RETURNS_RETAINED CFStringRef _Nullable _CFXMLDocCharacterEncoding(_CFXMLDocPtr doc);
180180
void _CFXMLDocSetCharacterEncoding(_CFXMLDocPtr doc, const unsigned char* _Nullable encoding);
181181
CF_RETURNS_RETAINED CFStringRef _Nullable _CFXMLDocVersion(_CFXMLDocPtr doc);
182-
void _CFXMLDocSetVersion(_CFXMLDocPtr doc, const unsigned char* _Nullable version);
182+
void _CFXMLDocSetVersion(_CFXMLDocPtr doc, const unsigned char* version);
183183
int _CFXMLDocProperties(_CFXMLDocPtr doc);
184184
void _CFXMLDocSetProperties(_CFXMLDocPtr doc, int newProperties);
185185
_CFXMLDTDPtr _Nullable _CFXMLDocDTD(_CFXMLDocPtr doc);
186186
void _CFXMLDocSetDTD(_CFXMLDocPtr doc, _CFXMLDTDPtr _Nullable dtd);
187187

188-
CF_RETURNS_RETAINED CFStringRef _Nullable _CFXMLEncodeEntities(_CFXMLDocPtr _Nullable doc, const unsigned char* string);
188+
CF_RETURNS_RETAINED CFStringRef _Nullable _CFXMLEncodeEntities(_CFXMLDocPtr doc, const unsigned char* string);
189189
_CFXMLEntityPtr _Nullable _CFXMLGetDocEntity(_CFXMLDocPtr doc, const char* entity);
190190
_CFXMLEntityPtr _Nullable _CFXMLGetDTDEntity(_CFXMLDocPtr doc, const char* entity);
191191
_CFXMLEntityPtr _Nullable _CFXMLGetParameterEntity(_CFXMLDocPtr doc, const char* entity);
@@ -205,32 +205,32 @@ CF_RETURNS_RETAINED CFStringRef _Nullable _CFXMLNodePrefix(_CFXMLNodePtr node);
205205

206206
bool _CFXMLDocValidate(_CFXMLDocPtr doc, CFErrorRef _Nullable * error);
207207

208-
_CFXMLDTDPtr _CFXMLNewDTD(_CFXMLDocPtr _Nullable doc, const unsigned char* name, const unsigned char* publicID, const unsigned char* systemID);
208+
_CFXMLDTDPtr _CFXMLNewDTD(_CFXMLDocPtr doc, const unsigned char* name, const unsigned char* publicID, const unsigned char* systemID);
209209
_CFXMLDTDNodePtr _Nullable _CFXMLParseDTDNode(const unsigned char* xmlString);
210210
_CFXMLDTDPtr _Nullable _CFXMLParseDTD(const unsigned char* URL);
211211
_CFXMLDTDPtr _Nullable _CFXMLParseDTDFromData(CFDataRef data, CFErrorRef _Nullable * error);
212212
CF_RETURNS_RETAINED CFStringRef _Nullable _CFXMLDTDExternalID(_CFXMLDTDPtr dtd);
213-
void _CFXMLDTDSetExternalID(_CFXMLDTDPtr dtd, const unsigned char* _Nullable externalID);
213+
void _CFXMLDTDSetExternalID(_CFXMLDTDPtr dtd, const unsigned char* externalID);
214214
CF_RETURNS_RETAINED CFStringRef _Nullable _CFXMLDTDSystemID(_CFXMLDTDPtr dtd);
215-
void _CFXMLDTDSetSystemID(_CFXMLDTDPtr dtd, const unsigned char* _Nullable systemID);
215+
void _CFXMLDTDSetSystemID(_CFXMLDTDPtr dtd, const unsigned char* systemID);
216216

217217
_CFXMLDTDNodePtr _Nullable _CFXMLDTDGetElementDesc(_CFXMLDTDPtr dtd, const unsigned char* name);
218218
_CFXMLDTDNodePtr _Nullable _CFXMLDTDGetAttributeDesc(_CFXMLDTDPtr dtd, const unsigned char* elementName, const unsigned char* name);
219219
_CFXMLDTDNodePtr _Nullable _CFXMLDTDGetNotationDesc(_CFXMLDTDPtr dtd, const unsigned char* name);
220220
_CFXMLDTDNodePtr _Nullable _CFXMLDTDGetEntityDesc(_CFXMLDTDPtr dtd, const unsigned char* name);
221221
_CFXMLDTDNodePtr _Nullable _CFXMLDTDGetPredefinedEntity(const unsigned char* name);
222222

223-
_CFXMLDTDNodePtr _Nullable _CFXMLDTDNewElementDesc(_CFXMLDTDPtr _Nullable dtd, const unsigned char* _Nullable name);
223+
_CFXMLDTDNodePtr _Nullable _CFXMLDTDNewElementDesc(_CFXMLDTDPtr dtd, const unsigned char* name);
224224
_CFXMLDTDNodePtr _Nullable _CFXMLDTDNewAttributeDesc(_CFXMLDTDPtr dtd, const unsigned char* name);
225225

226226
CFIndex _CFXMLDTDElementNodeGetType(_CFXMLDTDNodePtr node);
227227
CFIndex _CFXMLDTDEntityNodeGetType(_CFXMLDTDNodePtr node);
228228
CFIndex _CFXMLDTDAttributeNodeGetType(_CFXMLDTDNodePtr node);
229229

230230
CF_RETURNS_RETAINED CFStringRef _Nullable _CFXMLDTDNodeGetSystemID(_CFXMLDTDNodePtr node);
231-
void _CFXMLDTDNodeSetSystemID(_CFXMLDTDNodePtr node, const unsigned char* _Nullable systemID);
231+
void _CFXMLDTDNodeSetSystemID(_CFXMLDTDNodePtr node, const unsigned char* systemID);
232232
CF_RETURNS_RETAINED CFStringRef _Nullable _CFXMLDTDNodeGetPublicID(_CFXMLDTDNodePtr node);
233-
void _CFXMLDTDNodeSetPublicID(_CFXMLDTDNodePtr node, const unsigned char* _Nullable publicID);
233+
void _CFXMLDTDNodeSetPublicID(_CFXMLDTDNodePtr node, const unsigned char* publicID);
234234

235235
void _CFXMLFreeNode(_CFXMLNodePtr node);
236236
void _CFXMLFreeDocument(_CFXMLDocPtr doc);

Foundation/NSArray.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NS
5555
}
5656

5757
public convenience override init() {
58-
self.init(objects: [], count:0)
58+
self.init(objects: nil, count:0)
5959
}
6060

6161
public required init(objects: UnsafePointer<AnyObject?>, count cnt: Int) {
@@ -359,13 +359,13 @@ public class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NS
359359
return NSData(bytesNoCopy: unsafeBitCast(buffer, to: UnsafeMutablePointer<Void>.self), length: count * sizeof(Int), freeWhenDone: true)
360360
}
361361

362-
public func sortedArrayUsingFunction(_ comparator: @convention(c) (AnyObject, AnyObject, UnsafeMutablePointer<Void>?) -> Int, context: UnsafeMutablePointer<Void>?) -> [AnyObject] {
362+
public func sortedArrayUsingFunction(_ comparator: @convention(c) (AnyObject, AnyObject, UnsafeMutablePointer<Void>) -> Int, context: UnsafeMutablePointer<Void>) -> [AnyObject] {
363363
return sortedArrayWithOptions([]) { lhs, rhs in
364364
return NSComparisonResult(rawValue: comparator(lhs, rhs, context))!
365365
}
366366
}
367367

368-
public func sortedArrayUsingFunction(_ comparator: @convention(c) (AnyObject, AnyObject, UnsafeMutablePointer<Void>?) -> Int, context: UnsafeMutablePointer<Void>?, hint: NSData?) -> [AnyObject] {
368+
public func sortedArrayUsingFunction(_ comparator: @convention(c) (AnyObject, AnyObject, UnsafeMutablePointer<Void>) -> Int, context: UnsafeMutablePointer<Void>, hint: NSData?) -> [AnyObject] {
369369
return sortedArrayWithOptions([]) { lhs, rhs in
370370
return NSComparisonResult(rawValue: comparator(lhs, rhs, context))!
371371
}
@@ -653,7 +653,7 @@ public class NSMutableArray : NSArray {
653653
}
654654

655655
public init(capacity numItems: Int) {
656-
super.init(objects: [], count: 0)
656+
super.init(objects: nil, count: 0)
657657

658658
if self.dynamicType === NSMutableArray.self {
659659
_storage.reserveCapacity(numItems)
@@ -807,7 +807,7 @@ public class NSMutableArray : NSArray {
807807
}
808808
}
809809

810-
public func sortUsingFunction(_ compare: @convention(c) (AnyObject, AnyObject, UnsafeMutablePointer<Void>?) -> Int, context: UnsafeMutablePointer<Void>?) {
810+
public func sortUsingFunction(_ compare: @convention(c) (AnyObject, AnyObject, UnsafeMutablePointer<Void>) -> Int, context: UnsafeMutablePointer<Void>) {
811811
self.setArray(self.sortedArrayUsingFunction(compare, context: context))
812812
}
813813

Foundation/NSCFArray.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ internal func _CFSwiftArrayRemoveAllValues(_ array: AnyObject) {
8989
(array as! NSMutableArray).removeAllObjects()
9090
}
9191

92-
internal func _CFSwiftArrayReplaceValues(_ array: AnyObject, _ range: CFRange, _ newValues: UnsafeMutablePointer<Unmanaged<AnyObject>>, _ newCount: CFIndex) {
92+
internal func _CFSwiftArrayReplaceValues(_ array: AnyObject, _ range: CFRange, _ newValues: UnsafeMutablePointer<Unmanaged<AnyObject>?>, _ newCount: CFIndex) {
9393
NSUnimplemented()
9494
// (array as! NSMutableArray).replaceObjectsInRange(NSMakeRange(range.location, range.length), withObjectsFromArray: newValues.array(newCount))
9595
}

Foundation/NSCFDictionary.swift

+12-8
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ internal final class _NSCFDictionary : NSMutableDictionary {
6464
let cf = dict._cfObject
6565
count = CFDictionaryGetCount(cf)
6666

67-
let keys = UnsafeMutablePointer<UnsafePointer<Void>?>(allocatingCapacity: count)
67+
let keys = UnsafeMutablePointer<UnsafePointer<Void>>(allocatingCapacity: count)
6868
CFDictionaryGetKeysAndValues(cf, keys, nil)
6969

7070
for idx in 0..<count {
71-
let key = unsafeBitCast(keys.advanced(by: idx).pointee!, to: NSObject.self)
71+
let key = unsafeBitCast(keys.advanced(by: idx).pointee, to: NSObject.self)
7272
keyArray.append(key)
7373
}
7474
keys.deinitialize()
@@ -118,12 +118,12 @@ internal func _CFSwiftDictionaryGetValue(_ dictionary: AnyObject, key: AnyObject
118118
}
119119
}
120120

121-
internal func _CFSwiftDictionaryGetValueIfPresent(_ dictionary: AnyObject, key: AnyObject, value: UnsafeMutablePointer<Unmanaged<AnyObject>?>?) -> Bool {
121+
internal func _CFSwiftDictionaryGetValueIfPresent(_ dictionary: AnyObject, key: AnyObject, value: UnsafeMutablePointer<Unmanaged<AnyObject>?>) -> Bool {
122122
if let val = _CFSwiftDictionaryGetValue(dictionary, key: key) {
123-
value?.pointee = val
123+
value.pointee = val
124124
return true
125125
} else {
126-
value?.pointee = nil
126+
value.pointee = nil
127127
return false
128128
}
129129
}
@@ -140,14 +140,18 @@ internal func _CFSwiftDictionaryContainsValue(_ dictionary: AnyObject, value: An
140140
NSUnimplemented()
141141
}
142142

143-
internal func _CFSwiftDictionaryGetValuesAndKeys(_ dictionary: AnyObject, valuebuf: UnsafeMutablePointer<Unmanaged<AnyObject>?>?, keybuf: UnsafeMutablePointer<Unmanaged<AnyObject>?>?) {
143+
internal func _CFSwiftDictionaryGetValuesAndKeys(_ dictionary: AnyObject, valuebuf: UnsafeMutablePointer<Unmanaged<AnyObject>?>, keybuf: UnsafeMutablePointer<Unmanaged<AnyObject>?>) {
144144
var idx = 0
145145
if valuebuf == nil && keybuf == nil {
146146
return
147147
}
148148
(dictionary as! NSDictionary).enumerateKeysAndObjectsUsingBlock { key, value, _ in
149-
valuebuf?[idx] = Unmanaged<AnyObject>.passUnretained(value)
150-
keybuf?[idx] = Unmanaged<AnyObject>.passUnretained(key)
149+
if valuebuf != nil {
150+
valuebuf[idx] = Unmanaged<AnyObject>.passUnretained(value)
151+
}
152+
if keybuf != nil {
153+
keybuf[idx] = Unmanaged<AnyObject>.passUnretained(key)
154+
}
151155
idx += 1
152156
}
153157
}

Foundation/NSCFString.swift

+12-8
Original file line numberDiff line numberDiff line change
@@ -125,24 +125,26 @@ internal func _CFSwiftStringGetCharacters(_ str: AnyObject, range: CFRange, buff
125125
(str as! NSString).getCharacters(buffer, range: NSMakeRange(range.location, range.length))
126126
}
127127

128-
internal func _CFSwiftStringGetBytes(_ str: AnyObject, encoding: CFStringEncoding, range: CFRange, buffer: UnsafeMutablePointer<UInt8>?, maxBufLen: CFIndex, usedBufLen: UnsafeMutablePointer<CFIndex>?) -> CFIndex {
128+
internal func _CFSwiftStringGetBytes(_ str: AnyObject, encoding: CFStringEncoding, range: CFRange, buffer: UnsafeMutablePointer<UInt8>, maxBufLen: CFIndex, usedBufLen: UnsafeMutablePointer<CFIndex>) -> CFIndex {
129129
switch encoding {
130130
// TODO: Don't treat many encodings like they are UTF8
131131
case CFStringEncoding(kCFStringEncodingUTF8), CFStringEncoding(kCFStringEncodingISOLatin1), CFStringEncoding(kCFStringEncodingMacRoman), CFStringEncoding(kCFStringEncodingASCII), CFStringEncoding(kCFStringEncodingNonLossyASCII):
132132
let encodingView = (str as! NSString)._swiftObject.utf8
133133
let start = encodingView.startIndex
134-
if let buffer = buffer {
134+
if buffer != nil {
135135
for idx in 0..<range.length {
136136
let character = encodingView[start.advanced(by: idx + range.location)]
137137
buffer.advanced(by: idx).initialize(with: character)
138138
}
139139
}
140-
usedBufLen?.pointee = range.length
140+
if usedBufLen != nil {
141+
usedBufLen.pointee = range.length
142+
}
141143

142144
case CFStringEncoding(kCFStringEncodingUTF16):
143145
let encodingView = (str as! NSString)._swiftObject.utf16
144146
let start = encodingView.startIndex
145-
if let buffer = buffer {
147+
if buffer != nil {
146148
for idx in 0..<range.length {
147149
// Since character is 2 bytes but the buffer is in term of 1 byte values, we have to split it up
148150
let character = encodingView[start.advanced(by: idx + range.location)]
@@ -152,8 +154,10 @@ internal func _CFSwiftStringGetBytes(_ str: AnyObject, encoding: CFStringEncodin
152154
buffer.advanced(by: (idx * 2) + 1).initialize(with: byte1)
153155
}
154156
}
155-
// Every character was 2 bytes
156-
usedBufLen?.pointee = range.length * 2
157+
if usedBufLen != nil {
158+
// Every character was 2 bytes
159+
usedBufLen.pointee = range.length * 2
160+
}
157161

158162

159163
default:
@@ -176,11 +180,11 @@ internal func _CFSwiftStringCreateMutableCopy(_ str: AnyObject) -> Unmanaged<Any
176180
return Unmanaged<AnyObject>.passRetained((str as! NSString).mutableCopyWithZone(nil))
177181
}
178182

179-
internal func _CFSwiftStringFastCStringContents(_ str: AnyObject) -> UnsafePointer<Int8>? {
183+
internal func _CFSwiftStringFastCStringContents(_ str: AnyObject) -> UnsafePointer<Int8> {
180184
return (str as! NSString)._fastCStringContents
181185
}
182186

183-
internal func _CFSwiftStringFastContents(_ str: AnyObject) -> UnsafePointer<UniChar>? {
187+
internal func _CFSwiftStringFastContents(_ str: AnyObject) -> UnsafePointer<UniChar> {
184188
return (str as! NSString)._fastContents
185189
}
186190

0 commit comments

Comments
 (0)