<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On Apr 28, 2016, at 17:22, Andrew Trick via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class=""><br class=""><blockquote type="cite" class="">On Apr 28, 2016, at 11:10 AM, Chris Lattner <<a href="mailto:clattner@apple.com" class="">clattner@apple.com</a>> wrote:<br class=""><br class="">Hello Swift community,<br class=""><br class="">The review of "SE-0017: Change Unmanaged to use UnsafePointer" begins now and runs through May 3. The proposal is available here:<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><a href="https://github.com/apple/swift-evolution/blob/master/proposals/0017-convert-unmanaged-to-use-unsafepointer.md" class="">https://github.com/apple/swift-evolution/blob/master/proposals/0017-convert-unmanaged-to-use-unsafepointer.md</a><br class=""></blockquote><br class=""><br class="">I have some concerns, but let me just suggest a simple alternative and see what people think...<br class=""><br class="">- Leave the existing from/toOpaque API until we can come up with a better plan for moving away from OpaquePointer.<br class=""><br class="">- Add initializers to avoid boilerplate, but only for "safe" variants of the cast:<br class=""><br class="">extension Unmanaged {<br class=""> @_transparent<br class=""> public init(_ from : UnsafePointer<Instance>)<br class=""><br class=""> @_transparent<br class=""> public init?(_ from : UnsafePointer<Instance>?)<br class="">}<br class=""><br class="">extension UnsafeMutablePointer where Pointee : AnyObject {<br class=""> @_transparent<br class=""> public init(_ from : Unmanaged<Pointee>)<br class=""><br class=""> @_transparent<br class=""> public init?(_ from : Unmanaged<Pointee>?)<br class="">}<br class=""></div></div></blockquote><div><br class=""></div><div>This isn’t correct; an UnsafeMutablePointer<Foo> is a pointer to a <i class="">reference</i> to Foo. Unmanaged<Foo> is a wrapper around ‘unowned Foo’, i.e. it’s <i class="">just</i> the reference.</div><div><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div class=""><br class="">- This doesn't solve the stated problem of passing unmanaged pointers to 'void*' imports. Is that really an issue? I believe the correct fix is to stop importing 'void*' as UnsafePointer<Void>. We should have a nominally distinct "opaque" pointer type, 'void*' should be imported as that type, and casting from any UnsafePointer to the opaque pointer type should be inferred and implicit for function arguments. I can send a proposal for eliminating UnsafePointer<Void> next week, but the scope of that proposal will be much broader.</div></div></blockquote><br class=""></div><div>This is one of the few major use cases for Unmanaged: passing objects through C context pointers. If the type of a ‘void *’ pointer changes, then this proposal should use that type.</div><div><br class=""></div><div>(The other supported uses of Unmanaged are interacting with existing CF APIs that haven’t been audited, and dealing with fields of structs with class type, neither of which use fromOpaque/toOpaque. That last actually isn’t implemented correctly at the moment; we’re assuming those are all strong references, which they aren’t.)</div><div><br class=""></div><div>Jordan</div><br class=""></body></html>