Skip to content

Commit 234bc28

Browse files
author
Max Moiseev
committed
[stdlib] fixing compilation on Linux
1 parent e48f452 commit 234bc28

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

stdlib/private/SwiftPrivateLibcExtras/Subprocess.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func posixPipe() -> (readFD: CInt, writeFD: CInt) {
6464
/// stderr.
6565
public func spawnChild(args: [String])
6666
-> (pid: pid_t, stdinFD: CInt, stdoutFD: CInt, stderrFD: CInt) {
67-
var fileActions: posix_spawn_file_actions_t = nil
67+
var fileActions: posix_spawn_file_actions_t = _make_posix_spawn_file_actions_t()
6868
if swift_posix_spawn_file_actions_init(&fileActions) != 0 {
6969
preconditionFailure("swift_posix_spawn_file_actions_init() failed")
7070
}
@@ -140,6 +140,14 @@ public func spawnChild(args: [String])
140140
return (pid, childStdin.writeFD, childStdout.readFD, childStderr.readFD)
141141
}
142142

143+
internal func _make_posix_spawn_file_actions_t() -> posix_spawn_file_actions_t {
144+
#if os(Linux) || os(FreeBSD)
145+
return posix_spawn_file_actions_t()
146+
#else
147+
return nil
148+
#endif
149+
}
150+
143151
internal func _readAll(fd: CInt) -> String {
144152
var buffer = [UInt8](repeating: 0, count: 1024)
145153
var usedBytes = 0

stdlib/private/SwiftPrivatePthreadExtras/SwiftPrivatePthreadExtras.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public func _stdlib_pthread_create_block<Argument, Result>(
7171
let contextAsOpaque = OpaquePointer(bitPattern: Unmanaged.passRetained(context))
7272
let contextAsVoidPointer = UnsafeMutablePointer<Void>(contextAsOpaque)
7373

74-
var threadID: pthread_t = nil
74+
var threadID: pthread_t = _make_pthread_t()
7575
let result = pthread_create(&threadID, attr,
7676
invokeBlockContext, contextAsVoidPointer)
7777
if result == 0 {
@@ -81,6 +81,14 @@ public func _stdlib_pthread_create_block<Argument, Result>(
8181
}
8282
}
8383

84+
internal func _make_pthread_t() -> pthread_t {
85+
#if os(Linux) || os(FreeBSD)
86+
return pthread_t()
87+
#else
88+
return nil
89+
#endif
90+
}
91+
8492
/// Block-based wrapper for `pthread_join`.
8593
public func _stdlib_pthread_join<Result>(
8694
thread: pthread_t,

0 commit comments

Comments
 (0)