diff options
| author | Steven Fackler <[email protected]> | 2016-11-01 19:12:38 -0700 |
|---|---|---|
| committer | Steven Fackler <[email protected]> | 2016-11-01 19:12:38 -0700 |
| commit | 79c51d5e517ffe40e01c34577667c0a242a5f6ba (patch) | |
| tree | 42c88053809c3da19caf616035eadc107a0f47c8 /openssl/src/stack.rs | |
| parent | Merge pull request #506 from simias/stack (diff) | |
| download | rust-openssl-79c51d5e517ffe40e01c34577667c0a242a5f6ba.tar.xz rust-openssl-79c51d5e517ffe40e01c34577667c0a242a5f6ba.zip | |
Clean up stack destructor
Diffstat (limited to 'openssl/src/stack.rs')
| -rw-r--r-- | openssl/src/stack.rs | 41 |
1 files changed, 14 insertions, 27 deletions
diff --git a/openssl/src/stack.rs b/openssl/src/stack.rs index 2cc53b5f..bb1ddfda 100644 --- a/openssl/src/stack.rs +++ b/openssl/src/stack.rs @@ -9,12 +9,19 @@ use libc::c_int; use ffi; use types::{OpenSslType, Ref}; -/// Trait implemented by stackable types. This must *only* be -/// implemented on opaque types that can be directly casted into their -/// `CType`. +#[cfg(ossl10x)] +use ffi::{sk_pop as OPENSSL_sk_pop, sk_free as OPENSSL_sk_free}; +#[cfg(ossl110)] +use ffi::{OPENSSL_sk_pop, OPENSSL_sk_free}; + +/// Trait implemented by types which can be placed in a stack. +/// +/// Like `OpenSslType`, it should not be implemented for any type outside +/// of this crate. pub trait Stackable: OpenSslType { - /// C stack type for this element. Generally called - /// `stack_st_{ELEMENT_TYPE}`, normally hidden by the + /// The C stack type for this element. + /// + /// Generally called `stack_st_{ELEMENT_TYPE}`, normally hidden by the /// `STACK_OF(ELEMENT_TYPE)` macro in the OpenSSL API. type StackType; } @@ -30,30 +37,10 @@ impl<T: Stackable> Stack<T> { } impl<T: Stackable> Drop for Stack<T> { - #[cfg(ossl10x)] - fn drop(&mut self) { - unsafe { - loop { - let ptr = ffi::sk_pop(self.as_stack()); - - if ptr.is_null() { - break; - } - - // Build the owned version of the object just to run - // its `drop` implementation and delete the item. - T::from_ptr(ptr as *mut _); - } - - ffi::sk_free(self.0 as *mut _); - } - } - - #[cfg(ossl110)] fn drop(&mut self) { unsafe { loop { - let ptr = ffi::OPENSSL_sk_pop(self.as_stack()); + let ptr = OPENSSL_sk_pop(self.as_stack()); if ptr.is_null() { break; @@ -64,7 +51,7 @@ impl<T: Stackable> Drop for Stack<T> { T::from_ptr(ptr as *mut _); } - ffi::OPENSSL_sk_free(self.0 as *mut _); + OPENSSL_sk_free(self.0 as *mut _); } } } |