@@ -43,14 +43,14 @@ def _do_map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, hold
4343 else :
4444 arr_name = "ret"
4545 arr_len = ret_arr_len
46- if ty_info .c_ty == "int8_tArray" :
46+ if ty_info .c_ty == "int8_tArray" or ty_info . c_ty == "int16_tArray" :
4747 (set_pfx , set_sfx ) = self .consts .set_native_arr_contents (arr_name + "_arr" , arr_len , ty_info )
48- ret_conv = ("int8_tArray " + arr_name + "_arr = " + self .consts .create_native_arr_call (arr_len , ty_info ) + ";\n " + set_pfx , "" )
48+ ret_conv = (ty_info . c_ty + " " + arr_name + "_arr = " + self .consts .create_native_arr_call (arr_len , ty_info ) + ";\n " + set_pfx , "" )
4949 arg_conv_cleanup = None
5050 if not arr_len .isdigit ():
5151 arg_conv = ty_info .rust_obj + " " + arr_name + "_ref;\n "
5252 arg_conv = arg_conv + arr_name + "_ref." + arr_len + " = " + self .consts .get_native_arr_len_call [0 ] + arr_name + self .consts .get_native_arr_len_call [1 ] + ";\n "
53- if (not ty_info .is_ptr or not holds_ref ) and ty_info .rust_obj != "LDKu8slice" :
53+ if (not ty_info .is_ptr or not holds_ref ) and ( ty_info .rust_obj != "LDKu8slice" and ty_info . rust_obj != "LDKu16slice" ) :
5454 arg_conv = arg_conv + arr_name + "_ref." + ty_info .arr_access + " = MALLOC(" + arr_name + "_ref." + arr_len + ", \" " + ty_info .rust_obj + " Bytes\" );\n "
5555 arg_conv = arg_conv + self .consts .get_native_arr_contents (arr_name , arr_name + "_ref." + ty_info .arr_access , arr_name + "_ref." + arr_len , ty_info , True ) + ";"
5656 else :
@@ -59,10 +59,10 @@ def _do_map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, hold
5959 if ty_info .rust_obj == "LDKTransaction" or ty_info .rust_obj == "LDKWitness" :
6060 arg_conv = arg_conv + "\n " + arr_name + "_ref.data_is_owned = " + str (holds_ref ).lower () + ";"
6161 ret_conv = (ty_info .rust_obj + " " + arr_name + "_var = " , "" )
62- ret_conv = (ret_conv [0 ], ";\n int8_tArray " + arr_name + "_arr = " + self .consts .create_native_arr_call (arr_name + "_var." + arr_len , ty_info ) + ";\n " )
62+ ret_conv = (ret_conv [0 ], ";\n " + ty_info . c_ty + " " + arr_name + "_arr = " + self .consts .create_native_arr_call (arr_name + "_var." + arr_len , ty_info ) + ";\n " )
6363 (pfx , sfx ) = self .consts .set_native_arr_contents (arr_name + "_arr" , arr_name + "_var." + arr_len , ty_info )
6464 ret_conv = (ret_conv [0 ], ret_conv [1 ] + pfx + arr_name + "_var." + ty_info .arr_access + sfx + ";" )
65- if not holds_ref and ty_info .rust_obj != "LDKu8slice" :
65+ if not holds_ref and ( ty_info .rust_obj != "LDKu8slice" and ty_info . rust_obj != "LDKu16slice" ) :
6666 ret_conv = (ret_conv [0 ], ret_conv [1 ] + "\n " + ty_info .rust_obj .replace ("LDK" , "" ) + "_free(" + arr_name + "_var);" )
6767 from_hu_conv = self .consts .primitive_arr_from_hu (ty_info , None , arr_name )
6868 to_hu_conv = self .consts .primitive_arr_to_hu (ty_info , None , arr_name , arr_name + "_conv" )
@@ -74,10 +74,11 @@ def _do_map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, hold
7474 from_hu_conv = self .consts .primitive_arr_from_hu (ty_info , arr_len , arr_name )
7575 to_hu_conv = self .consts .primitive_arr_to_hu (ty_info , None , arr_name , arr_name + "_conv" )
7676 else :
77- arg_conv = "unsigned char " + arr_name + "_arr[" + arr_len + "];\n "
77+ # Note that we just blindly assume we should be using unsigned integers here.
78+ arg_conv = "u" + ty_info .subty .c_ty + " " + arr_name + "_arr[" + arr_len + "];\n "
7879 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 "
7980 arg_conv = arg_conv + self .consts .get_native_arr_contents (arr_name , arr_name + "_arr" , arr_len , ty_info , True ) + ";\n "
80- arg_conv = arg_conv + "unsigned char (*" + arr_name + "_ref)[" + arr_len + "] = &" + arr_name + "_arr;"
81+ arg_conv = arg_conv + "u" + ty_info . subty . c_ty + " (*" + arr_name + "_ref)[" + arr_len + "] = &" + arr_name + "_arr;"
8182 ret_conv = (ret_conv [0 ] + "*" , set_sfx + ";" )
8283 from_hu_conv = self .consts .primitive_arr_from_hu (ty_info , arr_len , arr_name )
8384 to_hu_conv = self .consts .primitive_arr_to_hu (ty_info , None , arr_name , arr_name + "_conv" )
@@ -429,15 +430,13 @@ def _do_map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, hold
429430 # underlying unlike Vecs, and it gives Java more freedom.
430431 base_conv = base_conv + "\n FREE(untag_ptr(" + ty_info .var_name + "));"
431432 if ty_info .rust_obj in self .complex_enums :
432- to_hu_conv_sfx = ""
433433 if needs_full_clone and (ty_info .rust_obj .replace ("LDK" , "" ) + "_clone" ) not in self .clone_fns :
434434 # We really need a full clone here, but for now we just implement
435435 # a manual clone explicitly for Option<Trait>s
436436 if ty_info .contains_trait :
437437 assert ty_info .rust_obj .startswith ("LDKCOption" ) # We don't support contained traits for anything else yet
438438 optional_ty = ty_info .rust_obj [11 :- 1 ]
439439 assert "LDK" + optional_ty in self .trait_structs # We don't support contained traits for anything else yet
440- to_hu_conv_sfx = self .consts .add_ref ("this" , ty_info .var_name )
441440 base_conv += "\n if (" + ty_info .var_name + "_conv.tag == " + ty_info .rust_obj + "_Some) {"
442441 base_conv += "\n \t // Manually implement clone for Java trait instances"
443442 optional_ty_info = self .java_c_types ("LDK" + optional_ty + " " + ty_info .var_name , None )
@@ -451,7 +450,7 @@ def _do_map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, hold
451450 ret_conv = (ret_conv [0 ], ";\n " + self .consts .ptr_c_ty + " " + ty_info .var_name + "_ref = tag_ptr(" + ty_info .var_name + "_copy, true);" )
452451 if from_hu_conv is None :
453452 from_hu_conv = (self .consts .get_ptr (ty_info .var_name ), "" )
454- from_hu_conv = (from_hu_conv [0 ], to_hu_conv_sfx )
453+ from_hu_conv = (from_hu_conv [0 ], self . consts . add_ref ( "this" , ty_info . var_name ) )
455454 fully_qualified_ty = self .consts .fully_qualified_hu_ty_path (ty_info )
456455 to_hu_call = fully_qualified_ty + ".constr_from_ptr(" + ty_info .var_name + ")"
457456 return ConvInfo (ty_info = ty_info , arg_name = ty_info .var_name ,
0 commit comments