<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 16, 2015, at 11:59 AM, Kevin Ballard &lt;<a href="mailto:kevin@sb.org" class="">kevin@sb.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class="">


<title class=""></title>

<div class=""><div class="">On Wed, Dec 16, 2015, at 11:49 AM, Joe Groff wrote:<br class=""></div>
<blockquote type="cite" class=""><div class="">&nbsp;</div>
<div class=""><blockquote type="cite" class=""><div class="">On Dec 16, 2015, at 11:47 AM, Kevin Ballard &lt;<a href="mailto:kevin@sb.org" class="">kevin@sb.org</a>&gt; wrote:<br class=""></div>
<div class="">&nbsp;</div>
<div class=""><div class=""><span class="font" style="font-family:Helvetica"><span class="size" style="font-size:12px">On Wed, Dec 16, 2015, at 11:42 AM, Joe Groff wrote:</span></span><br class=""></div>
<blockquote style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;orphans:auto;text-align:start;text-indent:0px;text-transform:none;white-space:normal;widows:auto;word-spacing:0px;-webkit-text-stroke-width:0px;" type="cite" class=""><div class="">&nbsp;</div>
<blockquote type="cite" class=""><div class="">On Dec 16, 2015, at 11:24 AM, Kevin Ballard via swift-dev &lt;<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>&gt; wrote:<br class=""></div>
<div class="">&nbsp;</div>
<div class="">On Wed, Dec 16, 2015, at 12:12 AM, Dave Abrahams wrote:<br class=""></div>
<blockquote type="cite" class=""><div class="">&nbsp;</div>
<blockquote type="cite" class="">Come to think of it, what's the actual use-case for withUnsafePointer()?<br class=""></blockquote><div class="">&nbsp;</div>
<div class="">I'm not sure we still have one that isn't covered by &amp;x; that's my point.<br class=""></div>
<div class="">&nbsp;</div>
<blockquote type="cite" class="">If a value is mutable, you can already use &amp;x or withUnsafeMutablePointer(), and if it's immutable, you can't call withUnsafePointer() today anyway. The proposed change would just make withUnsafePointer() into the equivalent of `var x = value; callSomethingWith(&amp;x)`. The only reason to really want a withUnsafePointer() function is if it can give you an UnsafePointer to an immutable value without copying it, but we can't do that. I'm inclined to say we should just get rid of withUnsafePointer() entirely, at least until such time as Swift has a way to pass immutable values by-ref.<br class=""></blockquote><div class="">&nbsp;</div>
<div class="">I'm inclined to agree. &nbsp;Proposal?<br class=""></div>
</blockquote><div class="">&nbsp;</div>
<div class="">Sure, I'll write one up. I suspect that withUnsafePointer() / withUnsafeMutablePointer() are likely to be rarely used today, and most uses can probably be trivially replaced with just passing a &amp;x ref, so this shouldn't be a big deal.<br class=""></div>
</blockquote><div class="">&nbsp;</div>
<div class="">We can't remove withUnsafe[Mutable]Pointer; as I mentioned to Dave, it's necessary to persist a pointer for more than one immediate call.<br class=""></div>
</blockquote><div class="">&nbsp;</div>
<div class=""><span class="font" style="font-family:Helvetica"><span class="size" style="font-size:12px">Rare cases like that can be covered by either declaring a nested function taking the pointer and calling it, calling an anonymous local closure of the right type, or even using withExtendedLifetime(&amp;x) { (ptr: UnsafePointer&lt;T&gt;) in ... }.</span></span><br class=""></div>
</div>
</blockquote><div class="">&nbsp;</div>
<div class="">These are all just withUnsafePointer with different spelling.<br class=""></div>
</div>
</blockquote><div class="">&nbsp;</div>
<div class="">That's true, but they all have the benefit of not requiring extra stdlib functions. <a href="http://swiftdoc.org" class="">swiftdoc.org</a> lists 36 global functions, a full 4 of which are withUnsafePointer + variants. The existence of the functions also implies that they're necessary to work with pointers (especially the documentation). My suspicion is that nearly all current uses of these functions can be replaced with &amp;x refs with no change in functionality. Even the stdlib only has a handful of uses of withUnsafeMutablePointer (and none at all for withUnsafePointer), and looking through them quickly, it looks like only the ones in&nbsp;public/core/Runtime.swift.gyb require a workaround.<br class=""></div>
<div class="">&nbsp;</div></div></div></blockquote><br class=""></div><div>The standard library isn't a representative sample, since it doesn't interact directly with that much C code. I would check out Github for more information; I've had a number of discussions with developers who were doing things that are only possible with withUnsafePointer.</div><div><br class=""></div><div>-Joe</div></body></html>