2017-03-26 18 views
1

私はCライブラリ - liblinphoneと統合しています。それは私のSwift 3 iOS appから呼び出す必要がある以下のtypedefと関数を持っています。Swift 3 CVaListPointerタイプの衝突

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

void linphone_core_set_log_handler(OrtpLogFunc logfunc); 

デバイス用にコンパイルするときよりもシミュレータのためにコンパイルするときスウィフトは違っva_listを解釈していることが表示されます。

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 
} 

ターゲットが場合にのみこれはコンパイル:ここ

はスウィフトC関数を使用するコードと

であるこれは、ターゲットは、デバイス場合にのみコンパイルシミュレータ

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を使用しているように見えますか?が最も安全です。これをシミュレータ用にコンパイルするにはどうしたらいいですか? シミュレータを標的とする場合バージョンのみコンパイル

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) ->()') 

シミュレータを標的とする場合最初バージョンのみをコンパイルしデバイスが、問題に、このコンパイラエラーを実行

ただし、のデバイスをターゲティングすると、このエラーが発生します。

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

Cヘッダーを変更せずにこの機能を受け入れる方法はありますか?

また、この作業を行うために私がSwiftでできることはありますか?

答えて

2

できるだけ早くAppleまたはswift.orgにバグレポートを送信する方がよいでしょう。

そして、この問題が修正されますまで、コーディングのこの種は、回避策を次のようになります。

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

これが機能しています。ありがとうございました!今、午後の残りの部分をバグレポートを書くのに費やす... – Troy