Skip to content

Commit b8ad84c

Browse files
bors[bot]Waridley
andauthored
Merge #924
924: use ManuallyDrop in ptrcalls to prevent drop reordering r=Bromeon a=Waridley On rustc 1.65.0-nightly (29e4a9ee0 2022-08-10), drops of args in some ptrcalls are seemingly being reordered to before the FFI call. Using `ManuallyDrop` prevents this. This could potentially be related to #894, but I'm not confident enough to say it will definitely fix it yet. Co-authored-by: Waridley <[email protected]>
2 parents 4d94f4f + f0e9b52 commit b8ad84c

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

bindings-generator/src/methods.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,12 @@ mod ptrcall {
468468
.map(|(name, ty)| generate_argument_pre(ty, name));
469469
let return_pre = generate_return_pre(&sig.return_type);
470470

471+
let arg_forgets = arguments.clone().map(|(name, _)| {
472+
quote! { let #name = ::std::mem::ManuallyDrop::new(#name); }
473+
});
474+
471475
let arg_drops = arguments.clone().map(|(name, _)| {
472-
quote! { drop(#name); }
476+
quote! { ::std::mem::ManuallyDrop::into_inner(#name); }
473477
});
474478

475479
quote! {
@@ -479,6 +483,8 @@ mod ptrcall {
479483
#(#args),*
480484
];
481485

486+
#(#arg_forgets)*
487+
482488
#return_pre
483489

484490
(gd_api.godot_method_bind_ptrcall)(method_bind, obj_ptr, argument_buffer.as_mut_ptr() as *mut _, ret_ptr as *mut _);

0 commit comments

Comments
 (0)