X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=java_strings.py;h=1f4ddaff009dfcf940632e9046082d18f5a7c8d6;hb=82e58787c9abe46b5d6f5898f07455feabed65db;hp=d4931cd912038295c89ab63ce11f0ffdbe9e35e7;hpb=9e0cfdcda96c1d503232f71096566b46de424738;p=ldk-java diff --git a/java_strings.py b/java_strings.py index d4931cd9..1f4ddaff 100644 --- a/java_strings.py +++ b/java_strings.py @@ -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); } } @@ -96,6 +99,7 @@ public class bindings { self.util_fn_pfx = """package org.ldk.structs; import org.ldk.impl.bindings; import java.util.Arrays; +import javax.annotation.Nullable; import org.ldk.enums.*; public class UtilMethods { @@ -473,6 +477,7 @@ import org.ldk.impl.bindings; import org.ldk.enums.*; import org.ldk.util.*; import java.util.Arrays; +import javax.annotation.Nullable; """ self.c_fn_ty_pfx = "JNIEXPORT " @@ -482,6 +487,7 @@ import java.util.Arrays; self.ptr_native_ty = "long" self.result_c_ty = "jclass" self.ptr_arr = "jobjectArray" + self.is_arr_some_check = ("", " != NULL") self.get_native_arr_len_call = ("(*env)->GetArrayLength(env, ", ")") def construct_jenv(self): @@ -846,7 +852,7 @@ import java.util.Arrays; 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: @@ -1021,7 +1027,7 @@ import java.util.Arrays; init_meth_params = "" init_meth_body = "" hu_conv_body = "" - for idx, field_ty in enumerate(var.fields): + for idx, (field_ty, field_docs) in enumerate(var.fields): if idx > 0: init_meth_params = init_meth_params + ", " @@ -1032,7 +1038,12 @@ import java.util.Arrays; init_meth_params = init_meth_params + field_path + " " + field_ty.arg_name else: out_java += "\t\t\tpublic " + field_ty.java_ty + " " + field_ty.arg_name + ";\n" - java_hu_subclasses = java_hu_subclasses + "\t\tpublic final " + field_ty.java_hu_ty + " " + field_ty.arg_name + ";\n" + if field_docs is not None: + java_hu_subclasses += "\t\t/**\n\t\t * " + field_docs.replace("\n", "\n\t\t * ") + "\n\t\t*/\n" + java_hu_subclasses += "\t\t" + if field_ty.nullable: + java_hu_subclasses += "@Nullable " + java_hu_subclasses += "public final " + field_ty.java_hu_ty + " " + field_ty.arg_name + ";\n" init_meth_params = init_meth_params + field_ty.java_ty + " " + field_ty.arg_name init_meth_body = init_meth_body + "this." + field_ty.arg_name + " = " + field_ty.arg_name + "; " if field_ty.to_hu_conv is not None: @@ -1066,7 +1077,7 @@ import java.util.Arrays; for var in variant_list: out_c += ("\t\tcase " + struct_name + "_" + var.var_name + ": {\n") c_params = [] - for idx, field_map in enumerate(var.fields): + for idx, (field_map, field_docs) in enumerate(var.fields): if field_map.ret_conv is not None: out_c += ("\t\t\t" + field_map.ret_conv[0].replace("\n", "\n\t\t\t")) if var.tuple_variant: @@ -1137,6 +1148,8 @@ import java.util.Arrays; meth_n = method_name[len(struct_meth) + 1 if len(struct_meth) != 0 else 0:].strip("_") if doc_comment is not None: out_java_struct += "\t/**\n\t * " + doc_comment.replace("\n", "\n\t * ") + "\n\t */\n" + if return_type_info.nullable: + out_java_struct += "\t@Nullable\n" if not takes_self: if meth_n == "new": out_java_struct += "\tpublic static " + return_type_info.java_hu_ty + " of(" @@ -1154,13 +1167,19 @@ import java.util.Arrays; continue if arg.java_ty != "void": if arg.arg_name in default_constructor_args: + assert not arg.nullable for explode_idx, explode_arg in enumerate(default_constructor_args[arg.arg_name]): if explode_idx != 0: out_java_struct += (", ") out_java_struct += ( explode_arg.java_hu_ty + " " + arg.arg_name + "_" + explode_arg.arg_name) else: - out_java_struct += (arg.java_hu_ty + " " + arg.arg_name) + if arg.nullable: + out_java_struct += "@Nullable " + ty_string = arg.java_hu_ty + if arg.java_fn_ty_arg[0] == "L" and arg.java_fn_ty_arg[len(arg.java_fn_ty_arg) - 1] == ";": + ty_string = arg.java_fn_ty_arg.strip("L;").replace("/", ".") + out_java_struct += ty_string + " " + arg.arg_name out_java += (");\n") out_c += (") {\n") if out_java_struct is not None: