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

Compilation fails on Linux with Swift 5.9-dev #429

Open
tokyovigilante opened this issue May 23, 2023 · 2 comments
Open

Compilation fails on Linux with Swift 5.9-dev #429

tokyovigilante opened this issue May 23, 2023 · 2 comments

Comments

@tokyovigilante
Copy link

tokyovigilante commented May 23, 2023

Importation of fclose on Linux appears to have changed with Swift 5.9 (Swift version 5.9-dev (LLVM 6665c55e557222b, Swift b370e7dbea9ca19)) and internal typealias FILEPointer = UnsafeMutablePointer<FILE> in NIOSSL/PosixPort.swift fails to compile.

/home/ryan/Projects/Develop/Tsunami/.build/checkouts/swift-nio-ssl/Sources/NIOSSL/PosixPort.swift:42:64: error: cannot convert value of type '(UnsafeMutablePointer<FILE>) -> Int32' (aka '(UnsafeMutablePointer<_IO_FILE>) -> Int32') to specified type '@convention(c) (FILEPointer?) -> CInt' (aka '@convention(c) (Optional<UnsafeMutablePointer<_IO_FILE>>) -> Int32') private let sysFclose: @convention(c) (FILEPointer?) -> CInt = fclose

Changing the sysFclose definition to private let sysFclose: @convention(c) (FILEPointer) -> CInt = fclose by putting making FILEPointer non-optional matches the expected method signature and allows compilation to succeed, but there may be a better way to solve this (or wrapping this in a Swift 5.9 conditional).

@Lukasa
Copy link
Contributor

Lukasa commented May 24, 2023

That's very weird: I can't entirely work out why this change would have happened, as I'd expect it to be a libc change. Still this is an easy enough tweak to make.

@Saljooq
Copy link
Contributor

Saljooq commented Nov 1, 2023

@Lukasa @tokyovigilante I tried to make an PR for suggestion but failed - not sure how to suggest code. The suggestions are quite small though and they work on my computer (I use Linux 6.5.9-arch2-1 - Glibc 2.38):
image

Here's the text changed:
// fclose has an non optional file pointer for linux glibc version 2.38
#if os(Linux)
internal typealias SYSFILEPointer = FILEPointer
#else
internal typealias SYSFILEPointer = Optional
#endif

and here's the code replaced for the return type for fclose:
private let sysFclose: @convention(c) (SYSFILEPointer) -> CInt = fclose

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 a pull request may close this issue.

3 participants