将 Kotlin c-interop 用于 Avro C 的问题

Problem with using Kotlin c-interop for Avro C

我们正在使用 Avro 制作一个 kotlin 多平台应用程序。 Avro java 用于 android,计划是将 Avro C 用于 iOS。我们已将 Avro C 集成到 kotlin 应用程序中,但我们在使用 c-interop 函数时遇到了问题。我认为这与我们传递输出变量(引用)的方式有关。

Kotlin 代码:

var json: String =
                "{"
                "  \"type\": \"record\","
                "  \"name\": \"list\","
                "  \"fields\": ["
                "    { \"name\": \"x\", \"type\": \"int\" },"
                "    { \"name\": \"y\", \"type\": \"int\" },"
                "    { \"name\": \"next\", \"type\": [\"null\",\"list\"]}"
                "  ]"
                "}";

var avro_c_schema: avro_schema_t? = null
var error: avro_schema_error_t? = null

var resultInt = avro_schema_from_json(json, json.length, cValuesOf(avro_c_schema), cValuesOf(error))

c 函数返回 0,这意味着没有任何错误,但引用变量 avro_c_schema 和错误为空。我猜这与互操作有关,也许我们没有错误地传递它们。

这里是 avro_schema_from_json_t 函数 source code

并且 this 是 Avro C 文档。

来自 cValuesOf 文档:

Returns sequence of immutable values CValues to pass them to C code.

所以我不认为你的情况是正确的方法。试试这个:

memScoped {
    val avro_c_schema = alloc<avro_schema_t>()
    val error = alloc<avro_schema_error_t>()

    var resultInt = avro_schema_from_json(json, json.length, avro_c_schema.ptr, error.ptr)
}