Skip to content

Commit 7e00f7e

Browse files
authored
Merge pull request #31853 from 3405691582/Semaphore_Typealias_OpenBSD
[stdlib] sem_t is a nullable pointer on OpenBSD.
2 parents 55447e6 + f1ca2e9 commit 7e00f7e

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

stdlib/public/Platform/Platform.swift

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -382,14 +382,21 @@ internal var _ignore = _UnsupportedPlatformError()
382382
//===----------------------------------------------------------------------===//
383383

384384
#if !os(Windows)
385+
386+
#if os(OpenBSD)
387+
public typealias Semaphore = UnsafeMutablePointer<sem_t?>
388+
#else
389+
public typealias Semaphore = UnsafeMutablePointer<sem_t>
390+
#endif
391+
385392
/// The value returned by `sem_open()` in the case of failure.
386-
public var SEM_FAILED: UnsafeMutablePointer<sem_t>? {
393+
public var SEM_FAILED: Semaphore? {
387394
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
388395
// The value is ABI. Value verified to be correct for OS X, iOS, watchOS, tvOS.
389-
return UnsafeMutablePointer<sem_t>(bitPattern: -1)
396+
return Semaphore(bitPattern: -1)
390397
#elseif os(Linux) || os(FreeBSD) || os(OpenBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku) || os(WASI)
391398
// The value is ABI. Value verified to be correct on Glibc.
392-
return UnsafeMutablePointer<sem_t>(bitPattern: 0)
399+
return Semaphore(bitPattern: 0)
393400
#else
394401
_UnsupportedPlatformError()
395402
#endif
@@ -398,7 +405,7 @@ public var SEM_FAILED: UnsafeMutablePointer<sem_t>? {
398405
public func sem_open(
399406
_ name: UnsafePointer<CChar>,
400407
_ oflag: Int32
401-
) -> UnsafeMutablePointer<sem_t>? {
408+
) -> Semaphore? {
402409
return _stdlib_sem_open2(name, oflag)
403410
}
404411

@@ -407,9 +414,10 @@ public func sem_open(
407414
_ oflag: Int32,
408415
_ mode: mode_t,
409416
_ value: CUnsignedInt
410-
) -> UnsafeMutablePointer<sem_t>? {
417+
) -> Semaphore? {
411418
return _stdlib_sem_open4(name, oflag, mode, value)
412419
}
420+
413421
#endif
414422

415423
//===----------------------------------------------------------------------===//

test/stdlib/POSIX.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import StdlibUnittest
66
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
77
import Darwin
8-
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku) || os(WASI)
8+
#elseif os(Linux) || os(FreeBSD) || os(OpenBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku) || os(WASI)
99
import Glibc
1010
#else
1111
#error("Unsupported platform")

0 commit comments

Comments
 (0)