On Wed, Jul 6, 2016 at 11:30 AM, Harlan Haskins <[email protected]>
wrote:

> 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.

Dmitri

-- 
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <[email protected]>*/
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to