Skip to content

Commit fe3f150

Browse files
committed
Revert "Continued update for SE-0107: Raw->Void migration."
This reverts commit 7ee8014.
1 parent 6cac595 commit fe3f150

File tree

8 files changed

+20
-25
lines changed

8 files changed

+20
-25
lines changed

Foundation/Data.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,7 @@ public struct Data : ReferenceConvertible, CustomStringConvertible, Equatable, H
173173
return nil
174174
case .custom(let b):
175175
return { (ptr, len) in
176-
let bytePtr = ptr.bindMemory(to: UInt8.self, capacity: len)
177-
b(bytePtr, len)
176+
b(UnsafeMutablePointer<UInt8>(ptr), len)
178177
}
179178
}
180179
}
@@ -440,8 +439,7 @@ public struct Data : ReferenceConvertible, CustomStringConvertible, Equatable, H
440439
_mapUnmanaged {
441440
$0.enumerateBytes { (ptr, range, stop) in
442441
var stopv = false
443-
let bytePtr = ptr.bindMemory(to: UInt8.self, capacity: range.length)
444-
block(buffer: UnsafeBufferPointer(start: bytePtr, count: range.length), byteIndex: range.length, stop: &stopv)
442+
block(buffer: UnsafeBufferPointer(start: UnsafePointer<UInt8>(ptr), count: range.length), byteIndex: range.length, stop: &stopv)
445443
if stopv {
446444
stop.pointee = true
447445
}

Foundation/IndexPath.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public struct IndexPath : ReferenceConvertible, Equatable, Hashable, MutableColl
158158
if count == 0 {
159159
_indexes = []
160160
} else {
161-
var ptr = malloc(count * sizeof(Element.self))?.bindMemory(to: Element.self, capacity: count * sizeof(Element.self))
161+
var ptr = UnsafeMutablePointer<Element>(malloc(count * sizeof(Element.self)))
162162
defer { free(ptr) }
163163

164164
nsIndexPath.getIndexes(ptr!, range: NSMakeRange(0, count))

Foundation/NSString.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ internal func _bytesInEncoding(_ str: NSString, _ encoding: String.Encoding, _ f
194194

195195
buffer.advanced(by: cLength).initialize(to: 0)
196196

197-
return UnsafePointer(buffer) // leaked and should be autoreleased via a NSData backing but we cannot here
197+
return buffer // leaked and should be autoreleased via a NSData backing but we cannot here
198198
}
199199

200200
internal func isALineSeparatorTypeCharacter(_ ch: unichar) -> Bool {
@@ -905,7 +905,7 @@ extension NSString {
905905
let lossyOk = options.contains(.allowLossy)
906906
let externalRep = options.contains(.externalRepresentation)
907907
let failOnPartial = options.contains(.failOnPartialEncodingConversion)
908-
let bytePtr = buffer?.bindMemory(to: UInt8.self, capacity: maxBufferCount)
908+
let bytePtr = buffer?.bindMemory(as: UInt8.self, capacity: maxBufferCount)
909909
numCharsProcessed = __CFStringEncodeByteStream(_cfObject, range.location, range.length, externalRep, cfStringEncoding, lossyOk ? (encoding == String.Encoding.ascii.rawValue ? 0xFF : 0x3F) : 0, bytePtr, bytePtr != nil ? maxBufferCount : 0, &totalBytesWritten)
910910
if (failOnPartial && numCharsProcessed < range.length) || numCharsProcessed == 0 {
911911
result = false
@@ -1230,7 +1230,7 @@ extension NSString {
12301230
}
12311231

12321232
public convenience init?(bytes: UnsafeRawPointer, length len: Int, encoding: UInt) {
1233-
let bytePtr = bytes.bindMemory(to: UInt8.self, capacity: len)
1233+
let bytePtr = bytes.bindMemory(as: UInt8.self, capacity: len)
12341234
guard let cf = CFStringCreateWithBytes(kCFAllocatorDefault, bytePtr, len, CFStringConvertNSStringEncodingToEncoding(encoding), true) else {
12351235
return nil
12361236
}
@@ -1265,7 +1265,7 @@ extension NSString {
12651265
public convenience init(contentsOf url: URL, encoding enc: UInt) throws {
12661266
let readResult = try NSData(contentsOf: url, options: [])
12671267

1268-
let bytePtr = readResult.bytes.bindMemory(to: UInt8.self, capacity: readResult.length)
1268+
let bytePtr = readResult.bindMemory(as: UInt8.self, capacity: readResult.length)
12691269
guard let cf = CFStringCreateWithBytes(kCFAllocatorDefault, bytePtr, readResult.length, CFStringConvertNSStringEncodingToEncoding(enc), true) else {
12701270
throw NSError(domain: NSCocoaErrorDomain, code: NSCocoaError.FileReadInapplicableStringEncodingError.rawValue, userInfo: [
12711271
"NSDebugDescription" : "Unable to create a string using the specified encoding."
@@ -1402,7 +1402,7 @@ extension NSMutableString {
14021402
let numOccurrences = CFArrayGetCount(findResults)
14031403
for cnt in 0..<numOccurrences {
14041404
let rangePtr = CFArrayGetValueAtIndex(findResults, backwards ? cnt : numOccurrences - cnt - 1)
1405-
replaceCharacters(in: NSRange(rangePtr!.load(as: CFRange.self)), with: replacement)
1405+
replaceCharacters(in: NSRange(range!.load(as: CFRange)), with: replacement)
14061406
}
14071407
return numOccurrences
14081408
} else {

Foundation/NSTask.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@ public class Task: NSObject {
108108
emptySourceContext.equal = runloopIsEqual
109109
emptySourceContext.perform = emptyRunLoopCallback
110110
managerThreadRunLoop!.withUnretainedReference {
111-
(refPtr: UnsafeMutablePointer<UInt8>) in
112-
emptySourceContext.info = UnsafeMutableRawPointer(refPtr)
111+
emptySourceContext.info = $0
113112
}
114113

115114
CFRunLoopAddSource(managerThreadRunLoop?._cfRunLoop, CFRunLoopSourceCreate(kCFAllocatorDefault, 0, &emptySourceContext), kCFRunLoopDefaultMode)
@@ -387,8 +386,7 @@ public class Task: NSObject {
387386
runLoopContext.equal = nstaskIsEqual
388387
runLoopContext.perform = emptyRunLoopCallback
389388
self.withUnretainedReference {
390-
(refPtr: UnsafeMutablePointer<UInt8>) in
391-
runLoopContext.info = UnsafeMutableRawPointer(refPtr)
389+
runLoopContext.info = $0
392390
}
393391
self.runLoopSourceContext = runLoopContext
394392

Foundation/NSTimer.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ public class Timer: NSObject {
3939
_fire = block
4040
var context = CFRunLoopTimerContext()
4141
withRetainedReference {
42-
(refPtr: UnsafeMutablePointer<UInt8>) in
43-
context.info = UnsafeMutableRawPointer(refPtr)
42+
context.info = $0
4443
}
4544
let timer = withUnsafeMutablePointer(&context) { (ctx: UnsafeMutablePointer<CFRunLoopTimerContext>) -> CFRunLoopTimer in
4645
var t = interval

Foundation/NSURL.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,10 @@ public class NSURL: NSObject, NSSecureCoding, NSCopying {
343343
let bytesNeeded = CFURLGetBytes(_cfObject, nil, 0)
344344
assert(bytesNeeded > 0)
345345

346-
let buffer = malloc(bytesNeeded)!.bindMemory(to: UInt8.self, capacity: bytesNeeded)
347-
let bytesFilled = CFURLGetBytes(_cfObject, buffer, bytesNeeded)
346+
let buffer = malloc(bytesNeeded)!
347+
let bytesFilled = CFURLGetBytes(_cfObject, UnsafeMutablePointer<UInt8>(buffer), bytesNeeded)
348348
if bytesFilled == bytesNeeded {
349-
return Data(bytesNoCopy: buffer, count: bytesNeeded, deallocator: .none)
349+
return Data(bytesNoCopy: UnsafeMutablePointer<UInt8>(buffer), count: bytesNeeded, deallocator: .none)
350350
} else {
351351
fatalError()
352352
}

Foundation/NSXMLNode.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ public class XMLNode: NSObject, NSCopying {
719719
var result: [XMLNode] = []
720720
for i in 0..<CFArrayGetCount(nodes) {
721721
let nodePtr = CFArrayGetValueAtIndex(nodes, i)!
722-
result.append(XMLNode._objectNodeForNode(_CFXMLNodePtr(mutating: nodePtr)))
722+
result.append(XMLNode._objectNodeForNode(_CFXMLNodePtr(nodePtr)))
723723
}
724724

725725
return result

Foundation/NSXMLParser.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -565,21 +565,21 @@ public class XMLParser : NSObject {
565565
XMLParser.setCurrentParser(self)
566566
if let stream = _stream {
567567
stream.open()
568-
let buffer = malloc(_chunkSize)!.bindMemory(to: UInt8.self, capacity: _chunkSize)
569-
var len = stream.read(buffer, maxLength: _chunkSize)
568+
let buffer = malloc(_chunkSize)!
569+
var len = stream.read(UnsafeMutablePointer<UInt8>(buffer), maxLength: _chunkSize)
570570
if len != -1 {
571571
while len > 0 {
572-
let data = Data(bytesNoCopy: buffer, count: len, deallocator: .none)
572+
let data = Data(bytesNoCopy: UnsafeMutablePointer<UInt8>(buffer), count: len, deallocator: .none)
573573
result = parseData(data)
574-
len = stream.read(buffer, maxLength: _chunkSize)
574+
len = stream.read(UnsafeMutablePointer<UInt8>(buffer), maxLength: _chunkSize)
575575
}
576576
} else {
577577
result = false
578578
}
579579
free(buffer)
580580
stream.close()
581581
} else if let data = _data {
582-
let buffer = malloc(_chunkSize)!.bindMemory(to: UInt8.self, capacity: _chunkSize)
582+
let buffer = malloc(_chunkSize)!
583583
var range = NSMakeRange(0, min(_chunkSize, data.count))
584584
while result {
585585
let chunk = data.withUnsafeBytes { (buffer: UnsafePointer<UInt8>) -> Data in

0 commit comments

Comments
 (0)