X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=java_strings.py;h=d73a15de87328d4114350a387f28a88e978a38b3;hb=3c80c9d8174c6a4355b2fc0790288ea46e4631e4;hp=682169295aed2849375c7841d70b50e271fdc7fe;hpb=9f93df58323e1dea5f3900d5d06b8506b8bc3278;p=ldk-java diff --git a/java_strings.py b/java_strings.py index 68216929..d73a15de 100644 --- a/java_strings.py +++ b/java_strings.py @@ -702,6 +702,12 @@ import java.util.Arrays; return (out_java, out_java_trait, out_c) + def trait_struct_inc_refcnt(self, ty_info): + base_conv = "\nif (" + ty_info.var_name + "_conv.free == " + ty_info.rust_obj + "_JCalls_free) {\n" + base_conv = base_conv + "\t// If this_arg is a JCalls struct, then we need to increment the refcnt in it.\n" + base_conv = base_conv + "\t" + ty_info.rust_obj + "_JCalls_clone(" + ty_info.var_name + "_conv.this_arg);\n}" + return base_conv + def map_complex_enum(self, struct_name, variant_list, camel_to_snake): java_hu_type = struct_name.replace("LDK", "") out_java_enum = "" @@ -785,3 +791,21 @@ import java.util.Arrays; out_c += ("\t}\n}\n") out_java_enum += ("}\n") return (out_java, out_java_enum, out_c) + + def map_opaque_struct(self, struct_name): + out_opaque_struct_human = "" + out_opaque_struct_human += self.hu_struct_file_prefix + out_opaque_struct_human += ("public class " + struct_name.replace("LDK","") + " extends CommonBase") + if struct_name.startswith("LDKLocked"): + out_opaque_struct_human += (" implements AutoCloseable") + out_opaque_struct_human += (" {\n") + out_opaque_struct_human += ("\t" + struct_name.replace("LDK", "") + "(Object _dummy, long ptr) { super(ptr); }\n") + if struct_name.startswith("LDKLocked"): + out_opaque_struct_human += ("\t@Override public void close() {\n") + else: + out_opaque_struct_human += ("\t@Override @SuppressWarnings(\"deprecation\")\n") + out_opaque_struct_human += ("\tprotected void finalize() throws Throwable {\n") + out_opaque_struct_human += ("\t\tsuper.finalize();\n") + out_opaque_struct_human += ("\t\tif (ptr != 0) { bindings." + struct_name.replace("LDK","") + "_free(ptr); }\n") + out_opaque_struct_human += ("\t}\n\n") + return out_opaque_struct_human