<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Zhao, it’s not a class.</div><div class=""><br class=""></div><div class="">Rien, unsafe pointers is the last thing I would ever want to introduce in my library…</div><div class=""><br class=""></div><div class="">Capturing self was clean, working perfectly, until Swift 3.0.2.</div><div class=""><br class=""></div><div class="">-Richard</div><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 16, 2016, at 02:49, Zhao Xin <<a href="mailto:owenzx@gmail.com" class="">owenzx@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="gmail_default"><span class="gmail-im"><font face="garamond, serif" class=""><div class="gmail_default">What is the type of self? If it is a class, try [unowned self].</div><div class="gmail_default"><br class=""></div><div class="gmail_default">Zhaoxin</div></font></span><span class="gmail-im"><div class=""><font face="georgia, serif" class=""><br class=""></font></div><div class=""><font face="georgia, serif" class=""><br class=""></font></div><div style="font-family:georgia,serif" class=""><font face="monospace, monospace" class=""><br class=""></font></div><div style="font-family:georgia,serif" class=""><font face="monospace, monospace" class=""><br class=""></font></div><div style="font-family:georgia,serif" class=""><font face="monospace, monospace" class=""><br class=""></font></div></span></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Fri, Dec 16, 2016 at 4:33 PM, Rien via swift-users <span dir="ltr" class=""><<a href="mailto:swift-users@swift.org" target="_blank" class="">swift-users@swift.org</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">How about using:<br class="">
<br class="">
UnsafeMutablePointer<<wbr class="">TypeOfSelf><br class="">
<br class="">
?<br class="">
<br class="">
Regards,<br class="">
Rien<br class="">
<br class="">
Site: <a href="http://balancingrock.nl/" rel="noreferrer" target="_blank" class="">http://balancingrock.nl</a><br class="">
Blog: <a href="http://swiftrien.blogspot.com/" rel="noreferrer" target="_blank" class="">http://swiftrien.blogspot.com</a><br class="">
Github: <a href="http://github.com/Swiftrien" rel="noreferrer" target="_blank" class="">http://github.com/Swiftrien</a><br class="">
Project: <a href="http://swiftfire.nl/" rel="noreferrer" target="_blank" class="">http://swiftfire.nl</a><br class="">
<div class="HOEnZb"><div class="h5"><br class="">
<br class="">
<br class="">
<br class="">
> On 16 Dec 2016, at 09:10, Richard Wei via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:<br class="">
><br class="">
> Capturing makes it immutable, which unfortunately can't solve this problem.<br class="">
><br class="">
> -Richard<br class="">
><br class="">
>> On Dec 16, 2016, at 02:05, Zhao Xin <<a href="mailto:owenzx@gmail.com" class="">owenzx@gmail.com</a>> wrote:<br class="">
>><br class="">
>> I did not test the code. But if you cannot implicitly capture a mutating self, you should do it explicitly, right?<br class="">
>><br class="">
>> let blockSize = min(512, count)<br class="">
>> let blockCount = (count+blockSize-1)/blockSize<br class="">
>> device.sync { [self] () -> () in // Launch CUDA kernel<br class="">
>> try! fill<<<(blockSize, blockCount)>>>[<br class="">
>> .pointer(to: &self), .value(value), .value(Int64(count))<br class="">
>> ]<br class="">
>> }<br class="">
>><br class="">
>> Hope above code works.<br class="">
>><br class="">
>> Zhaoxin<br class="">
>><br class="">
>> On Fri, Dec 16, 2016 at 3:46 PM, Richard Wei via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:<br class="">
>> Hi,<br class="">
>><br class="">
>> Swift 3.0.2 seems to have broken my code due to mutating self capture. But I have to pass inout self to the closure. Any workaround?<br class="">
>><br class="">
>> let blockSize = min(512, count)<br class="">
>> let blockCount = (count+blockSize-1)/blockSize<br class="">
>> device.sync { // Launch CUDA kernel<br class="">
>> try! fill<<<(blockSize, blockCount)>>>[<br class="">
>> .pointer(to: &self), .value(value), .value(Int64(count))<br class="">
>> ]<br class="">
>> }<br class="">
>><br class="">
>> <PastedGraphic-1.png><br class="">
>><br class="">
>> -Richard<br class="">
>><br class="">
>> ______________________________<wbr class="">_________________<br class="">
>> swift-users mailing list<br class="">
>> <a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">
>> <a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank" class="">https://lists.swift.org/<wbr class="">mailman/listinfo/swift-users</a><br class="">
>><br class="">
>><br class="">
><br class="">
> ______________________________<wbr class="">_________________<br class="">
> swift-users mailing list<br class="">
> <a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">
> <a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank" class="">https://lists.swift.org/<wbr class="">mailman/listinfo/swift-users</a><br class="">
<br class="">
______________________________<wbr class="">_________________<br class="">
swift-users mailing list<br class="">
<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank" class="">https://lists.swift.org/<wbr class="">mailman/listinfo/swift-users</a><br class="">
</div></div></blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></body></html>