From a9a18cf337f5cf800332b4d4b2ab9d7c4eb5f77d Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Thu, 17 Mar 2016 22:23:51 -0700 Subject: [PATCH] Simplify panic safety logic for new nightly --- openssl/src/ssl/bio.rs | 49 +++++------------------------------------- 1 file changed, 5 insertions(+), 44 deletions(-) diff --git a/openssl/src/ssl/bio.rs b/openssl/src/ssl/bio.rs index aa445562..31658cd0 100644 --- a/openssl/src/ssl/bio.rs +++ b/openssl/src/ssl/bio.rs @@ -74,8 +74,8 @@ unsafe fn state<'a, S: 'a>(bio: *mut BIO) -> &'a mut StreamState { } #[cfg(feature = "nightly")] -fn recover(f: F) -> Result> where F: FnOnce() -> T + ::std::panic::RecoverSafe { - ::std::panic::recover(f) +fn recover(f: F) -> Result> where F: FnOnce() -> T { + ::std::panic::recover(::std::panic::AssertRecoverSafe::new(f)) } #[cfg(not(feature = "nightly"))] @@ -83,45 +83,13 @@ fn recover(f: F) -> Result> where F: FnOnce() -> T { Ok(f()) } -#[cfg(feature = "nightly")] -use std::panic::AssertRecoverSafe; - -#[cfg(not(feature = "nightly"))] -struct AssertRecoverSafe(T); - -#[cfg(not(feature = "nightly"))] -impl AssertRecoverSafe { - fn new(t: T) -> Self { - AssertRecoverSafe(t) - } -} - -#[cfg(not(feature = "nightly"))] -impl ::std::ops::Deref for AssertRecoverSafe { - type Target = T; - - fn deref(&self) -> &T { - &self.0 - } -} - -#[cfg(not(feature = "nightly"))] -impl ::std::ops::DerefMut for AssertRecoverSafe { - fn deref_mut(&mut self) -> &mut T { - &mut self.0 - } -} - unsafe extern "C" fn bwrite(bio: *mut BIO, buf: *const c_char, len: c_int) -> c_int { BIO_clear_retry_flags(bio); let state = state::(bio); let buf = slice::from_raw_parts(buf as *const _, len as usize); - let result = { - let mut youre_not_my_supervisor = AssertRecoverSafe::new(&mut *state); - recover(move || youre_not_my_supervisor.stream.write(buf)) - }; + let result = recover(|| state.stream.write(buf)); match result { Ok(Ok(len)) => len as c_int, @@ -145,11 +113,7 @@ unsafe extern "C" fn bread(bio: *mut BIO, buf: *mut c_char, len: c_int) let state = state::(bio); let buf = slice::from_raw_parts_mut(buf as *mut _, len as usize); - let result = { - let mut youre_not_my_supervisor = AssertRecoverSafe::new(&mut *state); - let mut fuuuu = AssertRecoverSafe::new(buf); - recover(move || youre_not_my_supervisor.stream.read(&mut *fuuuu)) - }; + let result = recover(|| state.stream.read(buf)); match result { Ok(Ok(len)) => len as c_int, @@ -185,10 +149,7 @@ unsafe extern "C" fn ctrl(bio: *mut BIO, -> c_long { if cmd == BIO_CTRL_FLUSH { let state = state::(bio); - let result = { - let mut youre_not_my_supervisor = AssertRecoverSafe::new(&mut *state); - recover(move || youre_not_my_supervisor.stream.flush()) - }; + let result = recover(|| state.stream.flush()); match result { Ok(Ok(())) => 1,