Created
October 16, 2016 05:42
-
-
Save retep998/b9689de1e810ea40ec61ad0e6fb57a02 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
struct Bar { | |
~Bar() { | |
cout << "C++ destructor is firing" << endl; | |
} | |
}; | |
extern "C" { | |
void foo(); | |
void bar() { | |
cout << "C++ creating object with destructor" << endl; | |
Bar bar; | |
foo(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::panic::catch_unwind; | |
extern "C" { | |
fn bar(); | |
} | |
#[no_mangle] | |
pub extern "C" fn foo() { | |
panic!("Rust is panicking"); | |
} | |
fn main() { | |
println!("Rust main function"); | |
println!("Caught Rust panic: {:?}", catch_unwind(|| unsafe { bar() } )); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> cl /c bar.cpp /EHs /Zi; rustc -g foo.rs -Clink-arg="bar.obj"; ./foo.exe | |
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24215.1 for x64 | |
Copyright (C) Microsoft Corporation. All rights reserved. | |
bar.cpp | |
Rust main function | |
C++ creating object with destructor | |
thread 'main' panicked at 'Rust is panicking', foo.rs:9 | |
note: Run with `RUST_BACKTRACE=1` for a backtrace. | |
C++ destructor is firing | |
Caught Rust panic: Err(Any) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment