Swift 3 CVaListPointer类型冲突

Swift 3 CVaListPointer Type Conflict

我正在与 C 库 - liblinphone 集成。它具有我需要从我的 Swift 3 iOS 应用程序调用的以下 typedef 和函数。

typedef void (*OrtpLogFunc)(const char *domain, 
                            int lev, 
                            const char *fmt, 
                            va_list args);

void linphone_core_set_log_handler(OrtpLogFunc logfunc);

似乎 Swift 在为 模拟器 编译时与在为 设备[=50 编译时对 va_list 的解释不同=].

这是使用 C 函数的 Swift 代码和

仅当目标是 Device:

时才编译
class MyClass {
   func setupLogging() {
       linphone_core_set_log_handler(my_callback)
   }
}

func my_callback(_ domain: Optional<UnsafePointer<Int8>>, 
    level: OrtpLogLevel, 
    format: Optional<UnsafePointer<Int8>>, 
    args: CVaListPointer?) {    // NOTE: Optional CVAListPointer
        // do some logging
}

仅当目标是 Simulator:

时才编译
class MyClass {
   func setupLogging() {
       linphone_core_set_log_handler(my_callback)
   }
}

func my_callback(_ domain: Optional<UnsafePointer<Int8>>, 
    level: OrtpLogLevel, 
    format: Optional<UnsafePointer<Int8>>, 
    args: CVaListPointer) {    // NOTE: CVAListPointer is NOT optional
        // do some logging
}

当我在设备上 运行 时,日志记录工作,所以看起来使用可选的 CVaListPoint? 是最安全的,那么我如何让它编译对于模拟器。

第一个 版本仅在 设备 上编译和 运行s,但在针对 模拟器:

Swift Compiler Error
  C function pointer signature 
    '(Optional<UnsafePointer<Int8>>, OrtpLogLevel, 
      Optional<UnsafePointer<Int8>>, CVaListPointer?) -> ()' 
  is not compatible with expected type 'OrtpLogFunc' (aka 
    '@convention(c) 
     (Optional<UnsafePointer<Int8>>, OrtpLogLevel,
      Optional<UnsafePointer<Int8>>, CVaListPointer) -> ()')

second 版本仅在针对 模拟器 时编译,但当针对 设备 时,它会发出此错误:

Swift Compiler Error
  Cannot convert value of type 
    '(Optional<UnsafePointer<Int8>>, OrtpLogLevel, 
      Optional<UnsafePointer<Int8>>, CVaListPointer) -> ()' 
  to expected argument type 'OrtpLogFunc!'

有什么方法可以强制模拟器接受此功能而不更改 C 头文件吗?

或者,我可以在 Swift 中做些什么来完成这项工作?

您最好尽快将错误报告发送至 Apple or swift.org

并且,在解决此问题之前,这种编码将是一种解决方法:

let my_callback: OrtpLogFunc = {domain, level, format, _args in
    let args: CVaListPointer? = _args
    // do some logging
}