Hi, I'm facing an issue with cinterop generating `...
# kotlin-native
m
Hi, I'm facing an issue with cinterop generating
CValue<CFunction<...>>
which is impossible to use, I'm wondering if I'm missing something. I have some C code that looks like this:
Copy code
// from <https://github.com/awslabs/aws-c-auth/blob/main/include/aws/auth/credentials.h>

typedef void(aws_on_get_credentials_callback_fn)(struct aws_credentials *credentials, int error_code, void *user_data);

typedef int(aws_credentials_provider_get_credentials_fn)(
    struct aws_credentials_provider *provider,
    aws_on_get_credentials_callback_fn callback, // note: not a pointer, but used as one 
    void *user_data);
and this is what cinterop generates:
Copy code
public typealias aws_credentials_provider_get_credentials_fn = kotlinx.cinterop.CFunction<(kotlinx.cinterop.CPointer<libcrt.aws_credentials_provider>?, kotlinx.cinterop.CValue<libcrt.aws_on_get_credentials_callback_fn>, kotlinx.cinterop.COpaquePointer?) -> kotlin.Int>
Focusing on the
callback
, cinterop generates it as a
CValue<CFunction<...>>
, but from what I can tell, this is not possible because
CValue
takes a
T: CVariable
which does not include
CFunction
. Ideally this callback would be generated as a
CPointer<CFunction<...>>
. I understand it's not explicitly a pointer in the source code, but that's the intended use, and currently what cinterop generates is unusable. Has anyone else come across this issue working with CValue functions? My current workaround is to create duplicate implementations that declare the function as a pointer (i.e
aws_on_get_credentials_callback_fn *callback
), but I'm wondering if there's an easier way.