@@ -282,7 +282,7 @@ def _do_map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, hold
282282 ty_info .var_name = "ret"
283283
284284 if ty_info .rust_obj in self .opaque_structs :
285- from_hu_conv = (ty_info .var_name + " == null ? 0 : " + self .consts .get_ptr (ty_info .var_name ), self .consts .add_ref ("this" , ty_info .var_name ))
285+ 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 ))
286286 opaque_arg_conv = ty_info .rust_obj + " " + ty_info .var_name + "_conv;\n "
287287 opaque_arg_conv = opaque_arg_conv + ty_info .var_name + "_conv.inner = untag_ptr(" + ty_info .var_name + ");\n "
288288 opaque_arg_conv += ty_info .var_name + "_conv.is_owned = ptr_is_owned(" + ty_info .var_name + ");\n "
@@ -298,7 +298,7 @@ def _do_map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, hold
298298 if holds_ref :
299299 opaque_arg_conv += "\n " + ty_info .var_name + "_conv = " + ty_info .rust_obj .replace ("LDK" , "" ) + "_clone(&" + ty_info .var_name + "_conv);"
300300 else :
301- from_hu_conv = (ty_info .var_name + " == null ? 0 : " + ty_info .var_name + ".clone_ptr()" , "" )
301+ from_hu_conv = (ty_info .var_name + " == null ? " + self . consts . native_zero_ptr + " : " + ty_info .var_name + ".clone_ptr()" , "" )
302302 elif ty_info .passed_as_ptr :
303303 opaque_arg_conv += "\n // WARNING: we need a move here but no clone is available for " + ty_info .rust_obj + "\n "
304304 # TODO: Once we support features cloning (which just isn't in C yet), we can make this a compile error instead!
@@ -380,7 +380,7 @@ def _do_map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, hold
380380 if holds_ref :
381381 base_conv += "\n " + ty_info .var_name + "_conv = " + ty_info .rust_obj .replace ("LDK" , "" ) + "_clone(&" + ty_info .var_name + "_conv);"
382382 else :
383- from_hu_conv = (ty_info .var_name + " == null ? 0 : " + ty_info .var_name + ".clone_ptr()" , "" )
383+ from_hu_conv = (ty_info .var_name + " == null ? " + self . consts . native_zero_ptr + " : " + ty_info .var_name + ".clone_ptr()" , "" )
384384 base_conv += "\n " + "FREE(untag_ptr(" + ty_info .var_name + "));"
385385 else :
386386 base_conv = base_conv + self .consts .trait_struct_inc_refcnt (ty_info )
@@ -389,7 +389,7 @@ def _do_map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, hold
389389 else :
390390 base_conv = base_conv + "\n " + "FREE(untag_ptr(" + ty_info .var_name + "));"
391391 if from_hu_conv is None :
392- from_hu_conv = (ty_info .var_name + " == null ? 0 : " + self .consts .get_ptr (ty_info .var_name ), "" )
392+ from_hu_conv = (ty_info .var_name + " == null ? " + self . consts . native_zero_ptr + " : " + self .consts .get_ptr (ty_info .var_name ), "" )
393393 from_hu_conv = (from_hu_conv [0 ], self .consts .add_ref ("this" , ty_info .var_name ))
394394 return ConvInfo (ty_info = ty_info , arg_name = ty_info .var_name ,
395395 arg_conv = base_conv , arg_conv_name = ty_info .var_name + "_conv" , arg_conv_cleanup = None ,
@@ -408,7 +408,7 @@ def _do_map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, hold
408408 if holds_ref :
409409 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 + "));"
410410 else :
411- from_hu_conv = (ty_info .var_name + " == null ? 0 : " + ty_info .var_name + ".clone_ptr()" , "" )
411+ from_hu_conv = (ty_info .var_name + " == null ? " + self . consts . native_zero_ptr + " : " + ty_info .var_name + ".clone_ptr()" , "" )
412412 base_conv += "\n " + "FREE(untag_ptr(" + ty_info .var_name + "));"
413413 elif needs_full_clone :
414414 base_conv = base_conv + "\n // WARNING: we may need a move here but no clone is available for " + ty_info .rust_obj
@@ -456,7 +456,7 @@ def _do_map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, hold
456456 else :
457457 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 = " , ";" )
458458 if from_hu_conv is None :
459- from_hu_conv = (ty_info .var_name + " != null ? " + self .consts .get_ptr (ty_info .var_name ) + " : 0" , "" )
459+ from_hu_conv = (ty_info .var_name + " != null ? " + self .consts .get_ptr (ty_info .var_name ) + " : " + self . consts . native_zero_ptr , "" )
460460 return ConvInfo (ty_info = ty_info , arg_name = ty_info .var_name ,
461461 arg_conv = base_conv , arg_conv_name = ty_info .var_name + "_conv" , arg_conv_cleanup = None ,
462462 ret_conv = ret_conv , ret_conv_name = "tag_ptr(" + ty_info .var_name + "_conv, true)" ,
@@ -482,7 +482,7 @@ def _do_map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, hold
482482 else :
483483 to_hu_conv_sfx = ""
484484 if from_hu_conv is None :
485- from_hu_conv = (ty_info .var_name + " != null ? " + self .consts .get_ptr (ty_info .var_name ) + " : 0" , "" )
485+ from_hu_conv = (ty_info .var_name + " != null ? " + self .consts .get_ptr (ty_info .var_name ) + " : " + self . consts . native_zero_ptr , "" )
486486 return ConvInfo (ty_info = ty_info , arg_name = ty_info .var_name ,
487487 arg_conv = base_conv , arg_conv_name = ty_info .var_name + "_conv" , arg_conv_cleanup = None ,
488488 ret_conv = ret_conv , ret_conv_name = ret_conv_name ,
@@ -535,7 +535,7 @@ def _do_map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, hold
535535 ret_conv = ret_conv , ret_conv_name = "ref_" + ty_info .var_name ,
536536 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 + ")" ) + ";" ,
537537 to_hu_conv_name = ty_info .var_name + "_hu_conv" ,
538- from_hu_conv = (ty_info .var_name + " == null ? 0 : " + self .consts .get_ptr (ty_info .var_name ), from_hu_sfx ))
538+ from_hu_conv = (ty_info .var_name + " == null ? " + self . consts . native_zero_ptr + " : " + self .consts .get_ptr (ty_info .var_name ), from_hu_sfx ))
539539 elif ty_info .rust_obj in self .trait_structs :
540540 if ty_info .nonnull_ptr :
541541 arg_conv = "void* " + ty_info .var_name + "_ptr = untag_ptr(" + ty_info .var_name + ");\n "
@@ -564,15 +564,15 @@ def _do_map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, hold
564564 ret_conv_name = "tag_ptr(" + ty_info .var_name + "_clone, true)" ,
565565 to_hu_conv = self .consts .var_decl_statement (ty_info .java_hu_ty , "ret_hu_conv" , "new " + ty_info .java_hu_ty + "(null, " + ty_info .var_name + ")" ) + ";\n " + self .consts .add_ref ("ret_hu_conv" , "this" ) + ";" ,
566566 to_hu_conv_name = "ret_hu_conv" ,
567- from_hu_conv = (ty_info .var_name + " == null ? 0 : " + self .consts .get_ptr (ty_info .var_name ), "" ))
567+ from_hu_conv = (ty_info .var_name + " == null ? " + self . consts . native_zero_ptr + " : " + self .consts .get_ptr (ty_info .var_name ), "" ))
568568 else :
569569 return ConvInfo (ty_info = ty_info , arg_name = ty_info .var_name ,
570570 arg_conv = arg_conv , arg_conv_name = arg_conv_name , arg_conv_cleanup = None ,
571571 ret_conv = ("// WARNING: This object doesn't live past this scope, needs clone!\n " + self .consts .ptr_c_ty + " ret_" + ty_info .var_name + " = tag_ptr(" , ", false);" ),
572572 ret_conv_name = "ret_" + ty_info .var_name ,
573573 to_hu_conv = self .consts .var_decl_statement (ty_info .java_hu_ty , "ret_hu_conv" , "new " + ty_info .java_hu_ty + "(null, " + ty_info .var_name + ")" ) + ";\n " + self .consts .add_ref ("ret_hu_conv" , "this" ) + ";" ,
574574 to_hu_conv_name = "ret_hu_conv" ,
575- from_hu_conv = (ty_info .var_name + " == null ? 0 : " + self .consts .get_ptr (ty_info .var_name ), self .consts .add_ref ("this" , ty_info .var_name )))
575+ 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 )))
576576 ret_conv = (self .consts .ptr_c_ty + " ret_" + ty_info .var_name + " = tag_ptr(" , ", true);" )
577577 if holds_ref :
578578 ret_conv = (ret_conv [0 ], ", false);" )
0 commit comments