Skip to content

[SE-0127] Remove calls to withUnsafe[Mutable]Pointers #473

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

Merged
merged 1 commit into from
Jul 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Foundation/NSCalendar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,10 @@ public class Calendar: NSObject, NSCopying, NSSecureCoding {
public func range(of unit: Unit, forDate date: Date) -> DateInterval? {
var start: CFAbsoluteTime = 0.0
var ti: CFTimeInterval = 0.0
let res: Bool = withUnsafeMutablePointers(&start, &ti) { startp, tip in
return CFCalendarGetTimeRangeOfUnit(_cfObject, unit._cfValue, date.timeIntervalSinceReferenceDate, startp, tip)
let res: Bool = withUnsafeMutablePointer(&start) { startp in
withUnsafeMutablePointer(&ti) { tip in
return CFCalendarGetTimeRangeOfUnit(_cfObject, unit._cfValue, date.timeIntervalSinceReferenceDate, startp, tip)
}
}

if res {
Expand Down
6 changes: 4 additions & 2 deletions Foundation/NSPropertyList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ public class PropertyListSerialization : NSObject {
public class func propertyList(from data: Data, options opt: ReadOptions = [], format: UnsafeMutablePointer<PropertyListFormat>?) throws -> Any {
var fmt = kCFPropertyListBinaryFormat_v1_0
var error: Unmanaged<CFError>? = nil
let decoded = withUnsafeMutablePointers(&fmt, &error) { (outFmt: UnsafeMutablePointer<CFPropertyListFormat>, outErr: UnsafeMutablePointer<Unmanaged<CFError>?>) -> NSObject? in
return unsafeBitCast(CFPropertyListCreateWithData(kCFAllocatorSystemDefault, data._cfObject, CFOptionFlags(CFIndex(opt.rawValue)), outFmt, outErr), to: NSObject.self)
let decoded = withUnsafeMutablePointer(&fmt) { (outFmt: UnsafeMutablePointer<CFPropertyListFormat>) -> NSObject? in
withUnsafeMutablePointer(&error) { (outErr: UnsafeMutablePointer<Unmanaged<CFError>?>) -> NSObject? in
return unsafeBitCast(CFPropertyListCreateWithData(kCFAllocatorSystemDefault, data._cfObject, CFOptionFlags(CFIndex(opt.rawValue)), outFmt, outErr), to: NSObject.self)
}
}
#if os(OSX) || os(iOS)
format?.pointee = PropertyListFormat(rawValue: UInt(fmt.rawValue))!
Expand Down
8 changes: 5 additions & 3 deletions Foundation/NSThread.swift
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,11 @@ public class Thread: NSObject {
public var stackSize: Int {
get {
var size: Int = 0
return withUnsafeMutablePointers(&_attr, &size) { attr, sz in
pthread_attr_getstacksize(attr, sz)
return sz.pointee
return withUnsafeMutablePointer(&_attr) { attr in
withUnsafeMutablePointer(&size) { sz in
pthread_attr_getstacksize(attr, sz)
return sz.pointee
}
}
}
set {
Expand Down