Denis Siprun
04/18/2024, 8:09 AMactual fun platform() = "Shared Linux X64"
actual fun triggerLambda(callback: () -> Unit) {
callback()
}
Next, in my C++ application, I added the corresponding libshared.a and libshared_api.h files. In these files, the functions I need have the following structure, I will only show a part of it:
typedef void* libshared_KNativePtr;
typedef struct {
libshared_KNativePtr pinned;
} libshared_kref_kotlin_Function0;
// irrelevant code skipped here
struct {
struct {
struct {
struct {
// irrelevant code skipped here
const char* (*platform)();
void (*triggerLambda)(libshared_kref_kotlin_Function0 callback);
} root;
} kotlin;
} libshared_ExportedSymbols;
extern libshared_ExportedSymbols* libshared_symbols(void);
So, in my application, I can easily call the first function, for example like this:
auto ktText = libshared_symbols()->kotlin.root.platform();
And it works.
But I am having trouble calling the second function:
class KotlinNativeVM: //...
void foo() {
// works
auto ktText = libshared_symbols()->kotlin.root.platform();
libshared_kref_kotlin_Function0 callback;
auto lambda = []() {
// ...
};
callback.pinned = reinterpret_cast<libshared_KNativePtr>(&lambda);
// The program crashes
libshared_symbols()->kotlin.root.triggerLambda(callback);
}
}
Because such call causing app to crash.