diff --git a/src/gallium/frontends/rusticl/api/memory.rs b/src/gallium/frontends/rusticl/api/memory.rs index ee15d1e7b0f..8af0abaf62a 100644 --- a/src/gallium/frontends/rusticl/api/memory.rs +++ b/src/gallium/frontends/rusticl/api/memory.rs @@ -241,7 +241,7 @@ unsafe impl CLInfo for cl_mem { } else { 0 }), - CL_MEM_PROPERTIES => v.write::<&[cl_mem_properties]>(&mem.props), + CL_MEM_PROPERTIES => v.write::<&Properties>(&mem.props), CL_MEM_REFERENCE_COUNT => v.write::(if mem.is_buffer() { Buffer::refcnt(*self)? } else { @@ -295,12 +295,14 @@ fn create_buffer_with_properties( } } - let props = Properties::from_ptr_raw(properties); + // CL_INVALID_PROPERTY [...] if the same property name is specified more than once. + let props = Properties::from_ptr(properties).ok_or(CL_INVALID_PROPERTY)?; + // CL_INVALID_PROPERTY if a property name in properties is not a supported property name, if // the value specified for a supported property name is not valid, or if the same property name // is specified more than once. - if props.len() > 1 { - // we don't support any properties besides the 0 property + if !props.is_empty() { + // we don't support any properties return Err(CL_INVALID_PROPERTY); } @@ -798,12 +800,14 @@ fn create_image_with_properties( .find(|f| *f & filtered_flags == filtered_flags) .ok_or(CL_IMAGE_FORMAT_NOT_SUPPORTED)?; - let props = Properties::from_ptr_raw(properties); + // CL_INVALID_PROPERTY [...] if the same property name is specified more than once. + let props = Properties::from_ptr(properties).ok_or(CL_INVALID_PROPERTY)?; + // CL_INVALID_PROPERTY if a property name in properties is not a supported property name, if // the value specified for a supported property name is not valid, or if the same property name // is specified more than once. - if props.len() > 1 { - // we don't support any properties besides the 0 property + if !props.is_empty() { + // we don't support any properties return Err(CL_INVALID_PROPERTY); } diff --git a/src/gallium/frontends/rusticl/core/memory.rs b/src/gallium/frontends/rusticl/core/memory.rs index 672d2208a5a..0455733860e 100644 --- a/src/gallium/frontends/rusticl/core/memory.rs +++ b/src/gallium/frontends/rusticl/core/memory.rs @@ -204,7 +204,7 @@ pub struct MemBase { // it's a bit hacky, but storing the pointer as `usize` gives us `Send` and `Sync`. The // application is required to ensure no data races exist on the memory anyway. pub host_ptr: usize, - pub props: Vec, + pub props: Properties, pub cbs: Mutex>, pub gl_obj: Option, res: Option>>, @@ -396,7 +396,7 @@ impl MemBase { flags: cl_mem_flags, size: usize, host_ptr: *mut c_void, - props: Vec, + props: Properties, ) -> CLResult> { let res_type = if bit_check(flags, CL_MEM_ALLOC_HOST_PTR) { ResourceType::Staging @@ -457,7 +457,7 @@ impl MemBase { flags: flags, size: size, host_ptr: host_ptr, - props: Vec::new(), + props: Properties::default(), gl_obj: None, cbs: Mutex::new(Vec::new()), res: None, @@ -476,7 +476,7 @@ impl MemBase { mut image_desc: cl_image_desc, image_elem_size: u8, host_ptr: *mut c_void, - props: Vec, + props: Properties, ) -> CLResult> { // we have to sanitize the image_desc a little for internal use let api_image_desc = image_desc; @@ -641,7 +641,7 @@ impl MemBase { flags: flags, size: gl_mem_props.size(), host_ptr: 0, - props: Vec::new(), + props: Properties::default(), gl_obj: Some(GLObject { gl_object_target: gl_export_manager.export_in.target, gl_object_type: gl_object_type, diff --git a/src/gallium/frontends/rusticl/util/properties.rs b/src/gallium/frontends/rusticl/util/properties.rs index c9da30bcd3e..ca8997f93b8 100644 --- a/src/gallium/frontends/rusticl/util/properties.rs +++ b/src/gallium/frontends/rusticl/util/properties.rs @@ -5,27 +5,6 @@ pub struct Properties { /// This encapsulates a C property array, where the list is 0 terminated. impl Properties { - #[allow(clippy::not_unsafe_ptr_arg_deref)] - pub fn from_ptr_raw(mut p: *const T) -> Vec - where - T: Copy + Default + PartialEq, - { - let mut res: Vec = Vec::new(); - - if !p.is_null() { - unsafe { - while *p != T::default() { - res.push(*p); - res.push(*p.add(1)); - p = p.add(2); - } - } - res.push(T::default()); - } - - res - } - /// Creates a Properties object copying from the supplied pointer. /// /// It returns `None` if any property is found twice.