@@ -295,7 +295,10 @@ def _do_map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, hold
295
295
ty_info .var_name = "ret"
296
296
297
297
if ty_info .rust_obj in self .opaque_structs :
298
- from_hu_conv = (ty_info .var_name + " == null ? " + self .consts .native_zero_ptr + " : " + self .consts .get_ptr (ty_info .var_name ), self .consts .add_ref ("this" , ty_info .var_name ))
298
+ if is_nullable :
299
+ from_hu_conv = (ty_info .var_name + " == null ? " + self .consts .native_zero_ptr + " : " + self .consts .get_ptr (ty_info .var_name ), self .consts .add_ref ("this" , ty_info .var_name ))
300
+ else :
301
+ from_hu_conv = (self .consts .get_ptr (ty_info .var_name ), self .consts .add_ref ("this" , ty_info .var_name ))
299
302
opaque_arg_conv = ty_info .rust_obj + " " + ty_info .var_name + "_conv;\n "
300
303
opaque_arg_conv = opaque_arg_conv + ty_info .var_name + "_conv.inner = untag_ptr(" + ty_info .var_name + ");\n "
301
304
opaque_arg_conv += ty_info .var_name + "_conv.is_owned = ptr_is_owned(" + ty_info .var_name + ");\n "
@@ -310,8 +313,10 @@ def _do_map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, hold
310
313
# whereas in the first we prefer to clone in C to avoid additional Java code as much as possible.
311
314
if holds_ref :
312
315
opaque_arg_conv += "\n " + ty_info .var_name + "_conv = " + ty_info .rust_obj .replace ("LDK" , "" ) + "_clone(&" + ty_info .var_name + "_conv);"
313
- else :
316
+ elif is_nullable :
314
317
from_hu_conv = (ty_info .var_name + " == null ? " + self .consts .native_zero_ptr + " : " + ty_info .var_name + ".clone_ptr()" , "" )
318
+ else :
319
+ from_hu_conv = (ty_info .var_name + ".clone_ptr()" , "" )
315
320
elif ty_info .passed_as_ptr :
316
321
opaque_arg_conv += "\n // WARNING: we need a move here but no clone is available for " + ty_info .rust_obj + "\n "
317
322
# TODO: Once we support features cloning (which just isn't in C yet), we can make this a compile error instead!
@@ -421,7 +426,7 @@ def _do_map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, hold
421
426
if holds_ref :
422
427
base_conv += "\n " + ty_info .var_name + "_conv = " + ty_info .rust_obj .replace ("LDK" , "" ) + "_clone((" + ty_info .rust_obj + "*)untag_ptr(" + ty_info .var_name + "));"
423
428
else :
424
- from_hu_conv = (ty_info .var_name + " == null ? " + self . consts . native_zero_ptr + " : " + ty_info . var_name + " .clone_ptr()" , "" )
429
+ from_hu_conv = (ty_info .var_name + ".clone_ptr()" , "" )
425
430
base_conv += "\n " + "FREE(untag_ptr(" + ty_info .var_name + "));"
426
431
elif needs_full_clone :
427
432
base_conv = base_conv + "\n // WARNING: we may need a move here but no clone is available for " + ty_info .rust_obj
@@ -467,7 +472,7 @@ def _do_map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, hold
467
472
else :
468
473
ret_conv = (ty_info .rust_obj + "* " + ty_info .var_name + "_conv = MALLOC(sizeof(" + ty_info .rust_obj + "), \" " + ty_info .rust_obj + "\" );\n *" + ty_info .var_name + "_conv = " , ";" )
469
474
if from_hu_conv is None :
470
- from_hu_conv = (ty_info . var_name + " != null ? " + self .consts .get_ptr (ty_info .var_name ) + " : " + self . consts . native_zero_ptr , "" )
475
+ from_hu_conv = (self .consts .get_ptr (ty_info .var_name ), "" )
471
476
return ConvInfo (ty_info = ty_info , arg_name = ty_info .var_name ,
472
477
arg_conv = base_conv , arg_conv_name = ty_info .var_name + "_conv" , arg_conv_cleanup = None ,
473
478
ret_conv = ret_conv , ret_conv_name = "tag_ptr(" + ty_info .var_name + "_conv, true)" ,
@@ -493,7 +498,7 @@ def _do_map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, hold
493
498
else :
494
499
to_hu_conv_sfx = ""
495
500
if from_hu_conv is None :
496
- from_hu_conv = (ty_info . var_name + " != null ? " + self .consts .get_ptr (ty_info .var_name ) + " : " + self . consts . native_zero_ptr , "" )
501
+ from_hu_conv = (self .consts .get_ptr (ty_info .var_name ), "" )
497
502
return ConvInfo (ty_info = ty_info , arg_name = ty_info .var_name ,
498
503
arg_conv = base_conv , arg_conv_name = ty_info .var_name + "_conv" , arg_conv_cleanup = None ,
499
504
ret_conv = ret_conv , ret_conv_name = ret_conv_name ,
@@ -546,7 +551,7 @@ def _do_map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, hold
546
551
ret_conv = ret_conv , ret_conv_name = "ref_" + ty_info .var_name ,
547
552
to_hu_conv = self .consts .var_decl_statement (ty_info .java_hu_ty , ty_info .var_name + "_hu_conv" , ty_info .java_hu_ty + ".constr_from_ptr(" + ty_info .var_name + ")" ) + ";" ,
548
553
to_hu_conv_name = ty_info .var_name + "_hu_conv" ,
549
- from_hu_conv = (ty_info . var_name + " == null ? " + self . consts . native_zero_ptr + " : " + self .consts .get_ptr (ty_info .var_name ), from_hu_sfx ))
554
+ from_hu_conv = (self .consts .get_ptr (ty_info .var_name ), from_hu_sfx ))
550
555
elif ty_info .rust_obj in self .trait_structs :
551
556
if ty_info .nonnull_ptr :
552
557
arg_conv = "void* " + ty_info .var_name + "_ptr = untag_ptr(" + ty_info .var_name + ");\n "
@@ -568,7 +573,7 @@ def _do_map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, hold
568
573
arg_conv += "\t *" + ty_info .var_name + "_conv_ptr = " + ty_info .var_name + "_conv;\n "
569
574
arg_conv += "}"
570
575
arg_conv_name = ty_info .var_name + "_conv_ptr"
571
- from_hu_conv_pfx = ty_info . var_name + " == null ? " + self . consts . native_zero_ptr + " : " + self .consts .get_ptr (ty_info .var_name )
576
+ from_hu_conv_pfx = self .consts .get_ptr (ty_info .var_name )
572
577
if ty_info .rust_obj .replace ("LDK" , "" ) + "_clone" in self .clone_fns :
573
578
return ConvInfo (ty_info = ty_info , arg_name = ty_info .var_name ,
574
579
arg_conv = arg_conv , arg_conv_name = arg_conv_name , arg_conv_cleanup = None ,
0 commit comments