[swift-dev] Rebinding UnsafePointer makes it mutable
Andrew Trick
atrick at apple.com
Mon Sep 19 13:45:50 CDT 2016
> On Sep 19, 2016, at 1:24 AM, Martin R via swift-dev <swift-dev at swift.org> wrote:
>
> I noticed that both UnsafePointer and UnsafeMutablePointer have the identical method
>
> public func withMemoryRebound<T, Result>(to: T.Type, capacity count: Int, _ body: (UnsafeMutablePointer<T>) throws -> Result) rethrows -> Result
>
> so that rebinding an immutable pointer gives you a _mutable_ pointer. That is different from what
>
> Unsafe[Mutable]Pointer<Pointee> {
> func withMemoryRebound<T>(to: T.Type, capacity count: Int,
> _ body: (Unsafe[Mutable]Pointer<T>) throws -> ()) rethrows
> }
>
> in https://github.com/apple/swift-evolution/blob/master/proposals/0107-unsaferawpointer.md indicates. Perhaps I am misunderstanding something. Shouldn't rebinding an UnsafePointer result in an UnsafePointer again?
>
> Martin
You’re right. There is an inconsistency between the proposal and Swift 3 implementation. I’ve been thinking about whether it makes more sense to correct this sooner or later. I responded in more detail on swift-evolution.
-Andy
More information about the swift-dev
mailing list