apple / swift-nio-ssl

TLS Support for SwiftNIO, based on BoringSSL.
https://swiftpackageindex.com/apple/swift-nio-ssl/main/documentation/niossl
Apache License 2.0
385 stars 139 forks source link

Compilation fails on Linux with Swift 5.9-dev #429

Open tokyovigilante opened 1 year ago

tokyovigilante commented 1 year ago

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 commented 1 year ago

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 commented 8 months ago

@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