Is this limited to auditing the stdlib only or other APIs as well with Swift overlays/API notes?<br><div class="gmail_quote"><div dir="ltr">On Tue, Jul 19, 2016 at 16:47 Arnold Schwaighofer via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"># Replace `UnsafeMutablePointer` by `UnsafePointer` in non-mutating APIs<br>
<br>
* Proposal: [SE-0000](<a href="http://0000-change_unsafe_mutable_pointer_to_unsafe_pointer.md" rel="noreferrer" target="_blank">0000-change_unsafe_mutable_pointer_to_unsafe_pointer.md</a>)<br>
* Author: [Arnold Schwaighofer](<a href="https://github.com/aschwaighofer" rel="noreferrer" target="_blank">https://github.com/aschwaighofer</a>)<br>
* Status: **Pitch**<br>
* Review manager: TBD<br>
<br>
## Introduction<br>
<br>
`UnsafeMutablePointer` didn&#39;t always have an immutable variant, and when it was<br>
introduced there could have been many places that should have been changed to<br>
use it, but were not. `UnsafeMutablePointer` is still pervasive. We should<br>
survey the uses and make sure they&#39;re all using mutability only as appropriate.<br>
<br>
The only such occurrence I found was the `dprintf` API which should have a<br>
read-only format argument.<br>
<br>
- Swift bug: [SR-1958] (<a href="https://bugs.swift.org/browse/SR-1958" rel="noreferrer" target="_blank">https://bugs.swift.org/browse/SR-1958</a>)<br>
- Branch with changes to stdlib: [unsafe_mutable_pointer_to_unsafe_pointer] (<a href="https://github.com/aschwaighofer/swift/tree/unsafe_mutable_pointer_to_unsafe_pointer" rel="noreferrer" target="_blank">https://github.com/aschwaighofer/swift/tree/unsafe_mutable_pointer_to_unsafe_pointer</a>)<br>
<br>
## Motivation<br>
<br>
We should change uses of `UnsafeMutablePointer` with `UnsafePointer` to clearly<br>
express the intent of the API where appropriate.<br>
<br>
## Proposed solution<br>
<br>
The proposed solution is to change `dprintf` API to take a `UnsafePointer`<br>
argument.<br>
<br>
## Detailed design<br>
<br>
Change:<br>
```swift<br>
public func dprintf(_ fd: Int, _ format: UnsafeMutablePointer&lt;Int8&gt;, _ args: CVarArg...) -&gt; Int32<br>
```<br>
<br>
To<br>
```swift<br>
public func dprintf(_ fd: Int, _ format: UnsafePointer&lt;Int8&gt;, _ args: CVarArg...) -&gt; Int32<br>
```<br>
## Impact on existing code<br>
<br>
Existing coersions to `UnsafePointer` from `UnsafeMutablePointer` will allow<br>
existing code to work.<br>
<br>
## Alternatives considered<br>
<br>
Leave as is.<br>
<br>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div>