dont decref too early

This commit is contained in:
dankeyy 2023-03-12 01:02:58 +02:00
parent 1866b8845a
commit d91a90774b
No known key found for this signature in database
GPG Key ID: 9EBEF7DB1A70533D

View File

@ -221,9 +221,6 @@ JNIEXPORT jstring JNICALL Java_javaSource_Greeter_sayHello
// Call the Roc function to populate `ret`'s bytes. // Call the Roc function to populate `ret`'s bytes.
roc__mainForHost_1_exposed_generic(&ret, &arg); roc__mainForHost_1_exposed_generic(&ret, &arg);
decref((void *)&ret, alignof(uint8_t *));
// java being java making this a lot harder than it needs to be // java being java making this a lot harder than it needs to be
// https://stackoverflow.com/questions/32205446/getting-true-utf-8-characters-in-java-jni // https://stackoverflow.com/questions/32205446/getting-true-utf-8-characters-in-java-jni
// https://docs.oracle.com/javase/1.5.0/docs/guide/jni/spec/types.html#wp16542 // https://docs.oracle.com/javase/1.5.0/docs/guide/jni/spec/types.html#wp16542
@ -240,6 +237,8 @@ JNIEXPORT jstring JNICALL Java_javaSource_Greeter_sayHello
jstring result = (*env)->NewObject(env, stringClass, stringConstructor, byteArray, charsetName); jstring result = (*env)->NewObject(env, stringClass, stringConstructor, byteArray, charsetName);
// cleanup
decref((void *)&ret, alignof(uint8_t *));
(*env)->DeleteLocalRef(env, charsetName); (*env)->DeleteLocalRef(env, charsetName);
(*env)->ReleaseByteArrayElements(env, byteArray, bytes, 0); (*env)->ReleaseByteArrayElements(env, byteArray, bytes, 0);
(*env)->DeleteLocalRef(env, byteArray); (*env)->DeleteLocalRef(env, byteArray);