-
Notifications
You must be signed in to change notification settings - Fork 80
OpenBSD support. #365
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
OpenBSD support. #365
Conversation
* Ensure the swift-crypto dependency is conditioned for the platform. The relevant swift-crypto changes are not landed upstream yet, but when they are, this picks up the dependency. * Cast timestamps to time_t. This is done unconditionally here, because the standard specifies that `tv_sec` in `timespec` has type `time_t`, and doing so avoids a type mismatch error on the platform. * Since pthread types are pointers here, make the usual changes to capture the fact they are optional types on the Swift side. So far, this has been the only set of changes that have seemed necessary. Fixes swiftlang#114.
@swift-ci please test. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, thanks!
@@ -26,6 +26,9 @@ public final class Lock: @unchecked Sendable { | |||
#if os(Windows) | |||
@usableFromInline | |||
let mutex: UnsafeMutablePointer<SRWLOCK> = UnsafeMutablePointer.allocate(capacity: 1) | |||
#elseif os(OpenBSD) | |||
@usableFromInline | |||
let mutex: UnsafeMutablePointer<pthread_mutex_t?> = UnsafeMutablePointer.allocate(capacity: 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@3405691582 Do you know why there's this difference between BSDs and Darwin/Linux? I needed it for FreeBSD as well.
Can we safely just use the Optional variant on all platforms?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This happens because OpenBSD's value of pthread_t
and subsidiary types like pthread_mutex_t
is a pointer, whereas on Linux for example, it's typedef'd to an int (and pthread_mutex_t
to a union). Of course, there's no nullability annotations on the 'BSDs, so Swift is interpreting the type as an optional like it would any other nullable pointer.
After thinking about it briefly I think you have an incongruity either way, so I don't think you can use Optional always: you either have to declare, for example, mutex
as Optional here and then conditionally check the optional or not depending on platform at the callsite to pthread_mutex_init
, or you do what we do here, and conditionally declare mutex
as Optional or not.
No problem. Feel free to assign me another issue to track that if you'd like, or reopen the existing one. |
Ensure the swift-crypto dependency is conditioned for the platform.
The relevant swift-crypto changes are not landed upstream yet, but when they are, this picks up the dependency.
Cast timestamps to time_t.
This is done unconditionally here, because the standard specifies that
tv_sec
intimespec
has typetime_t
, and doing so avoids a type mismatch error on the platform.Since pthread types are pointers here, make the usual changes to capture the fact they are optional types on the Swift side.
So far, this has been the only set of changes that have seemed necessary.
Fixes #114.