Skip to content

[stdlib] sem_t is a nullable pointer on OpenBSD. #31853

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

Merged
merged 1 commit into from
May 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions stdlib/public/Platform/Platform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -382,14 +382,21 @@ internal var _ignore = _UnsupportedPlatformError()
//===----------------------------------------------------------------------===//

#if !os(Windows)

#if os(OpenBSD)
public typealias Semaphore = UnsafeMutablePointer<sem_t?>
#else
public typealias Semaphore = UnsafeMutablePointer<sem_t>
#endif

/// The value returned by `sem_open()` in the case of failure.
public var SEM_FAILED: UnsafeMutablePointer<sem_t>? {
public var SEM_FAILED: Semaphore? {
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
// The value is ABI. Value verified to be correct for OS X, iOS, watchOS, tvOS.
return UnsafeMutablePointer<sem_t>(bitPattern: -1)
return Semaphore(bitPattern: -1)
#elseif os(Linux) || os(FreeBSD) || os(OpenBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku) || os(WASI)
// The value is ABI. Value verified to be correct on Glibc.
return UnsafeMutablePointer<sem_t>(bitPattern: 0)
return Semaphore(bitPattern: 0)
#else
_UnsupportedPlatformError()
#endif
Expand All @@ -398,7 +405,7 @@ public var SEM_FAILED: UnsafeMutablePointer<sem_t>? {
public func sem_open(
_ name: UnsafePointer<CChar>,
_ oflag: Int32
) -> UnsafeMutablePointer<sem_t>? {
) -> Semaphore? {
return _stdlib_sem_open2(name, oflag)
}

Expand All @@ -407,9 +414,10 @@ public func sem_open(
_ oflag: Int32,
_ mode: mode_t,
_ value: CUnsignedInt
) -> UnsafeMutablePointer<sem_t>? {
) -> Semaphore? {
return _stdlib_sem_open4(name, oflag, mode, value)
}

#endif

//===----------------------------------------------------------------------===//
Expand Down
2 changes: 1 addition & 1 deletion test/stdlib/POSIX.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import StdlibUnittest
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
import Darwin
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku) || os(WASI)
#elseif os(Linux) || os(FreeBSD) || os(OpenBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku) || os(WASI)
import Glibc
#else
#error("Unsupported platform")
Expand Down