Skip to content

Conversation

jakepetroules
Copy link
Member

@jakepetroules jakepetroules commented Oct 2, 2025

This follows the existing pattern of wrapping dup/dup2 and pipe with FileDescriptor.duplicate and FileDescriptor.pipe, with additional overloads for passing the O_CLOEXEC and similar flags.

Forums pitch: https://forums.swift.org/t/pitch-swiftsystem-dup3-and-pipe2-cover-apis/

This follows the existing pattern of wrapping dup/dup2 and pipe with FileDescriptor.duplicate and FileDescriptor.pipe, with additional overloads for passing the O_CLOEXEC and similar flags.
@jakepetroules
Copy link
Member Author

@swift-ci test

Copy link
Contributor

@glessard glessard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this contribution!

try _duplicate(as: target, options: options.rawValue, retryOnInterrupt: retryOnInterrupt).get()
}

@available(System 0.0.2, *)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A @usableFromInline symbol requires availability.

try _pipe(options: options.rawValue).get()
}

@available(System 1.1.0, *)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, @usableFromInline symbols require availability.

@usableFromInline
internal func _duplicate(
as target: FileDescriptor?,
options: Int32,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't remove the old @usableFromInline symbol; it could be re-implemented by forwarding to the new implementation.

@available(System 1.1.0, *)
@usableFromInline
internal static func _pipe() -> Result<(readEnd: FileDescriptor, writeEnd: FileDescriptor), Errno> {
internal static func _pipe(options: Int32) -> Result<(readEnd: FileDescriptor, writeEnd: FileDescriptor), Errno> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above.

retryOnInterrupt: Bool = true
) throws -> FileDescriptor {
try _duplicate(as: target, retryOnInterrupt: retryOnInterrupt).get()
try _duplicate(as: target, options: 0, retryOnInterrupt: retryOnInterrupt).get()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The package version that will include this drops support for Swift toolchains older than 6.0. We could therefore make these @_aEIC entry points use typed throws, i.e. throws(ErrNo).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants