From: Matt Corallo Date: Sun, 12 Jan 2025 20:35:27 +0000 (+0000) Subject: [C#/TypeScript] Correct nullable array check in to-human conversions X-Git-Tag: v0.1.0.0~7 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=d6076a5ee0fd23960c2eef63e3ee5939d88cf498;p=ldk-java [C#/TypeScript] Correct nullable array check in to-human conversions ...we have a pointer/long at this point, we shoulnd't be comparing to `null` --- diff --git a/csharp_strings.py b/csharp_strings.py index 6a483e84..38330aef 100644 --- a/csharp_strings.py +++ b/csharp_strings.py @@ -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 + "]" diff --git a/gen_type_mapping.py b/gen_type_mapping.py index 0d5020c0..9c350a44 100644 --- a/gen_type_mapping.py +++ b/gen_type_mapping.py @@ -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" diff --git a/java_strings.py b/java_strings.py index 7e35d175..d358e6d5 100644 --- a/java_strings.py +++ b/java_strings.py @@ -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 + "]" diff --git a/typescript_strings.py b/typescript_strings.py index 9704a48f..ffdb5aa9 100644 --- a/typescript_strings.py +++ b/typescript_strings.py @@ -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):