@@ -351,10 +351,10 @@ fn writeln_trait<'a, 'b, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, ty
351
351
// the Rust type and a flag to indicate whether deallocation needs to
352
352
// happen) as well as provide an Option<>al function pointer which is
353
353
// called when the trait method is called which allows updating on the fly.
354
- write ! ( w, "\t pub {}: " , m. sig. ident) . unwrap ( ) ;
355
- generated_fields. push ( ( format ! ( "{}" , m. sig. ident) , None , None ) ) ;
354
+ write ! ( w, "\t pub {}: core::cell::UnsafeCell< " , m. sig. ident) . unwrap ( ) ;
355
+ generated_fields. push ( ( format ! ( "{}" , m. sig. ident) , Some ( ( "Clone::clone(unsafe { &*core::cell::UnsafeCell::get(" . to_owned ( ) , ")}).into()" ) ) , None ) ) ;
356
356
types. write_c_type ( w, & * r. elem , Some ( & meth_gen_types) , false ) ;
357
- writeln ! ( w, "," ) . unwrap ( ) ;
357
+ writeln ! ( w, "> ," ) . unwrap ( ) ;
358
358
writeln ! ( w, "\t /// Fill in the {} field as a reference to it will be given to Rust after this returns" , m. sig. ident) . unwrap ( ) ;
359
359
writeln ! ( w, "\t /// Note that this takes a pointer to this object, not the this_ptr like other methods do" ) . unwrap ( ) ;
360
360
writeln ! ( w, "\t /// This function pointer may be NULL if {} is filled in when this object is created and never needs updating." , m. sig. ident) . unwrap ( ) ;
@@ -430,7 +430,7 @@ fn writeln_trait<'a, 'b, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, ty
430
430
let is_clonable = types. is_clonable( s) ;
431
431
writeln!( w, "\t pub {}: crate::{}," , i, s) . unwrap( ) ;
432
432
( format!( "{}" , i) , if !is_clonable {
433
- Some ( format!( "crate::{}_clone_fields" , s) )
433
+ Some ( ( format!( "crate::{}_clone_fields( " , s) , ")" ) )
434
434
} else { None } , None )
435
435
} ) ;
436
436
}
@@ -513,7 +513,7 @@ fn writeln_trait<'a, 'b, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, ty
513
513
writeln!( w, "\t \t \t (f)(&self{});" , $impl_accessor) . unwrap( ) ;
514
514
write!( w, "\t \t }}\n \t \t " ) . unwrap( ) ;
515
515
$type_resolver. write_from_c_conversion_to_ref_prefix( w, & * r. elem, Some ( & meth_gen_types) ) ;
516
- write!( w, "self{}.{}" , $impl_accessor, m. sig. ident) . unwrap( ) ;
516
+ write!( w, "unsafe {{ &* self{}.{}.get() } }" , $impl_accessor, m. sig. ident) . unwrap( ) ;
517
517
$type_resolver. write_from_c_conversion_to_ref_suffix( w, & * r. elem, Some ( & meth_gen_types) ) ;
518
518
writeln!( w, "\n \t }}" ) . unwrap( ) ;
519
519
continue ;
@@ -557,9 +557,9 @@ fn writeln_trait<'a, 'b, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, ty
557
557
writeln ! ( w, "\t {} {{" , trait_name) . unwrap ( ) ;
558
558
writeln ! ( w, "\t \t this_arg: orig.this_arg," ) . unwrap ( ) ;
559
559
for ( field, clone_fn, _) in generated_fields. iter ( ) {
560
- if let Some ( f ) = clone_fn {
560
+ if let Some ( ( pfx , sfx ) ) = clone_fn {
561
561
// If the field isn't clonable, blindly assume its a trait and hope for the best.
562
- writeln ! ( w, "\t \t {}: {}( &orig.{}) ," , field, f , field) . unwrap ( ) ;
562
+ writeln ! ( w, "\t \t {}: {}&orig.{}{} ," , field, pfx , field, sfx ) . unwrap ( ) ;
563
563
} else {
564
564
writeln ! ( w, "\t \t {}: Clone::clone(&orig.{})," , field, field) . unwrap ( ) ;
565
565
}
@@ -1046,7 +1046,7 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, w_uses: &mut HashSet<String, NonRa
1046
1046
if let syn:: Type :: Reference ( r) = & * * rtype {
1047
1047
write!( w, "\n \t \t {}{}: " , $indent, $m. sig. ident) . unwrap( ) ;
1048
1048
types. write_empty_rust_val( Some ( & gen_types) , w, & * r. elem) ;
1049
- writeln!( w, ",\n {}\t \t set_{}: Some({}_{}_set_{})," , $indent, $m. sig. ident, ident, $trait. ident, $m. sig. ident) . unwrap( ) ;
1049
+ writeln!( w, ".into() ,\n {}\t \t set_{}: Some({}_{}_set_{})," , $indent, $m. sig. ident, ident, $trait. ident, $m. sig. ident) . unwrap( ) ;
1050
1050
printed = true ;
1051
1051
}
1052
1052
}
@@ -1198,9 +1198,9 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, w_uses: &mut HashSet<String, NonRa
1198
1198
writeln!( w, "\t // This is a bit race-y in the general case, but for our specific use-cases today, we're safe" ) . unwrap( ) ;
1199
1199
writeln!( w, "\t // Specifically, we must ensure that the first time we're called it can never be in parallel" ) . unwrap( ) ;
1200
1200
write!( w, "\t if " ) . unwrap( ) ;
1201
- $types. write_empty_rust_val_check( Some ( & meth_gen_types) , w, & * r. elem, & format!( "trait_self_arg.{}" , $m. sig. ident) ) ;
1201
+ $types. write_empty_rust_val_check( Some ( & meth_gen_types) , w, & * r. elem, & format!( "unsafe {{ &* trait_self_arg.{}.get() } }" , $m. sig. ident) ) ;
1202
1202
writeln!( w, " {{" ) . unwrap( ) ;
1203
- writeln!( w, "\t \t unsafe {{ &mut *(trait_self_arg as *const {} as *mut {} ) }}.{} = {}_{}_{}(trait_self_arg.this_arg);" , $trait . ident , $trait. ident, $m. sig. ident, ident, $trait. ident, $m. sig. ident) . unwrap( ) ;
1203
+ writeln!( w, "\t \t *unsafe {{ &mut *(&*( trait_self_arg as *const {})).{}.get( ) }} = {}_{}_{}(trait_self_arg.this_arg).into();" , $trait. ident, $m. sig. ident, ident, $trait. ident, $m. sig. ident) . unwrap( ) ;
1204
1204
writeln!( w, "\t }}" ) . unwrap( ) ;
1205
1205
writeln!( w, "}}" ) . unwrap( ) ;
1206
1206
}
0 commit comments