From: Matt Corallo Date: Fri, 15 Apr 2022 16:11:46 +0000 (+0000) Subject: Convert primitives before passing to host language X-Git-Tag: v0.0.106.0^2~3 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=d2b1ddd1a3bc8f3d91cb931b4e08b35c946a4af8;p=ldk-java Convert primitives before passing to host language This resolves an issue where we map unsigned primitives to their signed variants, and occasionally pass the unsigned variant (which is outside the bounds of the signed variant) to the host language. In Java this can cause a panic as the VM sees an int outside the range of a short (for example with network ports). --- diff --git a/gen_type_mapping.py b/gen_type_mapping.py index ad7d46fc..9aeee615 100644 --- a/gen_type_mapping.py +++ b/gen_type_mapping.py @@ -260,11 +260,19 @@ class TypeMappingGenerator: return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name, arg_conv = None, arg_conv_name = "arg", arg_conv_cleanup = None, ret_conv = None, ret_conv_name = None, to_hu_conv = "TODO 8", to_hu_conv_name = None, from_hu_conv = None) - elif ty_info.is_native_primitive: + elif ty_info.is_native_primitive and ty_info.c_ty != "void": assert not is_nullable return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name, - arg_conv = None, arg_conv_name = ty_info.var_name, arg_conv_cleanup = None, - ret_conv = None, ret_conv_name = None, to_hu_conv = None, to_hu_conv_name = None, from_hu_conv = None) + arg_conv = None, arg_conv_name = ty_info.var_name, arg_conv_cleanup = None, + ret_conv = (ty_info.c_ty + " " + ty_info.var_name + "_conv = ", ";"), ret_conv_name = ty_info.var_name + "_conv", + to_hu_conv = None, to_hu_conv_name = None, from_hu_conv = None) + elif ty_info.c_ty == "void": + assert ty_info.is_native_primitive + assert not is_nullable + return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name, + arg_conv = None, arg_conv_name = ty_info.var_name, arg_conv_cleanup = None, + ret_conv = None, ret_conv_name = ty_info.var_name, + to_hu_conv = None, to_hu_conv_name = None, from_hu_conv = None) else: if ty_info.var_name == "": ty_info.var_name = "ret"