Swift: OSAtomic functions take UnsafePointer<CType> instead CMutablePointer<CType>

Originator:davelee.com
Number:rdar://17220522 Date Originated:2014-06-07
Status:Open Resolved:
Product:Developer Tools Product Version:
Classification: Reproducible:
 
Summary:
When using the OSAtomic functions, I expect to be able to write code that uses output pointers as follows:

var count: CInt = 0
OSAtomicIncrement(&count) // Convert to CMutablePointer<CInt>

However, since the generated(?) Swift bridge definitions make use of UnsafePointer<T>, the calling code instead is:

var count: Int32 = 0
withUnsafePointer(&count, OSAtomicIncrement32)

This seems unnecessary. The reason for this conclusion is because the objc runtime has bridge definitions which are typed as CMutablePointer<CType>, and do allow code to be called as shown in the first example above.

Steps to Reproduce:
1. Install Xcode6-Beta
2. Create a New Swift File
3. Add the following code:

import Darwin

func foo() {
  var count: Int32 = 0
  OSAtomicIncrement32(&count)
}

Expected Results:
The above code is expected to compile and run properly.

Actual Results:
Compiler error: inout Int32' is not convertible to 'UnsafePointer<Int32>'

Version:
Version 6.0 (6A215l)

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!