[stdlib] sem_t is a nullable pointer on OpenBSD. #31853
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Platform defines sem_open in Swift that calls through to the underlying
platform functions because sem_open is variadic. However, the
definitions here assume sem_t is non-nullable, but this assumption only
holds when the platform has nullability annotations on the semaphore
type, or the semaphore type on the platform is not an opaque pointer.
On OpenBSD specifically, the semaphore type is an opaque pointer without
any nullability annotations. This means that the type gets inferred as
UnsafeMutablePointer<sem_t?>? instead of UnsafeMutablePointer<sem_t>?.
To make sure the pointer values returned and their types match, we
introduce a conditional typealias.
The other option is to coerce everything to UnsafeMutablePointer<sem_t>?
but this would be a rather blunt instrument. While sem_open is public in
stdlib, it is not so much codified stdlib API, so this is a slightly
nicer approach.