File tree Expand file tree Collapse file tree 5 files changed +65
-31
lines changed Expand file tree Collapse file tree 5 files changed +65
-31
lines changed Original file line number Diff line number Diff line change @@ -98,7 +98,7 @@ func spawnExecutable(
98
98
// least close all file descriptors higher than the highest inherited one.
99
99
// We are assuming here that the caller didn't set FD_CLOEXEC on any of
100
100
// these file descriptors.
101
- _ = _posix_spawn_file_actions_addclosefrom_np ? ( fileActions. baseAddress!, highestFD + 1 )
101
+ _ = swt_posix_spawn_file_actions_addclosefrom_np ( fileActions. baseAddress!, highestFD + 1 )
102
102
#else
103
103
#warning("Platform-specific implementation missing: cannot close unused file descriptors")
104
104
#endif
@@ -191,20 +191,6 @@ func spawnExecutable(
191
191
192
192
// MARK: -
193
193
194
- #if os(Linux) || os(FreeBSD)
195
- /// Close file descriptors above a given value when spawing a new process.
196
- ///
197
- /// This symbol is provided because the underlying function was added to glibc
198
- /// relatively recently and may not be available on all targets. Checking
199
- /// `__GLIBC_REQ()` is insufficient because `_DEFAULT_SOURCE` may not be
200
- /// defined at the point spawn.h is first included.
201
- private let _posix_spawn_file_actions_addclosefrom_np = {
202
- symbol ( named: " posix_spawn_file_actions_addclosefrom_np " ) . map {
203
- unsafeBitCast ( $0, to: ( @convention( c) ( UnsafeMutablePointer < posix_spawn_file_actions_t > , CInt) - > CInt) . self)
204
- }
205
- } ( )
206
- #endif
207
-
208
194
#if os(Windows)
209
195
/// Create a temporary instance of `STARTUPINFOEXW` to pass to
210
196
/// `CreateProcessW()`.
Original file line number Diff line number Diff line change @@ -109,7 +109,7 @@ private let _createWaitThreadImpl: Void = {
109
109
#if SWT_TARGET_OS_APPLE
110
110
_ = pthread_setname_np ( " Swift Testing exit test monitor " )
111
111
#elseif os(Linux)
112
- _ = _pthread_setname_np ? ( pthread_self ( ) , " SWT ExT monitor " )
112
+ _ = swt_pthread_setname_np ( pthread_self ( ) , " SWT ExT monitor " )
113
113
#elseif os(FreeBSD)
114
114
_ = pthread_set_name_np ( pthread_self ( ) , " SWT ex test monitor " )
115
115
#else
@@ -232,19 +232,4 @@ func wait(for processHandle: consuming HANDLE) async throws -> ExitCondition {
232
232
return . exitCode( CInt ( bitPattern: . init( status) ) )
233
233
}
234
234
#endif
235
-
236
- // MARK: -
237
-
238
- #if os(Linux)
239
- /// Set the name of the current thread.
240
- ///
241
- /// This symbol is provided because `pthread_setname_np()` is only declared if
242
- /// `_GNU_SOURCE` is set, but setting it causes build errors due to conflicts
243
- /// with Swift's Glibc module.
244
- private let _pthread_setname_np = {
245
- symbol ( named: " pthread_setname_np " ) . map {
246
- unsafeBitCast( $0, to: ( @convention( c) ( pthread_t, UnsafePointer < CChar > ) -> CInt) . self)
247
- }
248
- } ( )
249
- #endif
250
235
#endif
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ include(LibraryVersion)
12
12
include (TargetTriple )
13
13
add_library (_TestingInternals STATIC
14
14
Discovery.cpp
15
+ Stubs.cpp
15
16
Versions.cpp
16
17
WillThrow.cpp )
17
18
target_include_directories (_TestingInternals PUBLIC
Original file line number Diff line number Diff line change
1
+ //
2
+ // This source file is part of the Swift.org open source project
3
+ //
4
+ // Copyright (c) 2024 Apple Inc. and the Swift project authors
5
+ // Licensed under Apache License v2.0 with Runtime Library Exception
6
+ //
7
+ // See https://swift.org/LICENSE.txt for license information
8
+ // See https://swift.org/CONTRIBUTORS.txt for Swift project authors
9
+ //
10
+
11
+ // / This source file includes implementations of functions that _should_ simply
12
+ // / be `static` stubs in Stubs.h, but which for technical reasons cannot be
13
+ // / imported into Swift when defined in a header.
14
+ // /
15
+ // / Do not, as a rule, add function implementations in this file. Prefer to add
16
+ // / them to Stubs.h so that they can be inlined at compile- or link-time. Only
17
+ // / include functions here if Swift cannot successfully import and call them
18
+ // / otherwise.
19
+
20
+ #if defined(__linux__) || defined(__FreeBSD__)
21
+ #define _DEFAULT_SOURCE
22
+ #define _GNU_SOURCE
23
+ #endif
24
+
25
+ #include " Stubs.h"
26
+
27
+
28
+ #if defined(__linux__)
29
+ int swt_pthread_setname_np (pthread_t thread, const char *name) {
30
+ return pthread_setname_np (thread, name);
31
+ }
32
+ #endif
33
+
34
+ #if defined(__linux__) || defined(__FreeBSD__)
35
+ int swt_posix_spawn_file_actions_addclosefrom_np (posix_spawn_file_actions_t *fileActions, int from) {
36
+ #if defined(__GLIBC_REQ) && __GLIBC_REQ(2, 34)
37
+ return posix_spawn_file_actions_addclosefrom_np (fileActions, from);
38
+ #else
39
+ #warning glibc too old for posix_spawn_file_actions_addclosefrom_np
40
+ return 0 ;
41
+ #endif
42
+ }
43
+ #endif
Original file line number Diff line number Diff line change @@ -109,6 +109,25 @@ static char *_Nullable *_Null_unspecified swt_environ(void) {
109
109
}
110
110
#endif
111
111
112
+ #if defined(__linux__ )
113
+ /// Set the name of the current thread.
114
+ ///
115
+ /// This function declaration is provided because `pthread_setname_np()` is
116
+ /// only declared if `_GNU_SOURCE` is set, but setting it causes build errors
117
+ /// due to conflicts with Swift's Glibc module.
118
+ SWT_EXTERN int swt_pthread_setname_np (pthread_t thread , const char * name );
119
+ #endif
120
+
121
+ #if defined(__linux__ ) || defined(__FreeBSD__ )
122
+ /// Close file descriptors above a given value when spawing a new process.
123
+ ///
124
+ /// This symbol is provided because the underlying function was added to glibc
125
+ /// relatively recently and may not be available on all targets. Checking
126
+ /// `__GLIBC_REQ()` is insufficient because `_DEFAULT_SOURCE` may not be
127
+ /// defined at the point spawn.h is first included.
128
+ SWT_EXTERN int swt_posix_spawn_file_actions_addclosefrom_np (posix_spawn_file_actions_t * fileActions , int from );
129
+ #endif
130
+
112
131
#if !defined(__ANDROID__ )
113
132
#if __has_include (< signal .h > ) && defined(si_pid )
114
133
/// Get the value of the `si_pid` field of a `siginfo_t` structure.
You can’t perform that action at this time.
0 commit comments