Pass array type, not subty to primitive_arr_*_hu for more context
authorMatt Corallo <git@bluematt.me>
Tue, 27 Dec 2022 02:01:40 +0000 (02:01 +0000)
committerMatt Corallo <git@bluematt.me>
Tue, 27 Dec 2022 02:01:40 +0000 (02:01 +0000)
gen_type_mapping.py
java_strings.py
typescript_strings.py

index 583ddc11498d42c0cf24fc1ec9d8a562a684bb50..eac96eb83684e8eecc7853a790be712fa7efe0d2 100644 (file)
@@ -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:
index d3b3800d9283a9ad17b0ea19e9d6449ee90ba9db..6308ed518dd795e953f7ced3c3bdca265631fc75 100644 (file)
@@ -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):
index 64eae1fa4de7542a57e8fbe70586c14186ade47a..37d12b61818efbfa35fedc92e79b717364449a2c 100644 (file)
@@ -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":