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

fclose takes Nonnull FILE pointer in Swift >=5.9 #430

Closed tokyovigilante closed 8 months ago

tokyovigilante commented 1 year ago

Closes #429.

Lukasa commented 1 year ago

@swift-server-bot test this please

Lukasa commented 1 year ago

@swift-server-bot test this please

Lukasa commented 1 year ago

Hmm, this appears to be a bit overzealous, as our CI is failing the build:

16:45:30 /code/Sources/NIOSSL/PosixPort.swift:44:63: error: C function pointer signature '(UnsafeMutablePointer<FILE>?) -> Int32' (aka '(Optional<UnsafeMutablePointer<_IO_FILE>>) -> Int32') is not compatible with expected type '@convention(c) (FILEPointer) -> CInt' (aka '@convention(c) (UnsafeMutablePointer<_IO_FILE>) -> Int32')

What Linux distribution did you test on?

tokyovigilante commented 1 year ago

What Linux distribution did you test on?

Fedora rawhide, with Clang 16 and glibc 2.37.9.

Lukasa commented 1 year ago

This is probably more that combination. We can probably get around this by redeclaring the variable as a closure wrapping the underlying function:

private let sysFclose: @convention(c) (FILEPointer?) -> CInt = { fclose($0) }
Saljooq commented 8 months ago

@Lukasa I tried your fix but the argument had to be unwrapped, this is the version that worked:

private let sysFclose: @convention(c) (FILEPointer?) -> CInt =  { fclose($0!) }

cc: @tokyovigilante