Skip to content

Commit 6f9c9c2

Browse files
committed
Fix MSVC
1 parent ba68019 commit 6f9c9c2

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/libpanic_unwind/seh.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949

5050
use alloc::boxed::Box;
5151
use core::any::Any;
52-
use core::mem;
52+
use core::mem::{self, ManuallyDrop};
5353
use libc::{c_int, c_uint, c_void};
5454

5555
struct Exception {
@@ -264,7 +264,11 @@ pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
264264
// _CxxThrowException executes entirely on this stack frame, so there's no
265265
// need to otherwise transfer `data` to the heap. We just pass a stack
266266
// pointer to this function.
267-
let mut exception = Exception { data: Some(data) };
267+
//
268+
// The ManuallyDrop is needed here since we don't want Exception to be
269+
// dropped when unwinding. Instead it will be dropped by exception_cleanup
270+
// which is invoked by the C++ runtime.
271+
let mut exception = ManuallyDrop::new(Exception { data: Some(data) });
268272
let throw_ptr = &mut exception as *mut _ as *mut _;
269273

270274
// This... may seems surprising, and justifiably so. On 32-bit MSVC the

0 commit comments

Comments
 (0)