if (!get_lib_version_string().equals(version.get_ldk_java_bindings_version()))
throw new IllegalArgumentException("Compiled LDK library and LDK class failes do not match");
// Fetching the LDK versions from C also checks that the header and binaries match
- get_ldk_c_bindings_version();
- get_ldk_version();
+ System.err.println("Loaded LDK-Java Bindings " + version.get_ldk_java_bindings_version() + " with LDK " + get_ldk_version() + " and LDK-C-Bindings " + get_ldk_c_bindings_version());
}
static native void init(java.lang.Class c, java.lang.Class slicedef);
static native void init_class_cache();
}
}"""
+ 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
DEBUG_PRINT("LDK version did not match the header we built against\\n");
if (check_get_ldk_bindings_version() == NULL)
DEBUG_PRINT("LDK C Bindings version did not match the header we built against\\n");
- DEBUG_PRINT("Loaded LDK-Java Bindings with LDK %s and LDK-C-Bindings %s\\n", check_get_ldk_version(), check_get_ldk_bindings_version());
}
"""
self.file_ext = ".java"
self.ptr_c_ty = "int64_t"
self.ptr_native_ty = "long"
+ self.usize_c_ty = "int64_t"
+ self.usize_native_ty = "long"
+ self.native_zero_ptr = "0"
self.result_c_ty = "jclass"
self.ptr_arr = "jobjectArray"
self.is_arr_some_check = ("", " != NULL")
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(";"):
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: