From eed2624825eca3b9657c59c614472f5b02613e60 Mon Sep 17 00:00:00 2001 From: KeoFoxy Date: Wed, 11 Jun 2025 16:06:46 +0300 Subject: [PATCH 1/4] if let shorthand syntax --- Sources/_Subprocess/Platforms/Subprocess+Linux.swift | 2 +- Sources/_Subprocess/Platforms/Subprocess+Unix.swift | 2 +- .../_Subprocess/Platforms/Subprocess+Windows.swift | 2 +- Sources/_Subprocess/Subprocess+Configuration.swift | 12 ++++++------ 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Sources/_Subprocess/Platforms/Subprocess+Linux.swift b/Sources/_Subprocess/Platforms/Subprocess+Linux.swift index 9debf2e3..878aa514 100644 --- a/Sources/_Subprocess/Platforms/Subprocess+Linux.swift +++ b/Sources/_Subprocess/Platforms/Subprocess+Linux.swift @@ -262,7 +262,7 @@ private let setup: () = { default: fatalError("Unexpected exit status: \(siginfo.si_code)") } - if let status = status { + if let status { let pid = siginfo._sifields._sigchld.si_pid if let existing = continuations.removeValue(forKey: pid), case .continuation(let c) = existing { diff --git a/Sources/_Subprocess/Platforms/Subprocess+Unix.swift b/Sources/_Subprocess/Platforms/Subprocess+Unix.swift index bd110301..68c90687 100644 --- a/Sources/_Subprocess/Platforms/Subprocess+Unix.swift +++ b/Sources/_Subprocess/Platforms/Subprocess+Unix.swift @@ -404,7 +404,7 @@ extension FileDescriptor { continuation.resume(throwing: POSIXError(.init(rawValue: error) ?? .ENODEV)) return } - if let data = data { + if let data { buffer += Data(data) } if done { diff --git a/Sources/_Subprocess/Platforms/Subprocess+Windows.swift b/Sources/_Subprocess/Platforms/Subprocess+Windows.swift index 978cb139..01d6ec46 100644 --- a/Sources/_Subprocess/Platforms/Subprocess+Windows.swift +++ b/Sources/_Subprocess/Platforms/Subprocess+Windows.swift @@ -1070,7 +1070,7 @@ extension FileDescriptor { } } } - if let lastError = lastError { + if let lastError { continuation.resume(throwing: CocoaError.windowsError( underlying: lastError, errorCode: .fileReadUnknown) diff --git a/Sources/_Subprocess/Subprocess+Configuration.swift b/Sources/_Subprocess/Subprocess+Configuration.swift index 0b785790..069895a2 100644 --- a/Sources/_Subprocess/Subprocess+Configuration.swift +++ b/Sources/_Subprocess/Subprocess+Configuration.swift @@ -123,15 +123,15 @@ extension Subprocess { errorError = error // lolol } - if let inputError = inputError { + if let inputError { throw inputError } - if let outputError = outputError { + if let outputError { throw outputError } - if let errorError = errorError { + if let errorError { throw errorError } } @@ -165,13 +165,13 @@ extension Subprocess { errorError = error } - if let inputError = inputError { + if let inputError { throw inputError } - if let outputError = outputError { + if let outputError { throw outputError } - if let errorError = errorError { + if let errorError { throw errorError } } From 4d87088f8eb7917034c5d56c8e1312a2c20bc712 Mon Sep 17 00:00:00 2001 From: KeoFoxy Date: Wed, 11 Jun 2025 16:40:13 +0300 Subject: [PATCH 2/4] Omit internal access control --- Sources/JExtractSwiftLib/CodePrinter.swift | 4 +- .../Convenience/SwiftSyntax+Extensions.swift | 4 +- Sources/JExtractSwiftLib/Logger.swift | 2 +- Sources/JavaKit/JavaKitVM/LockedState.swift | 4 +- Sources/SwiftKitSwift/SwiftKit.swift | 2 +- Sources/_Subprocess/LockedState.swift | 4 +- .../Platforms/Subprocess+Darwin.swift | 8 +-- .../Platforms/Subprocess+Linux.swift | 8 +-- .../Platforms/Subprocess+Unix.swift | 32 +++++------ .../Platforms/Subprocess+Windows.swift | 48 ++++++++-------- .../Subprocess+AsyncDataSequence.swift | 2 +- .../Subprocess+Configuration.swift | 24 ++++---- Sources/_Subprocess/Subprocess+IO.swift | 56 +++++++++---------- Sources/_Subprocess/Subprocess+Teardown.swift | 4 +- Sources/_Subprocess/Subprocess.swift | 22 ++++---- Sources/_Subprocess/_nio_locks.swift | 6 +- 16 files changed, 115 insertions(+), 115 deletions(-) diff --git a/Sources/JExtractSwiftLib/CodePrinter.swift b/Sources/JExtractSwiftLib/CodePrinter.swift index 449cab3d..8c22fbee 100644 --- a/Sources/JExtractSwiftLib/CodePrinter.swift +++ b/Sources/JExtractSwiftLib/CodePrinter.swift @@ -53,14 +53,14 @@ public struct CodePrinter { self.mode = mode } - internal mutating func append(_ text: String) { + mutating func append(_ text: String) { contents.append(text) if self.verbose { Swift.print(text, terminator: "") } } - internal mutating func append(contentsOf text: S) + mutating func append(contentsOf text: S) where S: Sequence, S.Element == Character { contents.append(contentsOf: text) if self.verbose { diff --git a/Sources/JExtractSwiftLib/Convenience/SwiftSyntax+Extensions.swift b/Sources/JExtractSwiftLib/Convenience/SwiftSyntax+Extensions.swift index b732b9f8..da836d45 100644 --- a/Sources/JExtractSwiftLib/Convenience/SwiftSyntax+Extensions.swift +++ b/Sources/JExtractSwiftLib/Convenience/SwiftSyntax+Extensions.swift @@ -16,7 +16,7 @@ import SwiftDiagnostics import SwiftSyntax extension WithModifiersSyntax { - internal var accessControlModifiers: DeclModifierListSyntax { + var accessControlModifiers: DeclModifierListSyntax { modifiers.filter { modifier in modifier.isAccessControl } @@ -24,7 +24,7 @@ extension WithModifiersSyntax { } extension ImplicitlyUnwrappedOptionalTypeSyntax { - internal var asOptionalTypeSyntax: any TypeSyntaxProtocol { + var asOptionalTypeSyntax: any TypeSyntaxProtocol { OptionalTypeSyntax( leadingTrivia: leadingTrivia, unexpectedBeforeWrappedType, diff --git a/Sources/JExtractSwiftLib/Logger.swift b/Sources/JExtractSwiftLib/Logger.swift index 180ffb54..541dbae4 100644 --- a/Sources/JExtractSwiftLib/Logger.swift +++ b/Sources/JExtractSwiftLib/Logger.swift @@ -111,7 +111,7 @@ extension Logger.Level: ExpressibleByArgument { } extension Logger.Level { - internal var naturalIntegralValue: Int { + var naturalIntegralValue: Int { switch self { case .trace: return 0 diff --git a/Sources/JavaKit/JavaKitVM/LockedState.swift b/Sources/JavaKit/JavaKitVM/LockedState.swift index e095668c..b3082efc 100644 --- a/Sources/JavaKit/JavaKitVM/LockedState.swift +++ b/Sources/JavaKit/JavaKitVM/LockedState.swift @@ -13,9 +13,9 @@ //===----------------------------------------------------------------------===// #if canImport(os) -internal import os +import os #if FOUNDATION_FRAMEWORK && canImport(C.os.lock) -internal import C.os.lock +import C.os.lock #endif #elseif canImport(Bionic) import Bionic diff --git a/Sources/SwiftKitSwift/SwiftKit.swift b/Sources/SwiftKitSwift/SwiftKit.swift index 38b3c1c8..fb978163 100644 --- a/Sources/SwiftKitSwift/SwiftKit.swift +++ b/Sources/SwiftKitSwift/SwiftKit.swift @@ -34,7 +34,7 @@ public func _swiftjava_swift_isUniquelyReferenced(object: UnsafeMutableRawPointe @_alwaysEmitIntoClient @_transparent - internal func _swiftjava_withHeapObject( +func _swiftjava_withHeapObject( of object: AnyObject, _ body: (UnsafeMutableRawPointer) -> R ) -> R { diff --git a/Sources/_Subprocess/LockedState.swift b/Sources/_Subprocess/LockedState.swift index e095668c..b3082efc 100644 --- a/Sources/_Subprocess/LockedState.swift +++ b/Sources/_Subprocess/LockedState.swift @@ -13,9 +13,9 @@ //===----------------------------------------------------------------------===// #if canImport(os) -internal import os +import os #if FOUNDATION_FRAMEWORK && canImport(C.os.lock) -internal import C.os.lock +import C.os.lock #endif #elseif canImport(Bionic) import Bionic diff --git a/Sources/_Subprocess/Platforms/Subprocess+Darwin.swift b/Sources/_Subprocess/Platforms/Subprocess+Darwin.swift index 4ac2276e..e1e3bdcf 100644 --- a/Sources/_Subprocess/Platforms/Subprocess+Darwin.swift +++ b/Sources/_Subprocess/Platforms/Subprocess+Darwin.swift @@ -32,9 +32,9 @@ import _CShims // Darwin specific implementation extension Subprocess.Configuration { - internal typealias StringOrRawBytes = Subprocess.StringOrRawBytes + typealias StringOrRawBytes = Subprocess.StringOrRawBytes - internal func spawn( + func spawn( withInput input: Subprocess.ExecutionInput, output: Subprocess.ExecutionOutput, error: Subprocess.ExecutionOutput @@ -288,7 +288,7 @@ extension Subprocess.PlatformOptions: Hashable { } extension Subprocess.PlatformOptions : CustomStringConvertible, CustomDebugStringConvertible { - internal func description(withIndent indent: Int) -> String { + func description(withIndent indent: Int) -> String { let indent = String(repeating: " ", count: indent * 4) return """ PlatformOptions( @@ -315,7 +315,7 @@ PlatformOptions( // MARK: - Process Monitoring @Sendable -internal func monitorProcessTermination( +func monitorProcessTermination( forProcessWithIdentifier pid: Subprocess.ProcessIdentifier ) async throws -> Subprocess.TerminationStatus { return try await withCheckedThrowingContinuation { continuation in diff --git a/Sources/_Subprocess/Platforms/Subprocess+Linux.swift b/Sources/_Subprocess/Platforms/Subprocess+Linux.swift index 878aa514..c90bda0d 100644 --- a/Sources/_Subprocess/Platforms/Subprocess+Linux.swift +++ b/Sources/_Subprocess/Platforms/Subprocess+Linux.swift @@ -22,9 +22,9 @@ import _CShims // Linux specific implementations extension Subprocess.Configuration { - internal typealias StringOrRawBytes = Subprocess.StringOrRawBytes + typealias StringOrRawBytes = Subprocess.StringOrRawBytes - internal func spawn( + func spawn( withInput input: Subprocess.ExecutionInput, output: Subprocess.ExecutionOutput, error: Subprocess.ExecutionOutput @@ -180,7 +180,7 @@ extension Subprocess.PlatformOptions: Hashable { } extension Subprocess.PlatformOptions : CustomStringConvertible, CustomDebugStringConvertible { - internal func description(withIndent indent: Int) -> String { + func description(withIndent indent: Int) -> String { let indent = String(repeating: " ", count: indent * 4) return """ PlatformOptions( @@ -210,7 +210,7 @@ extension String { // MARK: - Process Monitoring @Sendable -internal func monitorProcessTermination( +func monitorProcessTermination( forProcessWithIdentifier pid: Subprocess.ProcessIdentifier ) async throws -> Subprocess.TerminationStatus { return try await withCheckedThrowingContinuation { continuation in diff --git a/Sources/_Subprocess/Platforms/Subprocess+Unix.swift b/Sources/_Subprocess/Platforms/Subprocess+Unix.swift index 68c90687..e61428e4 100644 --- a/Sources/_Subprocess/Platforms/Subprocess+Unix.swift +++ b/Sources/_Subprocess/Platforms/Subprocess+Unix.swift @@ -106,7 +106,7 @@ extension Subprocess { } } - internal func tryTerminate() -> Error? { + func tryTerminate() -> Error? { do { try self.send(.kill, toProcessGroup: true) } catch { @@ -124,9 +124,9 @@ extension Subprocess { // MARK: - Environment Resolution extension Subprocess.Environment { - internal static let pathEnvironmentVariableName = "PATH" + static let pathEnvironmentVariableName = "PATH" - internal func pathValue() -> String? { + func pathValue() -> String? { switch self.config { case .inherit(let overrides): // If PATH value exists in overrides, use it @@ -145,7 +145,7 @@ extension Subprocess.Environment { // This method follows the standard "create" rule: `env` needs to be // manually deallocated - internal func createEnv() -> [UnsafeMutablePointer?] { + func createEnv() -> [UnsafeMutablePointer?] { func createFullCString( fromKey keyContainer: Subprocess.StringOrRawBytes, value valueContainer: Subprocess.StringOrRawBytes @@ -212,7 +212,7 @@ extension Subprocess.Environment { extension Subprocess.Arguments { // This method follows the standard "create" rule: `args` needs to be // manually deallocated - internal func createArgs(withExecutablePath executablePath: String) -> [UnsafeMutablePointer?] { + func createArgs(withExecutablePath executablePath: String) -> [UnsafeMutablePointer?] { var argv: [UnsafeMutablePointer?] = self.storage.map { $0.createRawBytes() } // argv[0] = executable path if let override = self.executablePathOverride { @@ -246,7 +246,7 @@ extension Subprocess.ProcessIdentifier : CustomStringConvertible, CustomDebugStr // MARK: - Executable Searching extension Subprocess.Executable { - internal static var defaultSearchPaths: Set { + static var defaultSearchPaths: Set { return Set([ "/usr/bin", "/bin", @@ -256,7 +256,7 @@ extension Subprocess.Executable { ]) } - internal func resolveExecutablePath(withPathValue pathValue: String?) -> String? { + func resolveExecutablePath(withPathValue pathValue: String?) -> String? { switch self.storage { case .executable(let executableName): // If the executableName in is already a full path, return it directly @@ -289,7 +289,7 @@ extension Subprocess.Executable { // MARK: - Configuration extension Subprocess.Configuration { - internal func preSpawn() throws -> ( + func preSpawn() throws -> ( executablePath: String, env: [UnsafeMutablePointer?], argv: [UnsafeMutablePointer?], @@ -343,7 +343,7 @@ extension Subprocess.Configuration { ) } - internal static func pathAccessible(_ path: String, mode: Int32) -> Bool { + static func pathAccessible(_ path: String, mode: Int32) -> Bool { return path.withCString { return access($0, mode) == 0 } @@ -352,18 +352,18 @@ extension Subprocess.Configuration { // MARK: - FileDescriptor extensions extension FileDescriptor { - internal static func openDevNull( + static func openDevNull( withAcessMode mode: FileDescriptor.AccessMode ) throws -> FileDescriptor { let devnull: FileDescriptor = try .open("/dev/null", mode) return devnull } - internal var platformDescriptor: Subprocess.PlatformFileDescriptor { + var platformDescriptor: Subprocess.PlatformFileDescriptor { return self } - internal func readChunk(upToLength maxLength: Int) async throws -> Data? { + func readChunk(upToLength maxLength: Int) async throws -> Data? { return try await withCheckedThrowingContinuation { continuation in DispatchIO.read( fromFileDescriptor: self.rawValue, @@ -383,7 +383,7 @@ extension FileDescriptor { } } - internal func readUntilEOF(upToLength maxLength: Int) async throws -> Data { + func readUntilEOF(upToLength maxLength: Int) async throws -> Data { return try await withCheckedThrowingContinuation { continuation in let dispatchIO = DispatchIO( type: .stream, @@ -415,7 +415,7 @@ extension FileDescriptor { } } - internal func write(_ data: S) async throws where S.Element == UInt8 { + func write(_ data: S) async throws where S.Element == UInt8 { try await withCheckedThrowingContinuation { (continuation: CheckedContinuation) -> Void in let dispatchData: DispatchData = Array(data).withUnsafeBytes { return DispatchData(bytes: $0) @@ -439,13 +439,13 @@ extension FileDescriptor { } extension Subprocess { - internal typealias PlatformFileDescriptor = FileDescriptor + typealias PlatformFileDescriptor = FileDescriptor } // MARK: - Read Buffer Size extension Subprocess { @inline(__always) - internal static var readBufferSize: Int { + static var readBufferSize: Int { #if canImport(Darwin) return 16384 #else diff --git a/Sources/_Subprocess/Platforms/Subprocess+Windows.swift b/Sources/_Subprocess/Platforms/Subprocess+Windows.swift index 01d6ec46..f95fa197 100644 --- a/Sources/_Subprocess/Platforms/Subprocess+Windows.swift +++ b/Sources/_Subprocess/Platforms/Subprocess+Windows.swift @@ -21,7 +21,7 @@ import FoundationEssentials // Windows specific implementation extension Subprocess.Configuration { - internal func spawn( + func spawn( withInput input: Subprocess.ExecutionInput, output: Subprocess.ExecutionOutput, error: Subprocess.ExecutionOutput @@ -44,7 +44,7 @@ extension Subprocess.Configuration { } } - internal func spawnDirect( + func spawnDirect( withInput input: Subprocess.ExecutionInput, output: Subprocess.ExecutionOutput, error: Subprocess.ExecutionOutput @@ -141,7 +141,7 @@ extension Subprocess.Configuration { ) } - internal func spawnAsUser( + func spawnAsUser( withInput input: Subprocess.ExecutionInput, output: Subprocess.ExecutionOutput, error: Subprocess.ExecutionOutput, @@ -274,13 +274,13 @@ extension Subprocess { /// `ConsoleBehavior` defines how should the console appear /// when spawning a new process public struct ConsoleBehavior: Sendable, Hashable { - internal enum Storage: Sendable, Hashable { + enum Storage: Sendable, Hashable { case createNew case detatch case inherit } - internal let storage: Storage + let storage: Storage private init(_ storage: Storage) { self.storage = storage @@ -301,16 +301,16 @@ extension Subprocess { /// `ConsoleBehavior` defines how should the window appear /// when spawning a new process public struct WindowStyle: Sendable, Hashable { - internal enum Storage: Sendable, Hashable { + enum Storage: Sendable, Hashable { case normal case hidden case maximized case minimized } - internal let storage: Storage + let storage: Storage - internal var platformStyle: WORD { + var platformStyle: WORD { switch self.storage { case .hidden: return WORD(SW_HIDE) case .maximized: return WORD(SW_SHOWMAXIMIZED) @@ -401,7 +401,7 @@ extension Subprocess.PlatformOptions: Hashable { } extension Subprocess.PlatformOptions : CustomStringConvertible, CustomDebugStringConvertible { - internal func description(withIndent indent: Int) -> String { + func description(withIndent indent: Int) -> String { let indent = String(repeating: " ", count: indent * 4) return """ PlatformOptions( @@ -425,7 +425,7 @@ PlatformOptions( // MARK: - Process Monitoring @Sendable -internal func monitorProcessTermination( +func monitorProcessTermination( forProcessWithIdentifier pid: Subprocess.ProcessIdentifier ) async throws -> Subprocess.TerminationStatus { // Once the continuation resumes, it will need to unregister the wait, so @@ -580,7 +580,7 @@ extension Subprocess { } } - internal func tryTerminate() -> Error? { + func tryTerminate() -> Error? { do { try self.terminate(withExitCode: 0) } catch { @@ -595,7 +595,7 @@ extension Subprocess.Executable { // Technically not needed for CreateProcess since // it takes process name. It's here to support // Executable.resolveExecutablePath - internal func resolveExecutablePath(withPathValue pathValue: String?) -> String? { + func resolveExecutablePath(withPathValue pathValue: String?) -> String? { switch self.storage { case .executable(let executableName): return executableName.withCString( @@ -634,9 +634,9 @@ extension Subprocess.Executable { // MARK: - Environment Resolution extension Subprocess.Environment { - internal static let pathEnvironmentVariableName = "Path" + static let pathEnvironmentVariableName = "Path" - internal func pathValue() -> String? { + func pathValue() -> String? { switch self.config { case .inherit(let overrides): // If PATH value exists in overrides, use it @@ -663,7 +663,7 @@ extension Subprocess { /// Windows specific thread identifier associated with process public let threadID: DWORD - internal init( + init( processID: DWORD, threadID: DWORD ) { @@ -940,13 +940,13 @@ extension Subprocess.Configuration { // MARK: - PlatformFileDescriptor Type extension Subprocess { - internal typealias PlatformFileDescriptor = HANDLE + typealias PlatformFileDescriptor = HANDLE } // MARK: - Read Buffer Size extension Subprocess { @inline(__always) - internal static var readBufferSize: Int { + static var readBufferSize: Int { // FIXME: Use Platform.pageSize here var sysInfo: SYSTEM_INFO = SYSTEM_INFO() GetSystemInfo(&sysInfo) @@ -956,7 +956,7 @@ extension Subprocess { // MARK: - Pipe Support extension FileDescriptor { - internal static func pipe() throws -> ( + static func pipe() throws -> ( readEnd: FileDescriptor, writeEnd: FileDescriptor ) { @@ -992,7 +992,7 @@ extension FileDescriptor { ) } - internal static func openDevNull( + static func openDevNull( withAcessMode mode: FileDescriptor.AccessMode ) throws -> FileDescriptor { return try "NUL".withPlatformString { @@ -1024,7 +1024,7 @@ extension FileDescriptor { return HANDLE(bitPattern: _get_osfhandle(self.rawValue))! } - internal func read(upToLength maxLength: Int) async throws -> Data { + func read(upToLength maxLength: Int) async throws -> Data { // TODO: Figure out a better way to asynchornously read return try await withCheckedThrowingContinuation { continuation in DispatchQueue.global(qos: .userInitiated).async { @@ -1082,7 +1082,7 @@ extension FileDescriptor { } } - internal func write(_ data: S) async throws where S.Element == UInt8 { + func write(_ data: S) async throws where S.Element == UInt8 { // TODO: Figure out a better way to asynchornously write try await withCheckedThrowingContinuation { ( continuation: CheckedContinuation @@ -1117,7 +1117,7 @@ extension String { } // MARK: - CocoaError + Win32 -internal let NSUnderlyingErrorKey = "NSUnderlyingError" +let NSUnderlyingErrorKey = "NSUnderlyingError" extension CocoaError { static func windowsError(underlying: DWORD, errorCode: Code) -> CocoaError { @@ -1155,7 +1155,7 @@ private extension Optional where Wrapped == String { // MARK: - Remove these when merging back to SwiftFoundation extension String { - internal func withNTPathRepresentation( + func withNTPathRepresentation( _ body: (UnsafePointer) throws -> Result ) throws -> Result { guard !isEmpty else { @@ -1199,7 +1199,7 @@ struct Win32Error: Error { } } -internal extension UInt8 { +extension UInt8 { static var _slash: UInt8 { UInt8(ascii: "/") } static var _backslash: UInt8 { UInt8(ascii: "\\") } static var _colon: UInt8 { UInt8(ascii: ":") } diff --git a/Sources/_Subprocess/Subprocess+AsyncDataSequence.swift b/Sources/_Subprocess/Subprocess+AsyncDataSequence.swift index a3a3e393..c731c032 100644 --- a/Sources/_Subprocess/Subprocess+AsyncDataSequence.swift +++ b/Sources/_Subprocess/Subprocess+AsyncDataSequence.swift @@ -36,7 +36,7 @@ extension Subprocess { private var currentPosition: Int private var finished: Bool - internal init(fileDescriptor: FileDescriptor) { + init(fileDescriptor: FileDescriptor) { self.fileDescriptor = fileDescriptor self.buffer = [] self.currentPosition = 0 diff --git a/Sources/_Subprocess/Subprocess+Configuration.swift b/Sources/_Subprocess/Subprocess+Configuration.swift index 069895a2..8db73de5 100644 --- a/Sources/_Subprocess/Subprocess+Configuration.swift +++ b/Sources/_Subprocess/Subprocess+Configuration.swift @@ -33,7 +33,7 @@ extension Subprocess { /// spawning a subprocess. public struct Configuration: Sendable, Hashable { - internal enum RunState: Sendable { + enum RunState: Sendable { case workBody(Result) case monitorChildProcess(TerminationStatus) } @@ -138,7 +138,7 @@ extension Subprocess { /// Close each input individually, and throw the first error if there's multiple errors thrown @Sendable - internal func cleanupAll( + func cleanupAll( input: ExecutionInput, output: ExecutionOutput, error: ExecutionOutput @@ -176,7 +176,7 @@ extension Subprocess { } } - internal func run( + func run( output: RedirectedOutputMethod, error: RedirectedOutputMethod, _ body: sending @escaping (Subprocess, StandardInputWriter) async throws -> R @@ -251,7 +251,7 @@ extension Subprocess { } } - internal func run( + func run( input: InputMethod, output: RedirectedOutputMethod, error: RedirectedOutputMethod, @@ -357,12 +357,12 @@ extension Subprocess { /// `Subprocess.Executable` defines how should the executable /// be looked up for execution. public struct Executable: Sendable, Hashable { - internal enum Configuration: Sendable, Hashable { + enum Configuration: Sendable, Hashable { case executable(String) case path(FilePath) } - internal let storage: Configuration + let storage: Configuration private init(_config: Configuration) { self.storage = _config @@ -415,8 +415,8 @@ extension Subprocess { public struct Arguments: Sendable, ExpressibleByArrayLiteral, Hashable { public typealias ArrayLiteralElement = String - internal let storage: [StringOrRawBytes] - internal let executablePathOverride: StringOrRawBytes? + let storage: [StringOrRawBytes] + let executablePathOverride: StringOrRawBytes? /// Create an Arguments object using the given literal values public init(arrayLiteral elements: String...) { @@ -489,12 +489,12 @@ extension Subprocess.Arguments : CustomStringConvertible, CustomDebugStringConve extension Subprocess { /// A set of environment variables to use when executing the subprocess. public struct Environment: Sendable, Hashable { - internal enum Configuration: Sendable, Hashable { + enum Configuration: Sendable, Hashable { case inherit([StringOrRawBytes : StringOrRawBytes]) case custom([StringOrRawBytes : StringOrRawBytes]) } - internal let config: Configuration + let config: Configuration init(config: Configuration) { self.config = config @@ -630,7 +630,7 @@ extension Subprocess.TerminationStatus : CustomStringConvertible, CustomDebugStr // MARK: - Internal extension Subprocess { - internal enum StringOrRawBytes: Sendable, Hashable { + enum StringOrRawBytes: Sendable, Hashable { case string(String) case rawBytes([CChar]) @@ -737,7 +737,7 @@ public enum QualityOfService: Int, Sendable { case `default` = -1 } -internal func withAsyncTaskCancellationHandler( +func withAsyncTaskCancellationHandler( _ body: sending @escaping () async throws -> R, onCancel handler: sending @escaping () async -> Void ) async rethrows -> R { diff --git a/Sources/_Subprocess/Subprocess+IO.swift b/Sources/_Subprocess/Subprocess+IO.swift index 1b43e421..8a2f142b 100644 --- a/Sources/_Subprocess/Subprocess+IO.swift +++ b/Sources/_Subprocess/Subprocess+IO.swift @@ -43,18 +43,18 @@ extension Subprocess { /// `InputMethod` defines how should the standard input /// of the subprocess receive inputs. public struct InputMethod: Sendable, Hashable { - internal enum Storage: Sendable, Hashable { + enum Storage: Sendable, Hashable { case noInput case fileDescriptor(FileDescriptor, Bool) } - internal let method: Storage + let method: Storage - internal init(method: Storage) { + init(method: Storage) { self.method = method } - internal func createExecutionInput() throws -> ExecutionInput { + func createExecutionInput() throws -> ExecutionInput { switch self.method { case .noInput: let devnull: FileDescriptor = try .openDevNull(withAcessMode: .readOnly) @@ -88,15 +88,15 @@ extension Subprocess { /// `CollectedOutputMethod` defines how should Subprocess collect /// output from child process' standard output and standard error public struct CollectedOutputMethod: Sendable, Hashable { - internal enum Storage: Sendable, Hashable { + enum Storage: Sendable, Hashable { case discarded case fileDescriptor(FileDescriptor, Bool) case collected(Int) } - internal let method: Storage + let method: Storage - internal init(method: Storage) { + init(method: Storage) { self.method = method } @@ -122,7 +122,7 @@ extension Subprocess { return .init(method: .collected(limit)) } - internal func createExecutionOutput() throws -> ExecutionOutput { + func createExecutionOutput() throws -> ExecutionOutput { switch self.method { case .discarded: // Bind to /dev/null @@ -142,9 +142,9 @@ extension Subprocess { public struct RedirectedOutputMethod: Sendable, Hashable { typealias Storage = CollectedOutputMethod.Storage - internal let method: Storage + let method: Storage - internal init(method: Storage) { + init(method: Storage) { self.method = method } @@ -173,7 +173,7 @@ extension Subprocess { return .init(method: .fileDescriptor(fd, closeAfterSpawningProcess)) } - internal func createExecutionOutput() throws -> ExecutionOutput { + func createExecutionOutput() throws -> ExecutionOutput { switch self.method { case .discarded: // Bind to /dev/null @@ -191,10 +191,10 @@ extension Subprocess { // MARK: - Execution IO extension Subprocess { - internal final class ExecutionInput: Sendable, Hashable { + final class ExecutionInput: Sendable, Hashable { - internal enum Storage: Sendable, Hashable { + enum Storage: Sendable, Hashable { case noInput(FileDescriptor?) case customWrite(FileDescriptor?, FileDescriptor?) case fileDescriptor(FileDescriptor?, Bool) @@ -202,11 +202,11 @@ extension Subprocess { let storage: _Mutex - internal init(storage: Storage) { + init(storage: Storage) { self.storage = .init(storage) } - internal func getReadFileDescriptor() -> FileDescriptor? { + func getReadFileDescriptor() -> FileDescriptor? { return self.storage.withLock { switch $0 { case .noInput(let readFd): @@ -219,7 +219,7 @@ extension Subprocess { } } - internal func getWriteFileDescriptor() -> FileDescriptor? { + func getWriteFileDescriptor() -> FileDescriptor? { return self.storage.withLock { switch $0 { case .noInput(_), .fileDescriptor(_, _): @@ -230,7 +230,7 @@ extension Subprocess { } } - internal func closeChildSide() throws { + func closeChildSide() throws { try self.storage.withLock { switch $0 { case .noInput(let devnull): @@ -249,7 +249,7 @@ extension Subprocess { } } - internal func closeParentSide() throws { + func closeParentSide() throws { try self.storage.withLock { switch $0 { case .noInput(_), .fileDescriptor(_, _): @@ -264,7 +264,7 @@ extension Subprocess { } } - internal func closeAll() throws { + func closeAll() throws { try self.storage.withLock { switch $0 { case .noInput(let readFd): @@ -317,8 +317,8 @@ extension Subprocess { } } - internal final class ExecutionOutput: Sendable { - internal enum Storage: Sendable { + final class ExecutionOutput: Sendable { + enum Storage: Sendable { case discarded(FileDescriptor?) case fileDescriptor(FileDescriptor?, Bool) case collected(Int, FileDescriptor?, FileDescriptor?) @@ -326,11 +326,11 @@ extension Subprocess { private let storage: _Mutex - internal init(storage: Storage) { + init(storage: Storage) { self.storage = .init(storage) } - internal func getWriteFileDescriptor() -> FileDescriptor? { + func getWriteFileDescriptor() -> FileDescriptor? { return self.storage.withLock { switch $0 { case .discarded(let writeFd): @@ -343,7 +343,7 @@ extension Subprocess { } } - internal func getReadFileDescriptor() -> FileDescriptor? { + func getReadFileDescriptor() -> FileDescriptor? { return self.storage.withLock { switch $0 { case .discarded(_), .fileDescriptor(_, _): @@ -354,7 +354,7 @@ extension Subprocess { } } - internal func consumeCollectedFileDescriptor() -> (limit: Int, fd: FileDescriptor?)? { + func consumeCollectedFileDescriptor() -> (limit: Int, fd: FileDescriptor?)? { return self.storage.withLock { switch $0 { case .discarded(_), .fileDescriptor(_, _): @@ -367,7 +367,7 @@ extension Subprocess { } } - internal func closeChildSide() throws { + func closeChildSide() throws { try self.storage.withLock { switch $0 { case .discarded(let writeFd): @@ -386,7 +386,7 @@ extension Subprocess { } } - internal func closeParentSide() throws { + func closeParentSide() throws { try self.storage.withLock { switch $0 { case .discarded(_), .fileDescriptor(_, _): @@ -398,7 +398,7 @@ extension Subprocess { } } - internal func closeAll() throws { + func closeAll() throws { try self.storage.withLock { switch $0 { case .discarded(let writeFd): diff --git a/Sources/_Subprocess/Subprocess+Teardown.swift b/Sources/_Subprocess/Subprocess+Teardown.swift index 8b9af32d..290bb2f2 100644 --- a/Sources/_Subprocess/Subprocess+Teardown.swift +++ b/Sources/_Subprocess/Subprocess+Teardown.swift @@ -32,7 +32,7 @@ extension Subprocess { /// number of nanoseconds allowed for the child process to exit /// before proceeding to the next step. public struct TeardownStep: Sendable, Hashable { - internal enum Storage: Sendable, Hashable { + enum Storage: Sendable, Hashable { case sendSignal(Signal, allowedNanoseconds: UInt64) case kill } @@ -56,7 +56,7 @@ extension Subprocess { } extension Subprocess { - internal func runTeardownSequence(_ sequence: [TeardownStep]) async { + func runTeardownSequence(_ sequence: [TeardownStep]) async { // First insert the `.kill` step let finalSequence = sequence + [TeardownStep(storage: .kill)] for step in finalSequence { diff --git a/Sources/_Subprocess/Subprocess.swift b/Sources/_Subprocess/Subprocess.swift index 35f4a2c2..69c74967 100644 --- a/Sources/_Subprocess/Subprocess.swift +++ b/Sources/_Subprocess/Subprocess.swift @@ -30,11 +30,11 @@ public struct Subprocess: Sendable { /// The process identifier of the current subprocess public let processIdentifier: ProcessIdentifier - internal let executionInput: ExecutionInput - internal let executionOutput: ExecutionOutput - internal let executionError: ExecutionOutput + let executionInput: ExecutionInput + let executionOutput: ExecutionOutput + let executionError: ExecutionOutput #if os(Windows) - internal let consoleBehavior: PlatformOptions.ConsoleBehavior + let consoleBehavior: PlatformOptions.ConsoleBehavior #endif /// The standard output of the subprocess. @@ -149,7 +149,7 @@ extension Subprocess { /// The result returned by the closure passed to `.run` methods public let value: T - internal init(terminationStatus: TerminationStatus, value: T) { + init(terminationStatus: TerminationStatus, value: T) { self.terminationStatus = terminationStatus self.value = value } @@ -186,7 +186,7 @@ extension Subprocess { return output } - internal init( + init( processIdentifier: ProcessIdentifier, terminationStatus: TerminationStatus, standardOutput: Data?, @@ -253,18 +253,18 @@ Subprocess.CollectedResult( // MARK: - Internal extension Subprocess { - internal enum OutputCapturingState { + enum OutputCapturingState { case standardOutputCaptured(Data?) case standardErrorCaptured(Data?) } - internal typealias CapturedIOs = (standardOutput: Data?, standardError: Data?) + typealias CapturedIOs = (standardOutput: Data?, standardError: Data?) private func capture(fileDescriptor: FileDescriptor, maxLength: Int) async throws -> Data { return try await fileDescriptor.readUntilEOF(upToLength: maxLength) } - internal func captureStandardOutput() async throws -> Data? { + func captureStandardOutput() async throws -> Data? { guard let (limit, readFd) = self.executionOutput .consumeCollectedFileDescriptor(), let readFd = readFd else { @@ -276,7 +276,7 @@ extension Subprocess { return try await self.capture(fileDescriptor: readFd, maxLength: limit) } - internal func captureStandardError() async throws -> Data? { + func captureStandardError() async throws -> Data? { guard let (limit, readFd) = self.executionError .consumeCollectedFileDescriptor(), let readFd = readFd else { @@ -288,7 +288,7 @@ extension Subprocess { return try await self.capture(fileDescriptor: readFd, maxLength: limit) } - internal func captureIOs() async throws -> CapturedIOs { + func captureIOs() async throws -> CapturedIOs { return try await withThrowingTaskGroup(of: OutputCapturingState.self) { group in group.addTask { let stdout = try await self.captureStandardOutput() diff --git a/Sources/_Subprocess/_nio_locks.swift b/Sources/_Subprocess/_nio_locks.swift index 49053d04..d13830b6 100644 --- a/Sources/_Subprocess/_nio_locks.swift +++ b/Sources/_Subprocess/_nio_locks.swift @@ -290,7 +290,7 @@ public final class ConditionLock { /// This is currently the only way to do this in Swift: see /// https://forums.swift.org/t/support-debug-only-code/11037 for a discussion. @inlinable -internal func debugOnly(_ body: () -> Void) { +func debugOnly(_ body: () -> Void) { assert({ body(); return true }()) } @@ -460,7 +460,7 @@ extension LockStorage: @unchecked Sendable { } /// `SRWLOCK` type. public struct NIOLock { @usableFromInline - internal let _storage: LockStorage + let _storage: LockStorage /// Create a new lock. @inlinable @@ -487,7 +487,7 @@ public struct NIOLock { } @inlinable - internal func withLockPrimitive(_ body: (UnsafeMutablePointer) throws -> T) rethrows -> T { + func withLockPrimitive(_ body: (UnsafeMutablePointer) throws -> T) rethrows -> T { return try self._storage.withLockPrimitive(body) } } From 7ca47e0e49bd3bf52d2407e3e18fd7ebd0b3bb29 Mon Sep 17 00:00:00 2001 From: KeoFoxy Date: Wed, 11 Jun 2025 16:59:30 +0300 Subject: [PATCH 3/4] fix typos --- .../java/org/swift/swiftkit/SwiftArenaTest.java | 4 ++-- Sources/JavaKit/JavaValue.swift | 2 +- .../Platforms/Subprocess+Darwin.swift | 2 +- .../_Subprocess/Platforms/Subprocess+Linux.swift | 2 +- .../Platforms/Subprocess+Windows.swift | 16 ++++++++-------- .../_Subprocess/Subprocess+Configuration.swift | 4 ++-- Sources/_Subprocess/Subprocess+IO.swift | 10 +++++----- Sources/_Subprocess/Subprocess+Teardown.swift | 2 +- .../swift/swiftkit/SwiftValueWitnessTable.java | 2 +- USER_GUIDE.md | 4 ++-- 10 files changed, 24 insertions(+), 24 deletions(-) diff --git a/Samples/SwiftKitSampleApp/src/test/java/org/swift/swiftkit/SwiftArenaTest.java b/Samples/SwiftKitSampleApp/src/test/java/org/swift/swiftkit/SwiftArenaTest.java index 0d900a62..52d791a1 100644 --- a/Samples/SwiftKitSampleApp/src/test/java/org/swift/swiftkit/SwiftArenaTest.java +++ b/Samples/SwiftKitSampleApp/src/test/java/org/swift/swiftkit/SwiftArenaTest.java @@ -63,7 +63,7 @@ public void arena_markAsDestroyed_preventUseAfterFree_class() { try { unsafelyEscapedOutsideArenaScope.echoIntMethod(1); - fail("Expected exception to be thrown! Object was suposed to be dead."); + fail("Expected exception to be thrown! Object was supposed to be dead."); } catch (IllegalStateException ex) { return; } @@ -82,7 +82,7 @@ public void arena_markAsDestroyed_preventUseAfterFree_struct() { try { unsafelyEscapedOutsideArenaScope.echoIntMethod(1); - fail("Expected exception to be thrown! Object was suposed to be dead."); + fail("Expected exception to be thrown! Object was supposed to be dead."); } catch (IllegalStateException ex) { return; } diff --git a/Sources/JavaKit/JavaValue.swift b/Sources/JavaKit/JavaValue.swift index 310b54df..1bc156a0 100644 --- a/Sources/JavaKit/JavaValue.swift +++ b/Sources/JavaKit/JavaValue.swift @@ -34,7 +34,7 @@ import JavaTypes /// The protocol provides operations to bridge values in both directions: /// - `getJNIValue(in:)`: produces the JNI value (of type `JNIType`) for the /// `self` Swift value in the given JNI environment. -/// - `init(fromJNI:in:)`: intializes a Swift value from the JNI value (of +/// - `init(fromJNI:in:)`: initializes a Swift value from the JNI value (of /// type `JNIType`) in the given JNI environment. /// /// The protocol also provides hooks to tie into JNI, including operations to diff --git a/Sources/_Subprocess/Platforms/Subprocess+Darwin.swift b/Sources/_Subprocess/Platforms/Subprocess+Darwin.swift index e1e3bdcf..7bf2b2ac 100644 --- a/Sources/_Subprocess/Platforms/Subprocess+Darwin.swift +++ b/Sources/_Subprocess/Platforms/Subprocess+Darwin.swift @@ -224,7 +224,7 @@ extension Subprocess { public var launchRequirementData: Data? = nil /// An ordered list of steps in order to tear down the child /// process in case the parent task is cancelled before - /// the child proces terminates. + /// the child process terminates. /// Always ends in sending a `.kill` signal at the end. public var teardownSequence: [TeardownStep] = [] /// A closure to configure platform-specific diff --git a/Sources/_Subprocess/Platforms/Subprocess+Linux.swift b/Sources/_Subprocess/Platforms/Subprocess+Linux.swift index c90bda0d..5f013a3f 100644 --- a/Sources/_Subprocess/Platforms/Subprocess+Linux.swift +++ b/Sources/_Subprocess/Platforms/Subprocess+Linux.swift @@ -123,7 +123,7 @@ extension Subprocess { public var createSession: Bool = false /// An ordered list of steps in order to tear down the child /// process in case the parent task is cancelled before - /// the child proces terminates. + /// the child process terminates. /// Always ends in sending a `.kill` signal at the end. public var teardownSequence: [TeardownStep] = [] /// A closure to configure platform-specific diff --git a/Sources/_Subprocess/Platforms/Subprocess+Windows.swift b/Sources/_Subprocess/Platforms/Subprocess+Windows.swift index f95fa197..7ba1080e 100644 --- a/Sources/_Subprocess/Platforms/Subprocess+Windows.swift +++ b/Sources/_Subprocess/Platforms/Subprocess+Windows.swift @@ -276,7 +276,7 @@ extension Subprocess { public struct ConsoleBehavior: Sendable, Hashable { enum Storage: Sendable, Hashable { case createNew - case detatch + case detach case inherit } @@ -293,7 +293,7 @@ extension Subprocess { /// inherit its parent's console (the default). /// The new process can call the `AllocConsole` /// function at a later time to create a console. - public static let detatch: Self = .init(.detatch) + public static let detach: Self = .init(.detach) /// The subprocess inherits its parent's console. public static let inherit: Self = .init(.inherit) } @@ -658,7 +658,7 @@ extension Subprocess.Environment { extension Subprocess { /// A platform independent identifier for a subprocess. public struct ProcessIdentifier: Sendable, Hashable, Codable { - /// Windows specifc process identifier value + /// Windows specific process identifier value public let processID: DWORD /// Windows specific thread identifier associated with process public let threadID: DWORD @@ -755,7 +755,7 @@ extension Subprocess.Configuration { switch self.platformOptions.consoleBehavior.storage { case .createNew: flags |= CREATE_NEW_CONSOLE - case .detatch: + case .detach: flags |= DETACHED_PROCESS case .inherit: break @@ -853,7 +853,7 @@ extension Subprocess.Configuration { } // The first parameter of CreateProcessW, `lpApplicationName` // is optional. If it's nil, CreateProcessW uses argument[0] - // as the execuatble name. + // as the executable name. // We should only set lpApplicationName if it's different from // argument[0] (i.e. executablePathOverride) var applicationName: String? = nil @@ -1025,7 +1025,7 @@ extension FileDescriptor { } func read(upToLength maxLength: Int) async throws -> Data { - // TODO: Figure out a better way to asynchornously read + // TODO: Figure out a better way to asynchronously read return try await withCheckedThrowingContinuation { continuation in DispatchQueue.global(qos: .userInitiated).async { var totalBytesRead: Int = 0 @@ -1060,7 +1060,7 @@ extension FileDescriptor { } break } else { - // We succesfully read the current round + // We successfully read the current round totalBytesRead += Int(bytesRead) } @@ -1083,7 +1083,7 @@ extension FileDescriptor { } func write(_ data: S) async throws where S.Element == UInt8 { - // TODO: Figure out a better way to asynchornously write + // TODO: Figure out a better way to asynchronously write try await withCheckedThrowingContinuation { ( continuation: CheckedContinuation ) -> Void in diff --git a/Sources/_Subprocess/Subprocess+Configuration.swift b/Sources/_Subprocess/Subprocess+Configuration.swift index 8db73de5..92c07689 100644 --- a/Sources/_Subprocess/Subprocess+Configuration.swift +++ b/Sources/_Subprocess/Subprocess+Configuration.swift @@ -46,7 +46,7 @@ extension Subprocess { public var environment: Environment /// The working directory to use when running the executable. public var workingDirectory: FilePath - /// The platform specifc options to use when + /// The platform specific options to use when /// running the subprocess. public var platformOptions: PlatformOptions @@ -532,7 +532,7 @@ extension Subprocess.Environment : CustomStringConvertible, CustomDebugStringCon case .custom(let customDictionary): return customDictionary.dictionaryDescription case .inherit(let updateValue): - return "Inherting current environment with updates: \(updateValue.dictionaryDescription)" + return "Inheriting current environment with updates: \(updateValue.dictionaryDescription)" } } diff --git a/Sources/_Subprocess/Subprocess+IO.swift b/Sources/_Subprocess/Subprocess+IO.swift index 8a2f142b..a92c11cf 100644 --- a/Sources/_Subprocess/Subprocess+IO.swift +++ b/Sources/_Subprocess/Subprocess+IO.swift @@ -65,7 +65,7 @@ extension Subprocess { } /// Subprocess should read no input. This option is equivalent - /// to bind the stanard input to `/dev/null`. + /// to bind the standard input to `/dev/null`. public static var noInput: Self { return .init(method: .noInput) } @@ -100,7 +100,7 @@ extension Subprocess { self.method = method } - /// Subprocess shold dicard the child process output. + /// Subprocess should discard the child process output. /// This option is equivalent to binding the child process /// output to `/dev/null`. public static var discard: Self { @@ -148,7 +148,7 @@ extension Subprocess { self.method = method } - /// Subprocess shold dicard the child process output. + /// Subprocess should discard the child process output. /// This option is equivalent to binding the child process /// output to `/dev/null`. public static var discard: Self { @@ -160,7 +160,7 @@ extension Subprocess { public static var redirectToSequence: Self { return .init(method: .collected(128 * 1024)) } - /// Subprocess shold write the child process output + /// Subprocess should write the child process output /// to the file descriptor specified. /// - Parameters: /// - fd: the file descriptor to write to @@ -257,7 +257,7 @@ extension Subprocess { case .customWrite(let readFd, let writeFd): // The parent fd should have been closed // in the `body` when writer.finish() is called - // But in case it isn't call it agian + // But in case it isn't call it again try writeFd?.close() $0 = .customWrite(readFd, nil) } diff --git a/Sources/_Subprocess/Subprocess+Teardown.swift b/Sources/_Subprocess/Subprocess+Teardown.swift index 290bb2f2..322cbb73 100644 --- a/Sources/_Subprocess/Subprocess+Teardown.swift +++ b/Sources/_Subprocess/Subprocess+Teardown.swift @@ -79,7 +79,7 @@ extension Subprocess { try await Task.sleep(nanoseconds: allowedNanoseconds) return .processStillAlive } catch { - // teardown(using:) cancells this task + // teardown(using:) cancels this task // when process has exited return .processHasExited } diff --git a/SwiftKit/src/main/java/org/swift/swiftkit/SwiftValueWitnessTable.java b/SwiftKit/src/main/java/org/swift/swiftkit/SwiftValueWitnessTable.java index 53680f5f..5979e84a 100644 --- a/SwiftKit/src/main/java/org/swift/swiftkit/SwiftValueWitnessTable.java +++ b/SwiftKit/src/main/java/org/swift/swiftkit/SwiftValueWitnessTable.java @@ -56,7 +56,7 @@ public abstract class SwiftValueWitnessTable { MemoryLayout.PathElement.groupElement("vwt")); /** - * Given the address of Swift type metadata for a type, return the addres + * Given the address of Swift type metadata for a type, return the address * of the "full" type metadata that can be accessed via fullTypeMetadataLayout. */ public static MemorySegment fullTypeMetadata(MemorySegment typeMetadata) { diff --git a/USER_GUIDE.md b/USER_GUIDE.md index 2abe8ea0..66e2be1c 100644 --- a/USER_GUIDE.md +++ b/USER_GUIDE.md @@ -221,7 +221,7 @@ Note that we are passing the Jar file in the `classpath` argument when initializ ### Downcasting -All Java classes available in Swift provide `is` and `as` methods to check whether an object dynamically matches another type. The `is` operation is the equivalent of Java's `instanceof` and Swift's `is` operator, and will checkin whether a given object is of the specified type, e.g., +All Java classes available in Swift provide `is` and `as` methods to check whether an object dynamically matches another type. The `is` operation is the equivalent of Java's `instanceof` and Swift's `is` operator, and will checking whether a given object is of the specified type, e.g., ```swift if myObject.is(URL.self) { @@ -620,7 +620,7 @@ The project is still very early days, however the general outline of using this - These `.swiftinterface` files are imported by jextract-swift which generates `*.java` files - The generated Java files contain generated code for efficient native invocations. -You can then use Swift libraries in Java just by calling the apropriate methods and initializers. +You can then use Swift libraries in Java just by calling the appropriate methods and initializers. ## `jextract-swift`: Generating Java bridging files From 343694a5cb19de4667e9429c4d18c68c86be2ed6 Mon Sep 17 00:00:00 2001 From: KeoFoxy Date: Thu, 12 Jun 2025 11:49:36 +0300 Subject: [PATCH 4/4] Discard changes in Subprocess --- Sources/_Subprocess/LockedState.swift | 4 +- .../Platforms/Subprocess+Darwin.swift | 10 +-- .../Platforms/Subprocess+Linux.swift | 12 ++-- .../Platforms/Subprocess+Unix.swift | 34 +++++----- .../Platforms/Subprocess+Windows.swift | 66 +++++++++---------- .../Subprocess+AsyncDataSequence.swift | 2 +- .../Subprocess+Configuration.swift | 40 +++++------ Sources/_Subprocess/Subprocess+IO.swift | 66 +++++++++---------- Sources/_Subprocess/Subprocess+Teardown.swift | 6 +- Sources/_Subprocess/Subprocess.swift | 22 +++---- Sources/_Subprocess/_nio_locks.swift | 6 +- 11 files changed, 134 insertions(+), 134 deletions(-) diff --git a/Sources/_Subprocess/LockedState.swift b/Sources/_Subprocess/LockedState.swift index b3082efc..e095668c 100644 --- a/Sources/_Subprocess/LockedState.swift +++ b/Sources/_Subprocess/LockedState.swift @@ -13,9 +13,9 @@ //===----------------------------------------------------------------------===// #if canImport(os) -import os +internal import os #if FOUNDATION_FRAMEWORK && canImport(C.os.lock) -import C.os.lock +internal import C.os.lock #endif #elseif canImport(Bionic) import Bionic diff --git a/Sources/_Subprocess/Platforms/Subprocess+Darwin.swift b/Sources/_Subprocess/Platforms/Subprocess+Darwin.swift index 7bf2b2ac..4ac2276e 100644 --- a/Sources/_Subprocess/Platforms/Subprocess+Darwin.swift +++ b/Sources/_Subprocess/Platforms/Subprocess+Darwin.swift @@ -32,9 +32,9 @@ import _CShims // Darwin specific implementation extension Subprocess.Configuration { - typealias StringOrRawBytes = Subprocess.StringOrRawBytes + internal typealias StringOrRawBytes = Subprocess.StringOrRawBytes - func spawn( + internal func spawn( withInput input: Subprocess.ExecutionInput, output: Subprocess.ExecutionOutput, error: Subprocess.ExecutionOutput @@ -224,7 +224,7 @@ extension Subprocess { public var launchRequirementData: Data? = nil /// An ordered list of steps in order to tear down the child /// process in case the parent task is cancelled before - /// the child process terminates. + /// the child proces terminates. /// Always ends in sending a `.kill` signal at the end. public var teardownSequence: [TeardownStep] = [] /// A closure to configure platform-specific @@ -288,7 +288,7 @@ extension Subprocess.PlatformOptions: Hashable { } extension Subprocess.PlatformOptions : CustomStringConvertible, CustomDebugStringConvertible { - func description(withIndent indent: Int) -> String { + internal func description(withIndent indent: Int) -> String { let indent = String(repeating: " ", count: indent * 4) return """ PlatformOptions( @@ -315,7 +315,7 @@ PlatformOptions( // MARK: - Process Monitoring @Sendable -func monitorProcessTermination( +internal func monitorProcessTermination( forProcessWithIdentifier pid: Subprocess.ProcessIdentifier ) async throws -> Subprocess.TerminationStatus { return try await withCheckedThrowingContinuation { continuation in diff --git a/Sources/_Subprocess/Platforms/Subprocess+Linux.swift b/Sources/_Subprocess/Platforms/Subprocess+Linux.swift index 5f013a3f..9debf2e3 100644 --- a/Sources/_Subprocess/Platforms/Subprocess+Linux.swift +++ b/Sources/_Subprocess/Platforms/Subprocess+Linux.swift @@ -22,9 +22,9 @@ import _CShims // Linux specific implementations extension Subprocess.Configuration { - typealias StringOrRawBytes = Subprocess.StringOrRawBytes + internal typealias StringOrRawBytes = Subprocess.StringOrRawBytes - func spawn( + internal func spawn( withInput input: Subprocess.ExecutionInput, output: Subprocess.ExecutionOutput, error: Subprocess.ExecutionOutput @@ -123,7 +123,7 @@ extension Subprocess { public var createSession: Bool = false /// An ordered list of steps in order to tear down the child /// process in case the parent task is cancelled before - /// the child process terminates. + /// the child proces terminates. /// Always ends in sending a `.kill` signal at the end. public var teardownSequence: [TeardownStep] = [] /// A closure to configure platform-specific @@ -180,7 +180,7 @@ extension Subprocess.PlatformOptions: Hashable { } extension Subprocess.PlatformOptions : CustomStringConvertible, CustomDebugStringConvertible { - func description(withIndent indent: Int) -> String { + internal func description(withIndent indent: Int) -> String { let indent = String(repeating: " ", count: indent * 4) return """ PlatformOptions( @@ -210,7 +210,7 @@ extension String { // MARK: - Process Monitoring @Sendable -func monitorProcessTermination( +internal func monitorProcessTermination( forProcessWithIdentifier pid: Subprocess.ProcessIdentifier ) async throws -> Subprocess.TerminationStatus { return try await withCheckedThrowingContinuation { continuation in @@ -262,7 +262,7 @@ private let setup: () = { default: fatalError("Unexpected exit status: \(siginfo.si_code)") } - if let status { + if let status = status { let pid = siginfo._sifields._sigchld.si_pid if let existing = continuations.removeValue(forKey: pid), case .continuation(let c) = existing { diff --git a/Sources/_Subprocess/Platforms/Subprocess+Unix.swift b/Sources/_Subprocess/Platforms/Subprocess+Unix.swift index e61428e4..bd110301 100644 --- a/Sources/_Subprocess/Platforms/Subprocess+Unix.swift +++ b/Sources/_Subprocess/Platforms/Subprocess+Unix.swift @@ -106,7 +106,7 @@ extension Subprocess { } } - func tryTerminate() -> Error? { + internal func tryTerminate() -> Error? { do { try self.send(.kill, toProcessGroup: true) } catch { @@ -124,9 +124,9 @@ extension Subprocess { // MARK: - Environment Resolution extension Subprocess.Environment { - static let pathEnvironmentVariableName = "PATH" + internal static let pathEnvironmentVariableName = "PATH" - func pathValue() -> String? { + internal func pathValue() -> String? { switch self.config { case .inherit(let overrides): // If PATH value exists in overrides, use it @@ -145,7 +145,7 @@ extension Subprocess.Environment { // This method follows the standard "create" rule: `env` needs to be // manually deallocated - func createEnv() -> [UnsafeMutablePointer?] { + internal func createEnv() -> [UnsafeMutablePointer?] { func createFullCString( fromKey keyContainer: Subprocess.StringOrRawBytes, value valueContainer: Subprocess.StringOrRawBytes @@ -212,7 +212,7 @@ extension Subprocess.Environment { extension Subprocess.Arguments { // This method follows the standard "create" rule: `args` needs to be // manually deallocated - func createArgs(withExecutablePath executablePath: String) -> [UnsafeMutablePointer?] { + internal func createArgs(withExecutablePath executablePath: String) -> [UnsafeMutablePointer?] { var argv: [UnsafeMutablePointer?] = self.storage.map { $0.createRawBytes() } // argv[0] = executable path if let override = self.executablePathOverride { @@ -246,7 +246,7 @@ extension Subprocess.ProcessIdentifier : CustomStringConvertible, CustomDebugStr // MARK: - Executable Searching extension Subprocess.Executable { - static var defaultSearchPaths: Set { + internal static var defaultSearchPaths: Set { return Set([ "/usr/bin", "/bin", @@ -256,7 +256,7 @@ extension Subprocess.Executable { ]) } - func resolveExecutablePath(withPathValue pathValue: String?) -> String? { + internal func resolveExecutablePath(withPathValue pathValue: String?) -> String? { switch self.storage { case .executable(let executableName): // If the executableName in is already a full path, return it directly @@ -289,7 +289,7 @@ extension Subprocess.Executable { // MARK: - Configuration extension Subprocess.Configuration { - func preSpawn() throws -> ( + internal func preSpawn() throws -> ( executablePath: String, env: [UnsafeMutablePointer?], argv: [UnsafeMutablePointer?], @@ -343,7 +343,7 @@ extension Subprocess.Configuration { ) } - static func pathAccessible(_ path: String, mode: Int32) -> Bool { + internal static func pathAccessible(_ path: String, mode: Int32) -> Bool { return path.withCString { return access($0, mode) == 0 } @@ -352,18 +352,18 @@ extension Subprocess.Configuration { // MARK: - FileDescriptor extensions extension FileDescriptor { - static func openDevNull( + internal static func openDevNull( withAcessMode mode: FileDescriptor.AccessMode ) throws -> FileDescriptor { let devnull: FileDescriptor = try .open("/dev/null", mode) return devnull } - var platformDescriptor: Subprocess.PlatformFileDescriptor { + internal var platformDescriptor: Subprocess.PlatformFileDescriptor { return self } - func readChunk(upToLength maxLength: Int) async throws -> Data? { + internal func readChunk(upToLength maxLength: Int) async throws -> Data? { return try await withCheckedThrowingContinuation { continuation in DispatchIO.read( fromFileDescriptor: self.rawValue, @@ -383,7 +383,7 @@ extension FileDescriptor { } } - func readUntilEOF(upToLength maxLength: Int) async throws -> Data { + internal func readUntilEOF(upToLength maxLength: Int) async throws -> Data { return try await withCheckedThrowingContinuation { continuation in let dispatchIO = DispatchIO( type: .stream, @@ -404,7 +404,7 @@ extension FileDescriptor { continuation.resume(throwing: POSIXError(.init(rawValue: error) ?? .ENODEV)) return } - if let data { + if let data = data { buffer += Data(data) } if done { @@ -415,7 +415,7 @@ extension FileDescriptor { } } - func write(_ data: S) async throws where S.Element == UInt8 { + internal func write(_ data: S) async throws where S.Element == UInt8 { try await withCheckedThrowingContinuation { (continuation: CheckedContinuation) -> Void in let dispatchData: DispatchData = Array(data).withUnsafeBytes { return DispatchData(bytes: $0) @@ -439,13 +439,13 @@ extension FileDescriptor { } extension Subprocess { - typealias PlatformFileDescriptor = FileDescriptor + internal typealias PlatformFileDescriptor = FileDescriptor } // MARK: - Read Buffer Size extension Subprocess { @inline(__always) - static var readBufferSize: Int { + internal static var readBufferSize: Int { #if canImport(Darwin) return 16384 #else diff --git a/Sources/_Subprocess/Platforms/Subprocess+Windows.swift b/Sources/_Subprocess/Platforms/Subprocess+Windows.swift index 7ba1080e..978cb139 100644 --- a/Sources/_Subprocess/Platforms/Subprocess+Windows.swift +++ b/Sources/_Subprocess/Platforms/Subprocess+Windows.swift @@ -21,7 +21,7 @@ import FoundationEssentials // Windows specific implementation extension Subprocess.Configuration { - func spawn( + internal func spawn( withInput input: Subprocess.ExecutionInput, output: Subprocess.ExecutionOutput, error: Subprocess.ExecutionOutput @@ -44,7 +44,7 @@ extension Subprocess.Configuration { } } - func spawnDirect( + internal func spawnDirect( withInput input: Subprocess.ExecutionInput, output: Subprocess.ExecutionOutput, error: Subprocess.ExecutionOutput @@ -141,7 +141,7 @@ extension Subprocess.Configuration { ) } - func spawnAsUser( + internal func spawnAsUser( withInput input: Subprocess.ExecutionInput, output: Subprocess.ExecutionOutput, error: Subprocess.ExecutionOutput, @@ -274,13 +274,13 @@ extension Subprocess { /// `ConsoleBehavior` defines how should the console appear /// when spawning a new process public struct ConsoleBehavior: Sendable, Hashable { - enum Storage: Sendable, Hashable { + internal enum Storage: Sendable, Hashable { case createNew - case detach + case detatch case inherit } - let storage: Storage + internal let storage: Storage private init(_ storage: Storage) { self.storage = storage @@ -293,7 +293,7 @@ extension Subprocess { /// inherit its parent's console (the default). /// The new process can call the `AllocConsole` /// function at a later time to create a console. - public static let detach: Self = .init(.detach) + public static let detatch: Self = .init(.detatch) /// The subprocess inherits its parent's console. public static let inherit: Self = .init(.inherit) } @@ -301,16 +301,16 @@ extension Subprocess { /// `ConsoleBehavior` defines how should the window appear /// when spawning a new process public struct WindowStyle: Sendable, Hashable { - enum Storage: Sendable, Hashable { + internal enum Storage: Sendable, Hashable { case normal case hidden case maximized case minimized } - let storage: Storage + internal let storage: Storage - var platformStyle: WORD { + internal var platformStyle: WORD { switch self.storage { case .hidden: return WORD(SW_HIDE) case .maximized: return WORD(SW_SHOWMAXIMIZED) @@ -401,7 +401,7 @@ extension Subprocess.PlatformOptions: Hashable { } extension Subprocess.PlatformOptions : CustomStringConvertible, CustomDebugStringConvertible { - func description(withIndent indent: Int) -> String { + internal func description(withIndent indent: Int) -> String { let indent = String(repeating: " ", count: indent * 4) return """ PlatformOptions( @@ -425,7 +425,7 @@ PlatformOptions( // MARK: - Process Monitoring @Sendable -func monitorProcessTermination( +internal func monitorProcessTermination( forProcessWithIdentifier pid: Subprocess.ProcessIdentifier ) async throws -> Subprocess.TerminationStatus { // Once the continuation resumes, it will need to unregister the wait, so @@ -580,7 +580,7 @@ extension Subprocess { } } - func tryTerminate() -> Error? { + internal func tryTerminate() -> Error? { do { try self.terminate(withExitCode: 0) } catch { @@ -595,7 +595,7 @@ extension Subprocess.Executable { // Technically not needed for CreateProcess since // it takes process name. It's here to support // Executable.resolveExecutablePath - func resolveExecutablePath(withPathValue pathValue: String?) -> String? { + internal func resolveExecutablePath(withPathValue pathValue: String?) -> String? { switch self.storage { case .executable(let executableName): return executableName.withCString( @@ -634,9 +634,9 @@ extension Subprocess.Executable { // MARK: - Environment Resolution extension Subprocess.Environment { - static let pathEnvironmentVariableName = "Path" + internal static let pathEnvironmentVariableName = "Path" - func pathValue() -> String? { + internal func pathValue() -> String? { switch self.config { case .inherit(let overrides): // If PATH value exists in overrides, use it @@ -658,12 +658,12 @@ extension Subprocess.Environment { extension Subprocess { /// A platform independent identifier for a subprocess. public struct ProcessIdentifier: Sendable, Hashable, Codable { - /// Windows specific process identifier value + /// Windows specifc process identifier value public let processID: DWORD /// Windows specific thread identifier associated with process public let threadID: DWORD - init( + internal init( processID: DWORD, threadID: DWORD ) { @@ -755,7 +755,7 @@ extension Subprocess.Configuration { switch self.platformOptions.consoleBehavior.storage { case .createNew: flags |= CREATE_NEW_CONSOLE - case .detach: + case .detatch: flags |= DETACHED_PROCESS case .inherit: break @@ -853,7 +853,7 @@ extension Subprocess.Configuration { } // The first parameter of CreateProcessW, `lpApplicationName` // is optional. If it's nil, CreateProcessW uses argument[0] - // as the executable name. + // as the execuatble name. // We should only set lpApplicationName if it's different from // argument[0] (i.e. executablePathOverride) var applicationName: String? = nil @@ -940,13 +940,13 @@ extension Subprocess.Configuration { // MARK: - PlatformFileDescriptor Type extension Subprocess { - typealias PlatformFileDescriptor = HANDLE + internal typealias PlatformFileDescriptor = HANDLE } // MARK: - Read Buffer Size extension Subprocess { @inline(__always) - static var readBufferSize: Int { + internal static var readBufferSize: Int { // FIXME: Use Platform.pageSize here var sysInfo: SYSTEM_INFO = SYSTEM_INFO() GetSystemInfo(&sysInfo) @@ -956,7 +956,7 @@ extension Subprocess { // MARK: - Pipe Support extension FileDescriptor { - static func pipe() throws -> ( + internal static func pipe() throws -> ( readEnd: FileDescriptor, writeEnd: FileDescriptor ) { @@ -992,7 +992,7 @@ extension FileDescriptor { ) } - static func openDevNull( + internal static func openDevNull( withAcessMode mode: FileDescriptor.AccessMode ) throws -> FileDescriptor { return try "NUL".withPlatformString { @@ -1024,8 +1024,8 @@ extension FileDescriptor { return HANDLE(bitPattern: _get_osfhandle(self.rawValue))! } - func read(upToLength maxLength: Int) async throws -> Data { - // TODO: Figure out a better way to asynchronously read + internal func read(upToLength maxLength: Int) async throws -> Data { + // TODO: Figure out a better way to asynchornously read return try await withCheckedThrowingContinuation { continuation in DispatchQueue.global(qos: .userInitiated).async { var totalBytesRead: Int = 0 @@ -1060,7 +1060,7 @@ extension FileDescriptor { } break } else { - // We successfully read the current round + // We succesfully read the current round totalBytesRead += Int(bytesRead) } @@ -1070,7 +1070,7 @@ extension FileDescriptor { } } } - if let lastError { + if let lastError = lastError { continuation.resume(throwing: CocoaError.windowsError( underlying: lastError, errorCode: .fileReadUnknown) @@ -1082,8 +1082,8 @@ extension FileDescriptor { } } - func write(_ data: S) async throws where S.Element == UInt8 { - // TODO: Figure out a better way to asynchronously write + internal func write(_ data: S) async throws where S.Element == UInt8 { + // TODO: Figure out a better way to asynchornously write try await withCheckedThrowingContinuation { ( continuation: CheckedContinuation ) -> Void in @@ -1117,7 +1117,7 @@ extension String { } // MARK: - CocoaError + Win32 -let NSUnderlyingErrorKey = "NSUnderlyingError" +internal let NSUnderlyingErrorKey = "NSUnderlyingError" extension CocoaError { static func windowsError(underlying: DWORD, errorCode: Code) -> CocoaError { @@ -1155,7 +1155,7 @@ private extension Optional where Wrapped == String { // MARK: - Remove these when merging back to SwiftFoundation extension String { - func withNTPathRepresentation( + internal func withNTPathRepresentation( _ body: (UnsafePointer) throws -> Result ) throws -> Result { guard !isEmpty else { @@ -1199,7 +1199,7 @@ struct Win32Error: Error { } } -extension UInt8 { +internal extension UInt8 { static var _slash: UInt8 { UInt8(ascii: "/") } static var _backslash: UInt8 { UInt8(ascii: "\\") } static var _colon: UInt8 { UInt8(ascii: ":") } diff --git a/Sources/_Subprocess/Subprocess+AsyncDataSequence.swift b/Sources/_Subprocess/Subprocess+AsyncDataSequence.swift index c731c032..a3a3e393 100644 --- a/Sources/_Subprocess/Subprocess+AsyncDataSequence.swift +++ b/Sources/_Subprocess/Subprocess+AsyncDataSequence.swift @@ -36,7 +36,7 @@ extension Subprocess { private var currentPosition: Int private var finished: Bool - init(fileDescriptor: FileDescriptor) { + internal init(fileDescriptor: FileDescriptor) { self.fileDescriptor = fileDescriptor self.buffer = [] self.currentPosition = 0 diff --git a/Sources/_Subprocess/Subprocess+Configuration.swift b/Sources/_Subprocess/Subprocess+Configuration.swift index 92c07689..0b785790 100644 --- a/Sources/_Subprocess/Subprocess+Configuration.swift +++ b/Sources/_Subprocess/Subprocess+Configuration.swift @@ -33,7 +33,7 @@ extension Subprocess { /// spawning a subprocess. public struct Configuration: Sendable, Hashable { - enum RunState: Sendable { + internal enum RunState: Sendable { case workBody(Result) case monitorChildProcess(TerminationStatus) } @@ -46,7 +46,7 @@ extension Subprocess { public var environment: Environment /// The working directory to use when running the executable. public var workingDirectory: FilePath - /// The platform specific options to use when + /// The platform specifc options to use when /// running the subprocess. public var platformOptions: PlatformOptions @@ -123,22 +123,22 @@ extension Subprocess { errorError = error // lolol } - if let inputError { + if let inputError = inputError { throw inputError } - if let outputError { + if let outputError = outputError { throw outputError } - if let errorError { + if let errorError = errorError { throw errorError } } /// Close each input individually, and throw the first error if there's multiple errors thrown @Sendable - func cleanupAll( + internal func cleanupAll( input: ExecutionInput, output: ExecutionOutput, error: ExecutionOutput @@ -165,18 +165,18 @@ extension Subprocess { errorError = error } - if let inputError { + if let inputError = inputError { throw inputError } - if let outputError { + if let outputError = outputError { throw outputError } - if let errorError { + if let errorError = errorError { throw errorError } } - func run( + internal func run( output: RedirectedOutputMethod, error: RedirectedOutputMethod, _ body: sending @escaping (Subprocess, StandardInputWriter) async throws -> R @@ -251,7 +251,7 @@ extension Subprocess { } } - func run( + internal func run( input: InputMethod, output: RedirectedOutputMethod, error: RedirectedOutputMethod, @@ -357,12 +357,12 @@ extension Subprocess { /// `Subprocess.Executable` defines how should the executable /// be looked up for execution. public struct Executable: Sendable, Hashable { - enum Configuration: Sendable, Hashable { + internal enum Configuration: Sendable, Hashable { case executable(String) case path(FilePath) } - let storage: Configuration + internal let storage: Configuration private init(_config: Configuration) { self.storage = _config @@ -415,8 +415,8 @@ extension Subprocess { public struct Arguments: Sendable, ExpressibleByArrayLiteral, Hashable { public typealias ArrayLiteralElement = String - let storage: [StringOrRawBytes] - let executablePathOverride: StringOrRawBytes? + internal let storage: [StringOrRawBytes] + internal let executablePathOverride: StringOrRawBytes? /// Create an Arguments object using the given literal values public init(arrayLiteral elements: String...) { @@ -489,12 +489,12 @@ extension Subprocess.Arguments : CustomStringConvertible, CustomDebugStringConve extension Subprocess { /// A set of environment variables to use when executing the subprocess. public struct Environment: Sendable, Hashable { - enum Configuration: Sendable, Hashable { + internal enum Configuration: Sendable, Hashable { case inherit([StringOrRawBytes : StringOrRawBytes]) case custom([StringOrRawBytes : StringOrRawBytes]) } - let config: Configuration + internal let config: Configuration init(config: Configuration) { self.config = config @@ -532,7 +532,7 @@ extension Subprocess.Environment : CustomStringConvertible, CustomDebugStringCon case .custom(let customDictionary): return customDictionary.dictionaryDescription case .inherit(let updateValue): - return "Inheriting current environment with updates: \(updateValue.dictionaryDescription)" + return "Inherting current environment with updates: \(updateValue.dictionaryDescription)" } } @@ -630,7 +630,7 @@ extension Subprocess.TerminationStatus : CustomStringConvertible, CustomDebugStr // MARK: - Internal extension Subprocess { - enum StringOrRawBytes: Sendable, Hashable { + internal enum StringOrRawBytes: Sendable, Hashable { case string(String) case rawBytes([CChar]) @@ -737,7 +737,7 @@ public enum QualityOfService: Int, Sendable { case `default` = -1 } -func withAsyncTaskCancellationHandler( +internal func withAsyncTaskCancellationHandler( _ body: sending @escaping () async throws -> R, onCancel handler: sending @escaping () async -> Void ) async rethrows -> R { diff --git a/Sources/_Subprocess/Subprocess+IO.swift b/Sources/_Subprocess/Subprocess+IO.swift index a92c11cf..1b43e421 100644 --- a/Sources/_Subprocess/Subprocess+IO.swift +++ b/Sources/_Subprocess/Subprocess+IO.swift @@ -43,18 +43,18 @@ extension Subprocess { /// `InputMethod` defines how should the standard input /// of the subprocess receive inputs. public struct InputMethod: Sendable, Hashable { - enum Storage: Sendable, Hashable { + internal enum Storage: Sendable, Hashable { case noInput case fileDescriptor(FileDescriptor, Bool) } - let method: Storage + internal let method: Storage - init(method: Storage) { + internal init(method: Storage) { self.method = method } - func createExecutionInput() throws -> ExecutionInput { + internal func createExecutionInput() throws -> ExecutionInput { switch self.method { case .noInput: let devnull: FileDescriptor = try .openDevNull(withAcessMode: .readOnly) @@ -65,7 +65,7 @@ extension Subprocess { } /// Subprocess should read no input. This option is equivalent - /// to bind the standard input to `/dev/null`. + /// to bind the stanard input to `/dev/null`. public static var noInput: Self { return .init(method: .noInput) } @@ -88,19 +88,19 @@ extension Subprocess { /// `CollectedOutputMethod` defines how should Subprocess collect /// output from child process' standard output and standard error public struct CollectedOutputMethod: Sendable, Hashable { - enum Storage: Sendable, Hashable { + internal enum Storage: Sendable, Hashable { case discarded case fileDescriptor(FileDescriptor, Bool) case collected(Int) } - let method: Storage + internal let method: Storage - init(method: Storage) { + internal init(method: Storage) { self.method = method } - /// Subprocess should discard the child process output. + /// Subprocess shold dicard the child process output. /// This option is equivalent to binding the child process /// output to `/dev/null`. public static var discard: Self { @@ -122,7 +122,7 @@ extension Subprocess { return .init(method: .collected(limit)) } - func createExecutionOutput() throws -> ExecutionOutput { + internal func createExecutionOutput() throws -> ExecutionOutput { switch self.method { case .discarded: // Bind to /dev/null @@ -142,13 +142,13 @@ extension Subprocess { public struct RedirectedOutputMethod: Sendable, Hashable { typealias Storage = CollectedOutputMethod.Storage - let method: Storage + internal let method: Storage - init(method: Storage) { + internal init(method: Storage) { self.method = method } - /// Subprocess should discard the child process output. + /// Subprocess shold dicard the child process output. /// This option is equivalent to binding the child process /// output to `/dev/null`. public static var discard: Self { @@ -160,7 +160,7 @@ extension Subprocess { public static var redirectToSequence: Self { return .init(method: .collected(128 * 1024)) } - /// Subprocess should write the child process output + /// Subprocess shold write the child process output /// to the file descriptor specified. /// - Parameters: /// - fd: the file descriptor to write to @@ -173,7 +173,7 @@ extension Subprocess { return .init(method: .fileDescriptor(fd, closeAfterSpawningProcess)) } - func createExecutionOutput() throws -> ExecutionOutput { + internal func createExecutionOutput() throws -> ExecutionOutput { switch self.method { case .discarded: // Bind to /dev/null @@ -191,10 +191,10 @@ extension Subprocess { // MARK: - Execution IO extension Subprocess { - final class ExecutionInput: Sendable, Hashable { + internal final class ExecutionInput: Sendable, Hashable { - enum Storage: Sendable, Hashable { + internal enum Storage: Sendable, Hashable { case noInput(FileDescriptor?) case customWrite(FileDescriptor?, FileDescriptor?) case fileDescriptor(FileDescriptor?, Bool) @@ -202,11 +202,11 @@ extension Subprocess { let storage: _Mutex - init(storage: Storage) { + internal init(storage: Storage) { self.storage = .init(storage) } - func getReadFileDescriptor() -> FileDescriptor? { + internal func getReadFileDescriptor() -> FileDescriptor? { return self.storage.withLock { switch $0 { case .noInput(let readFd): @@ -219,7 +219,7 @@ extension Subprocess { } } - func getWriteFileDescriptor() -> FileDescriptor? { + internal func getWriteFileDescriptor() -> FileDescriptor? { return self.storage.withLock { switch $0 { case .noInput(_), .fileDescriptor(_, _): @@ -230,7 +230,7 @@ extension Subprocess { } } - func closeChildSide() throws { + internal func closeChildSide() throws { try self.storage.withLock { switch $0 { case .noInput(let devnull): @@ -249,7 +249,7 @@ extension Subprocess { } } - func closeParentSide() throws { + internal func closeParentSide() throws { try self.storage.withLock { switch $0 { case .noInput(_), .fileDescriptor(_, _): @@ -257,14 +257,14 @@ extension Subprocess { case .customWrite(let readFd, let writeFd): // The parent fd should have been closed // in the `body` when writer.finish() is called - // But in case it isn't call it again + // But in case it isn't call it agian try writeFd?.close() $0 = .customWrite(readFd, nil) } } } - func closeAll() throws { + internal func closeAll() throws { try self.storage.withLock { switch $0 { case .noInput(let readFd): @@ -317,8 +317,8 @@ extension Subprocess { } } - final class ExecutionOutput: Sendable { - enum Storage: Sendable { + internal final class ExecutionOutput: Sendable { + internal enum Storage: Sendable { case discarded(FileDescriptor?) case fileDescriptor(FileDescriptor?, Bool) case collected(Int, FileDescriptor?, FileDescriptor?) @@ -326,11 +326,11 @@ extension Subprocess { private let storage: _Mutex - init(storage: Storage) { + internal init(storage: Storage) { self.storage = .init(storage) } - func getWriteFileDescriptor() -> FileDescriptor? { + internal func getWriteFileDescriptor() -> FileDescriptor? { return self.storage.withLock { switch $0 { case .discarded(let writeFd): @@ -343,7 +343,7 @@ extension Subprocess { } } - func getReadFileDescriptor() -> FileDescriptor? { + internal func getReadFileDescriptor() -> FileDescriptor? { return self.storage.withLock { switch $0 { case .discarded(_), .fileDescriptor(_, _): @@ -354,7 +354,7 @@ extension Subprocess { } } - func consumeCollectedFileDescriptor() -> (limit: Int, fd: FileDescriptor?)? { + internal func consumeCollectedFileDescriptor() -> (limit: Int, fd: FileDescriptor?)? { return self.storage.withLock { switch $0 { case .discarded(_), .fileDescriptor(_, _): @@ -367,7 +367,7 @@ extension Subprocess { } } - func closeChildSide() throws { + internal func closeChildSide() throws { try self.storage.withLock { switch $0 { case .discarded(let writeFd): @@ -386,7 +386,7 @@ extension Subprocess { } } - func closeParentSide() throws { + internal func closeParentSide() throws { try self.storage.withLock { switch $0 { case .discarded(_), .fileDescriptor(_, _): @@ -398,7 +398,7 @@ extension Subprocess { } } - func closeAll() throws { + internal func closeAll() throws { try self.storage.withLock { switch $0 { case .discarded(let writeFd): diff --git a/Sources/_Subprocess/Subprocess+Teardown.swift b/Sources/_Subprocess/Subprocess+Teardown.swift index 322cbb73..8b9af32d 100644 --- a/Sources/_Subprocess/Subprocess+Teardown.swift +++ b/Sources/_Subprocess/Subprocess+Teardown.swift @@ -32,7 +32,7 @@ extension Subprocess { /// number of nanoseconds allowed for the child process to exit /// before proceeding to the next step. public struct TeardownStep: Sendable, Hashable { - enum Storage: Sendable, Hashable { + internal enum Storage: Sendable, Hashable { case sendSignal(Signal, allowedNanoseconds: UInt64) case kill } @@ -56,7 +56,7 @@ extension Subprocess { } extension Subprocess { - func runTeardownSequence(_ sequence: [TeardownStep]) async { + internal func runTeardownSequence(_ sequence: [TeardownStep]) async { // First insert the `.kill` step let finalSequence = sequence + [TeardownStep(storage: .kill)] for step in finalSequence { @@ -79,7 +79,7 @@ extension Subprocess { try await Task.sleep(nanoseconds: allowedNanoseconds) return .processStillAlive } catch { - // teardown(using:) cancels this task + // teardown(using:) cancells this task // when process has exited return .processHasExited } diff --git a/Sources/_Subprocess/Subprocess.swift b/Sources/_Subprocess/Subprocess.swift index 69c74967..35f4a2c2 100644 --- a/Sources/_Subprocess/Subprocess.swift +++ b/Sources/_Subprocess/Subprocess.swift @@ -30,11 +30,11 @@ public struct Subprocess: Sendable { /// The process identifier of the current subprocess public let processIdentifier: ProcessIdentifier - let executionInput: ExecutionInput - let executionOutput: ExecutionOutput - let executionError: ExecutionOutput + internal let executionInput: ExecutionInput + internal let executionOutput: ExecutionOutput + internal let executionError: ExecutionOutput #if os(Windows) - let consoleBehavior: PlatformOptions.ConsoleBehavior + internal let consoleBehavior: PlatformOptions.ConsoleBehavior #endif /// The standard output of the subprocess. @@ -149,7 +149,7 @@ extension Subprocess { /// The result returned by the closure passed to `.run` methods public let value: T - init(terminationStatus: TerminationStatus, value: T) { + internal init(terminationStatus: TerminationStatus, value: T) { self.terminationStatus = terminationStatus self.value = value } @@ -186,7 +186,7 @@ extension Subprocess { return output } - init( + internal init( processIdentifier: ProcessIdentifier, terminationStatus: TerminationStatus, standardOutput: Data?, @@ -253,18 +253,18 @@ Subprocess.CollectedResult( // MARK: - Internal extension Subprocess { - enum OutputCapturingState { + internal enum OutputCapturingState { case standardOutputCaptured(Data?) case standardErrorCaptured(Data?) } - typealias CapturedIOs = (standardOutput: Data?, standardError: Data?) + internal typealias CapturedIOs = (standardOutput: Data?, standardError: Data?) private func capture(fileDescriptor: FileDescriptor, maxLength: Int) async throws -> Data { return try await fileDescriptor.readUntilEOF(upToLength: maxLength) } - func captureStandardOutput() async throws -> Data? { + internal func captureStandardOutput() async throws -> Data? { guard let (limit, readFd) = self.executionOutput .consumeCollectedFileDescriptor(), let readFd = readFd else { @@ -276,7 +276,7 @@ extension Subprocess { return try await self.capture(fileDescriptor: readFd, maxLength: limit) } - func captureStandardError() async throws -> Data? { + internal func captureStandardError() async throws -> Data? { guard let (limit, readFd) = self.executionError .consumeCollectedFileDescriptor(), let readFd = readFd else { @@ -288,7 +288,7 @@ extension Subprocess { return try await self.capture(fileDescriptor: readFd, maxLength: limit) } - func captureIOs() async throws -> CapturedIOs { + internal func captureIOs() async throws -> CapturedIOs { return try await withThrowingTaskGroup(of: OutputCapturingState.self) { group in group.addTask { let stdout = try await self.captureStandardOutput() diff --git a/Sources/_Subprocess/_nio_locks.swift b/Sources/_Subprocess/_nio_locks.swift index d13830b6..49053d04 100644 --- a/Sources/_Subprocess/_nio_locks.swift +++ b/Sources/_Subprocess/_nio_locks.swift @@ -290,7 +290,7 @@ public final class ConditionLock { /// This is currently the only way to do this in Swift: see /// https://forums.swift.org/t/support-debug-only-code/11037 for a discussion. @inlinable -func debugOnly(_ body: () -> Void) { +internal func debugOnly(_ body: () -> Void) { assert({ body(); return true }()) } @@ -460,7 +460,7 @@ extension LockStorage: @unchecked Sendable { } /// `SRWLOCK` type. public struct NIOLock { @usableFromInline - let _storage: LockStorage + internal let _storage: LockStorage /// Create a new lock. @inlinable @@ -487,7 +487,7 @@ public struct NIOLock { } @inlinable - func withLockPrimitive(_ body: (UnsafeMutablePointer) throws -> T) rethrows -> T { + internal func withLockPrimitive(_ body: (UnsafeMutablePointer) throws -> T) rethrows -> T { return try self._storage.withLockPrimitive(body) } }