Hi all!
I am having a weird problem. Nim code is compiled to a static library and is used inside a React Native project as a native dependency. Some Nim functions defer to code written in Go (being thin wrappers), others provide native Nim implementations.
iOS works allright.
On Android there is an NDK wrapper written in C (a single file using JNI) that is using the Nim library. For instance, this is a sample wrapper function:
jstring Java_testFn(JNIEnv* env, jobject thiz, jstring jarg) {
const char * arg = (*env)->GetStringUTFChars(env, jarg, 0);
const char * result = testFn(publicKey);
(*env)->ReleaseStringUTFChars(env, jarg, arg);
return (*env)->NewStringUTF(env, result);
}
If testFn is a native Nim implementation, it crashes. Even fns as simple as:
proc testFn*(pubKey: cstring): cstring =
let smth = "abc"
result = nil
crash with code 11. However, if let smth... line is removed, this fixes the problem. Also, if I set --gc:none, this helps. Nim fns that directly invoke functions exported from Go work without issues.
Can someone please help? Is there some compiler switch/GC setting that can help?
Thanks!