]> git.bitcoin.ninja Git - ldk-java/commitdiff
[TS] Don't null-check array conversions that aren't nullable
authorMatt Corallo <git@bluematt.me>
Fri, 6 Oct 2023 17:52:57 +0000 (17:52 +0000)
committerMatt Corallo <git@bluematt.me>
Sat, 7 Oct 2023 17:23:06 +0000 (17:23 +0000)
These can generate a warning in calling methods that actually don't
allow null.

csharp_strings.py
gen_type_mapping.py
java_strings.py
typescript_strings.py

index b5f816edea8b9771f9f48a32ae73efd0440d6f41..74830d0458ce2a56bc23a15fd3a5e76b130cf906 100644 (file)
@@ -494,7 +494,7 @@ namespace org { namespace ldk { namespace structs {
         else:
             return "FREE(" + arr_name + ")"
 
-    def map_hu_array_elems(self, arr_name, conv_name, arr_ty, elem_ty):
+    def map_hu_array_elems(self, arr_name, conv_name, arr_ty, elem_ty, is_nullable):
         if elem_ty.java_hu_ty == "UInt5":
             return arr_name + " != null ? InternalUtils.convUInt5Array(" + arr_name + ") : null"
         elif elem_ty.java_hu_ty == "WitnessVersion":
index 2dfdd6414e4d2e776af1f62357cf9fcc11a830e8..f68ce6de5e3bf47457e6ca7467256fdd446df295 100644 (file)
@@ -224,11 +224,11 @@ class TypeMappingGenerator:
                         else:
                             hu_conv_b = iterator[0] + subty.from_hu_conv[1] + ";" + iterator[1]
                     if from_hu_conv is not None:
-                        arr_conv = self.consts.primitive_arr_from_hu(ty_info, None, self.consts.map_hu_array_elems(arr_name, conv_name, ty_info, subty))
+                        arr_conv = self.consts.primitive_arr_from_hu(ty_info, None, self.consts.map_hu_array_elems(arr_name, conv_name, ty_info, subty, is_nullable))
                         assert arr_conv[1] == ""
                         from_hu_conv = (arr_conv[0], hu_conv_b)
                     else:
-                        from_hu_conv = (self.consts.map_hu_array_elems(arr_name, conv_name, ty_info, subty), hu_conv_b)
+                        from_hu_conv = (self.consts.map_hu_array_elems(arr_name, conv_name, ty_info, subty, is_nullable), hu_conv_b)
 
                 return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
                     arg_conv = arg_conv, arg_conv_name = arg_conv_name, arg_conv_cleanup = arg_conv_cleanup,
index 946e1650ee8def0da217ab173ca89698f8554942..abe038d0f403a74bb0ba2735818d087921b3248d 100644 (file)
@@ -707,7 +707,7 @@ import javax.annotation.Nullable;
         else:
             return "(*env)->Release" + ty_info.java_ty.strip("[]").title() + "ArrayElements(env, " + arr_name + ", " + dest_name + ", 0)"
 
-    def map_hu_array_elems(self, arr_name, conv_name, arr_ty, elem_ty):
+    def map_hu_array_elems(self, arr_name, conv_name, arr_ty, elem_ty, is_nullable):
         if elem_ty.java_ty == "long" and elem_ty.java_hu_ty != "long":
             return arr_name + " != null ? Arrays.stream(" + arr_name + ").mapToLong(" + conv_name + " -> " + elem_ty.from_hu_conv[0] + ").toArray() : null"
         elif elem_ty.java_ty == "long":
index b9f63b386a9888aac8bc7fa2a47c4ae394ddb53e..92c734ac0f1eb912b8ca4087a884e7ca9e0aa4e7 100644 (file)
@@ -799,11 +799,14 @@ import * as bindings from '../bindings.mjs'
         else:
             return "FREE(" + arr_name + ")"
 
-    def map_hu_array_elems(self, arr_name, conv_name, arr_ty, elem_ty):
+    def map_hu_array_elems(self, arr_name, conv_name, arr_ty, elem_ty, is_nullable):
         if elem_ty.rust_obj == "LDKU5":
             return arr_name + " != null ? bindings.uint5ArrToBytes(" + arr_name + ") : null"
         assert elem_ty.c_ty == "uint64_t" or elem_ty.c_ty.endswith("Array") or elem_ty.rust_obj == "LDKStr"
-        return arr_name + " != null ? " + arr_name + ".map(" + conv_name + " => " + elem_ty.from_hu_conv[0] + ") : null"
+        if is_nullable:
+            return arr_name + " != null ? " + arr_name + ".map(" + conv_name + " => " + elem_ty.from_hu_conv[0] + ") : null"
+        else:
+            return arr_name + ".map(" + conv_name + " => " + elem_ty.from_hu_conv[0] + ")"
 
     def str_ref_to_native_call(self, var_name, str_len):
         return "str_ref_to_ts(" + var_name + ", " + str_len + ")"