Skip to content

Commit e895321

Browse files
committed
Handle uintptr_ts better in JNI bindings
This fixes bugs building for 32-bit platforms as the JNI functions would expect `uintptr_t`s (32-bit) but Java expects a long (64-bit). We can't just replace them all with int64_ts as we need to have `uintptr_t`s still in _jcalls functions which we pass function pointers to C.
1 parent 0165af9 commit e895321

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

gen_type_mapping.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, holds_re
7777
#if ty_info.is_ptr or holds_ref:
7878
# ty_info.subty.requires_clone = False
7979
ty_info.subty.requires_clone = not ty_info.is_ptr or not holds_ref
80-
if ty_info.subty.rust_obj is not None and ty_info.subty.rust_obj == "LDKChannelMonitor":
80+
if not ty_info.subty.is_native_primitive and ty_info.subty.rust_obj == "LDKChannelMonitor":
8181
# We take a Vec of references to ChannelMonitors as input to ChannelManagerReadArgs, if we clone them,
8282
# we end up freeing the clones after creating the ChannelManagerReadArgs before calling the read
8383
# function itself, resulting in a segfault. Thus, we manually check and ensure we don't clone for
@@ -89,7 +89,7 @@ def map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, holds_re
8989
arg_conv = ty_info.rust_obj + " " + arr_name + "_constr;\n"
9090
arg_conv = arg_conv + arr_name + "_constr." + arr_len + " = " + self.consts.get_native_arr_len_call[0] + arr_name + self.consts.get_native_arr_len_call[1] + ";\n"
9191
arg_conv = arg_conv + "if (" + arr_name + "_constr." + arr_len + " > 0)\n"
92-
if subty.rust_obj is None:
92+
if subty.is_native_primitive:
9393
szof = subty.c_ty
9494
else:
9595
szof = subty.rust_obj
@@ -186,7 +186,7 @@ def map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, holds_re
186186
ret_conv_name = ty_info.var_name + "_conv", to_hu_conv = None, to_hu_conv_name = None, from_hu_conv = None)
187187
elif ty_info.var_name == "" and not print_void:
188188
# We don't have a parameter name, and want one, just call it arg
189-
if ty_info.rust_obj is not None:
189+
if not ty_info.is_native_primitive:
190190
assert(not is_free or ty_info.rust_obj not in self.opaque_structs)
191191
return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
192192
arg_conv = ty_info.rust_obj + " arg_conv = *(" + ty_info.rust_obj + "*)arg;\nFREE((void*)arg);",
@@ -197,7 +197,7 @@ def map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, holds_re
197197
return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
198198
arg_conv = None, arg_conv_name = "arg", arg_conv_cleanup = None,
199199
ret_conv = None, ret_conv_name = None, to_hu_conv = "TODO 8", to_hu_conv_name = None, from_hu_conv = None)
200-
elif ty_info.rust_obj is None:
200+
elif ty_info.is_native_primitive:
201201
return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
202202
arg_conv = None, arg_conv_name = ty_info.var_name, arg_conv_cleanup = None,
203203
ret_conv = None, ret_conv_name = None, to_hu_conv = None, to_hu_conv_name = None, from_hu_conv = None)

genbindings.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,8 @@ def java_c_types(fn_arg, ret_arr_len):
225225
c_ty = "int64_t"
226226
fn_arg = fn_arg[8:].strip()
227227
else:
228-
c_ty = "intptr_t"
228+
c_ty = "int64_t"
229+
rust_obj = "uintptr_t"
229230
fn_arg = fn_arg[9:].strip()
230231
is_primitive = True
231232
elif is_const and fn_arg.startswith("char *"):
@@ -307,7 +308,6 @@ def java_c_types(fn_arg, ret_arr_len):
307308
c_ty = consts.ptr_c_ty
308309
java_ty = consts.ptr_native_ty
309310
fn_ty_arg = "J"
310-
is_primitive = False
311311

312312
var_is_arr = var_is_arr_regex.match(fn_arg)
313313
if var_is_arr is not None or ret_arr_len is not None:
@@ -348,7 +348,7 @@ def java_c_types(fn_arg, ret_arr_len):
348348
clone_fns.add(reg_fn.group(2))
349349
else:
350350
rty = java_c_types(reg_fn.group(1), None)
351-
if rty is not None and rty.rust_obj is not None and reg_fn.group(2) == rty.java_hu_ty + "_new":
351+
if rty is not None and not rty.is_native_primitive and reg_fn.group(2) == rty.java_hu_ty + "_new":
352352
constructor_fns[rty.rust_obj] = reg_fn.group(3)
353353
continue
354354
arr_fn = fn_ret_arr_regex.match(line)

0 commit comments

Comments
 (0)