- assert(ty_info.c_ty == "jbyteArray")
- return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
- arg_conv = "unsigned char " + arr_name + "_arr[" + arr_len + "];\n" +
- "(*_env)->GetByteArrayRegion (_env, """ + arr_name + ", 0, " + arr_len + ", " + arr_name + "_arr);\n" +
- "unsigned char (*""" + arr_name + "_ref)[" + arr_len + "] = &" + arr_name + "_arr;",
- arg_conv_name = arr_name + "_ref",
- ret_conv = ("jbyteArray " + arr_name + "_arr = (*_env)->NewByteArray(_env, " + arr_len + ");\n" +
- "(*_env)->SetByteArrayRegion(_env, " + arr_name + "_arr, 0, " + arr_len + ", *",
- ");"),
- ret_conv_name = arr_name + "_arr")
- elif ty_info.var_name != "":
- # If we have a parameter name, print it (noting that it may indicate its a pointer)
- if ty_info.rust_obj is not None:
- assert(ty_info.passed_as_ptr)
- if not ty_info.is_ptr:
- if ty_info.rust_obj in unitary_enums:
- return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
- arg_conv = ty_info.rust_obj + " " + ty_info.var_name + "_conv = " + ty_info.rust_obj + "_from_java(_env, " + ty_info.var_name + ");",
- arg_conv_name = ty_info.var_name + "_conv",
- ret_conv = ("jclass " + ty_info.var_name + "_conv = " + ty_info.rust_obj + "_to_java(_env, ", ");"),
- ret_conv_name = ty_info.var_name + "_conv")
- base_conv = ty_info.rust_obj + " " + ty_info.var_name + "_conv = *(" + ty_info.rust_obj + "*)" + ty_info.var_name + ";";
- if ty_info.rust_obj in trait_structs:
- if not is_free:
- base_conv = base_conv + "\nif (" + ty_info.var_name + "_conv.free == " + ty_info.rust_obj + "_JCalls_free) {\n"
- base_conv = base_conv + "\t// If this_arg is a JCalls struct, then we need to increment the refcnt in it.\n"
- base_conv = base_conv + "\t" + ty_info.rust_obj + "_JCalls_clone(" + ty_info.var_name + "_conv.this_arg);\n}"
- else:
- base_conv = base_conv + "\n" + "FREE((void*)" + ty_info.var_name + ");"
- return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
- arg_conv = base_conv,
- arg_conv_name = ty_info.var_name + "_conv",
- ret_conv = None, ret_conv_name = None)
- base_conv = base_conv + "\nFREE((void*)" + ty_info.var_name + ");";
- if ty_info.rust_obj in opaque_structs:
- return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
- arg_conv = base_conv + "\n" + ty_info.var_name + "_conv.is_owned = true;",
- arg_conv_name = ty_info.var_name + "_conv",
- ret_conv = None, ret_conv_name = None)
+ if ty_info.c_ty == "int8_tArray":
+ (set_pfx, set_sfx) = consts.set_native_arr_contents(arr_name + "_arr", arr_len, ty_info)
+ ret_conv = ("int8_tArray " + arr_name + "_arr = " + consts.create_native_arr_call(arr_len, ty_info) + ";\n" + set_pfx, "")
+ arg_conv_cleanup = None
+ if not arr_len.isdigit():
+ arg_conv = ty_info.rust_obj + " " + arr_name + "_ref;\n"
+ arg_conv = arg_conv + arr_name + "_ref." + arr_len + " = " + consts.get_native_arr_len_call[0] + arr_name + consts.get_native_arr_len_call[1] + ";\n"
+ if (not ty_info.is_ptr or not holds_ref) and ty_info.rust_obj != "LDKu8slice":
+ arg_conv = arg_conv + arr_name + "_ref." + ty_info.arr_access + " = MALLOC(" + arr_name + "_ref." + arr_len + ", \"" + ty_info.rust_obj + " Bytes\");\n"
+ arg_conv = arg_conv + consts.get_native_arr_contents(arr_name, arr_name + "_ref." + ty_info.arr_access, arr_name + "_ref." + arr_len, ty_info, True) + ";"
+ else:
+ arg_conv = arg_conv + arr_name + "_ref." + ty_info.arr_access + " = " + consts.get_native_arr_contents(arr_name, "NO_DEST", arr_name + "_ref." + arr_len, ty_info, False) + ";"
+ arg_conv_cleanup = consts.cleanup_native_arr_ref_contents(arr_name, arr_name + "_ref." + ty_info.arr_access, arr_name + "_ref." + arr_len, ty_info)
+ if ty_info.rust_obj == "LDKTransaction":
+ arg_conv = arg_conv + "\n" + arr_name + "_ref.data_is_owned = " + str(holds_ref).lower() + ";"
+ ret_conv = (ty_info.rust_obj + " " + arr_name + "_var = ", "")
+ ret_conv = (ret_conv[0], ";\nint8_tArray " + arr_name + "_arr = " + consts.create_native_arr_call(arr_name + "_var." + arr_len, ty_info) + ";\n")
+ (pfx, sfx) = consts.set_native_arr_contents(arr_name + "_arr", arr_name + "_var." + arr_len, ty_info)
+ 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);")
+ elif ty_info.rust_obj is not None:
+ arg_conv = ty_info.rust_obj + " " + arr_name + "_ref;\n"
+ arg_conv = arg_conv + "CHECK(" + consts.get_native_arr_len_call[0] + arr_name + consts.get_native_arr_len_call[1] + " == " + arr_len + ");\n"
+ arg_conv = arg_conv + 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 + ";")
+ else:
+ arg_conv = "unsigned char " + arr_name + "_arr[" + arr_len + "];\n"
+ arg_conv = arg_conv + "CHECK(" + consts.get_native_arr_len_call[0] + arr_name + consts.get_native_arr_len_call[1] + " == " + arr_len + ");\n"
+ arg_conv = arg_conv + 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 + ";")
+ return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
+ arg_conv = arg_conv, arg_conv_name = arr_name + "_ref", arg_conv_cleanup = arg_conv_cleanup,
+ ret_conv = ret_conv, ret_conv_name = arr_name + "_arr", to_hu_conv = None, to_hu_conv_name = None, from_hu_conv = None)
+ else:
+ assert not arr_len.isdigit() # fixed length arrays not implemented
+ assert ty_info.java_ty[len(ty_info.java_ty) - 2:] == "[]"
+ conv_name = "arr_conv_" + str(len(ty_info.java_hu_ty))
+ idxc = chr(ord('a') + (len(ty_info.java_hu_ty) % 26))
+ ty_info.subty.var_name = conv_name
+ #XXX: We'd really prefer to only ever set to False, avoiding lots of clone, but need smarter free logic
+ #if ty_info.is_ptr or holds_ref:
+ # ty_info.subty.requires_clone = False
+ ty_info.subty.requires_clone = not ty_info.is_ptr or not holds_ref
+ subty = map_type_with_info(ty_info.subty, False, None, is_free, holds_ref)
+ if arr_name == "":
+ arr_name = "arg"
+ arg_conv = ty_info.rust_obj + " " + arr_name + "_constr;\n"
+ arg_conv = arg_conv + arr_name + "_constr." + arr_len + " = " + consts.get_native_arr_len_call[0] + arr_name + consts.get_native_arr_len_call[1] + ";\n"
+ arg_conv = arg_conv + "if (" + arr_name + "_constr." + arr_len + " > 0)\n"
+ if subty.rust_obj is None:
+ szof = subty.c_ty
+ else:
+ szof = subty.rust_obj
+ arg_conv = arg_conv + "\t" + arr_name + "_constr." + ty_info.arr_access + " = MALLOC(" + arr_name + "_constr." + arr_len + " * sizeof(" + szof + "), \"" + ty_info.rust_obj + " Elements\");\n"
+ arg_conv = arg_conv + "else\n"
+ arg_conv = arg_conv + "\t" + arr_name + "_constr." + ty_info.arr_access + " = NULL;\n"
+ get_arr = consts.get_native_arr_contents(arr_name, "NO_DEST", arr_name + "_constr." + arr_len, ty_info, False)
+ if get_arr != None:
+ arg_conv = arg_conv + subty.c_ty + "* " + arr_name + "_vals = " + get_arr + ";\n"
+ arg_conv = arg_conv + "for (size_t " + idxc + " = 0; " + idxc + " < " + arr_name + "_constr." + arr_len + "; " + idxc + "++) {\n"
+ if get_arr != None:
+ arg_conv = arg_conv + "\t" + subty.c_ty + " " + conv_name + " = " + arr_name + "_vals[" + idxc + "];"
+ if subty.arg_conv is not None:
+ arg_conv = arg_conv + "\n\t" + subty.arg_conv.replace("\n", "\n\t")
+ else:
+ arg_conv = arg_conv + "\t" + subty.c_ty + " " + conv_name + " = " + consts.get_native_arr_elem(arr_name, idxc, ty_info) + ";\n"
+ arg_conv = arg_conv + "\t" + subty.arg_conv.replace("\n", "\n\t")
+ arg_conv = arg_conv + "\n\t" + arr_name + "_constr." + ty_info.arr_access + "[" + idxc + "] = " + subty.arg_conv_name + ";\n}"
+ if get_arr != None:
+ cleanup = consts.cleanup_native_arr_ref_contents(arr_name, arr_name + "_vals", arr_name + "_constr." + arr_len, ty_info)
+ if cleanup is not None:
+ arg_conv = arg_conv + "\n" + cleanup + ";"
+ if ty_info.is_ptr:
+ arg_conv_name = "&" + arr_name + "_constr"
+ else:
+ arg_conv_name = arr_name + "_constr"
+ arg_conv_cleanup = None
+ if ty_info.is_ptr:
+ arg_conv_cleanup = "FREE(" + arr_name + "_constr." + ty_info.arr_access + ");"