]> git.bitcoin.ninja Git - ldk-java/commitdiff
[C#/TypeScript] Correct nullable array check in to-human conversions
authorMatt Corallo <git@bluematt.me>
Sun, 12 Jan 2025 20:35:27 +0000 (20:35 +0000)
committerMatt Corallo <git@bluematt.me>
Fri, 17 Jan 2025 18:57:14 +0000 (18:57 +0000)
...we have a pointer/long at this point, we shoulnd't be comparing
to `null`

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

index 6a483e84badf883fe4d4056b33e9bf9be2fb493d..38330aef6d69a6c74baac5d6cc4a8d6e0ff234d1 100644 (file)
@@ -595,6 +595,9 @@ int CS_LDK_register_{fn_suffix}_invoker(invoker_{fn_suffix} invoker) {{
         else:
             assert False
 
+    def check_c_arr_null(self, arr_name):
+        return arr_name + " != 0"
+
     def constr_hu_array(self, ty_info, arr_len):
         base_ty = ty_info.subty.java_hu_ty.split("[")[0].split("<")[0]
         conv = "new " + base_ty + "[" + arr_len + "]"
index 0d5020c0573fa44736aeaca1dbb3947be48640ad..9c350a4406a3bbbf3c10d50c720057033076a42b 100644 (file)
@@ -194,7 +194,7 @@ class TypeMappingGenerator:
                     to_hu_conv += ";\n"
                     pfx = ""
                     if is_nullable:
-                        to_hu_conv += "if (" + arr_name + " != null) {\n"
+                        to_hu_conv += "if (" + self.consts.check_c_arr_null(arr_name) + ") {\n"
                         pfx = "\t"
                     to_hu_conv += pfx + self.consts.for_n_in_range(idxc, "0", conv_name + "_len") + "\n"
 
index 7e35d17529d0e8ea127c25e104b0f73996a8f3da..d358e6d508c8aa84c5a01bae620a234acf4e4f9a 100644 (file)
@@ -786,6 +786,8 @@ import javax.annotation.Nullable;
         return arr_name + ".length"
     def get_java_arr_elem(self, elem_ty, arr_name, idx):
         return arr_name + "[" + idx + "]"
+    def check_c_arr_null(self, arr_name):
+        return arr_name + " != null"
     def constr_hu_array(self, ty_info, arr_len):
         base_ty = ty_info.subty.java_hu_ty.split("[")[0].split("<")[0]
         conv = "new " + base_ty + "[" + arr_len + "]"
index 9704a48f0a5b9b1e7b3973153bc57450baa3ebe7..ffdb5aa93c382831c014c1e80fdbd4bf680bc195 100644 (file)
@@ -858,6 +858,8 @@ import * as bindings from '../bindings.mjs'
             return "bindings.getU32ArrayElem(" + arr_name + ", " + idx + ")"
         else:
             assert False
+    def check_c_arr_null(self, arr_name):
+        return arr_name + " != 0"
     def constr_hu_array(self, ty_info, arr_len):
         return "new Array(" + arr_len + ").fill(null)"
     def cleanup_converted_native_array(self, ty_info, arr_name):