]> git.bitcoin.ninja Git - ldk-java/commitdiff
Remap non-clonable move-passed optional fn args into Option<&Type>
authorMatt Corallo <git@bluematt.me>
Fri, 24 Sep 2021 02:05:03 +0000 (02:05 +0000)
committerMatt Corallo <git@bluematt.me>
Fri, 24 Sep 2021 21:28:51 +0000 (21:28 +0000)
This may break in the future, so we print a huge warning.

genbindings.py

index a08ea2aad920e60257aa94da2ade105548a0a0fd..cc63c11aa3b8b276b140e09816c9804dcdb8d457 100755 (executable)
@@ -459,8 +459,23 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java:
                     takes_self_ptr = True
             elif argument_conversion_info.arg_name in params_nullable:
                 argument_conversion_info.nullable = True
+                if argument_conversion_info.arg_conv is not None and "Warning" in argument_conversion_info.arg_conv:
+                    arg_ty_info = java_c_types(argument, None)
+                    print("WARNING: Remapping argument " + arg_ty_info.var_name + " of function " + method_name + " to a reference")
+                    print("    The argument appears to require a move, or not clonable, and is nullable.")
+                    print("    Normally for arguments that require a move and are not clonable, we split")
+                    print("    the argument into the type's constructor's arguments and just use those to")
+                    print("    construct a new object on the fly.")
+                    print("    However, because the object is nullable, doing so would mean we can no")
+                    print("    longer allow the user to pass null, as we now have an argument list instead.")
+                    print("    Thus, we blindly assume its really an Option<&Type> instead of an Option<Type>.")
+                    print("    It may or may not actually be a reference, but its the simplest mapping option")
+                    print("    and also the only use of this code today.")
+                    arg_ty_info.requires_clone = False
+                    argument_conversion_info = type_mapping_generator.map_type_with_info(arg_ty_info, False, None, is_free, True)
+                    assert argument_conversion_info.arg_conv is not None and "Warning" not in argument_conversion_info.arg_conv
+
             if argument_conversion_info.arg_conv is not None and "Warning" in argument_conversion_info.arg_conv:
-                assert not argument_conversion_info.arg_name in params_nullable
                 if argument_conversion_info.rust_obj in constructor_fns:
                     assert not is_free
                     for explode_arg in constructor_fns[argument_conversion_info.rust_obj].split(','):