Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Sources/TSCUtility/dlopen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import protocol Foundation.CustomNSError
import var Foundation.NSLocalizedDescriptionKey
import TSCLibc

// FIXME: deprecate 2/2022, remove once clients transitioned
@available(*, deprecated, message: "moved to swift-driver")
public final class DLHandle {
#if os(Windows)
typealias Handle = HMODULE
Expand Down Expand Up @@ -48,6 +50,8 @@ public final class DLHandle {
}
}

// FIXME: deprecate 2/2022, remove once clients transitioned
@available(*, deprecated, message: "moved to swift-driver")
public struct DLOpenFlags: RawRepresentable, OptionSet {

#if !os(Windows)
Expand Down Expand Up @@ -77,6 +81,8 @@ public struct DLOpenFlags: RawRepresentable, OptionSet {
}
}

// FIXME: deprecate 2/2022, remove once clients transitioned
@available(*, deprecated, message: "moved to swift-driver")
public enum DLError: Error {
case `open`(String)
case close(String)
Expand All @@ -88,6 +94,8 @@ extension DLError: CustomNSError {
}
}

// FIXME: deprecate 2/2022, remove once clients transitioned
@available(*, deprecated, message: "moved to swift-driver")
public func dlopen(_ path: String?, mode: DLOpenFlags) throws -> DLHandle {
#if os(Windows)
guard let handle = path?.withCString(encodedAs: UTF16.self, LoadLibraryW) else {
Expand All @@ -101,6 +109,8 @@ public func dlopen(_ path: String?, mode: DLOpenFlags) throws -> DLHandle {
return DLHandle(rawValue: handle)
}

// FIXME: deprecate 2/2022, remove once clients transitioned
@available(*, deprecated, message: "moved to swift-driver")
public func dlsym<T>(_ handle: DLHandle, symbol: String) -> T? {
#if os(Windows)
guard let ptr = GetProcAddress(handle.rawValue!, symbol) else {
Expand All @@ -114,11 +124,15 @@ public func dlsym<T>(_ handle: DLHandle, symbol: String) -> T? {
return unsafeBitCast(ptr, to: T.self)
}

// FIXME: deprecate 2/2022, remove once clients transitioned
@available(*, deprecated, message: "moved to swift-driver")
public func dlclose(_ handle: DLHandle) throws {
try handle.close()
}

#if !os(Windows)
// FIXME: deprecate 2/2022, remove once clients transitioned
@available(*, deprecated, message: "moved to swift-driver")
public func dlerror() -> String? {
if let err: UnsafeMutablePointer<Int8> = dlerror() {
return String(cString: err)
Expand Down