Make Mat::new_*_with_data functions unsafe
MODIFY
binding-generator/src/settings.rs
binding-generator/src/settings.rs
@@ -605,6 +605,10 @@ pub static FUNC_UNSAFE: Lazy<HashSet<&str>> = Lazy::new(|| hashset! {
"cv__OutputArray_create_const_int_const_intX_int_int_bool_int",
"cv__OutputArray_create_const_int_int_int_int_bool_int",
// allows passing arbitrary data
+ "cv_Mat_Mat_int_int_int_voidX_size_t",
+ "cv_Mat_Mat_Size_int_voidX_size_t",
+ "cv_Mat_Mat_int_const_intX_int_voidX_const_size_tX",
+ "cv_Mat_Mat_const_vector_int_X_int_voidX_const_size_tX",
"cv_Mat_setData_unsigned_charX",
"cv_UMatData_setData_unsigned_charX",
// no bounds checking

MODIFY
tests/imgcodecs.rs
tests/imgcodecs.rs
-use std::mem::transmute;
+use std::ffi::c_void;
use opencv::{
core::{self, Size, Vec3b},
@@ -21,7 +21,7 @@ fn decode() -> Result<()> {
{
let mut bytes = PIXEL.to_vec();
- let src = Mat::new_rows_cols_with_data(1, PIXEL.len() as _, u8::typ(), unsafe { transmute(bytes.as_mut_ptr()) }, core::Mat_AUTO_STEP)?;
+ let src = unsafe { Mat::new_rows_cols_with_data(1, PIXEL.len() as _, u8::typ(), bytes.as_mut_ptr() as *mut c_void, core::Mat_AUTO_STEP) }?;
let mut dest = Mat::default()?;
imgcodecs::imdecode_to(&src, imgcodecs::IMREAD_COLOR, &mut dest)?;
assert_eq!(dest.size()?, Size::new(1, 1));

MODIFY
tests/mat.rs
tests/mat.rs
-use std::mem::transmute;
+use std::ffi::c_void;
use matches::assert_matches;
@@ -397,7 +397,7 @@ fn mat_operations() -> Result<()> {
#[test]
fn mat_from_data() -> Result<()> {
let mut bytes = PIXEL.to_vec();
- let src = Mat::new_rows_cols_with_data(1, PIXEL.len() as _, u8::typ(), unsafe { transmute(bytes.as_mut_ptr()) }, core::Mat_AUTO_STEP)?;
+ let src = unsafe { Mat::new_rows_cols_with_data(1, PIXEL.len() as _, u8::typ(), bytes.as_mut_ptr() as *mut c_void, core::Mat_AUTO_STEP)? };
assert_eq!(src.size()?, Size::new(PIXEL.len() as _, 1));
assert_eq!(src.total()?, PIXEL.len());
let row = src.at_row::<u8>(0)?;

Make Mat::new_*_with_data functions unsafe