Skip to content

Commit d6076a5

Browse files
committed
[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`
1 parent 924271f commit d6076a5

4 files changed

+8
-1
lines changed

csharp_strings.py

+3
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,9 @@ def get_java_arr_elem(self, elem_ty, arr_name, idx):
595595
else:
596596
assert False
597597

598+
def check_c_arr_null(self, arr_name):
599+
return arr_name + " != 0"
600+
598601
def constr_hu_array(self, ty_info, arr_len):
599602
base_ty = ty_info.subty.java_hu_ty.split("[")[0].split("<")[0]
600603
conv = "new " + base_ty + "[" + arr_len + "]"

gen_type_mapping.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def _do_map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, hold
194194
to_hu_conv += ";\n"
195195
pfx = ""
196196
if is_nullable:
197-
to_hu_conv += "if (" + arr_name + " != null) {\n"
197+
to_hu_conv += "if (" + self.consts.check_c_arr_null(arr_name) + ") {\n"
198198
pfx = "\t"
199199
to_hu_conv += pfx + self.consts.for_n_in_range(idxc, "0", conv_name + "_len") + "\n"
200200

java_strings.py

+2
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,8 @@ def get_java_arr_len(self, arr_name):
786786
return arr_name + ".length"
787787
def get_java_arr_elem(self, elem_ty, arr_name, idx):
788788
return arr_name + "[" + idx + "]"
789+
def check_c_arr_null(self, arr_name):
790+
return arr_name + " != null"
789791
def constr_hu_array(self, ty_info, arr_len):
790792
base_ty = ty_info.subty.java_hu_ty.split("[")[0].split("<")[0]
791793
conv = "new " + base_ty + "[" + arr_len + "]"

typescript_strings.py

+2
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,8 @@ def get_java_arr_elem(self, elem_ty, arr_name, idx):
858858
return "bindings.getU32ArrayElem(" + arr_name + ", " + idx + ")"
859859
else:
860860
assert False
861+
def check_c_arr_null(self, arr_name):
862+
return arr_name + " != 0"
861863
def constr_hu_array(self, ty_info, arr_len):
862864
return "new Array(" + arr_len + ").fill(null)"
863865
def cleanup_converted_native_array(self, ty_info, arr_name):

0 commit comments

Comments
 (0)