diff --git a/rust/libceed/src/basis.rs b/rust/libceed/src/basis.rs index a3188f7bfb..2e719097e7 100644 --- a/rust/libceed/src/basis.rs +++ b/rust/libceed/src/basis.rs @@ -172,7 +172,7 @@ impl<'a> Basis<'a> { }) } - pub(crate) fn from_raw(ptr: bind_ceed::CeedBasis) -> crate::Result { + pub(crate) unsafe fn from_raw(ptr: bind_ceed::CeedBasis) -> crate::Result { Ok(Self { ptr, _lifeline: PhantomData, diff --git a/rust/libceed/src/elem_restriction.rs b/rust/libceed/src/elem_restriction.rs index 1bbf6b0643..081e08c61b 100644 --- a/rust/libceed/src/elem_restriction.rs +++ b/rust/libceed/src/elem_restriction.rs @@ -192,7 +192,7 @@ impl<'a> ElemRestriction<'a> { }) } - pub(crate) fn from_raw(ptr: bind_ceed::CeedElemRestriction) -> crate::Result { + pub(crate) unsafe fn from_raw(ptr: bind_ceed::CeedElemRestriction) -> crate::Result { Ok(Self { ptr, _lifeline: PhantomData, @@ -351,7 +351,7 @@ impl<'a> ElemRestriction<'a> { self.check_error(unsafe { bind_ceed::CeedElemRestrictionCreateVector(self.ptr, &mut ptr_lvector, null) })?; - Vector::from_raw(ptr_lvector) + unsafe { Vector::from_raw(ptr_lvector) } } /// Create an Evector for an ElemRestriction @@ -380,7 +380,7 @@ impl<'a> ElemRestriction<'a> { self.check_error(unsafe { bind_ceed::CeedElemRestrictionCreateVector(self.ptr, null, &mut ptr_evector) })?; - Vector::from_raw(ptr_evector) + unsafe { Vector::from_raw(ptr_evector) } } /// Create Vectors for an ElemRestriction @@ -410,8 +410,8 @@ impl<'a> ElemRestriction<'a> { self.check_error(unsafe { bind_ceed::CeedElemRestrictionCreateVector(self.ptr, &mut ptr_lvector, &mut ptr_evector) })?; - let lvector = Vector::from_raw(ptr_lvector)?; - let evector = Vector::from_raw(ptr_evector)?; + let lvector = unsafe { Vector::from_raw(ptr_lvector)? }; + let evector = unsafe { Vector::from_raw(ptr_evector)? }; Ok((lvector, evector)) } diff --git a/rust/libceed/src/operator.rs b/rust/libceed/src/operator.rs index 6f2cb11409..828ac5b998 100644 --- a/rust/libceed/src/operator.rs +++ b/rust/libceed/src/operator.rs @@ -27,27 +27,26 @@ pub struct OperatorField<'a> { // Implementations // ----------------------------------------------------------------------------- impl<'a> OperatorField<'a> { - pub(crate) fn from_raw( + pub(crate) unsafe fn from_raw( ptr: bind_ceed::CeedOperatorField, ceed: crate::Ceed, ) -> crate::Result { let vector = { let mut vector_ptr = std::ptr::null_mut(); - ceed.check_error(unsafe { - bind_ceed::CeedOperatorFieldGetVector(ptr, &mut vector_ptr) - })?; + ceed.check_error(bind_ceed::CeedOperatorFieldGetVector(ptr, &mut vector_ptr))?; crate::Vector::from_raw(vector_ptr)? }; let elem_restriction = { let mut elem_restriction_ptr = std::ptr::null_mut(); - ceed.check_error(unsafe { - bind_ceed::CeedOperatorFieldGetElemRestriction(ptr, &mut elem_restriction_ptr) - })?; + ceed.check_error(bind_ceed::CeedOperatorFieldGetElemRestriction( + ptr, + &mut elem_restriction_ptr, + ))?; crate::ElemRestriction::from_raw(elem_restriction_ptr)? }; let basis = { let mut basis_ptr = std::ptr::null_mut(); - ceed.check_error(unsafe { bind_ceed::CeedOperatorFieldGetBasis(ptr, &mut basis_ptr) })?; + ceed.check_error(bind_ceed::CeedOperatorFieldGetBasis(ptr, &mut basis_ptr))?; crate::Basis::from_raw(basis_ptr)? }; Ok(Self { @@ -558,7 +557,7 @@ impl<'a> Operator<'a> { }) } - fn from_raw(ptr: bind_ceed::CeedOperator) -> crate::Result { + unsafe fn from_raw(ptr: bind_ceed::CeedOperator) -> crate::Result { Ok(Self { op_core: OperatorCore { ptr, @@ -881,7 +880,7 @@ impl<'a> Operator<'a> { crate::Ceed { ptr } }; let inputs = (0..num_inputs as usize) - .map(|i| crate::OperatorField::from_raw(inputs_slice[i], ceed.clone())) + .map(|i| unsafe { crate::OperatorField::from_raw(inputs_slice[i], ceed.clone()) }) .collect::>>()?; Ok(inputs) } @@ -951,7 +950,7 @@ impl<'a> Operator<'a> { crate::Ceed { ptr } }; let outputs = (0..num_outputs as usize) - .map(|i| crate::OperatorField::from_raw(outputs_slice[i], ceed.clone())) + .map(|i| unsafe { crate::OperatorField::from_raw(outputs_slice[i], ceed.clone()) }) .collect::>>()?; Ok(outputs) } @@ -1720,9 +1719,9 @@ impl<'a> Operator<'a> { &mut ptr_restrict, ) })?; - let op_coarse = Operator::from_raw(ptr_coarse)?; - let op_prolong = Operator::from_raw(ptr_prolong)?; - let op_restrict = Operator::from_raw(ptr_restrict)?; + let op_coarse = unsafe { Operator::from_raw(ptr_coarse)? }; + let op_prolong = unsafe { Operator::from_raw(ptr_prolong)? }; + let op_restrict = unsafe { Operator::from_raw(ptr_restrict)? }; Ok((op_coarse, op_prolong, op_restrict)) } @@ -1910,9 +1909,9 @@ impl<'a> Operator<'a> { &mut ptr_restrict, ) })?; - let op_coarse = Operator::from_raw(ptr_coarse)?; - let op_prolong = Operator::from_raw(ptr_prolong)?; - let op_restrict = Operator::from_raw(ptr_restrict)?; + let op_coarse = unsafe { Operator::from_raw(ptr_coarse)? }; + let op_prolong = unsafe { Operator::from_raw(ptr_prolong)? }; + let op_restrict = unsafe { Operator::from_raw(ptr_restrict)? }; Ok((op_coarse, op_prolong, op_restrict)) } @@ -2100,9 +2099,9 @@ impl<'a> Operator<'a> { &mut ptr_restrict, ) })?; - let op_coarse = Operator::from_raw(ptr_coarse)?; - let op_prolong = Operator::from_raw(ptr_prolong)?; - let op_restrict = Operator::from_raw(ptr_restrict)?; + let op_coarse = unsafe { Operator::from_raw(ptr_coarse)? }; + let op_prolong = unsafe { Operator::from_raw(ptr_prolong)? }; + let op_restrict = unsafe { Operator::from_raw(ptr_restrict)? }; Ok((op_coarse, op_prolong, op_restrict)) } } diff --git a/rust/libceed/src/vector.rs b/rust/libceed/src/vector.rs index a6fd181907..3394ecd870 100644 --- a/rust/libceed/src/vector.rs +++ b/rust/libceed/src/vector.rs @@ -166,7 +166,7 @@ impl<'a> VectorSliceWrapper<'a> { ) })?; Ok(Self { - vector: crate::Vector::from_raw(vec.ptr_copy_mut()?)?, + vector: unsafe { crate::Vector::from_raw(vec.ptr_copy_mut()?)? }, _slice: slice, }) } @@ -252,7 +252,7 @@ impl<'a> Vector<'a> { }) } - pub(crate) fn from_raw(ptr: bind_ceed::CeedVector) -> crate::Result { + pub(crate) unsafe fn from_raw(ptr: bind_ceed::CeedVector) -> crate::Result { Ok(Self { ptr, _lifeline: PhantomData,