これは、 vapi ファイルに void ポインター typedef を書き込むにはどうすればよいですか?へのフォローアップの質問です。
[Compact] class
現在、unixODBCsSQLAllocHandle
関数で割り当てられたハンドルを表す4 つのほぼ同一のes があります。
最初のもの (ENV タイプ ハンドル用) は次のようになります。
[CCode (cname = "void", free_function = "EnvironmentHandle.free")]
[Compact]
public class EnvironmentHandle {
[CCode (cname = "SQLAllocHandle")]
private static Return allocate_internal (HandleType type, void* nothing, out EnvironmentHandle output_handle);
public static Return allocate (out EnvironmentHandle output_handle) {
return allocate_internal (HandleType.ENV, null, out output_handle);
}
[CCode (cname = "SQLFreeHandle")]
private static Return free_internal (HandleType type, EnvironmentHandle handle);
public static Return free (EnvironmentHandle handle) {
return free_internal (HandleType.ENV, handle);
}
}
これはコンパイルされません。
として静的クラスメソッドを使用することは可能free_function
ですか?
そうでない場合、少なくともfree_function
vapiファイルにカスタムを書き込む方法はありますか?
SQLFreeHandle
関数はハンドルの型とハンドルを引数として取るため、カスタム関数が必要です。
vapi ユーザーの観点から、本当に重要なことは次のとおりです。
[CCode (cname = "void")]
[Compact]
public class EnvironmentHandle {
public static Return allocate (out EnvironmentHandle output_handle);
}
他の唯一の解決策は[SimpleType] struct
、元の質問で apmasell が提案したように a を使用することです。SQLHANLDE
これにより、 aが実際には参照型であるという事実が隠されます。
私の現在の実装の完全なコードは、オンラインで入手できます: https://github.com/antiochus/unixodbc-vala/tree/0486f54dc3f86d9c8bf31071980e4f171aca9591