From: Matt Corallo Date: Tue, 27 Dec 2022 02:01:40 +0000 (+0000) Subject: Pass array type, not subty to primitive_arr_*_hu for more context X-Git-Tag: v0.0.113.0^2~18 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=1d1229d708592d16cbeddc56ab2629e50889dc27;p=ldk-java Pass array type, not subty to primitive_arr_*_hu for more context --- diff --git a/gen_type_mapping.py b/gen_type_mapping.py index 583ddc11..eac96eb8 100644 --- a/gen_type_mapping.py +++ b/gen_type_mapping.py @@ -64,23 +64,23 @@ class TypeMappingGenerator: ret_conv = (ret_conv[0], ret_conv[1] + pfx + arr_name + "_var." + ty_info.arr_access + sfx + ";") if not holds_ref and ty_info.rust_obj != "LDKu8slice": ret_conv = (ret_conv[0], ret_conv[1] + "\n" + ty_info.rust_obj.replace("LDK", "") + "_free(" + arr_name + "_var);") - from_hu_conv = self.consts.primitive_arr_from_hu(ty_info.subty, None, arr_name) - to_hu_conv = self.consts.primitive_arr_to_hu(ty_info.subty, None, arr_name, arr_name + "_conv") + from_hu_conv = self.consts.primitive_arr_from_hu(ty_info, None, arr_name) + to_hu_conv = self.consts.primitive_arr_to_hu(ty_info, None, arr_name, arr_name + "_conv") elif ty_info.rust_obj is not None: arg_conv = ty_info.rust_obj + " " + arr_name + "_ref;\n" 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" arg_conv = arg_conv + self.consts.get_native_arr_contents(arr_name, arr_name + "_ref." + ty_info.arr_access, arr_len, ty_info, True) + ";" ret_conv = (ret_conv[0], "." + ty_info.arr_access + set_sfx + ";") - from_hu_conv = self.consts.primitive_arr_from_hu(ty_info.subty, arr_len, arr_name) - to_hu_conv = self.consts.primitive_arr_to_hu(ty_info.subty, None, arr_name, arr_name + "_conv") + from_hu_conv = self.consts.primitive_arr_from_hu(ty_info, arr_len, arr_name) + to_hu_conv = self.consts.primitive_arr_to_hu(ty_info, None, arr_name, arr_name + "_conv") else: arg_conv = "unsigned char " + arr_name + "_arr[" + arr_len + "];\n" 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" arg_conv = arg_conv + self.consts.get_native_arr_contents(arr_name, arr_name + "_arr", arr_len, ty_info, True) + ";\n" arg_conv = arg_conv + "unsigned char (*" + arr_name + "_ref)[" + arr_len + "] = &" + arr_name + "_arr;" ret_conv = (ret_conv[0] + "*", set_sfx + ";") - from_hu_conv = self.consts.primitive_arr_from_hu(ty_info.subty, arr_len, arr_name) - to_hu_conv = self.consts.primitive_arr_to_hu(ty_info.subty, None, arr_name, arr_name + "_conv") + from_hu_conv = self.consts.primitive_arr_from_hu(ty_info, arr_len, arr_name) + to_hu_conv = self.consts.primitive_arr_to_hu(ty_info, None, arr_name, arr_name + "_conv") to_hu_conv_name = None if to_hu_conv is not None: to_hu_conv_name = arr_name + "_conv" @@ -208,12 +208,12 @@ class TypeMappingGenerator: to_hu_conv += "\n" + cleanup to_hu_conv_name = conv_name + "_arr" else: - to_hu_conv = self.consts.primitive_arr_to_hu(ty_info.subty, None, arr_name, arr_name + "_conv") + to_hu_conv = self.consts.primitive_arr_to_hu(ty_info, None, arr_name, arr_name + "_conv") if to_hu_conv is not None: to_hu_conv_name = arr_name + "_conv" else: to_hu_conv_name = None - from_hu_conv = self.consts.primitive_arr_from_hu(ty_info.subty, None, arr_name) + from_hu_conv = self.consts.primitive_arr_from_hu(ty_info, None, arr_name) if subty.from_hu_conv is not None: hu_conv_b = "" if subty.from_hu_conv[1] != "": @@ -223,7 +223,7 @@ 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.subty, 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)) assert arr_conv[1] == "" from_hu_conv = (arr_conv[0], hu_conv_b) else: diff --git a/java_strings.py b/java_strings.py index d3b3800d..6308ed51 100644 --- a/java_strings.py +++ b/java_strings.py @@ -702,11 +702,12 @@ import javax.annotation.Nullable; def cleanup_converted_native_array(self, ty_info, arr_name): return None - def primitive_arr_from_hu(self, mapped_ty, fixed_len, arr_name): + def primitive_arr_from_hu(self, arr_ty, fixed_len, arr_name): + mapped_ty = arr_ty.subty if fixed_len is not None: return ("InternalUtils.check_arr_len(" + arr_name + ", " + fixed_len + ")", "") return None - def primitive_arr_to_hu(self, primitive_ty, fixed_len, arr_name, conv_name): + def primitive_arr_to_hu(self, arr_ty, fixed_len, arr_name, conv_name): return None def java_arr_ty_str(self, elem_ty_str): diff --git a/typescript_strings.py b/typescript_strings.py index 64eae1fa..37d12b61 100644 --- a/typescript_strings.py +++ b/typescript_strings.py @@ -757,7 +757,8 @@ import * as bindings from '../bindings.mjs' def cleanup_converted_native_array(self, ty_info, arr_name): return "bindings.freeWasmMemory(" + arr_name + ")" - def primitive_arr_from_hu(self, mapped_ty, fixed_len, arr_name): + def primitive_arr_from_hu(self, arr_ty, fixed_len, arr_name): + mapped_ty = arr_ty.subty inner = arr_name if fixed_len is not None: assert mapped_ty.c_ty == "int8_t" @@ -774,7 +775,8 @@ import * as bindings from '../bindings.mjs' print(mapped_ty.c_ty) assert False - def primitive_arr_to_hu(self, mapped_ty, fixed_len, arr_name, conv_name): + def primitive_arr_to_hu(self, arr_ty, fixed_len, arr_name, conv_name): + mapped_ty = arr_ty.subty if mapped_ty.c_ty == "uint8_t" or mapped_ty.c_ty == "int8_t": return "const " + conv_name + ": Uint8Array = bindings.decodeUint8Array(" + arr_name + ");" elif mapped_ty.c_ty == "uint64_t" or mapped_ty.c_ty == "int64_t":