I’ve generated some bindings from the RocksDB C he...
# kotlin-native
a
I’ve generated some bindings from the RocksDB C headers, and I’m trying to open a database. This is the generated binding:
Copy code
public external expect fun rocksdb_open(
  options: CValuesRef<rocksdb_options_t>?, 
  name: String?, 
  errptr: CValuesRef<CPointerVar<ByteVar>>?
): CPointer<rocksdb_t>?
I need to pass in
errptr
, but how can I create a value with type
CValuesRef<CPointerVar<ByteVar>>
?
k
str.cstr.ptr
. You need to free the memory this allocates afterwards.
What is the C type it's looking for?
a
Copy code
extern ROCKSDB_LIBRARY_API rocksdb_t* rocksdb_open(
    const rocksdb_options_t* options, const char* name, char** errptr);
k
It's looking for an array of strings, not a single string.
look at
allocArrayOfPointersTo
for your strings.
a
ahh okay, that’s weird. There’s no comments/docs on the C API so I’m a bit lost
thanks, I’ll take a look
k
It's hard to tell you exactly what you need without more context, but I think that will be helpful
You could also consider using
allocArray
a
unfortunately this is all the context I have
Copy code
// open DB
  char *err = NULL;
  db = rocksdb_open(options, DBPath, &err);
  assert(!err);
v
Could be something like
Copy code
val err = allocPointerTo<ByteVar>()
a
nice, thanks!
allocPointerTo<ByteVar>()
compiles
Copy code
memScoped {
    val err = allocPointerTo<ByteVar>()
    val db = rocksdb_open(
      options,
      "rdb_test_01",
      err.ptr,
    )

    var result = err.pointed?.value
    require(result == null) {
      "error opening db: $result"
    }