-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Supported FileHandle API for Swift #1889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@swift-ci please test |
1 similar comment
@swift-ci please test |
Foundation/FileHandle.swift
Outdated
@@ -405,6 +280,213 @@ open class FileHandle : NSObject, NSSecureCoding { | |||
public static var supportsSecureCoding: Bool { | |||
return true | |||
} | |||
|
|||
private var _isPlatformHandleValid: Bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be a good idea to move this up into the Windows/Non-Windows FD & handle blocks at the top to keep all the fd and fd checks in one place.
I think the |
Should also have at least one test for each of the new methods (one and the same for |
Oh, right. We need to probably do a subclass check in the implementation, because the new entry points are (on purpose) |
@millenomi Is this new API going to be added to the Foundation SDK overlay? Also, why some API (like |
} | ||
|
||
@available(swift 5.0) | ||
public func close() throws { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be nicer to write this as:
guard _isPlatformHandleValid else { return }
#if os(Windows)
guard CloseHandle(_handle) != FALSE else {
throw _NSErrorWithWindowsError(GetLastError(), reading: true)
}
_handle = INVALID_HANDLE_VALUE
#else
gurad _close(_fd) >= 0 else {
throw _NSErrorWithErrno(errno, reading: true)
}
_fd = -1
#endif
@pvieito I cannot comment on future Mac SDKs. The API that return |
@@ -35,20 +35,19 @@ class TestPipe: XCTestCase { | |||
pipes = [] | |||
} | |||
|
|||
func test_Pipe() { | |||
func test_Pipe() throws { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this disqualify the test from XCTest (acknowledging that we do not automatically discover them at this time).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No; this is a pattern we use elsewhere that XCTest supports.
@millenomi - I don't think that @pvieito was asking about future macOS SDKs, I think he was asking about the Swift repository side. |
Tests will be forthcoming in a separate patch. |
@swift-ci please test |
LGTM |
@swift-ci please test |
there it goes. |
@millenomi Should we be porting these changes to |
Our intent is to line this up with the next release of Swift. |
Adds API to FileHandle that allows clients to catch and handle errors, rather than panic with
fatalError
on I/O issues. This API will be supported going forward and is not experimental.