[swift-evolution] Unmanaged, and COpaquePointer vs. Unsafe(Mutable)Pointer
rjmccall at apple.com
Tue Dec 8 11:37:46 CST 2015
> On Dec 8, 2015, at 12:26 AM, Jacob Bandes-Storch via swift-evolution <swift-evolution at swift.org> wrote:
> One hopes to avoid COpaquePointer and Unsafe(Mutable)Pointer, but in practice I've had occasion to use them a few times.
> Things that are nice:
> - Unmanaged.passUnretained/takeRetained/etc. which make memory management semantics explicit.
> Things I've been frustrated by:
> - An API takes UnsafeMutablePointer<Void>, but Unmanaged.toOpaque() returns a COpaquePointer.
> - An API gives me UnsafeMutablePointer<Void>, but Unmanaged.fromOpaque() takes a COpaquePointer.
> In practice, I end up with monstrosities like:
> I think a few things could help:
> - Phase out COpaquePointer in favor of UnsafePointer<Void> (is this already happening?)
I think this is planned, but it would be good to verify that. We should definitely be consistent about which type we’re using.
> - Add implicit conversion from COpaquePointer to Unsafe(Mutable)Pointer<Void>, and/or vice versa.
> - Even better, add implicit conversion from Unmanaged<T> to COpaquePointer or UnsafePointer<Void>, behaving the way toOpaque() currently does. Also, replace Unmanaged.fromOpaque() with an initializer Unmanaged(_: UnsafePointer<Void>).
We try very hard to avoid adding new implicit conversions.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution