Expand the criteria for cloning when passing to Rust
[ldk-java] / java_strings.py
index 3482dfb9b63b3e011957c581ce273325b31f69ee..b6b1f13fdaae7c1d9abe8f9afe68f9a09855a458 100644 (file)
@@ -44,7 +44,7 @@ public class bindings {
                try {
                        // Try to load natively first, this works on Android and in testing.
                        System.loadLibrary(\"lightningjni\");
-               } catch (UnsatisfiedLinkError _ignored) {
+               } catch (UnsatisfiedLinkError system_load_err) {
                        // Otherwise try to load from the library jar.
                        File tmpdir = new File(System.getProperty("java.io.tmpdir"), "ldk-java-nativelib");
                        tmpdir.mkdir(); // If it fails to create, assume it was there already
@@ -56,6 +56,9 @@ public class bindings {
                                Files.copy(is, libpath, StandardCopyOption.REPLACE_EXISTING);
                                Runtime.getRuntime().load(libpath.toString());
                        } catch (IOException e) {
+                               System.err.println("Failed to load LDK native library.");
+                               System.err.println("System LDK native library load failed with: " + system_load_err);
+                               System.err.println("Resource-based LDK native library load failed with: " + e);
                                throw new IllegalArgumentException(e);
                        }
                }
@@ -846,10 +849,13 @@ import javax.annotation.Nullable;
                     out_c = out_c + "\t" + fn_line.ret_ty_info.c_ty + " ret = (*env)->CallObjectMethod(env, obj, j_calls->" + fn_line.fn_name + "_meth"
                 elif fn_line.ret_ty_info.c_ty == "void":
                     out_c += "\t(*env)->Call" + fn_line.ret_ty_info.java_ty.title() + "Method(env, obj, j_calls->" + fn_line.fn_name + "_meth"
+                elif fn_line.ret_ty_info.java_ty == "String":
+                    # Manually write out String methods as they're just an Object
+                    out_c += "\t" + fn_line.ret_ty_info.c_ty + " ret = (*env)->CallObjectMethod(env, obj, j_calls->" + fn_line.fn_name + "_meth"
                 elif not fn_line.ret_ty_info.passed_as_ptr:
                     out_c += "\t" + fn_line.ret_ty_info.c_ty + " ret = (*env)->Call" + fn_line.ret_ty_info.java_ty.title() + "Method(env, obj, j_calls->" + fn_line.fn_name + "_meth"
                 else:
-                    out_c = out_c + "\t" + fn_line.ret_ty_info.rust_obj + "* ret = (" + fn_line.ret_ty_info.rust_obj + "*)(*env)->CallLongMethod(env, obj, j_calls->" + fn_line.fn_name + "_meth"
+                    out_c = out_c + "\tuint64_t ret = (*env)->CallLongMethod(env, obj, j_calls->" + fn_line.fn_name + "_meth"
 
                 for idx, arg_info in enumerate(fn_line.args_ty):
                     if arg_info.ret_conv is not None: