Skip to content
This repository was archived by the owner on Apr 21, 2023. It is now read-only.

Commit de53022

Browse files
committed
Merge branch 'refs/heads/pull/30'
2 parents 0db3f1c + 77e9512 commit de53022

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

PythonKit/PythonLibrary.swift

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ import WinSDK
2727
// The `PythonLibrary` struct that loads Python symbols at runtime.
2828
//===----------------------------------------------------------------------===//
2929

30+
#if canImport(Darwin)
31+
let RTLD_DEFAULT = UnsafeMutableRawPointer(bitPattern: -2)
32+
#else
33+
let RTLD_DEFAULT: UnsafeMutableRawPointer? = nil
34+
#endif
35+
3036
public struct PythonLibrary {
3137
private static let shared = PythonLibrary()
3238
private static let pythonInitializeSymbolName = "Py_Initialize"
@@ -160,6 +166,10 @@ private extension PythonLibrary {
160166
static var libraryVersionSeparator = ""
161167
#endif
162168

169+
private static var isPythonLibraryPreloaded: Bool {
170+
return self.loadSymbol(RTLD_DEFAULT, self.pythonInitializeSymbolName) != nil
171+
}
172+
163173
static let libraryPaths: [String] = {
164174
var libraryPaths: [String] = []
165175
for librarySearchPath in librarySearchPaths {
@@ -173,14 +183,10 @@ private extension PythonLibrary {
173183
}
174184
return libraryPaths
175185
}()
176-
177-
static var isPythonLibraryLoaded: Bool {
178-
return self.loadSymbol(nil, self.pythonInitializeSymbolName) != nil
179-
}
180-
186+
181187
static func loadPythonLibrary() -> UnsafeMutableRawPointer? {
182-
if self.isPythonLibraryLoaded {
183-
return nil
188+
if self.isPythonLibraryPreloaded {
189+
return RTLD_DEFAULT
184190
}
185191
else if let pythonLibraryPath = Environment.library.value {
186192
return self.loadPythonLibrary(at: pythonLibraryPath)

0 commit comments

Comments
 (0)