+static inline jstring str_ref_to_java(JNIEnv *env, const char* chars, size_t len) {
+ // Sadly we need to create a temporary because Java can't accept a char* without a 0-terminator
+ char* conv_buf = MALLOC(len + 1, "str conv buf");
+ memcpy(conv_buf, chars, len);
+ conv_buf[len] = 0;
+ jstring ret = (*env)->NewStringUTF(env, conv_buf);
+ FREE(conv_buf);
+ return ret;
+}
+static inline LDKStr java_to_owned_str(JNIEnv *env, jstring str) {
+ uint64_t str_len = (*env)->GetStringUTFLength(env, str);
+ char* newchars = MALLOC(str_len + 1, "String chars");
+ const char* jchars = (*env)->GetStringUTFChars(env, str, NULL);
+ memcpy(newchars, jchars, str_len);
+ newchars[str_len] = 0;
+ (*env)->ReleaseStringUTFChars(env, str, jchars);
+ LDKStr res = {
+ .chars = newchars,
+ .len = str_len,
+ .chars_is_owned = true
+ };
+ return res;
+}
+
+JNIEXPORT jstring JNICALL Java_org_ldk_impl_bindings_get_1lib_1version_1string(JNIEnv *env, jclass _c) {
+ return str_ref_to_java(env, "<git_version_ldk_garbagecollected>", strlen("<git_version_ldk_garbagecollected>"));
+}
+JNIEXPORT jstring JNICALL Java_org_ldk_impl_bindings_get_1ldk_1c_1bindings_1version(JNIEnv *env, jclass _c) {
+ return str_ref_to_java(env, check_get_ldk_bindings_version(), strlen(check_get_ldk_bindings_version()));
+}
+JNIEXPORT jstring JNICALL Java_org_ldk_impl_bindings_get_1ldk_1version(JNIEnv *env, jclass _c) {
+ return str_ref_to_java(env, check_get_ldk_version(), strlen(check_get_ldk_version()));
+}