Update bindings branch to v0.0.112.
[ldk-java] / java_strings.py
index bcfc1f37e4fc8a02e87d9d716020c06fb196a81d..b2a9d853767ef03ddd8401753849c567ad92f6f1 100644 (file)
@@ -151,6 +151,27 @@ class CommonBase {
        }
 }"""
 
+        self.scalar_defn = """public class BigEndianScalar extends CommonBase {
+       /** The bytes of the scalar value, in big endian */
+       public final byte[] scalar_bytes;
+
+       BigEndianScalar(java.lang.Object _dummy, long ptr) {
+               super(ptr);
+               this.scalar_bytes = bindings.BigEndianScalar_get_bytes(ptr);
+       }
+       public BigEndianScalar(byte[] scalar_bytes) {
+               super(bindings.BigEndianScalar_new(scalar_bytes));
+               this.scalar_bytes = bindings.BigEndianScalar_get_bytes(ptr);
+       }
+
+       @Override @SuppressWarnings(\"deprecation\")
+       protected void finalize() throws Throwable {
+               super.finalize();
+               if (ptr != 0) { bindings.BigEndianScalar_free(ptr); }
+       }
+}"""
+
+
         self.c_file_pfx = """#include <jni.h>
 // On OSX jlong (ie long long) is not equivalent to int64_t, so we override here
 #define int64_t jlong
@@ -704,7 +725,7 @@ import javax.annotation.Nullable;
         return var + ".ptr" + " = 0;"
 
     def add_ref(self, holder, referent):
-        return holder + ".ptrs_to.add(" + referent + ")"
+        return "if (" + holder + " != null) { " + holder + ".ptrs_to.add(" + referent + "); }"
 
     def fully_qualified_hu_ty_path(self, ty):
         if ty.java_fn_ty_arg.startswith("L") and ty.java_fn_ty_arg.endswith(";"):
@@ -992,8 +1013,8 @@ import javax.annotation.Nullable;
                 if fn_line.ret_ty_info.c_ty.endswith("Array"):
                     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_hu_ty == "String":
+                    out_c += "\t(*env)->CallVoidMethod(env, obj, j_calls->" + fn_line.fn_name + "_meth"
+                elif fn_line.ret_ty_info.java_hu_ty == "String" or "org/ldk/enums" in fn_line.ret_ty_info.java_fn_ty_arg:
                     # 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: