[swift-evolution] Open Issues Affecting Standard Library API Stability

Dmitri Gribenko gribozavr at gmail.com
Wed Jul 6 13:47:40 CDT 2016

On Wed, Jul 6, 2016 at 11:30 AM, Harlan Haskins <harlan at harlanhaskins.com>

> I’ve also seen unsafeAddressOf(_:) used when interfacing with C function
> pointers when the lifetime of an object is guaranteed. Many C APIs vend an
> API like:
> void perform_action(void (*callback)(void *data), void *initial_data);
> For which it is expected to use unsafeAddressOf on a class instance, like:
> perform_action({ data in
>   let _self = unsafeBitCast(data, to: MyClass.self)
>   _self.foo()
> }, data: unsafeAddressOf(self))
> It’s unsafe and error-prone, sure, but that’s why we have `unsafe` in the
> name 😅 — I’ve had to use this to interface with libclang.

Hi Harlan,

For this case, Unmanaged is the recommended API.


(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160706/089f3e1d/attachment.html>

More information about the swift-evolution mailing list