I'm trying to use K/N with libsecret. It includes the following struct:
typedef struct {
const gchar *name;
SecretSchemaFlags flags;
SecretSchemaAttribute attributes[32];
} SecretSchema;
(from here: https://developer.gnome.org/libsecret/0.18/libsecret-SecretSchema.html#SecretSchema)
cinterop generated following class:
@kotlinx.cinterop.internal.CStruct public final class SecretSchema public constructor(rawPtr: kotlinx.cinterop.NativePtr /* = kotlin.native.internal.NativePtr */) : kotlinx.cinterop.CStructVar {
@kotlinx.cinterop.internal.CStruct.VarType public companion object : kotlinx.cinterop.CStructVar.Type {
}
public final val attributes: kotlinx.cinterop.CArrayPointer<org.libsecret.SecretSchemaAttribute> /* = kotlinx.cinterop.CPointer<org.libsecret.SecretSchemaAttribute> */ /* compiled code */
public final var flags: org.libsecret.SecretSchemaFlags /* = kotlin.UInt */ /* compiled code */
public final var name: kotlinx.cinterop.CPointer<org.libsecret.gcharVar /* = kotlinx.cinterop.ByteVarOf<kotlin.Byte> */>? /* compiled code */
public final var reserved: org.libsecret.gint /* = kotlin.Int */ /* compiled code */
public final var reserved1: org.libsecret.gpointer? /* = kotlinx.cinterop.CPointer<out kotlinx.cinterop.CPointed>? */ /* compiled code */
public final var reserved2: org.libsecret.gpointer? /* = kotlinx.cinterop.CPointer<out kotlinx.cinterop.CPointed>? */ /* compiled code */
public final var reserved3: org.libsecret.gpointer? /* = kotlinx.cinterop.CPointer<out kotlinx.cinterop.CPointed>? */ /* compiled code */
public final var reserved4: org.libsecret.gpointer? /* = kotlinx.cinterop.CPointer<out kotlinx.cinterop.CPointed>? */ /* compiled code */
public final var reserved5: org.libsecret.gpointer? /* = kotlinx.cinterop.CPointer<out kotlinx.cinterop.CPointed>? */ /* compiled code */
public final var reserved6: org.libsecret.gpointer? /* = kotlinx.cinterop.CPointer<out kotlinx.cinterop.CPointed>? */ /* compiled code */
public final var reserved7: org.libsecret.gpointer? /* = kotlinx.cinterop.CPointer<out kotlinx.cinterop.CPointed>? */ /* compiled code */
}
and I'm trying to define it like:
alloc<SecretSchema> {
name = "com.charlag.tuta-bridge".cstr.ptr
flags = SECRET_SCHEMA_NONE
}
however, I don't see a way to modify attributes
because CArrayPointer
(CPointer
) does not expose modification methods.
I've also noticed some of the reserved
fields. Should I use them instead?
here's example of how it's used in C: https://developer.gnome.org/libsecret/0.18/c-examples.html#c-schema-example
As far as I can see, the most straightforward option here would be to use the
[]
operator and assign allocatedSecretSchemaAttribute
to those addresses. To learn more about pointer types interaction, check this documentation page. It might be a bit out-of-date, but further questions could be asked here or at the kotlinlang Slack.