-
Notifications
You must be signed in to change notification settings - Fork 71
Passing nil as a dispatch block fails on newest version of Xcode #15
Comments
This is with Xcode 7.1? I guess we need a branch for Swift 0.2.1. |
Perhaps, but that would mess things up with Carthage & Cocoapods. This fix shouldn't break any old version of Swift since it's only changing nil to be an empty closure, so I don't see why creating a new branch would be necessary in this case. |
Well, passing in NULL aka DISPATCH_DATA_DESTRUCTOR_DEFAULT is the intended thing here. That nil cannot be used is likely a bug in Swift (well, in the tagging of the API). Need to review this. |
Passing in {} is wrong and quite likely crashes the program. I'll test it with 7.1b and file a Radar with Apple later on. |
Works fine for me as-is in Xcode 7.1 (7B91b). What version do you use? |
I'm on Xcode 7.1 Beta (7B75). Could you explain why passing |
I'm downloading Xcode 7.2 Beta (just released today I think) and test passing |
You might want to upgrade to the 7.1 release. Passing in DISPATCH_DATA_DESTRUCTOR_DEFAULT (nil) tells GCD to copy the memory buffer being passed in (and maintain it internally). The buffer being passed into the asyncWrite() function is temporary (conceptually on the stack) and will be gone eventually. If you pass a free-handler-block to GCD (instead of nil) you guarantee that the ptr being passed in will stay valid until that free-block is called. Which is wrong here, as the stack buffer will disappear or become corrupt. As with all async stuff it can be hard to repro. The buffer may still be kinda valid and just have a few corruptions etc. P.S.: This is just another reason why SwiftSockets is not really for production but more of a demo. Production software should use GCD channels and not copy any memory. |
Thanks for explaining that! Issue disappeared on newest version of Xcode (7.2 beta), so I guess this should remain closed. |
The following lines of code don't build on the newest version of Xcode:
with the following error:
I'll submit a pull request which changes
nil
to{}
(an empty block), which should work.The text was updated successfully, but these errors were encountered: