[swift-evolution] [Pitch] Don't require & for UnsafeRawPointer

Charles Srstka cocoadev at charlessoft.com
Wed May 17 16:33:43 CDT 2017


There’s also no guarantee that unsafeBitCast won’t be used to mess with any argument to *anything* in ways that it’s not supposed to. This is just one of the perils of using unsafe APIs, of which UnsafePointer is a part.

By taking an UnsafePointer, however, the API is claiming it won’t mutate the pointer, much like a const void * in C. If it does in fact mutate it, that should be logged as a bug against the API, and the interface should be changed to use UnsafeMutablePointer instead.

Charles

> On May 17, 2017, at 4:09 PM, Guillaume Lessard via swift-evolution <swift-evolution at swift.org> wrote:
> 
> How would you deal with the existence of:
> UnsafeMutablePointer<Pointee>.init(mutating other: UnsafePointer<Pointee>)
> 
> No unsafe pointer can guarantee that it won’t be used to mutate its pointee.
> Requiring a mutable variable seems like truth in advertising.
> 
> Sincerely,
> Guillaume Lessard
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution



More information about the swift-evolution mailing list