<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">COpaquePointer is IMO a vestige that should be eliminated completely. We'd ultimately like to import opaque C structs as distinct, non-constructible types in Swift, so that they can still be well-typed UnsafePointer&lt;OpaqueThing&gt; types in Swift.<div class=""><br class=""></div><div class="">-Joe</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 8, 2015, at 12:26 AM, Jacob Bandes-Storch via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><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&lt;Void&gt;, but Unmanaged.toOpaque() returns a COpaquePointer.</div><div class=""><br class=""></div><div class="">- An API gives me UnsafeMutablePointer&lt;Void&gt;, 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&lt;AnyObject&gt;.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&lt;Void&gt; (is this already happening?)</div><div class=""><br class=""></div><div class="">- Add implicit conversion from COpaquePointer to Unsafe(Mutable)Pointer&lt;Void&gt;, and/or vice versa.</div><div class=""><br class=""></div><div class="">- Even better, add implicit conversion from Unmanaged&lt;T&gt; to COpaquePointer or UnsafePointer&lt;Void&gt;, behaving the way toOpaque() currently does. Also, replace Unmanaged.fromOpaque() with an initializer Unmanaged(_: UnsafePointer&lt;Void&gt;).</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">What are others' experiences? Would it be feasible/favorable to have some of these conversions?</div><div class=""><br class=""></div><div class="">Jacob Bandes-Storch<br class=""></div></div></div></div>
</div></div></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=RoDF4MveSEMYBIqIJA6ub1g8cOZ-2BVYvqV-2FqygPhjPn93Yl5gbcNpN-2FPb4FmhoA92QzH0eWXWybssNEyqqAfWAxHjMpFefRA3XPNppX0E9rFDt2-2Fct0ijzC10jW-2FBebItTlnM7hnR6c6EdLzVIKaf35qiPMNPbhPekPF1xc14TojIzAhGJQ7NGrDLgw1aIVfsr8h4jC0ygg05pkZZwzrFJ-2FLMlch7PsWrgwBK-2BhJv61w-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;" class="">
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></div></body></html>