Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift 3 Support #62

Merged
merged 27 commits into from Sep 12, 2016
Merged

Swift 3 Support #62

merged 27 commits into from Sep 12, 2016

Conversation

mattprowse
Copy link
Contributor

Moves ReactiveTask to Swift 3, targeting Xcode 8 beta 1. I'll keep the PR updated as each new beta appears.

  • Currently uses ReactiveCocoa's RAC5-swift3 branch, and the same targets as RAC for Quick, Nimble, and Result.
  • The deployment target had to be raised to 10.10 to match ReactiveCocoa.
  • All tests pass except "should launch a task with standard input", which crashes on run. I'll figure out why and update the PR with a fix if possible.
  • The only major changes made to the ReactiveTask API are the lowercasing of all enum cases as per the Swift 3 API guidelines, and the replacement of NSData with Data.

@@ -73,6 +73,7 @@
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
enableThreadSanitizer = "YES"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean to leave this on?

…e Swift 3 migrator moving `@noescape` attributes.

Abbreviate `String.Encoding.utf8` to `.utf8`.
Replace one remaining use of `NSString(data:encoding:)` with `String(data:encoding:)`.
Disable Thread Sanitizer.
@mattprowse
Copy link
Contributor Author

Thanks for the feedback! All comments should be covered by the latest commit.

@mdiep
Copy link
Member

mdiep commented Jun 30, 2016

Is this still a WIP?

@mattprowse
Copy link
Contributor Author

One of the tests is still crashing somewhere deep inside ReactiveCocoa, so I probably need to figure that out before it's ready to merge.

@@ -215,7 +215,7 @@ private final class Pipe {
let bytes = UnsafeMutablePointer<UInt8>(allocatingCapacity: data.count)
data.copyBytes(to: bytes, count: data.count)
let buffer = UnsafeBufferPointer(start: bytes, count: data.count)
let dispatchData = DispatchData(bytes: buffer)
let dispatchData = DispatchData(bytesNoCopy: buffer, deallocator: .custom(nil, {}))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes the crashing test, but it feels to me like a non-ideal thing to have to do. I mean it seems to work, I guess because dispatchData only gets used while data (which owns the bytes) exists.

It would be preferable to create dispatchData by copying the bytes in data, but doing so causes an EXC_BAD_ACCESS when dispatchData gets deallocated.

@mattprowse
Copy link
Contributor Author

I managed to get the final test to pass, though I don't feel great about the fix (see line note here). A more experienced set of eyes might be able to come up with something better.

@mattprowse mattprowse changed the title [WIP] Swift 3 Support Swift 3 Support Jul 5, 2016
CURRENT_PROJECT_VERSION = 1;
ENABLE_TESTABILITY = YES;
GCC_NO_COMMON_BLOCKS = YES;
MACOSX_DEPLOYMENT_TARGET = 10.9;
MACOSX_DEPLOYMENT_TARGET = 10.10;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The RAC target was switched back to 10.9. Can we keep this at 10.9 too?

@mdiep
Copy link
Member

mdiep commented Aug 6, 2016

Just a couple changes, then this looks good. 👍🏻

Also, the Xcode 7 build should be dropped from .travis.yml—then CI will pass.

Replace manual pointer creation with NSData.withUnsafeBytes.
Remove Xcode 7 build from .travis.yml.
@mattprowse
Copy link
Contributor Author

Thanks for the feedback! I've made the changes as request. I've also updated the Cartfile to point at ReactiveCocoa's master branch since that's where RAC5 development seems to be now.

dispatch_io_write(channel, 0, dispatchData, self.queue) { (done, data, error) in
let dispatchData = data.withUnsafeBytes { (bytes: UnsafePointer<UInt8>) -> DispatchData in
let buffer = UnsafeBufferPointer(start: bytes, count: data.count)
return DispatchData(bytesNoCopy: buffer, deallocator: .custom(nil, {}))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is bytesNoCopy safe to use here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd much prefer to not use bytesNoCopy, but using DispatchData(bytes: buffer) crashes with EXC_BAD_ACCESS when the DispatchData deallocates.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked into this case and the other one below. I'm not sure what's going on. 😕 Maybe we should wait for the next Xcode build?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be fixed in Xcode 8 beta 6 so I've made the change and pushed it through.

Handle recent API changes in ReactiveCocoa.
Tests currently don't run; waiting for a beta 6 compatible version of Quick.
Tests now run again.
…ta(bytes:).

This no longer causes a crash as of Xcode 8 beta 6.
// return Data(bytes: bytes, count: dispatchData.count)
// }
// }
//}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should remove this. ☺️

Fix memory leak in use of UnsafeMutablePointer.
@mdiep
Copy link
Member

mdiep commented Sep 12, 2016

Looks good. Thanks!

@mdiep mdiep merged commit fcb3007 into Carthage:master Sep 12, 2016
@mattprowse
Copy link
Contributor Author

🎉

@mattprowse mattprowse deleted the swift3 branch March 17, 2019 09:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants