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