- var_is_arr = var_is_arr_regex.match(fn_arg)
- if var_is_arr is not None or ret_arr_len is not None:
- assert(not take_by_ptr)
- assert(not is_ptr)
- java_ty = java_ty + "[]"
- c_ty = c_ty + "Array"
- if var_is_arr is not None:
- return TypeInfo(rust_obj=None, java_ty=java_ty, java_fn_ty_arg="[" + fn_ty_arg, c_ty=c_ty,
- passed_as_ptr=False, is_ptr=False, var_name=var_is_arr.group(1), arr_len=var_is_arr.group(2))
- return TypeInfo(rust_obj=rust_obj, java_ty=java_ty, java_fn_ty_arg=fn_ty_arg, c_ty=c_ty, passed_as_ptr=is_ptr or take_by_ptr,
- is_ptr=is_ptr, var_name=fn_arg, arr_len=None)
-
- def map_type(fn_arg, print_void, ret_arr_len, is_free):
- ty_info = java_c_types(fn_arg, ret_arr_len)
-
- if ty_info.c_ty == "void":
- if not print_void:
- return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
- arg_conv = None, arg_conv_name = None, ret_conv = None, ret_conv_name = None)
-
- if ty_info.c_ty.endswith("Array"):
- arr_len = ty_info.arr_len
- if arr_len is not None:
- arr_name = ty_info.var_name
- else:
- arr_name = "ret"
- arr_len = ret_arr_len
- 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)
-
- 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)
- else:
- assert(not is_free)
- 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 + "*)" + ty_info.var_name + ";",
- arg_conv_name = ty_info.var_name + "_conv",
- ret_conv = None, ret_conv_name = None)
- elif ty_info.is_ptr:
- return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
- arg_conv = None, arg_conv_name = ty_info.var_name, ret_conv = None, ret_conv_name = None)
- elif ty_info.java_ty == "String":
- return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
- arg_conv = None, arg_conv_name = None,
- ret_conv = ("jstring " + ty_info.var_name + "_conv = (*_env)->NewStringUTF(_env, ", ");"), ret_conv_name = ty_info.var_name + "_conv")
- else:
- return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
- arg_conv = None, arg_conv_name = ty_info.var_name, ret_conv = None, ret_conv_name = None)
- elif not print_void:
- # We don't have a parameter name, and want one, just call it arg
- if ty_info.rust_obj is not None:
- assert(not is_free or ty_info.rust_obj not in opaque_structs);
- return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
- arg_conv = ty_info.rust_obj + " arg_conv = *(" + ty_info.rust_obj + "*)arg;\nFREE((void*)arg);",
- arg_conv_name = "arg_conv",
- ret_conv = None, ret_conv_name = None)
- else:
- assert(not is_free)
- return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
- arg_conv = None, arg_conv_name = "arg", ret_conv = None, ret_conv_name = None)
+ tyn = fn_arg[8:].split(" ")
+ assert tyn[0].endswith("Z")
+ if tyn[0] == "u64Z":
+ new_arg = "uint64_t"
+ else:
+ new_arg = "LDK" + tyn[0][:-1]
+ for a in tyn[1:]:
+ new_arg = new_arg + " " + a
+ res = java_c_types(new_arg, ret_arr_len)
+ if res is None:
+ assert java_c_types_none_allowed
+ return None
+ if is_ptr:
+ res.pass_by_ref = True
+ if res.is_native_primitive or res.passed_as_ptr:
+ return TypeInfo(rust_obj=fn_arg.split(" ")[0], java_ty=res.java_ty + "[]", java_hu_ty=res.java_hu_ty + "[]",
+ java_fn_ty_arg="[" + res.java_fn_ty_arg, c_ty=res.c_ty + "Array", passed_as_ptr=False, is_ptr=is_ptr, is_const=is_const,
+ var_name=res.var_name, arr_len="datalen", arr_access="data", subty=res, is_native_primitive=False)
+ else:
+ return TypeInfo(rust_obj=fn_arg.split(" ")[0], java_ty=res.java_ty + "[]", java_hu_ty=res.java_hu_ty + "[]",
+ java_fn_ty_arg="[" + res.java_fn_ty_arg, c_ty=consts.ptr_arr, passed_as_ptr=False, is_ptr=is_ptr, is_const=is_const,
+ var_name=res.var_name, arr_len="datalen", arr_access="data", subty=res, is_native_primitive=False)
+
+ is_primitive = False
+ arr_len = None
+ mapped_type = []
+ java_type_plural = None
+ if fn_arg.startswith("void"):
+ java_ty = "void"
+ c_ty = "void"
+ fn_ty_arg = "V"
+ fn_arg = fn_arg[4:].strip()
+ is_primitive = True
+ elif fn_arg.startswith("bool"):
+ java_ty = "boolean"
+ c_ty = "jboolean"
+ fn_ty_arg = "Z"
+ fn_arg = fn_arg[4:].strip()
+ is_primitive = True
+ elif fn_arg.startswith("uint8_t"):
+ mapped_type = consts.c_type_map['uint8_t']
+ java_ty = mapped_type[0]
+ c_ty = "int8_t"
+ fn_ty_arg = "B"
+ fn_arg = fn_arg[7:].strip()
+ is_primitive = True
+ elif fn_arg.startswith("uint16_t"):
+ mapped_type = consts.c_type_map['uint16_t']
+ java_ty = mapped_type[0]
+ c_ty = "int16_t"
+ fn_ty_arg = "S"
+ fn_arg = fn_arg[8:].strip()
+ is_primitive = True
+ elif fn_arg.startswith("uint32_t"):
+ mapped_type = consts.c_type_map['uint32_t']
+ java_ty = mapped_type[0]
+ c_ty = "int32_t"
+ fn_ty_arg = "I"
+ fn_arg = fn_arg[8:].strip()
+ is_primitive = True
+ elif fn_arg.startswith("uint64_t") or fn_arg.startswith("uintptr_t"):
+ # TODO: uintptr_t is arch-dependent :(
+ mapped_type = consts.c_type_map['uint64_t']
+ java_ty = mapped_type[0]
+ fn_ty_arg = "J"
+ if fn_arg.startswith("uint64_t"):
+ c_ty = "int64_t"
+ fn_arg = fn_arg[8:].strip()