Skip to content

Commit d2b1ddd

Browse files
committed
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).
1 parent 9aa1eeb commit d2b1ddd

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

gen_type_mapping.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,19 @@ def _do_map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, hold
260260
return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
261261
arg_conv = None, arg_conv_name = "arg", arg_conv_cleanup = None,
262262
ret_conv = None, ret_conv_name = None, to_hu_conv = "TODO 8", to_hu_conv_name = None, from_hu_conv = None)
263-
elif ty_info.is_native_primitive:
263+
elif ty_info.is_native_primitive and ty_info.c_ty != "void":
264264
assert not is_nullable
265265
return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
266-
arg_conv = None, arg_conv_name = ty_info.var_name, arg_conv_cleanup = None,
267-
ret_conv = None, ret_conv_name = None, to_hu_conv = None, to_hu_conv_name = None, from_hu_conv = None)
266+
arg_conv = None, arg_conv_name = ty_info.var_name, arg_conv_cleanup = None,
267+
ret_conv = (ty_info.c_ty + " " + ty_info.var_name + "_conv = ", ";"), ret_conv_name = ty_info.var_name + "_conv",
268+
to_hu_conv = None, to_hu_conv_name = None, from_hu_conv = None)
269+
elif ty_info.c_ty == "void":
270+
assert ty_info.is_native_primitive
271+
assert not is_nullable
272+
return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
273+
arg_conv = None, arg_conv_name = ty_info.var_name, arg_conv_cleanup = None,
274+
ret_conv = None, ret_conv_name = ty_info.var_name,
275+
to_hu_conv = None, to_hu_conv_name = None, from_hu_conv = None)
268276
else:
269277
if ty_info.var_name == "":
270278
ty_info.var_name = "ret"

0 commit comments

Comments
 (0)