Skip to content

Commit 1d1229d

Browse files
committed
Pass array type, not subty to primitive_arr_*_hu for more context
1 parent 3a51335 commit 1d1229d

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

gen_type_mapping.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,23 +64,23 @@ def _do_map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, hold
6464
ret_conv = (ret_conv[0], ret_conv[1] + pfx + arr_name + "_var." + ty_info.arr_access + sfx + ";")
6565
if not holds_ref and ty_info.rust_obj != "LDKu8slice":
6666
ret_conv = (ret_conv[0], ret_conv[1] + "\n" + ty_info.rust_obj.replace("LDK", "") + "_free(" + arr_name + "_var);")
67-
from_hu_conv = self.consts.primitive_arr_from_hu(ty_info.subty, None, arr_name)
68-
to_hu_conv = self.consts.primitive_arr_to_hu(ty_info.subty, None, arr_name, arr_name + "_conv")
67+
from_hu_conv = self.consts.primitive_arr_from_hu(ty_info, None, arr_name)
68+
to_hu_conv = self.consts.primitive_arr_to_hu(ty_info, None, arr_name, arr_name + "_conv")
6969
elif ty_info.rust_obj is not None:
7070
arg_conv = ty_info.rust_obj + " " + arr_name + "_ref;\n"
7171
arg_conv = arg_conv + "CHECK(" + self.consts.get_native_arr_len_call[0] + arr_name + self.consts.get_native_arr_len_call[1] + " == " + arr_len + ");\n"
7272
arg_conv = arg_conv + self.consts.get_native_arr_contents(arr_name, arr_name + "_ref." + ty_info.arr_access, arr_len, ty_info, True) + ";"
7373
ret_conv = (ret_conv[0], "." + ty_info.arr_access + set_sfx + ";")
74-
from_hu_conv = self.consts.primitive_arr_from_hu(ty_info.subty, arr_len, arr_name)
75-
to_hu_conv = self.consts.primitive_arr_to_hu(ty_info.subty, None, arr_name, arr_name + "_conv")
74+
from_hu_conv = self.consts.primitive_arr_from_hu(ty_info, arr_len, arr_name)
75+
to_hu_conv = self.consts.primitive_arr_to_hu(ty_info, None, arr_name, arr_name + "_conv")
7676
else:
7777
arg_conv = "unsigned char " + arr_name + "_arr[" + arr_len + "];\n"
7878
arg_conv = arg_conv + "CHECK(" + self.consts.get_native_arr_len_call[0] + arr_name + self.consts.get_native_arr_len_call[1] + " == " + arr_len + ");\n"
7979
arg_conv = arg_conv + self.consts.get_native_arr_contents(arr_name, arr_name + "_arr", arr_len, ty_info, True) + ";\n"
8080
arg_conv = arg_conv + "unsigned char (*" + arr_name + "_ref)[" + arr_len + "] = &" + arr_name + "_arr;"
8181
ret_conv = (ret_conv[0] + "*", set_sfx + ";")
82-
from_hu_conv = self.consts.primitive_arr_from_hu(ty_info.subty, arr_len, arr_name)
83-
to_hu_conv = self.consts.primitive_arr_to_hu(ty_info.subty, None, arr_name, arr_name + "_conv")
82+
from_hu_conv = self.consts.primitive_arr_from_hu(ty_info, arr_len, arr_name)
83+
to_hu_conv = self.consts.primitive_arr_to_hu(ty_info, None, arr_name, arr_name + "_conv")
8484
to_hu_conv_name = None
8585
if to_hu_conv is not None:
8686
to_hu_conv_name = arr_name + "_conv"
@@ -208,12 +208,12 @@ def _do_map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, hold
208208
to_hu_conv += "\n" + cleanup
209209
to_hu_conv_name = conv_name + "_arr"
210210
else:
211-
to_hu_conv = self.consts.primitive_arr_to_hu(ty_info.subty, None, arr_name, arr_name + "_conv")
211+
to_hu_conv = self.consts.primitive_arr_to_hu(ty_info, None, arr_name, arr_name + "_conv")
212212
if to_hu_conv is not None:
213213
to_hu_conv_name = arr_name + "_conv"
214214
else:
215215
to_hu_conv_name = None
216-
from_hu_conv = self.consts.primitive_arr_from_hu(ty_info.subty, None, arr_name)
216+
from_hu_conv = self.consts.primitive_arr_from_hu(ty_info, None, arr_name)
217217
if subty.from_hu_conv is not None:
218218
hu_conv_b = ""
219219
if subty.from_hu_conv[1] != "":
@@ -223,7 +223,7 @@ def _do_map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, hold
223223
else:
224224
hu_conv_b = iterator[0] + subty.from_hu_conv[1] + ";" + iterator[1]
225225
if from_hu_conv is not None:
226-
arr_conv = self.consts.primitive_arr_from_hu(ty_info.subty, None, self.consts.map_hu_array_elems(arr_name, conv_name, ty_info, subty))
226+
arr_conv = self.consts.primitive_arr_from_hu(ty_info, None, self.consts.map_hu_array_elems(arr_name, conv_name, ty_info, subty))
227227
assert arr_conv[1] == ""
228228
from_hu_conv = (arr_conv[0], hu_conv_b)
229229
else:

java_strings.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -702,11 +702,12 @@ def constr_hu_array(self, ty_info, arr_len):
702702
def cleanup_converted_native_array(self, ty_info, arr_name):
703703
return None
704704

705-
def primitive_arr_from_hu(self, mapped_ty, fixed_len, arr_name):
705+
def primitive_arr_from_hu(self, arr_ty, fixed_len, arr_name):
706+
mapped_ty = arr_ty.subty
706707
if fixed_len is not None:
707708
return ("InternalUtils.check_arr_len(" + arr_name + ", " + fixed_len + ")", "")
708709
return None
709-
def primitive_arr_to_hu(self, primitive_ty, fixed_len, arr_name, conv_name):
710+
def primitive_arr_to_hu(self, arr_ty, fixed_len, arr_name, conv_name):
710711
return None
711712

712713
def java_arr_ty_str(self, elem_ty_str):

typescript_strings.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,8 @@ def constr_hu_array(self, ty_info, arr_len):
757757
def cleanup_converted_native_array(self, ty_info, arr_name):
758758
return "bindings.freeWasmMemory(" + arr_name + ")"
759759

760-
def primitive_arr_from_hu(self, mapped_ty, fixed_len, arr_name):
760+
def primitive_arr_from_hu(self, arr_ty, fixed_len, arr_name):
761+
mapped_ty = arr_ty.subty
761762
inner = arr_name
762763
if fixed_len is not None:
763764
assert mapped_ty.c_ty == "int8_t"
@@ -774,7 +775,8 @@ def primitive_arr_from_hu(self, mapped_ty, fixed_len, arr_name):
774775
print(mapped_ty.c_ty)
775776
assert False
776777

777-
def primitive_arr_to_hu(self, mapped_ty, fixed_len, arr_name, conv_name):
778+
def primitive_arr_to_hu(self, arr_ty, fixed_len, arr_name, conv_name):
779+
mapped_ty = arr_ty.subty
778780
if mapped_ty.c_ty == "uint8_t" or mapped_ty.c_ty == "int8_t":
779781
return "const " + conv_name + ": Uint8Array = bindings.decodeUint8Array(" + arr_name + ");"
780782
elif mapped_ty.c_ty == "uint64_t" or mapped_ty.c_ty == "int64_t":

0 commit comments

Comments
 (0)