Skip to content

Commit

Permalink
std: Don't require rust_try as an exported symbol
Browse files Browse the repository at this point in the history
This commit adds a small non-generic non-inlineable shim function to
`rt::unwind::try` which the compiler can take care of for managing the exported
symbol instead of having to edit `src/rt/rust_try.ll`
  • Loading branch information
alexcrichton committed May 19, 2015
1 parent 3d32cf5 commit 74f4f39
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions src/libstd/rt/unwind/mod.rs
Expand Up @@ -127,16 +127,31 @@ extern {}
/// run.
pub unsafe fn try<F: FnOnce()>(f: F) -> Result<(), Box<Any + Send>> {
let mut f = Some(f);
return inner_try(try_fn::<F>, &mut f as *mut _ as *mut c_void);

let prev = PANICKING.with(|s| s.get());
PANICKING.with(|s| s.set(false));
let ep = rust_try(try_fn::<F>, &mut f as *mut _ as *mut c_void);
PANICKING.with(|s| s.set(prev));
return if ep.is_null() {
Ok(())
} else {
Err(imp::cleanup(ep))
};
// If an inner function were not used here, then this generic function `try`
// uses the native symbol `rust_try`, for which the code is statically
// linked into the standard library. This means that the DLL for the
// standard library must have `rust_try` as an exposed symbol that
// downstream crates can link against (because monomorphizations of `try` in
// downstream crates will have a reference to the `rust_try` symbol).
//
// On MSVC this requires the symbol `rust_try` to be tagged with
// `dllexport`, but it's easier to not have conditional `src/rt/rust_try.ll`
// files and instead just have this non-generic shim the compiler can take
// care of exposing correctly.
unsafe fn inner_try(f: extern fn(*mut c_void), data: *mut c_void)
-> Result<(), Box<Any + Send>> {
let prev = PANICKING.with(|s| s.get());
PANICKING.with(|s| s.set(false));
let ep = rust_try(f, data);
PANICKING.with(|s| s.set(prev));
if ep.is_null() {
Ok(())
} else {
Err(imp::cleanup(ep))
}
}

extern fn try_fn<F: FnOnce()>(opt_closure: *mut c_void) {
let opt_closure = opt_closure as *mut Option<F>;
Expand Down

0 comments on commit 74f4f39

Please sign in to comment.