@@ -27,18 +27,20 @@ import WinSDK
27
27
// The `PythonLibrary` struct that loads Python symbols at runtime.
28
28
//===----------------------------------------------------------------------===//
29
29
30
- #if canImport(Darwin)
31
- let RTLD_DEFAULT = UnsafeMutableRawPointer ( bitPattern: - 2 )
32
- #else
33
- let RTLD_DEFAULT : UnsafeMutableRawPointer ? = nil
34
- #endif
35
-
36
30
public struct PythonLibrary {
37
31
private static let shared = PythonLibrary ( )
38
32
private static let pythonInitializeSymbolName = " Py_Initialize "
39
33
private static let pythonLegacySymbolName = " PyString_AsString "
40
34
private static var librarySymbolsLoaded = false
41
35
36
+ #if canImport(Darwin)
37
+ private static let defaultLibraryHandle = UnsafeMutableRawPointer ( bitPattern: - 2 ) // RTLD_DEFAULT
38
+ #elseif canImport(Glibc)
39
+ private static let defaultLibraryHandle : UnsafeMutableRawPointer ? = nil // RTLD_DEFAULT
40
+ #elseif os(Windows)
41
+ private static let defaultLibraryHandle : UnsafeMutableRawPointer ? = nil // Unsupported
42
+ #endif
43
+
42
44
private let pythonLibraryHandle : UnsafeMutableRawPointer ?
43
45
private let isLegacyPython : Bool
44
46
@@ -167,7 +169,7 @@ private extension PythonLibrary {
167
169
#endif
168
170
169
171
private static var isPythonLibraryPreloaded : Bool {
170
- return self . loadSymbol ( RTLD_DEFAULT , self . pythonInitializeSymbolName) != nil
172
+ return self . loadSymbol ( self . defaultLibraryHandle , self . pythonInitializeSymbolName) != nil
171
173
}
172
174
173
175
static let libraryPaths : [ String ] = {
@@ -183,10 +185,10 @@ private extension PythonLibrary {
183
185
}
184
186
return libraryPaths
185
187
} ( )
186
-
188
+
187
189
static func loadPythonLibrary( ) -> UnsafeMutableRawPointer ? {
188
190
if self . isPythonLibraryPreloaded {
189
- return RTLD_DEFAULT
191
+ return self . defaultLibraryHandle
190
192
}
191
193
else if let pythonLibraryPath = Environment . library. value {
192
194
return self . loadPythonLibrary ( at: pythonLibraryPath)
0 commit comments