我正在尝试将字符串从 C 传递到 java,并且我正在通过以下跟踪重新启动,有人可以帮助我了解如何解决这个问题吗?
PC: 2cf57c7c (__GI_strlen+0xc glibc-2.4/string/strlen.c:42) RA: 2cf202a0 (vfprintf+0x42c0 glibc-2.4/stdio-common/vfprintf.c:1549)
我的 JNI 代码如下所示:
JNIEXPORT jstring JNICALL xxx_nativeGetParentName
(JNIEnv *env, jobject obj, jstring childName)
{
log("nativeGetParentName entered\n");
char *name;
Node* parentName = NULL;
jstring jstr = NULL;
name = (char *)(*env)->GetStringUTFChars(env, childName, NULL);
if (name == NULL)
return NULL;
log("about to call mpe_hnGetParentName\n");
int retCode = mpe_GetParentName(name,&parentName); // Call to the C function which holds the implementation
(*env)->ReleaseStringUTFChars(env,childName,name);
if (retCode != 0 ) {
log("mpe_GetParentName called with return code=%d\n", retCode);
return NULL;
}
if(parentName[0] != NULL) {
jstr= (*env)->NewStringUTF(env, parentName[0]); // Hitting the reboot exactly here!
log("getting ParentName Succeded=%s\n", jstr);
free(parentUuid);
}
return jstr;
}
C 函数调用的原型如下所示:
i32 GetParentName(Node childName, Node **parentName);
该节点本质上是一个字符数组:
typedef char[] Node;
我成功地从 C 方法中获取了 parentName,但是当我尝试映射到 JString 时,我正在重新启动。
提前致谢!