Skip to content
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

Use POSIXErrorCode instead of direct errno E constants from wasi-libc #811

Closed
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
10 changes: 9 additions & 1 deletion Sources/FoundationEssentials/Error/CocoaError+FilePath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,15 @@ extension CocoaError {
var userInfo = userInfo

// (130280235) POSIXError.Code does not have a case for EOPNOTSUPP
if errno != EOPNOTSUPP {
let _EOPNOTSUPP: Int32
#if os(WASI)
// wasi-libc's errno.h constants cannot be directly imported into Swift
// so we use Swift stdlib's POSIXErrorCode instead
_EOPNOTSUPP = POSIXErrorCode.EOPNOTSUPP.rawValue
Copy link
Contributor

Choose a reason for hiding this comment

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

This workaround here was put in place because the POSIXErrorCode.EOPNOTSUPP does not exist on platforms like Darwin (likely an oversight / a missing enum case). Does that case actually exist on WASI? If so, we might as well avoid this check entirely and just always evaluate the true branch of the if statement rather than worrying about storing this variable on a per-platform basis.

Also, is this something that can/should be fixed in the WASI overlay? There are a few other places where we use these error code constants that I expect would hit the same issue

Copy link
Member Author

Choose a reason for hiding this comment

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

Also, is this something that can/should be fixed in the WASI overlay? There are a few other places where we use these error code constants that I expect would hit the same issue

Good pointing! This reminds me that we already provide errno constant shims in the overlay, and I just realized it missed some of them including EOPNOTSUPP.

So this change should be unnecessary after swiftlang/swift#75671

#else
_EOPNOTSUPP = EOPNOTSUPP
#endif
if errno != _EOPNOTSUPP {
guard let code = POSIXError.Code(rawValue: errno) else {
fatalError("Invalid posix errno \(errno)")
}
Expand Down