]> git.bitcoin.ninja Git - ldk-java/commitdiff
Handle methods taking non-ref self by using standard conversion
authorMatt Corallo <git@bluematt.me>
Sat, 5 Jun 2021 16:49:20 +0000 (16:49 +0000)
committerMatt Corallo <git-ldk-build@bluematt.me>
Tue, 8 Jun 2021 20:26:10 +0000 (20:26 +0000)
genbindings.py
java_strings.py
typescript_strings.py

index f35932ef39257637c61a3ce237fed7cf7dd7cb18..a03fa4c4d2baa4751ecc34af81592bb6a8c96dfd 100755 (executable)
@@ -416,12 +416,15 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java:
         argument_types = []
         default_constructor_args = {}
         takes_self = False
+        takes_self_ptr = False
         args_known = True
 
         for argument_index, argument in enumerate(method_arguments):
             argument_conversion_info = type_mapping_generator.map_type(argument, False, None, is_free, True)
             if argument_index == 0 and argument_conversion_info.java_hu_ty == struct_meth:
                 takes_self = True
+                if argument_conversion_info.ty_info.is_ptr:
+                    takes_self_ptr = True
             if argument_conversion_info.arg_conv is not None and "Warning" in argument_conversion_info.arg_conv:
                 if argument_conversion_info.rust_obj in constructor_fns:
                     assert not is_free
@@ -439,7 +442,7 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java:
 
         out_java.write("\t// " + line)
         (out_java_delta, out_c_delta, out_java_struct_delta) = \
-            consts.map_function(argument_types, c_call_string, method_name, return_type_info, struct_meth, default_constructor_args, takes_self, args_known, type_mapping_generator, doc_comment)
+            consts.map_function(argument_types, c_call_string, method_name, return_type_info, struct_meth, default_constructor_args, takes_self, takes_self_ptr, args_known, type_mapping_generator, doc_comment)
         out_java.write(out_java_delta)
 
         if is_free:
index 94998db17a6dbade2c919bc505ca3a7b9821236f..223b544d440b32f6427d0a77cf394eb4ed04420b 100644 (file)
@@ -1034,7 +1034,7 @@ import java.util.Arrays;
         return out_opaque_struct_human
 
 
-    def map_function(self, argument_types, c_call_string, method_name, return_type_info, struct_meth, default_constructor_args, takes_self, args_known, type_mapping_generator, doc_comment):
+    def map_function(self, argument_types, c_call_string, method_name, return_type_info, struct_meth, default_constructor_args, takes_self, takes_self_as_ref, args_known, type_mapping_generator, doc_comment):
         out_java = ""
         out_c = ""
         out_java_struct = None
@@ -1076,7 +1076,7 @@ import java.util.Arrays;
             for idx, arg in enumerate(argument_types):
                 if idx != 0:
                     if not takes_self or idx > 1:
-                        out_java_struct += (", ")
+                        out_java_struct += ", "
                 elif takes_self:
                     continue
                 if arg.java_ty != "void":
@@ -1177,6 +1177,8 @@ import java.util.Arrays;
                     else:
                         out_java_struct += ("\t\t" + info.from_hu_conv[1].replace("\n", "\n\t\t") + ";\n")
 
+            if takes_self and not takes_self_as_ref:
+                out_java_struct += "\t\t" + argument_types[0].from_hu_conv[1].replace("\n", "\n\t\t").replace("this_arg", "this") + ";\n"
             if return_type_info.to_hu_conv_name is not None:
                 out_java_struct += ("\t\treturn " + return_type_info.to_hu_conv_name + ";\n")
             elif return_type_info.java_ty != "void" and return_type_info.rust_obj != "LDK" + struct_meth:
index eb14c1554a70e2bf5d4fdcc544249438442e9686..d5d4499d91c7ad46228345a43b956578a3dbd925 100644 (file)
@@ -933,7 +933,7 @@ const decodeString = (stringPointer, free = true) => {
 """
         return out_opaque_struct_human
 
-    def map_function(self, argument_types, c_call_string, method_name, return_type_info, struct_meth, default_constructor_args, takes_self, args_known, type_mapping_generator, doc_comment):
+    def map_function(self, argument_types, c_call_string, method_name, return_type_info, struct_meth, default_constructor_args, takes_self, takes_self_as_ref, args_known, type_mapping_generator, doc_comment):
         out_java = ""
         out_c = ""
         out_java_struct = None