[swift-dev] UnsafeMutablePointer.init()

Dave Abrahams dabrahams at apple.com
Fri Feb 19 17:20:50 CST 2016

on Fri Feb 19 2016, Guillaume Lessard <swift-dev-AT-swift.org> wrote:

> In the currently planned version of the future, UnsafeMutablePointer
> loses its no-parameter initializer. I saw this as unnecessary, but it
> didn’t raise a red flag for me until trying to initialize a pthread_t
> in cross-platform code.
> On Darwin, pthread_t maps to UnsafeMutablePointer:
> public typealias pthread_t = __darwin_pthread_t
> public typealias __darwin_pthread_t = UnsafeMutablePointer<_opaque_pthread_t>
> On Linux, it does not (from /usr/include/x86_64-linux-gnu/bits/pthreadtypes.h):
> typedef unsigned long int pthread_t;
> As a result, there is no longer an initializer that works in both cases without generating a deprecation warning.
> Is the solution to fix this with new import overlays, or to reinstate
> UnsafeMutablePointer.init() ?

I am not sure about whether we want UnsafeMutablePointer.init() in the
stdlib, but...

What about just extending UnsafeMutablePointer with your own init()?


More information about the swift-dev mailing list