<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div><blockquote type="cite" class=""><div class="">On Dec 8, 2015, at 12:26 AM, Jacob Bandes-Storch via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><div class=""><div dir="ltr" class="">One hopes to avoid COpaquePointer and Unsafe(Mutable)Pointer, but in practice I've had occasion to use them a few times.<div class=""><br class=""></div><div class="">Things that are nice:</div><div class=""><br class=""></div><div class="">- Unmanaged.passUnretained/takeRetained/etc. which make memory management semantics explicit.</div><div class=""><div class=""><br class=""></div><div class="">Things I've been frustrated by:</div><div class=""><br class=""></div><div class="">- An API takes UnsafeMutablePointer<Void>, but Unmanaged.toOpaque() returns a COpaquePointer.</div><div class=""><br class=""></div><div class="">- An API gives me UnsafeMutablePointer<Void>, but Unmanaged.fromOpaque() takes a COpaquePointer.</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">In practice, I end up with monstrosities like:</div><div class=""><br class=""></div><div class=""><span style="font-family:monospace,monospace" class="">Unmanaged.passRetained(CFCopyDescription(Unmanaged<AnyObject>.fromOpaque(COpaquePointer($0)).takeUnretainedValue()))</span></div><div class=""><br clear="all" class=""><div class=""><div class="gmail_signature"><div dir="ltr" class=""><div class=""><br class=""></div><div class="">I think a few things could help:</div><div class=""><br class=""></div><div class="">- Phase out COpaquePointer in favor of UnsafePointer<Void> (is this already happening?)</div></div></div></div></div></div></div></div></blockquote><div><br class=""></div>I think this is planned, but it would be good to verify that. We should definitely be consistent about which type we’re using.</div><div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><div class=""><div class=""><div class="gmail_signature"><div dir="ltr" class=""><div class="">- Add implicit conversion from COpaquePointer to Unsafe(Mutable)Pointer<Void>, and/or vice versa.</div></div></div></div></div></div></div></div></blockquote><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><div class=""><div class=""><div class="gmail_signature"><div dir="ltr" class=""><div class=""><br class=""></div><div class="">- 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>).</div></div></div></div></div></div></div></div></blockquote><div><br class=""></div>We try very hard to avoid adding new implicit conversions.</div><div><br class=""></div><div>John.</div></body></html>