X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-c-bindings%2Fsrc%2Fc_types%2Fmod.rs;h=d14fe6fc792df937f914aae656e8b61dfd52e773;hb=2d0cdbd33e63a82b5c9215d21a730e3e7a96ee74;hp=813e401b8e7e2b5f567b8791117c815c02aa0d61;hpb=65884fffee4c717623cef441acb82035f3f92308;p=rust-lightning diff --git a/lightning-c-bindings/src/c_types/mod.rs b/lightning-c-bindings/src/c_types/mod.rs index 813e401b..d14fe6fc 100644 --- a/lightning-c-bindings/src/c_types/mod.rs +++ b/lightning-c-bindings/src/c_types/mod.rs @@ -326,83 +326,53 @@ impl Clone for CVecTempl { #[repr(C)] pub struct C2TupleTempl { - pub a: *mut A, - pub b: *mut B, + pub a: A, + pub b: B, } impl From<(A, B)> for C2TupleTempl { fn from(tup: (A, B)) -> Self { Self { - a: Box::into_raw(Box::new(tup.0)), - b: Box::into_raw(Box::new(tup.1)), + a: tup.0, + b: tup.1, } } } impl C2TupleTempl { pub(crate) fn to_rust(mut self) -> (A, B) { - let res = (unsafe { *Box::from_raw(self.a) }, unsafe { *Box::from_raw(self.b) }); - self.a = std::ptr::null_mut(); - self.b = std::ptr::null_mut(); - res + (self.a, self.b) } } pub extern "C" fn C2TupleTempl_free(_res: C2TupleTempl) { } -impl Drop for C2TupleTempl { - fn drop(&mut self) { - if !self.a.is_null() { - unsafe { Box::from_raw(self.a) }; - } - if !self.b.is_null() { - unsafe { Box::from_raw(self.b) }; - } - } -} impl Clone for C2TupleTempl { fn clone(&self) -> Self { Self { - a: Box::into_raw(Box::new(unsafe { &*self.a }.clone())), - b: Box::into_raw(Box::new(unsafe { &*self.b }.clone())) + a: self.a.clone(), + b: self.b.clone() } } } #[repr(C)] pub struct C3TupleTempl { - pub a: *mut A, - pub b: *mut B, - pub c: *mut C, + pub a: A, + pub b: B, + pub c: C, } impl From<(A, B, C)> for C3TupleTempl { fn from(tup: (A, B, C)) -> Self { Self { - a: Box::into_raw(Box::new(tup.0)), - b: Box::into_raw(Box::new(tup.1)), - c: Box::into_raw(Box::new(tup.2)), + a: tup.0, + b: tup.1, + c: tup.2, } } } impl C3TupleTempl { pub(crate) fn to_rust(mut self) -> (A, B, C) { - let res = (unsafe { *Box::from_raw(self.a) }, unsafe { *Box::from_raw(self.b) }, unsafe { *Box::from_raw(self.c) }); - self.a = std::ptr::null_mut(); - self.b = std::ptr::null_mut(); - self.c = std::ptr::null_mut(); - res + (self.a, self.b, self.c) } } pub extern "C" fn C3TupleTempl_free(_res: C3TupleTempl) { } -impl Drop for C3TupleTempl { - fn drop(&mut self) { - if !self.a.is_null() { - unsafe { Box::from_raw(self.a) }; - } - if !self.b.is_null() { - unsafe { Box::from_raw(self.b) }; - } - if !self.c.is_null() { - unsafe { Box::from_raw(self.c) }; - } - } -} /// Utility to make it easy to set a pointer to null and get its original value in line. pub(crate) trait TakePointer {