[swift-evolution] Unmanaged, and COpaquePointer vs. Unsafe(Mutable)Pointer

Jacob Bandes-Storch jtbandes at gmail.com
Tue Dec 8 02:26:30 CST 2015

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

- 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(_:

What are others' experiences? Would it be feasible/favorable to have some
of these conversions?

Jacob Bandes-Storch
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151208/353afabc/attachment.html>

More information about the swift-evolution mailing list