From 9dab9d717d95991d7ea746a62b5233303f63ff2d Mon Sep 17 00:00:00 2001 From: Magnus Ulimoen Date: Wed, 23 Mar 2022 18:36:59 +0100 Subject: [PATCH 1/7] Remove unnecessary unsafe --- src/globals.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/globals.rs b/src/globals.rs index b705055d3..ecb063c3d 100644 --- a/src/globals.rs +++ b/src/globals.rs @@ -329,18 +329,18 @@ lazy_static! { // File drivers lazy_static! { - pub static ref H5FD_CORE: hid_t = unsafe { h5lock!(H5FD_core_init()) }; - pub static ref H5FD_SEC2: hid_t = unsafe { h5lock!(H5FD_sec2_init()) }; - pub static ref H5FD_STDIO: hid_t = unsafe { h5lock!(H5FD_stdio_init()) }; - pub static ref H5FD_FAMILY: hid_t = unsafe { h5lock!(H5FD_family_init()) }; - pub static ref H5FD_LOG: hid_t = unsafe { h5lock!(H5FD_log_init()) }; - pub static ref H5FD_MULTI: hid_t = unsafe { h5lock!(H5FD_multi_init()) }; + pub static ref H5FD_CORE: hid_t = h5lock!(H5FD_core_init()); + pub static ref H5FD_SEC2: hid_t = h5lock!(H5FD_sec2_init()); + pub static ref H5FD_STDIO: hid_t = h5lock!(H5FD_stdio_init()); + pub static ref H5FD_FAMILY: hid_t = h5lock!(H5FD_family_init()); + pub static ref H5FD_LOG: hid_t = h5lock!(H5FD_log_init()); + pub static ref H5FD_MULTI: hid_t = h5lock!(H5FD_multi_init()); } // MPI-IO file driver #[cfg(feature = "have-parallel")] lazy_static! { - pub static ref H5FD_MPIO: hid_t = unsafe { h5lock!(H5FD_mpio_init()) }; + pub static ref H5FD_MPIO: hid_t = h5lock!(H5FD_mpio_init()); } #[cfg(not(feature = "have-parallel"))] lazy_static! { @@ -350,7 +350,7 @@ lazy_static! { // Direct VFD #[cfg(feature = "have-direct")] lazy_static! { - pub static ref H5FD_DIRECT: hid_t = unsafe { h5lock!(H5FD_direct_init()) }; + pub static ref H5FD_DIRECT: hid_t = h5lock!(H5FD_direct_init()); } #[cfg(not(feature = "have-direct"))] lazy_static! { From 1f6203e0d1310b77a60b839f1ede0ae2c90debd5 Mon Sep 17 00:00:00 2001 From: Magnus Ulimoen Date: Wed, 23 Mar 2022 18:55:05 +0100 Subject: [PATCH 2/7] Ignore clippy lint --- src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib.rs b/src/lib.rs index ae96cce44..587b0539c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -40,6 +40,7 @@ #![cfg_attr(feature = "cargo-clippy", allow(clippy::missing_panics_doc))] #![cfg_attr(feature = "cargo-clippy", allow(clippy::missing_const_for_fn))] #![cfg_attr(feature = "cargo-clippy", allow(clippy::option_if_let_else))] +#![cfg_attr(feature = "cargo-clippy", allow(clippy::return_self_not_must_use))] #![cfg_attr(all(feature = "cargo-clippy", test), allow(clippy::cyclomatic_complexity))] #![cfg_attr(not(test), allow(dead_code))] // To build docs locally: From 1b4188268631768909bd877b82f7b6d83e2dade5 Mon Sep 17 00:00:00 2001 From: Magnus Ulimoen Date: Fri, 8 Apr 2022 23:17:34 +0200 Subject: [PATCH 3/7] Use addr_of where applicable --- src/class.rs | 4 ++-- src/dim.rs | 2 +- src/error.rs | 4 ++-- src/hl/attribute.rs | 3 ++- src/hl/container.rs | 4 ++-- src/hl/dataset.rs | 2 +- src/hl/dataspace.rs | 4 ++-- src/hl/datatype.rs | 19 +++++++++++-------- src/hl/filters.rs | 8 ++++---- src/hl/filters/blosc.rs | 18 +++++++++--------- src/hl/filters/lzf.rs | 10 +++++----- src/hl/group.rs | 3 ++- src/hl/plist.rs | 4 ++-- src/hl/plist/dataset_create.rs | 6 +++--- src/hl/plist/file_access.rs | 16 +++++++++------- src/hl/selection.rs | 1 + src/util.rs | 3 ++- 17 files changed, 60 insertions(+), 51 deletions(-) diff --git a/src/class.rs b/src/class.rs index abcd7cb60..e859b14f9 100644 --- a/src/class.rs +++ b/src/class.rs @@ -1,6 +1,6 @@ use std::fmt; use std::mem; -use std::ptr; +use std::ptr::{self, addr_of}; use crate::internal_prelude::*; @@ -53,7 +53,7 @@ pub trait ObjectClass: Sized { unsafe fn cast_unchecked(self) -> T { // This method requires you to be 18 years or older to use it // (note: if it wasn't a trait method, it could be marked as const) - let obj = ptr::read((&self as *const Self).cast()); + let obj = ptr::read(addr_of!(self).cast()); mem::forget(self); obj } diff --git a/src/dim.rs b/src/dim.rs index d7b49d037..9b1bf82b1 100644 --- a/src/dim.rs +++ b/src/dim.rs @@ -72,7 +72,7 @@ macro_rules! impl_tuple { #[inline] fn dims(&self) -> Vec { unsafe { - slice::from_raw_parts(self as *const _ as *const _, self.ndim()) + slice::from_raw_parts((self as *const Self).cast(), self.ndim()) }.iter().cloned().collect() } } diff --git a/src/error.rs b/src/error.rs index a8e7778e7..bc9085ff1 100644 --- a/src/error.rs +++ b/src/error.rs @@ -4,7 +4,7 @@ use std::fmt; use std::io; use std::ops::Deref; use std::panic; -use std::ptr; +use std::ptr::{self, addr_of_mut}; use ndarray::ShapeError; @@ -96,7 +96,7 @@ impl ErrorStack { } let mut data = CallbackData { stack: ExpandedErrorStack::new(), err: None }; - let data_ptr: *mut c_void = (&mut data as *mut CallbackData).cast::(); + let data_ptr: *mut c_void = addr_of_mut!(data).cast::(); let stack_id = self.handle().id(); h5lock!({ diff --git a/src/hl/attribute.rs b/src/hl/attribute.rs index 0f700fe0b..8943e0aa8 100644 --- a/src/hl/attribute.rs +++ b/src/hl/attribute.rs @@ -1,5 +1,6 @@ use std::fmt::{self, Debug}; use std::ops::Deref; +use std::ptr::addr_of_mut; use hdf5_sys::{ h5::{H5_index_t, H5_iter_order_t}, @@ -62,7 +63,7 @@ impl Attribute { let callback_fn: H5A_operator2_t = Some(attributes_callback); let iteration_position: *mut hsize_t = &mut { 0_u64 }; let mut result: Vec = Vec::new(); - let other_data: *mut c_void = &mut result as *const _ as *mut c_void; + let other_data: *mut c_void = addr_of_mut!(result).cast(); h5call!(H5Aiterate2( obj.handle().id(), diff --git a/src/hl/container.rs b/src/hl/container.rs index ec0ffab77..560035d57 100644 --- a/src/hl/container.rs +++ b/src/hl/container.rs @@ -371,7 +371,7 @@ impl ByteReader { if !hdf5_types::USING_H5_ALLOCATOR { crate::hl::plist::set_vlen_manager_libc(xfer.id())?; } - Ok(ByteReader { obj, pos: 0, obj_space, dt: mem_dtype, xfer }) + Ok(Self { obj, pos: 0, obj_space, dt: mem_dtype, xfer }) } fn dataset_len(&self) -> usize { @@ -494,7 +494,7 @@ impl Container { /// /// ``ByteReader`` only supports 1-D `u8` datasets. pub fn as_byte_reader(&self) -> Result { - ByteReader::new(&self) + ByteReader::new(self) } /// Returns the datatype of the dataset/attribute. diff --git a/src/hl/dataset.rs b/src/hl/dataset.rs index cf5dc9795..d0cc1dc03 100644 --- a/src/hl/dataset.rs +++ b/src/hl/dataset.rs @@ -684,7 +684,7 @@ impl DatasetBuilderInner { /// /// This requires the `lzf` crate feature pub fn lzf(&mut self) { - self.with_dcpl(|pl| pl.lzf()); + self.with_dcpl(DatasetCreateBuilder::lzf); } #[cfg(feature = "blosc")] diff --git a/src/hl/dataspace.rs b/src/hl/dataspace.rs index 4350e8ef3..e75b21317 100644 --- a/src/hl/dataspace.rs +++ b/src/hl/dataspace.rs @@ -143,9 +143,9 @@ impl Dataspace { } else { h5lock!({ let mut len: size_t = 0; - h5try!(H5Sencode1(self.id(), ptr::null_mut(), &mut len as *mut _)); + h5try!(H5Sencode1(self.id(), ptr::null_mut(), ptr::addr_of_mut!(len))); let mut buf = vec![0_u8; len]; - h5try!(H5Sencode1(self.id(), buf.as_mut_ptr().cast(), &mut len as *mut _)); + h5try!(H5Sencode1(self.id(), buf.as_mut_ptr().cast(), ptr::addr_of_mut!(len))); Ok(buf) }) } diff --git a/src/hl/datatype.rs b/src/hl/datatype.rs index 0da96ba4c..358d3ad42 100644 --- a/src/hl/datatype.rs +++ b/src/hl/datatype.rs @@ -2,6 +2,7 @@ use std::borrow::Borrow; use std::cmp::{Ordering, PartialEq, PartialOrd}; use std::fmt::{self, Debug, Display}; use std::ops::Deref; +use std::ptr::{addr_of, addr_of_mut}; use hdf5_sys::h5t::{ H5T_cdata_t, H5T_class_t, H5T_cset_t, H5T_order_t, H5T_sign_t, H5T_str_t, H5Tarray_create2, @@ -171,8 +172,8 @@ impl Datatype { let dst = dst.borrow(); let mut cdata = H5T_cdata_t::default(); h5lock!({ - let noop = H5Tfind(*H5T_NATIVE_INT, *H5T_NATIVE_INT, &mut (&mut cdata as *mut _)); - if H5Tfind(self.id(), dst.id(), &mut (&mut cdata as *mut _)) == noop { + let noop = H5Tfind(*H5T_NATIVE_INT, *H5T_NATIVE_INT, &mut addr_of_mut!(cdata)); + if H5Tfind(self.id(), dst.id(), &mut addr_of_mut!(cdata)) == noop { Some(Conversion::NoOp) } else { match H5Tcompiler_conv(self.id(), dst.id()) { @@ -235,7 +236,7 @@ impl Datatype { let mut members: Vec = Vec::new(); for idx in 0..h5try!(H5Tget_nmembers(id)) as _ { let mut value: u64 = 0; - h5try!(H5Tget_member_value(id, idx, (&mut value as *mut u64).cast())); + h5try!(H5Tget_member_value(id, idx, addr_of_mut!(value).cast())); let name = H5Tget_member_name(id, idx); members.push(EnumMember { name: string_from_cstr(name), value }); h5_free_memory(name.cast()); @@ -277,7 +278,7 @@ impl Datatype { let ndims = h5try!(H5Tget_array_ndims(id)); if ndims == 1 { let mut len: hsize_t = 0; - h5try!(H5Tget_array_dims2(id, &mut len as *mut _)); + h5try!(H5Tget_array_dims2(id, addr_of_mut!(len))); Ok(TD::FixedArray(Box::new(base_dt.to_descriptor()?), len as _)) } else { Err("Multi-dimensional array datatypes are not supported".into()) @@ -344,15 +345,17 @@ impl Datatype { }), TD::Boolean => { let bool_id = h5try!(H5Tenum_create(*H5T_NATIVE_INT8)); + let zero = 0_i8; h5try!(H5Tenum_insert( bool_id, b"FALSE\0".as_ptr().cast(), - (&0_i8 as *const i8).cast() + addr_of!(zero).cast(), )); + let one = 1_i8; h5try!(H5Tenum_insert( bool_id, b"TRUE\0".as_ptr().cast(), - (&1_i8 as *const i8).cast() + addr_of!(one).cast(), )); Ok(bool_id) } @@ -364,7 +367,7 @@ impl Datatype { h5try!(H5Tenum_insert( enum_id, name.as_ptr(), - (&member.value as *const u64).cast() + addr_of!(member.value).cast() )); } Ok(enum_id) @@ -383,7 +386,7 @@ impl Datatype { TD::FixedArray(ref ty, len) => { let elem_dt = Self::from_descriptor(ty)?; let dims = len as hsize_t; - Ok(h5try!(H5Tarray_create2(elem_dt.id(), 1, &dims as *const _))) + Ok(h5try!(H5Tarray_create2(elem_dt.id(), 1, addr_of!(dims)))) } TD::FixedAscii(size) => string_type(Some(size), H5T_cset_t::H5T_CSET_ASCII), TD::FixedUnicode(size) => string_type(Some(size), H5T_cset_t::H5T_CSET_UTF8), diff --git a/src/hl/filters.rs b/src/hl/filters.rs index 207bad997..0c873a551 100644 --- a/src/hl/filters.rs +++ b/src/hl/filters.rs @@ -1,5 +1,5 @@ use std::collections::HashMap; -use std::ptr; +use std::ptr::{self, addr_of_mut}; use hdf5_sys::h5p::{ H5Pget_filter2, H5Pget_nfilters, H5Pset_deflate, H5Pset_filter, H5Pset_fletcher32, H5Pset_nbit, @@ -180,7 +180,7 @@ impl Filter { return FilterInfo::default(); } let mut flags: c_uint = 0; - h5lock!(H5Zget_filter_info(filter_id, &mut flags as *mut _)); + h5lock!(H5Zget_filter_info(filter_id, addr_of_mut!(flags))); FilterInfo { is_available: true, encode_enabled: flags & H5Z_FILTER_CONFIG_ENCODE_ENABLED != 0, @@ -503,8 +503,8 @@ impl Filter { let filter_id = h5try!(H5Pget_filter2( plist_id, idx as _, - &mut flags as *mut _, - &mut cd_nelmts as *mut _, + addr_of_mut!(flags), + addr_of_mut!(cd_nelmts), cd_values.as_mut_ptr(), name.len() as _, name.as_mut_ptr(), diff --git a/src/hl/filters/blosc.rs b/src/hl/filters/blosc.rs index 5d307064d..f1ea55e5d 100644 --- a/src/hl/filters/blosc.rs +++ b/src/hl/filters/blosc.rs @@ -1,4 +1,4 @@ -use std::ptr; +use std::ptr::{self, addr_of_mut}; use std::slice; use lazy_static::lazy_static; @@ -25,7 +25,7 @@ const BLOSC_FILTER_NAME: &[u8] = b"blosc\0"; pub const BLOSC_FILTER_ID: H5Z_filter_t = 32001; const BLOSC_FILTER_VERSION: c_uint = 2; -const BLOSC_FILTER_INFO: H5Z_class2_t = H5Z_class2_t { +const BLOSC_FILTER_INFO: &H5Z_class2_t = &H5Z_class2_t { version: H5Z_CLASS_T_VERS as _, id: BLOSC_FILTER_ID, encoder_present: 1, @@ -41,7 +41,7 @@ lazy_static! { unsafe { blosc_init(); } - let ret = unsafe { H5Zregister((&BLOSC_FILTER_INFO as *const H5Z_class2_t).cast()) }; + let ret = unsafe { H5Zregister((BLOSC_FILTER_INFO as *const H5Z_class2_t).cast()) }; if H5ErrorCode::is_err_code(ret) { return Err("Can't register Blosc filter"); } @@ -62,8 +62,8 @@ extern "C" fn set_local_blosc(dcpl_id: hid_t, type_id: hid_t, _space_id: hid_t) H5Pget_filter_by_id2( dcpl_id, BLOSC_FILTER_ID, - &mut flags as *mut _, - &mut nelmts as *mut _, + addr_of_mut!(flags), + addr_of_mut!(nelmts), values.as_mut_ptr(), 0, ptr::null_mut(), @@ -158,7 +158,7 @@ fn parse_blosc_cdata(cd_nelmts: size_t, cd_values: *const c_uint) -> Option= 7 { - let r = unsafe { blosc_compcode_to_compname(cdata[6] as _, &mut cfg.compname as *mut _) }; + let r = unsafe { blosc_compcode_to_compname(cdata[6] as _, addr_of_mut!(cfg.compname)) }; if r == -1 { let complist = string_from_cstr(unsafe { blosc_list_compressors() }); let errmsg = format!( @@ -221,9 +221,9 @@ unsafe fn filter_blosc_decompress( let (mut cbytes, mut blocksize): (size_t, size_t) = (0, 0); blosc_cbuffer_sizes( *buf, - &mut outbuf_size as *mut _, - &mut cbytes as *mut _, - &mut blocksize as *mut _, + addr_of_mut!(outbuf_size), + addr_of_mut!(cbytes), + addr_of_mut!(blocksize), ); let outbuf = libc::malloc(outbuf_size); if outbuf.is_null() { diff --git a/src/hl/filters/lzf.rs b/src/hl/filters/lzf.rs index 2ca6823f9..14751c715 100644 --- a/src/hl/filters/lzf.rs +++ b/src/hl/filters/lzf.rs @@ -1,4 +1,4 @@ -use std::ptr; +use std::ptr::{self, addr_of_mut}; use std::slice; use lazy_static::lazy_static; @@ -15,7 +15,7 @@ const LZF_FILTER_NAME: &[u8] = b"lzf\0"; pub const LZF_FILTER_ID: H5Z_filter_t = 32000; const LZF_FILTER_VERSION: c_uint = 4; -const LZF_FILTER_INFO: H5Z_class2_t = H5Z_class2_t { +const LZF_FILTER_INFO: &H5Z_class2_t = &H5Z_class2_t { version: H5Z_CLASS_T_VERS as _, id: LZF_FILTER_ID, encoder_present: 1, @@ -28,7 +28,7 @@ const LZF_FILTER_INFO: H5Z_class2_t = H5Z_class2_t { lazy_static! { static ref LZF_INIT: Result<(), &'static str> = { - let ret = unsafe { H5Zregister((&LZF_FILTER_INFO as *const H5Z_class2_t).cast()) }; + let ret = unsafe { H5Zregister((LZF_FILTER_INFO as *const H5Z_class2_t).cast()) }; if H5ErrorCode::is_err_code(ret) { return Err("Can't register LZF filter"); } @@ -49,8 +49,8 @@ extern "C" fn set_local_lzf(dcpl_id: hid_t, type_id: hid_t, _space_id: hid_t) -> H5Pget_filter_by_id2( dcpl_id, LZF_FILTER_ID, - &mut flags as *mut _, - &mut nelmts as *mut _, + addr_of_mut!(flags), + addr_of_mut!(nelmts), values.as_mut_ptr(), 0, ptr::null_mut(), diff --git a/src/hl/group.rs b/src/hl/group.rs index d5a0166d1..0f5443f9e 100644 --- a/src/hl/group.rs +++ b/src/hl/group.rs @@ -1,6 +1,7 @@ use std::fmt::{self, Debug}; use std::ops::Deref; use std::panic; +use std::ptr::addr_of_mut; use hdf5_sys::{ h5::{hsize_t, H5_index_t, H5_iter_order_t}, @@ -339,7 +340,7 @@ impl Group { // Store our references on the heap let mut vtable = Vtable { f: &mut op, d: &mut val }; - let other_data = (&mut vtable as *mut Vtable<_, _>).cast::(); + let other_data = addr_of_mut!(vtable).cast::(); h5call!(H5Literate( self.id(), diff --git a/src/hl/plist.rs b/src/hl/plist.rs index e5c79b564..c7af196cb 100644 --- a/src/hl/plist.rs +++ b/src/hl/plist.rs @@ -1,7 +1,7 @@ use std::fmt::{self, Debug, Display}; use std::ops::Deref; use std::panic; -use std::ptr; +use std::ptr::{self, addr_of_mut}; use std::str::FromStr; use hdf5_sys::h5p::{ @@ -184,7 +184,7 @@ impl PropertyList { } let mut data = Vec::new(); - let data_ptr: *mut c_void = (&mut data as *mut Vec<_>).cast(); + let data_ptr: *mut c_void = addr_of_mut!(data).cast(); h5lock!(H5Piterate(self.id(), ptr::null_mut(), Some(callback), data_ptr)); data diff --git a/src/hl/plist/dataset_create.rs b/src/hl/plist/dataset_create.rs index f3c3f8852..e968f8a51 100644 --- a/src/hl/plist/dataset_create.rs +++ b/src/hl/plist/dataset_create.rs @@ -2,7 +2,7 @@ use std::fmt::{self, Debug}; use std::ops::Deref; -use std::ptr; +use std::ptr::{self, addr_of_mut}; #[cfg(feature = "1.10.0")] use bitflags::bitflags; @@ -809,8 +809,8 @@ impl DatasetCreate { idx as _, NAME_LEN as _, name.as_mut_ptr(), - &mut offset as *mut _, - &mut size as *mut _, + addr_of_mut!(offset), + addr_of_mut!(size), )); #[allow(clippy::absurd_extreme_comparisons)] external.push(ExternalFile { diff --git a/src/hl/plist/file_access.rs b/src/hl/plist/file_access.rs index b8d6db75b..291785660 100644 --- a/src/hl/plist/file_access.rs +++ b/src/hl/plist/file_access.rs @@ -13,7 +13,7 @@ use std::fmt::{self, Debug}; use std::iter; use std::mem; use std::ops::Deref; -use std::ptr; +use std::ptr::{self, addr_of, addr_of_mut}; use bitflags::bitflags; @@ -1449,7 +1449,8 @@ impl FileAccessBuilder { h5try!(H5Pset_evict_on_close(id, hbool_t::from(v))); } if let Some(v) = self.mdc_image_config { - h5try!(H5Pset_mdc_image_config(id, &v.into() as *const _)); + let v = v.into(); + h5try!(H5Pset_mdc_image_config(id, addr_of!(v))); } } if let Some(v) = self.sieve_buf_size { @@ -1480,7 +1481,8 @@ impl FileAccessBuilder { } } if let Some(ref v) = self.mdc_config { - h5try!(H5Pset_mdc_config(id, &v.clone().into() as *const _)); + let v = v.clone().into(); + h5try!(H5Pset_mdc_config(id, addr_of!(v))); } Ok(()) } @@ -1516,7 +1518,7 @@ impl FileAccess { let mut drv = CoreDriver::default(); let mut increment: size_t = 0; let mut filebacked: hbool_t = 0; - h5try!(H5Pget_fapl_core(self.id(), &mut increment as *mut _, &mut filebacked as *mut _)); + h5try!(H5Pget_fapl_core(self.id(), addr_of_mut!(increment), addr_of_mut!(filebacked))); drv.increment = increment as _; drv.filebacked = filebacked > 0; #[cfg(feature = "1.8.13")] @@ -1525,8 +1527,8 @@ impl FileAccess { let mut page_size: size_t = 0; h5try!(H5Pget_core_write_tracking( self.id(), - &mut is_enabled as *mut _, - &mut page_size as *mut _, + addr_of_mut!(is_enabled), + addr_of_mut!(page_size), )); if is_enabled > 0 { drv.write_tracking = page_size; @@ -1558,7 +1560,7 @@ impl FileAccess { memb_fapl.as_mut_ptr(), memb_name.as_mut_ptr(), memb_addr.as_mut_ptr(), - &mut relax as *mut _, + addr_of_mut!(relax), )); let mut mapping: [u8; N] = unsafe { mem::zeroed() }; let mut layout = MultiLayout::default(); diff --git a/src/hl/selection.rs b/src/hl/selection.rs index 9f074aca4..ad7779cc5 100644 --- a/src/hl/selection.rs +++ b/src/hl/selection.rs @@ -24,6 +24,7 @@ unsafe fn get_points_selection(space_id: hid_t) -> Result> { let mut coords = vec![0; npoints * ndim]; h5check(H5Sget_select_elem_pointlist(space_id, 0, npoints as _, coords.as_mut_ptr()))?; let coords = if mem::size_of::() == mem::size_of::() { + #[allow(clippy::transmute_undefined_repr)] mem::transmute(coords) } else { coords.iter().map(|&x| x as _).collect() diff --git a/src/util.rs b/src/util.rs index 51b78e426..443b92cdd 100644 --- a/src/util.rs +++ b/src/util.rs @@ -21,7 +21,8 @@ pub fn to_cstring>(string: S) -> Result { /// Convert a fixed-length (possibly zero-terminated) char buffer to a string. pub fn string_from_fixed_bytes(bytes: &[c_char], len: usize) -> String { let len = bytes.iter().position(|&c| c == 0).unwrap_or(len); - let s = unsafe { str::from_utf8_unchecked(&*(&bytes[..len] as *const _ as *const _)) }; + let bytes = &bytes[..len]; + let s = unsafe { str::from_utf8_unchecked(&*(bytes as *const [c_char] as *const [u8])) }; s.to_owned() } From c45b716314734e292ecf2081793ab95cfa489d19 Mon Sep 17 00:00:00 2001 From: Magnus Ulimoen Date: Wed, 28 Sep 2022 21:01:47 +0200 Subject: [PATCH 4/7] Derive Eq where PartialEq --- hdf5-sys/src/h5.rs | 4 ++-- hdf5-sys/src/h5c.rs | 6 +++--- hdf5-sys/src/h5d.rs | 20 ++++++++++---------- hdf5-sys/src/h5e.rs | 4 ++-- hdf5-sys/src/h5f.rs | 14 +++++++------- hdf5-sys/src/h5fd.rs | 2 +- hdf5-sys/src/h5g.rs | 2 +- hdf5-sys/src/h5i.rs | 2 +- hdf5-sys/src/h5l.rs | 2 +- hdf5-sys/src/h5o.rs | 4 ++-- hdf5-sys/src/h5pl.rs | 2 +- hdf5-sys/src/h5r.rs | 4 ++-- hdf5-sys/src/h5s.rs | 6 +++--- hdf5-sys/src/h5t.rs | 28 ++++++++++++++-------------- hdf5-sys/src/h5z.rs | 6 +++--- hdf5-types/src/array.rs | 2 +- 16 files changed, 54 insertions(+), 54 deletions(-) diff --git a/hdf5-sys/src/h5.rs b/hdf5-sys/src/h5.rs index ba6bc5d48..4b6b2f10e 100644 --- a/hdf5-sys/src/h5.rs +++ b/hdf5-sys/src/h5.rs @@ -27,7 +27,7 @@ pub type hbool_t = u8; pub type hbool_t = c_uint; #[repr(C)] -#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub enum H5_iter_order_t { H5_ITER_UNKNOWN = -1, H5_ITER_INC = 0, @@ -37,7 +37,7 @@ pub enum H5_iter_order_t { } #[repr(C)] -#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub enum H5_index_t { H5_INDEX_UNKNOWN = -1, H5_INDEX_NAME = 0, diff --git a/hdf5-sys/src/h5c.rs b/hdf5-sys/src/h5c.rs index 8df09e70b..5c17bf407 100644 --- a/hdf5-sys/src/h5c.rs +++ b/hdf5-sys/src/h5c.rs @@ -4,21 +4,21 @@ pub use self::H5C_cache_flash_incr_mode::*; pub use self::H5C_cache_incr_mode::*; #[repr(C)] -#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub enum H5C_cache_incr_mode { H5C_incr__off = 0, H5C_incr__threshold = 1, } #[repr(C)] -#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub enum H5C_cache_flash_incr_mode { H5C_flash_incr__off = 0, H5C_flash_incr__add_space = 1, } #[repr(C)] -#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub enum H5C_cache_decr_mode { H5C_decr__off = 0, H5C_decr__threshold = 1, diff --git a/hdf5-sys/src/h5d.rs b/hdf5-sys/src/h5d.rs index d279367c8..8a72e452b 100644 --- a/hdf5-sys/src/h5d.rs +++ b/hdf5-sys/src/h5d.rs @@ -18,7 +18,7 @@ pub const H5D_CHUNK_CACHE_W0_DEFAULT: c_float = -1.0; #[cfg(not(feature = "1.10.0"))] #[repr(C)] -#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub enum H5D_layout_t { H5D_LAYOUT_ERROR = -1, H5D_COMPACT = 0, @@ -39,7 +39,7 @@ pub const H5D_CHUNK_BTREE: H5D_chunk_index_t = 0; pub const H5D_CHUNK_IDX_BTREE: H5D_chunk_index_t = H5D_CHUNK_BTREE; #[repr(C)] -#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub enum H5D_alloc_time_t { H5D_ALLOC_TIME_ERROR = -1, H5D_ALLOC_TIME_DEFAULT = 0, @@ -55,7 +55,7 @@ impl Default for H5D_alloc_time_t { } #[repr(C)] -#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub enum H5D_space_status_t { H5D_SPACE_STATUS_ERROR = -1, H5D_SPACE_STATUS_NOT_ALLOCATED = 0, @@ -64,7 +64,7 @@ pub enum H5D_space_status_t { } #[repr(C)] -#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub enum H5D_fill_time_t { H5D_FILL_TIME_ERROR = -1, H5D_FILL_TIME_ALLOC = 0, @@ -79,7 +79,7 @@ impl Default for H5D_fill_time_t { } #[repr(C)] -#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub enum H5D_fill_value_t { H5D_FILL_VALUE_ERROR = -1, H5D_FILL_VALUE_UNDEFINED = 0, @@ -94,7 +94,7 @@ impl Default for H5D_fill_value_t { } #[repr(C)] -#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub enum H5D_mpio_actual_chunk_opt_mode_t { H5D_MPIO_NO_CHUNK_OPTIMIZATION = 0, H5D_MPIO_LINK_CHUNK = 1, @@ -102,7 +102,7 @@ pub enum H5D_mpio_actual_chunk_opt_mode_t { } #[repr(C)] -#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub enum H5D_mpio_actual_io_mode_t { H5D_MPIO_NO_COLLECTIVE = 0, H5D_MPIO_CHUNK_INDEPENDENT = 1, @@ -112,7 +112,7 @@ pub enum H5D_mpio_actual_io_mode_t { } #[repr(C)] -#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub enum H5D_mpio_no_collective_cause_t { H5D_MPIO_COLLECTIVE = 0, H5D_MPIO_SET_INDEPENDENT = 1, @@ -218,7 +218,7 @@ mod hdf5_1_10_0 { use super::*; #[repr(C)] - #[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] + #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub enum H5D_layout_t { H5D_LAYOUT_ERROR = -1, H5D_COMPACT = 0, @@ -229,7 +229,7 @@ mod hdf5_1_10_0 { } #[repr(C)] - #[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] + #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub enum H5D_vds_view_t { H5D_VDS_ERROR = -1, H5D_VDS_FIRST_MISSING = 0, diff --git a/hdf5-sys/src/h5e.rs b/hdf5-sys/src/h5e.rs index 1ff4d8b9e..c7f38d97c 100644 --- a/hdf5-sys/src/h5e.rs +++ b/hdf5-sys/src/h5e.rs @@ -14,7 +14,7 @@ use crate::internal_prelude::*; pub const H5E_DEFAULT: hid_t = 0; #[repr(C)] -#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub enum H5E_type_t { H5E_MAJOR = 0, H5E_MINOR = 1, @@ -54,7 +54,7 @@ impl Default for H5E_error2_t { } #[repr(C)] -#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub enum H5E_direction_t { H5E_WALK_UPWARD = 0, H5E_WALK_DOWNWARD = 1, diff --git a/hdf5-sys/src/h5f.rs b/hdf5-sys/src/h5f.rs index 5f9096436..7bbeef9e3 100644 --- a/hdf5-sys/src/h5f.rs +++ b/hdf5-sys/src/h5f.rs @@ -47,14 +47,14 @@ pub const H5F_MPIO_DEBUG_KEY: &str = "H5F_mpio_debug_key"; pub const H5F_UNLIMITED: hsize_t = !0; #[repr(C)] -#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub enum H5F_scope_t { H5F_SCOPE_LOCAL = 0, H5F_SCOPE_GLOBAL = 1, } #[repr(C)] -#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub enum H5F_close_degree_t { H5F_CLOSE_DEFAULT = 0, H5F_CLOSE_WEAK = 1, @@ -97,7 +97,7 @@ impl Default for H5F_info1_t__sohm { } #[repr(C)] -#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub enum H5F_mem_t { H5FD_MEM_NOLIST = -1, H5FD_MEM_DEFAULT = 0, @@ -112,7 +112,7 @@ pub enum H5F_mem_t { #[cfg(not(feature = "1.10.2"))] #[repr(C)] -#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub enum H5F_libver_t { H5F_LIBVER_EARLIEST = 0, H5F_LIBVER_LATEST = 1, @@ -120,7 +120,7 @@ pub enum H5F_libver_t { #[cfg(feature = "1.10.2")] #[repr(C)] -#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub enum H5F_libver_t { H5F_LIBVER_ERROR = -1, H5F_LIBVER_EARLIEST = 0, @@ -297,7 +297,7 @@ mod hdf5_1_10_0 { Option herr_t>; #[repr(C)] - #[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] + #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub enum H5F_file_space_type_t { H5F_FILE_SPACE_DEFAULT = 0, H5F_FILE_SPACE_ALL_PERSIST = 1, @@ -341,7 +341,7 @@ mod hdf5_1_10_1 { use super::*; #[repr(C)] - #[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] + #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub enum H5F_fspace_strategy_t { H5F_FSPACE_STRATEGY_FSM_AGGR = 0, H5F_FSPACE_STRATEGY_PAGE = 1, diff --git a/hdf5-sys/src/h5fd.rs b/hdf5-sys/src/h5fd.rs index dfdc5bc34..f50e937d2 100644 --- a/hdf5-sys/src/h5fd.rs +++ b/hdf5-sys/src/h5fd.rs @@ -269,7 +269,7 @@ impl Default for H5FD_t { } #[repr(C)] -#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub enum H5FD_file_image_op_t { H5FD_FILE_IMAGE_OP_NO_OP = 0, H5FD_FILE_IMAGE_OP_PROPERTY_LIST_SET = 1, diff --git a/hdf5-sys/src/h5g.rs b/hdf5-sys/src/h5g.rs index f80b17c19..5554d99f4 100644 --- a/hdf5-sys/src/h5g.rs +++ b/hdf5-sys/src/h5g.rs @@ -26,7 +26,7 @@ pub const fn H5G_USERTYPE(X: c_uint) -> c_uint { } #[repr(C)] -#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub enum H5G_storage_type_t { H5G_STORAGE_TYPE_UNKNOWN = -1, H5G_STORAGE_TYPE_SYMBOL_TABLE = 0, diff --git a/hdf5-sys/src/h5i.rs b/hdf5-sys/src/h5i.rs index e9ed5a1c6..a4046df51 100644 --- a/hdf5-sys/src/h5i.rs +++ b/hdf5-sys/src/h5i.rs @@ -4,7 +4,7 @@ pub use self::H5I_type_t::*; use crate::internal_prelude::*; #[repr(C)] -#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub enum H5I_type_t { H5I_UNINIT = -2, H5I_BADID = -1, diff --git a/hdf5-sys/src/h5l.rs b/hdf5-sys/src/h5l.rs index c70d4fd9d..2d3d76feb 100644 --- a/hdf5-sys/src/h5l.rs +++ b/hdf5-sys/src/h5l.rs @@ -14,7 +14,7 @@ pub const H5L_SAME_LOC: hid_t = 0; pub const H5L_LINK_CLASS_T_VERS: c_uint = 0; #[repr(C)] -#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub enum H5L_type_t { H5L_TYPE_ERROR = -1, H5L_TYPE_HARD = 0, diff --git a/hdf5-sys/src/h5o.rs b/hdf5-sys/src/h5o.rs index eae91e04f..ad4fe0571 100644 --- a/hdf5-sys/src/h5o.rs +++ b/hdf5-sys/src/h5o.rs @@ -82,7 +82,7 @@ pub const H5O_NATIVE_INFO_META_SIZE: c_uint = 0x0010; pub const H5O_NATIVE_INFO_ALL: c_uint = H5O_NATIVE_INFO_HDR | H5O_NATIVE_INFO_META_SIZE; #[repr(C)] -#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub enum H5O_type_t { H5O_TYPE_UNKNOWN = -1, H5O_TYPE_GROUP, @@ -195,7 +195,7 @@ pub type H5O_iterate2_t = Option< >; #[repr(C)] -#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub enum H5O_mcdt_search_ret_t { H5O_MCDT_SEARCH_ERROR = -1, H5O_MCDT_SEARCH_CONT = 0, diff --git a/hdf5-sys/src/h5pl.rs b/hdf5-sys/src/h5pl.rs index 5bf9250e6..0015b2862 100644 --- a/hdf5-sys/src/h5pl.rs +++ b/hdf5-sys/src/h5pl.rs @@ -6,7 +6,7 @@ mod hdf5_1_8_15 { use super::*; #[repr(C)] - #[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] + #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub enum H5PL_type_t { H5PL_TYPE_ERROR = -1, H5PL_TYPE_FILTER = 0, diff --git a/hdf5-sys/src/h5r.rs b/hdf5-sys/src/h5r.rs index f1ac374e3..7964bcee9 100644 --- a/hdf5-sys/src/h5r.rs +++ b/hdf5-sys/src/h5r.rs @@ -11,7 +11,7 @@ use crate::h5g::H5G_obj_t; use crate::h5o::H5O_type_t; #[repr(C)] -#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] #[cfg(not(feature = "1.12.0"))] pub enum H5R_type_t { H5R_BADTYPE = -1, @@ -21,7 +21,7 @@ pub enum H5R_type_t { } #[repr(C)] -#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] #[cfg(feature = "1.12.0")] pub enum H5R_type_t { H5R_BADTYPE = -1, diff --git a/hdf5-sys/src/h5s.rs b/hdf5-sys/src/h5s.rs index ff9e9d7e7..5247f53a4 100644 --- a/hdf5-sys/src/h5s.rs +++ b/hdf5-sys/src/h5s.rs @@ -19,7 +19,7 @@ pub const H5S_SEL_ITER_GET_SEQ_LIST_SORTED: c_uint = 0x0001; pub const H5S_SEL_ITER_SHARE_WITH_DATASPACE: c_uint = 0x0002; #[repr(C)] -#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub enum H5S_class_t { H5S_NO_CLASS = -1, H5S_SCALAR = 0, @@ -28,7 +28,7 @@ pub enum H5S_class_t { } #[repr(C)] -#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub enum H5S_seloper_t { H5S_SELECT_NOOP = -1, H5S_SELECT_SET = 0, @@ -43,7 +43,7 @@ pub enum H5S_seloper_t { } #[repr(C)] -#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub enum H5S_sel_type { H5S_SEL_ERROR = -1, H5S_SEL_NONE = 0, diff --git a/hdf5-sys/src/h5t.rs b/hdf5-sys/src/h5t.rs index 97ed1f15e..4a702df89 100644 --- a/hdf5-sys/src/h5t.rs +++ b/hdf5-sys/src/h5t.rs @@ -22,7 +22,7 @@ pub use { use crate::internal_prelude::*; #[repr(C)] -#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub enum H5T_class_t { H5T_NO_CLASS = -1, H5T_INTEGER = 0, @@ -41,7 +41,7 @@ pub enum H5T_class_t { #[cfg(feature = "1.8.6")] #[repr(C)] -#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub enum H5T_order_t { H5T_ORDER_ERROR = -1, H5T_ORDER_LE = 0, @@ -53,7 +53,7 @@ pub enum H5T_order_t { #[cfg(not(feature = "1.8.6"))] #[repr(C)] -#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub enum H5T_order_t { H5T_ORDER_ERROR = -1, H5T_ORDER_LE = 0, @@ -63,7 +63,7 @@ pub enum H5T_order_t { } #[repr(C)] -#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub enum H5T_sign_t { H5T_SGN_ERROR = -1, H5T_SGN_NONE = 0, @@ -72,7 +72,7 @@ pub enum H5T_sign_t { } #[repr(C)] -#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub enum H5T_norm_t { H5T_NORM_ERROR = -1, H5T_NORM_IMPLIED = 0, @@ -81,7 +81,7 @@ pub enum H5T_norm_t { } #[repr(C)] -#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub enum H5T_cset_t { H5T_CSET_ERROR = -1, H5T_CSET_ASCII = 0, @@ -111,7 +111,7 @@ impl Default for H5T_cset_t { pub const H5T_NCSET: H5T_cset_t = H5T_CSET_RESERVED_2; #[repr(C)] -#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub enum H5T_str_t { H5T_STR_ERROR = -1, H5T_STR_NULLTERM = 0, @@ -135,7 +135,7 @@ pub enum H5T_str_t { pub const H5T_NSTR: H5T_str_t = H5T_STR_RESERVED_3; #[repr(C)] -#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub enum H5T_pad_t { H5T_PAD_ERROR = -1, H5T_PAD_ZERO = 0, @@ -145,7 +145,7 @@ pub enum H5T_pad_t { } #[repr(C)] -#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub enum H5T_cmd_t { H5T_CONV_INIT = 0, H5T_CONV_CONV = 1, @@ -153,7 +153,7 @@ pub enum H5T_cmd_t { } #[repr(C)] -#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub enum H5T_bkg_t { H5T_BKG_NO = 0, H5T_BKG_TEMP = 1, @@ -176,7 +176,7 @@ impl Default for H5T_cdata_t { } #[repr(C)] -#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub enum H5T_pers_t { H5T_PERS_DONTCARE = -1, H5T_PERS_HARD = 0, @@ -184,7 +184,7 @@ pub enum H5T_pers_t { } #[repr(C)] -#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub enum H5T_direction_t { H5T_DIR_DEFAULT = 0, H5T_DIR_ASCEND = 1, @@ -192,7 +192,7 @@ pub enum H5T_direction_t { } #[repr(C)] -#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub enum H5T_conv_except_t { H5T_CONV_EXCEPT_RANGE_HI = 0, H5T_CONV_EXCEPT_RANGE_LOW = 1, @@ -204,7 +204,7 @@ pub enum H5T_conv_except_t { } #[repr(C)] -#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub enum H5T_conv_ret_t { H5T_CONV_ABORT = -1, H5T_CONV_UNHANDLED = 0, diff --git a/hdf5-sys/src/h5z.rs b/hdf5-sys/src/h5z.rs index 823a91599..69ffbcd84 100644 --- a/hdf5-sys/src/h5z.rs +++ b/hdf5-sys/src/h5z.rs @@ -62,7 +62,7 @@ pub const H5Z_FILTER_CONFIG_ENCODE_ENABLED: c_uint = 0x0001; pub const H5Z_FILTER_CONFIG_DECODE_ENABLED: c_uint = 0x0002; #[repr(C)] -#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub enum H5Z_SO_scale_type_t { H5Z_SO_FLOAT_DSCALE = 0, H5Z_SO_FLOAT_ESCALE = 1, @@ -70,7 +70,7 @@ pub enum H5Z_SO_scale_type_t { } #[repr(C)] -#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub enum H5Z_EDC_t { H5Z_ERROR_EDC = -1, H5Z_DISABLE_EDC = 0, @@ -79,7 +79,7 @@ pub enum H5Z_EDC_t { } #[repr(C)] -#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub enum H5Z_cb_return_t { H5Z_CB_ERROR = -1, H5Z_CB_FAIL = 0, diff --git a/hdf5-types/src/array.rs b/hdf5-types/src/array.rs index 7eb300096..f5b8956c5 100644 --- a/hdf5-types/src/array.rs +++ b/hdf5-types/src/array.rs @@ -67,7 +67,7 @@ impl Drop for VarLenArray { impl Clone for VarLenArray { #[inline] fn clone(&self) -> Self { - Self::from_slice(&*self) + Self::from_slice(self) } } From e7d263f2e9ed4d5a34bcfde019bcd4161a89dd41 Mon Sep 17 00:00:00 2001 From: Magnus Ulimoen Date: Wed, 28 Sep 2022 21:17:21 +0200 Subject: [PATCH 5/7] Minor clippy lints --- hdf5-src/build.rs | 2 +- hdf5-sys/build.rs | 2 +- src/hl/file.rs | 2 +- src/hl/location.rs | 4 ++-- src/hl/plist/dataset_access.rs | 2 +- src/hl/plist/file_access.rs | 11 ++--------- src/util.rs | 2 +- 7 files changed, 9 insertions(+), 16 deletions(-) diff --git a/hdf5-src/build.rs b/hdf5-src/build.rs index 0ba8be70e..86d5d60f1 100644 --- a/hdf5-src/build.rs +++ b/hdf5-src/build.rs @@ -41,7 +41,7 @@ fn main() { let zlib_lib = "z"; cfg.define("HDF5_ENABLE_Z_LIB_SUPPORT", "ON") .define("H5_ZLIB_HEADER", &zlib_header) - .define("ZLIB_STATIC_LIBRARY", &zlib_lib); + .define("ZLIB_STATIC_LIBRARY", zlib_lib); println!("cargo:zlib_header={}", zlib_header.to_str().unwrap()); println!("cargo:zlib={}", zlib_lib); } diff --git a/hdf5-sys/build.rs b/hdf5-sys/build.rs index 6da3daa80..13d73b189 100644 --- a/hdf5-sys/build.rs +++ b/hdf5-sys/build.rs @@ -565,7 +565,7 @@ impl LibrarySearcher { } } } - let header = Header::parse(&inc_dir); + let header = Header::parse(inc_dir); if let Some(version) = self.version { assert_eq!(header.version, version, "HDF5 header version mismatch",); } diff --git a/src/hl/file.rs b/src/hl/file.rs index 6e7d1d9b7..ddd8b8f4f 100644 --- a/src/hl/file.rs +++ b/src/hl/file.rs @@ -50,7 +50,7 @@ impl ObjectClass for File { fn short_repr(&self) -> Option { let basename = match Path::new(&self.filename()).file_name() { Some(s) => s.to_string_lossy().into_owned(), - None => "".to_owned(), + None => String::new(), }; let mode = if self.is_read_only() { "read-only" } else { "read/write" }; Some(format!("\"{}\" ({})", basename, mode)) diff --git a/src/hl/location.rs b/src/hl/location.rs index e1dc154c9..82adea4f7 100644 --- a/src/hl/location.rs +++ b/src/hl/location.rs @@ -70,13 +70,13 @@ impl Location { /// have a name (e.g., an anonymous dataset). pub fn name(&self) -> String { // TODO: should this return Result or an empty string if it fails? - h5lock!(get_h5_str(|m, s| H5Iget_name(self.id(), m, s)).unwrap_or_else(|_| "".to_string())) + h5lock!(get_h5_str(|m, s| H5Iget_name(self.id(), m, s)).unwrap_or_else(|_| String::new())) } /// Returns the name of the file containing the named object (or the file itself). pub fn filename(&self) -> String { // TODO: should this return Result or an empty string if it fails? - h5lock!(get_h5_str(|m, s| H5Fget_name(self.id(), m, s)).unwrap_or_else(|_| "".to_string())) + h5lock!(get_h5_str(|m, s| H5Fget_name(self.id(), m, s)).unwrap_or_else(|_| String::new())) } /// Returns a handle to the file containing the named object (or the file itself). diff --git a/src/hl/plist/dataset_access.rs b/src/hl/plist/dataset_access.rs index 4f448c1dc..71b15ab50 100644 --- a/src/hl/plist/dataset_access.rs +++ b/src/hl/plist/dataset_access.rs @@ -271,7 +271,7 @@ impl DatasetAccess { #[cfg(feature = "1.8.17")] pub fn efile_prefix(&self) -> String { - self.get_efile_prefix().ok().unwrap_or_else(|| "".into()) + self.get_efile_prefix().ok().unwrap_or_default() } #[cfg(feature = "1.10.0")] diff --git a/src/hl/plist/file_access.rs b/src/hl/plist/file_access.rs index 291785660..1b5004794 100644 --- a/src/hl/plist/file_access.rs +++ b/src/hl/plist/file_access.rs @@ -702,7 +702,7 @@ impl Default for MetadataCacheConfig { rpt_fcn_enabled: false, open_trace_file: false, close_trace_file: false, - trace_file_name: "".into(), + trace_file_name: String::new(), evictions_enabled: true, set_initial_size: true, initial_size: 1 << 21, @@ -857,20 +857,13 @@ mod cache_image_config { pub use self::cache_image_config::*; #[cfg(feature = "1.10.0")] -#[derive(Clone, Debug, PartialEq, Eq)] +#[derive(Clone, Debug, Default, PartialEq, Eq)] pub struct CacheLogOptions { pub is_enabled: bool, pub location: String, pub start_on_access: bool, } -#[cfg(feature = "1.10.0")] -impl Default for CacheLogOptions { - fn default() -> Self { - Self { is_enabled: false, location: "".into(), start_on_access: false } - } -} - #[cfg(feature = "1.10.2")] mod libver { use super::*; diff --git a/src/util.rs b/src/util.rs index 443b92cdd..37b1bd316 100644 --- a/src/util.rs +++ b/src/util.rs @@ -63,7 +63,7 @@ where let len = 1_isize + (func(ptr::null_mut(), 0)).try_into().unwrap_or(-1); ensure!(len > 0, "negative string length in get_h5_str()"); if len == 1 { - Ok("".to_owned()) + Ok(String::new()) } else { let mut buf = vec![0; len as usize]; func(buf.as_mut_ptr(), len as _); From 67f80f0e33f16eefb4f723472357cca391117ffa Mon Sep 17 00:00:00 2001 From: Magnus Ulimoen Date: Wed, 28 Sep 2022 21:45:51 +0200 Subject: [PATCH 6/7] Change hdf5 download location in CI --- .github/workflows/ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6a2aef240..312531041 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -218,11 +218,11 @@ jobs: DL_PATH=hdf5-1.12.0-Std-win10_64-vs16.zip echo "MSI_PATH=hdf\\HDF5-1.12.0-win64.msi" >> $GITHUB_ENV else - VERSION=1.13.0 - DL_PATH=windows/hdf5-1.13.0-Std-win10_64-vs16.zip - echo "MSI_PATH=hdf\\HDF5-1.13.0-win64.msi" >> $GITHUB_ENV + VERSION=1.13.2 + DL_PATH=windows/hdf5-1.13.2-Std-win10_64-vs16.zip + echo "MSI_PATH=hdf\\HDF5-1.13.2-win64.msi" >> $GITHUB_ENV fi - BASE_URL=https://support.hdfgroup.org/ftp/HDF5/prev-releases + BASE_URL=https://support.hdfgroup.org/ftp/HDF5/releases echo "DL_URL=$BASE_URL/hdf5-${{matrix.version}}/hdf5-$VERSION/bin/$DL_PATH" >> $GITHUB_ENV echo "C:\\Program Files\\HDF_Group\\HDF5\\$VERSION\\bin" >> $GITHUB_PATH - name: Install HDF5 (${{matrix.version}}) From d58bcb9fa7f476adff4787718f3b99f241257c71 Mon Sep 17 00:00:00 2001 From: Magnus Ulimoen Date: Thu, 29 Sep 2022 10:47:53 +0200 Subject: [PATCH 7/7] Bump msrv (dependency req.) --- .github/workflows/ci.yml | 2 +- CHANGELOG.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 312531041..88a72e462 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -245,7 +245,7 @@ jobs: with: {submodules: true} - name: Install Rust uses: actions-rs/toolchain@v1 - with: {toolchain: 1.51, profile: minimal, override: true} + with: {toolchain: 1.54, profile: minimal, override: true} - name: Build and test all crates run: cargo test --workspace -vv --features=hdf5-sys/static --exclude=hdf5-derive diff --git a/CHANGELOG.md b/CHANGELOG.md index 6503a2cea..25bc7cc4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ ### Changed - The `H5Type` derive macro now uses `proc-macro-error` to emit error messages. +- MSRV is now `1.54` following a bump in a dependency. ### Fixed