mark Mat::ptr functions as unsafe
MODIFY
gen_rust.py
gen_rust.py
@@ -422,6 +422,14 @@ func_unsafe_list = {
"cv_Mat_Mat_Size_int",
"cv_Mat_Mat_VectorOfint_int",
"cv_Mat_set_data_uchar_X",
+ "cv_Mat_ptr_int",
+ "cv_Mat_ptr_const_int",
+ "cv_Mat_ptr_int_int",
+ "cv_Mat_ptr_const_int_int",
+ "cv_Mat_ptr_int_int_int",
+ "cv_Mat_ptr_const_int_int_int",
+ "cv_Mat_ptr_const_int_X",
+ "cv_Mat_ptr_const_const_int_X",
}
# dict of types to replace if cannot be handled automatically
@@ -823,10 +831,10 @@ class FuncInfo(GeneralInfo):
.map(crate::templ::receive_string_mut)"""),
"rust_safe_rv_const_raw_ptr": template("""
- .and_then(|x| unsafe { x.as_ref() }.ok_or_else(|| Error::new(core::StsNullPtr, format!("Function returned Null pointer"))))"""),
+ .and_then(|x| ${unsafety_call}{ x.as_ref() }.ok_or_else(|| Error::new(core::StsNullPtr, format!("Function returned Null pointer"))))"""),
"rust_safe_rv_mut_raw_ptr": template("""
- .and_then(|x| unsafe { x.as_mut() }.ok_or_else(|| Error::new(core::StsNullPtr, format!("Function returned Null pointer"))))"""),
+ .and_then(|x| ${unsafety_call}{ x.as_mut() }.ok_or_else(|| Error::new(core::StsNullPtr, format!("Function returned Null pointer"))))"""),
"rust_safe_rv_vector_box_ptr": template(""".map(|ptr| ${rv_rust_full} { ptr })"""),

MODIFY
src/hub/manual/core/mat.rs
src/hub/manual/core/mat.rs
@@ -165,13 +165,13 @@ impl Mat {
/// more than 2 dimensions, so we can't perform a real bounds check here.
#[inline(always)]
pub(crate) fn _at_3d<T: DataType>(&self, i0: i32, i1: i32, i2: i32) -> Result<&T> {
- self.match_format::<T>().and_then(|_| self.ptr_3d(i0, i1, i2).map(|x| unsafe { &*(x as *const _ as *const T) }))
+ self.match_format::<T>().and_then(|_| unsafe { self.ptr_3d(i0, i1, i2) }.map(|x| unsafe { &*(x as *const _ as *const T) }))
}
/// See safety caveats of `Mat::_at_3d()`
#[inline(always)]
pub(crate) fn _at_3d_mut<T: DataType>(&mut self, i0: i32, i1: i32, i2: i32) -> Result<&mut T> {
- self.match_format::<T>().and_then(|_| self.ptr_3d_mut(i0, i1, i2).map(|x| unsafe { &mut *(x as *mut _ as *mut T) }))
+ self.match_format::<T>().and_then(|_| unsafe { self.ptr_3d_mut(i0, i1, i2) }.map(|x| unsafe { &mut *(x as *mut _ as *mut T) }))
}
/// Return a complete read-only row

mark Mat::ptr functions as unsafe