From aa5591c4d64be76215bd27241a5c5b7d6ee34a01 Mon Sep 17 00:00:00 2001 From: bibin Date: Wed, 23 Aug 2023 16:28:54 -0400 Subject: [PATCH 1/3] fix type mismatch error for arm fix the formatting erros --- src/error.rs | 2 +- src/io.rs | 2 +- src/pack.rs | 19 ++++++++-------- src/record.rs | 62 +++++++++++++++++++++++++-------------------------- src/trace.rs | 48 ++++++++++++++++++++++----------------- src/util.rs | 23 ++++++++++++++----- 6 files changed, 87 insertions(+), 69 deletions(-) diff --git a/src/error.rs b/src/error.rs index ea62598..06a1f61 100644 --- a/src/error.rs +++ b/src/error.rs @@ -8,7 +8,7 @@ use crate::{raw, MSErrorCode, MSResult}; const MS_NOERROR: c_long = raw::MS_NOERROR as c_long; const MS_ENDOFFILE: c_long = raw::MS_ENDOFFILE as c_long; -const MS_NSTERROR: c_long = raw::NSTERROR; +const MS_NSTERROR: c_long = raw::NSTERROR as c_long; /// Utility function which turns a libmseed error into a result. pub(crate) fn check>(code: T) -> MSResult { diff --git a/src/io.rs b/src/io.rs index 3afe65d..c9d3dcb 100644 --- a/src/io.rs +++ b/src/io.rs @@ -266,7 +266,7 @@ impl MSWriter { Some(record_handler::), (&mut self.writer) as *mut _ as *mut c_void, max_rec_len, - encoding as c_char, + (encoding as c_char).try_into().unwrap(), ptr::null_mut(), flags.bits(), 0, diff --git a/src/pack.rs b/src/pack.rs index f30ee6d..942fb3c 100644 --- a/src/pack.rs +++ b/src/pack.rs @@ -68,15 +68,15 @@ where extra_ptr = cloned.into_raw(); } - let mut cnt_samples: c_long = 0; - let cnt_samples_ptr = &mut cnt_samples as *mut _; + let cnt_samples: c_long = 0; + let cnt_samples_ptr = &mut cnt_samples.into(); let cnt_records = unsafe { check(raw::mstl3_pack( mstl.get_raw_mut(), Some(rh_wrapper::), (&mut record_handler) as *mut _ as *mut c_void, info.rec_len, - info.encoding as c_char, + (info.encoding as c_char).try_into().unwrap(), cnt_samples_ptr, flags.bits(), 0, @@ -289,7 +289,7 @@ where unsafe { let sid_len = info.sid().as_bytes_with_nul().len(); ptr::copy_nonoverlapping(info.sid().as_ptr(), (*msr).sid.as_mut_ptr(), sid_len); - (*msr).encoding = info.encoding as c_char; + (*msr).encoding = (info.encoding as c_char).try_into().unwrap(); (*msr).sampletype = { use MSDataEncoding::*; match info.encoding { @@ -305,7 +305,8 @@ where (*msr).pubversion = info.pub_version; (*msr).formatversion = info.format_version; (*msr).numsamples = c_long::try_from(data_samples.len()) - .map_err(|e| MSError::from_str(&format!("invalid data sample length ({})", e)))?; + .map_err(|e| MSError::from_str(&format!("invalid data sample length ({})", e)))? + .into(); (*msr).datasamples = data_samples.as_mut_ptr() as *mut _ as *mut c_void; (*msr).datasize = mem::size_of_val(data_samples); (*msr).extralength = 0; @@ -321,8 +322,8 @@ where } } - let mut cnt_samples: c_long = 0; - let cnt_samples_ptr = &mut cnt_samples as *mut _; + let cnt_samples: c_long = 0; + let cnt_samples_ptr = &mut cnt_samples.into(); let cnt_records = unsafe { check(raw::msr3_pack( @@ -380,8 +381,8 @@ pub fn pack_record( where F: FnMut(&[u8]), { - let mut cnt_samples: c_long = 0; - let cnt_samples_ptr = &mut cnt_samples as *mut _; + let cnt_samples: c_long = 0; + let cnt_samples_ptr = &mut cnt_samples.into(); let cnt_records = unsafe { check(raw::msr3_pack( diff --git a/src/record.rs b/src/record.rs index 1ed1dfc..4299ca7 100644 --- a/src/record.rs +++ b/src/record.rs @@ -32,7 +32,7 @@ pub fn detect>(buf: T) -> MSResult { let rec_len = unsafe { check(raw::ms3_detect( buf.as_ptr() as *const _, - buf.len() as c_ulong, + (buf.len() as c_ulong).into(), format_version_ptr, )) }?; @@ -50,7 +50,7 @@ pub fn detect>(buf: T) -> MSResult { } /// An enumeration of possible sample types. -#[repr(i8)] +#[repr(u8)] #[derive(Debug, Eq, PartialEq, Copy, Clone)] pub enum MSSampleType { /// Unknown data sample type. @@ -67,7 +67,7 @@ pub enum MSSampleType { impl MSSampleType { /// Creates a `MSSampleType` from the given `ch`. - pub fn from_char(ch: c_char) -> Self { + pub fn from_char(ch: u8) -> Self { match ch { 116 => Self::Text, // t 105 => Self::Integer32, // i @@ -79,41 +79,41 @@ impl MSSampleType { } /// An enumeration of possible data encodings. -#[repr(i8)] +#[repr(u8)] #[derive(Debug, Eq, PartialEq, Copy, Clone)] pub enum MSDataEncoding { /// Text encoding (UTF-8) - Text = raw::DE_TEXT as c_char, + Text = raw::DE_TEXT as u8, /// 16-bit integer encoding - Integer16 = raw::DE_INT16 as c_char, + Integer16 = raw::DE_INT16 as u8, /// 32-bit integer encoding - Integer32 = raw::DE_INT32 as c_char, + Integer32 = raw::DE_INT32 as u8, /// 32-bit floating point encoding (IEEE) - Float32 = raw::DE_FLOAT32 as c_char, + Float32 = raw::DE_FLOAT32 as u8, /// 64-bit floating point encoding (IEEE) - Float64 = raw::DE_FLOAT64 as c_char, + Float64 = raw::DE_FLOAT64 as u8, /// Steim-1 compressed integer encoding - Steim1 = raw::DE_STEIM1 as c_char, + Steim1 = raw::DE_STEIM1 as u8, /// Steim-2 compressed integer encoding - Steim2 = raw::DE_STEIM2 as c_char, + Steim2 = raw::DE_STEIM2 as u8, /// **Legacy**: GEOSCOPE 24-bit integer encoding - GeoScope24 = raw::DE_GEOSCOPE24 as c_char, + GeoScope24 = raw::DE_GEOSCOPE24 as u8, /// **Legacy**: GEOSCOPE 16-bit gain ranged, 3-bit exponent - GeoScope163 = raw::DE_GEOSCOPE163 as c_char, + GeoScope163 = raw::DE_GEOSCOPE163 as u8, /// **Legacy**: GEOSCOPE 16-bit gain ranged, 4-bit exponent - GeoScope164 = raw::DE_GEOSCOPE164 as c_char, + GeoScope164 = raw::DE_GEOSCOPE164 as u8, /// **Legacy**: CDSN 16-bit gain ranged - CDSN = raw::DE_CDSN as c_char, + CDSN = raw::DE_CDSN as u8, /// **Legacy**: SRO 16-bit gain ranged - SRO = raw::DE_SRO as c_char, + SRO = raw::DE_SRO as u8, /// **Legacy**: DWWSSN 16-bit gain ranged - DWWSSN = raw::DE_DWWSSN as c_char, + DWWSSN = raw::DE_DWWSSN as u8, } impl MSDataEncoding { /// Create a `MSDataEncoding` from the given `ch`. - pub fn from_char(ch: c_char) -> MSResult { - match ch as c_uint { + pub fn from_char(ch: u8) -> MSResult { + match ch as u32 { raw::DE_TEXT => Ok(Self::Text), raw::DE_INT16 => Ok(Self::Integer16), raw::DE_INT32 => Ok(Self::Integer32), @@ -180,7 +180,7 @@ impl MSRecord { let buf = &*(buf as *const [_] as *const [c_char]); check(raw::msr3_parse( buf.as_ptr(), - buf.len() as c_ulong, + (buf.len() as c_ulong).into(), (&mut msr) as *mut *mut MS3Record, flags.bits(), 0, @@ -213,7 +213,7 @@ impl MSRecord { if !self.ptr().datasamples.is_null() { return Ok(self.num_samples()); } - unsafe { check(raw::msr3_unpack_data(self.0, 0)) } + unsafe { check(raw::msr3_unpack_data(self.0, 0).try_into().unwrap()) } } /// Returns the [FDSN source identifier](https://docs.fdsn.org/projects/source-identifiers/). @@ -224,7 +224,7 @@ impl MSRecord { /// Returns a lossy version of the [FDSN source identifier](https://docs.fdsn.org/projects/source-identifiers/). pub fn sid_lossy(&self) -> String { - util::i8_to_string(&(self.ptr().sid)) + util::to_string(&(self.ptr().sid)) } /// Returns the network code identifier of the record. @@ -278,12 +278,12 @@ impl MSRecord { /// Returns the start time of the record (i.e. the time of the first sample). pub fn start_time(&self) -> MSResult { - util::nstime_to_time(self.ptr().starttime) + util::nstime_to_time(self.ptr().starttime.try_into().unwrap()) } /// Calculates the end time of the last sample in the record. pub fn end_time(&self) -> MSResult { - unsafe { util::nstime_to_time(check_nst(raw::msr3_endtime(self.0))?) } + unsafe { util::nstime_to_time(check_nst(raw::msr3_endtime(self.0).try_into().unwrap())?) } } /// Returns the nominal sample rate as samples per second (`Hz`) @@ -293,7 +293,7 @@ impl MSRecord { /// Returns the data encoding format of the record. pub fn encoding(&self) -> MSResult { - MSDataEncoding::from_char(self.ptr().encoding) + MSDataEncoding::from_char(self.ptr().encoding as _) } /// Returns the record publication version. @@ -303,7 +303,7 @@ impl MSRecord { /// Returns the number of data samples as indicated by the raw record. pub fn sample_cnt(&self) -> c_long { - self.ptr().samplecnt + self.ptr().samplecnt.try_into().unwrap() } /// Returns the CRC of the record. @@ -352,17 +352,17 @@ impl MSRecord { /// Returns the number of (unpacked) data samples. pub fn num_samples(&self) -> c_long { - self.ptr().numsamples + self.ptr().numsamples.try_into().unwrap() } /// Returns the record sample type. pub fn sample_type(&self) -> MSSampleType { - MSSampleType::from_char(self.ptr().sampletype) + MSSampleType::from_char(self.ptr().sampletype as _) } /// Creates a new independently owned [`MSRecord`] from the underlying record. pub fn try_clone(&self) -> MSResult { - let rv = unsafe { raw::msr3_duplicate(self.0, true as i8) }; + let rv = unsafe { raw::msr3_duplicate(self.0, true as _) }; if rv.is_null() { return Err(MSError::from_str("failed to duplicate")); @@ -411,7 +411,7 @@ impl fmt::Display for MSRecord { v.samplecnt, self.sample_rate_hz(), util::nstime_to_string( - v.starttime, + v.starttime.try_into().unwrap(), MSTimeFormat::IsoMonthDayDoyZ, MSSubSeconds::NanoMicro ) @@ -470,7 +470,7 @@ impl fmt::Display for RecordDisplay<'_> { )?; let start_time = unsafe { (*self.rec.get_raw()).starttime }; let start_time = util::nstime_to_string( - start_time, + start_time.try_into().unwrap(), MSTimeFormat::IsoMonthDayDoyZ, MSSubSeconds::NanoMicro, ) diff --git a/src/trace.rs b/src/trace.rs index 8377f7a..057cebe 100644 --- a/src/trace.rs +++ b/src/trace.rs @@ -43,12 +43,12 @@ impl MSTraceId { /// Returns the time of the the first sample. pub fn start_time(&self) -> MSResult { - util::nstime_to_time(self.ptr().earliest) + util::nstime_to_time(self.ptr().earliest.try_into().unwrap()) } /// Returns the time of the the last sample. pub fn end_time(&self) -> MSResult { - util::nstime_to_time(self.ptr().latest) + util::nstime_to_time(self.ptr().latest.try_into().unwrap()) } /// Returns the number of [`MSTraceSegment`]s for this trace identifier. @@ -106,12 +106,12 @@ impl<'id> MSTraceSegment<'id> { /// Returns the time of the the first sample. pub fn start_time(&self) -> MSResult { - util::nstime_to_time(self.ptr().starttime) + util::nstime_to_time(self.ptr().starttime.try_into().unwrap()) } /// Returns the time of the the last sample. pub fn end_time(&self) -> MSResult { - util::nstime_to_time(self.ptr().endtime) + util::nstime_to_time(self.ptr().endtime.try_into().unwrap()) } /// Returns the nominal sample rate as samples per second (`Hz`) @@ -121,7 +121,7 @@ impl<'id> MSTraceSegment<'id> { /// Returns the number of samples in trace coverage. pub fn sample_cnt(&self) -> c_long { - self.ptr().samplecnt + self.ptr().samplecnt.try_into().unwrap() } /// Returns the data samples of the trace segment. @@ -151,12 +151,12 @@ impl<'id> MSTraceSegment<'id> { /// Returns the number of (unpacked) data samples. pub fn num_samples(&self) -> c_long { - self.ptr().numsamples + self.ptr().numsamples.try_into().unwrap() } /// Returns the trace segment sample type. pub fn sample_type(&self) -> MSSampleType { - MSSampleType::from_char(self.ptr().sampletype) + MSSampleType::from_char(self.ptr().sampletype as _) } /// Returns whether the data samples are unpacked. @@ -208,8 +208,8 @@ impl DataSampleType for c_int { let rv = unsafe { check(raw::mstl3_convertsamples( seg, - MSSampleType::Integer32 as i8, - truncate as i8, + MSSampleType::Integer32 as _, + truncate as _, )) }; @@ -225,8 +225,8 @@ impl DataSampleType for c_float { let rv = unsafe { check(raw::mstl3_convertsamples( seg, - MSSampleType::Float32 as i8, - truncate as i8, + MSSampleType::Float32 as _, + truncate as _, )) }; @@ -242,8 +242,8 @@ impl DataSampleType for c_double { let rv = unsafe { check(raw::mstl3_convertsamples( seg, - MSSampleType::Float64 as i8, - truncate as i8, + MSSampleType::Float64 as _, + truncate as _, )) }; @@ -390,7 +390,7 @@ impl MSTraceList { check(raw::mstl3_readbuffer( (&mut rv.get_raw_mut()) as *mut *mut _, buf.as_ptr(), - buf.len() as c_ulong, + (buf.len() as c_ulong).into(), 0, flags.bits(), ptr::null_mut(), @@ -430,7 +430,7 @@ impl MSTraceList { rec.into_raw(), ptr::null_mut(), 0, - autoheal as c_char, + (autoheal as c_char).try_into().unwrap(), MSControlFlags::empty().bits(), ptr::null_mut(), ) @@ -521,14 +521,20 @@ impl fmt::Display for TraceListDisplay<'_> { }; for tseg in tid.iter() { let start_time = unsafe { (*tseg.inner).starttime }; - let start_time_str = - util::nstime_to_string(start_time, self.time_format, MSSubSeconds::NanoMicro) - .map_err(|_| fmt::Error)?; + let start_time_str = util::nstime_to_string( + start_time.try_into().unwrap(), + self.time_format, + MSSubSeconds::NanoMicro, + ) + .map_err(|_| fmt::Error)?; let end_time = unsafe { (*tseg.inner).endtime }; - let end_time_str = - util::nstime_to_string(end_time, self.time_format, MSSubSeconds::NanoMicro) - .map_err(|_| fmt::Error)?; + let end_time_str = util::nstime_to_string( + end_time.try_into().unwrap(), + self.time_format, + MSSubSeconds::NanoMicro, + ) + .map_err(|_| fmt::Error)?; if self.gap > 0 { let mut gap: f64 = 0.0; diff --git a/src/util.rs b/src/util.rs index e670210..14e3042 100644 --- a/src/util.rs +++ b/src/util.rs @@ -73,7 +73,13 @@ pub fn nstime_to_time(nst: c_long) -> MSResult { let mut nsec = 0; unsafe { check(raw::ms_nstime2time( - nst, &mut year, &mut yday, &mut hour, &mut min, &mut sec, &mut nsec, + nst.into(), + &mut year, + &mut yday, + &mut hour, + &mut min, + &mut sec, + &mut nsec, ))? }; @@ -95,8 +101,13 @@ pub fn nstime_to_string( .unwrap() .into_raw(); unsafe { - if raw::ms_nstime2timestr(nst, time, time_format.as_raw(), subsecond_format.as_raw()) - .is_null() + if raw::ms_nstime2timestr( + nst.into(), + time, + time_format.as_raw(), + subsecond_format.as_raw(), + ) + .is_null() { return Err(MSError::from_str("failed to convert nstime to string")); } @@ -109,8 +120,8 @@ pub fn time_to_nstime(t: &time::OffsetDateTime) -> i64 { t.unix_timestamp() } -/// Utility function safely converting a slice of `i8` values into a `String`. -pub(crate) fn i8_to_string(buf: &[i8]) -> String { +/// Utility function safely converting a slice of `c_char` values into a `String`. +pub(crate) fn to_string(buf: &[c_char]) -> String { let v: Vec = buf .iter() .map(|x| *x as u8) // cast i8 as u8 @@ -139,7 +150,7 @@ impl NetStaLocCha { pub fn from_sid(sid: &[c_char]) -> MSResult { let s0 = " "; let s1 = " "; - let sid = CString::new(i8_to_string(sid)).unwrap().into_raw(); + let sid = CString::new(to_string(sid)).unwrap().into_raw(); let xnet = CString::new(s0).unwrap().into_raw(); let xsta = CString::new(s0).unwrap().into_raw(); let xloc = CString::new(s0).unwrap().into_raw(); From 2f773b2fe94877d03104103914f828aa3880ae89 Mon Sep 17 00:00:00 2001 From: bibin Date: Thu, 24 Aug 2023 13:06:39 -0400 Subject: [PATCH 2/3] avoid typecasting twice and use as _ fix formatting error --- src/io.rs | 2 +- src/pack.rs | 12 ++++++------ src/record.rs | 20 ++++++++++---------- src/trace.rs | 22 +++++++++++----------- src/util.rs | 10 ++-------- 5 files changed, 30 insertions(+), 36 deletions(-) diff --git a/src/io.rs b/src/io.rs index c9d3dcb..1ec7bbe 100644 --- a/src/io.rs +++ b/src/io.rs @@ -266,7 +266,7 @@ impl MSWriter { Some(record_handler::), (&mut self.writer) as *mut _ as *mut c_void, max_rec_len, - (encoding as c_char).try_into().unwrap(), + encoding as _, ptr::null_mut(), flags.bits(), 0, diff --git a/src/pack.rs b/src/pack.rs index 942fb3c..e4f12f1 100644 --- a/src/pack.rs +++ b/src/pack.rs @@ -69,14 +69,14 @@ where } let cnt_samples: c_long = 0; - let cnt_samples_ptr = &mut cnt_samples.into(); + let cnt_samples_ptr = (&mut cnt_samples.into()) as *mut _; let cnt_records = unsafe { check(raw::mstl3_pack( mstl.get_raw_mut(), Some(rh_wrapper::), (&mut record_handler) as *mut _ as *mut c_void, info.rec_len, - (info.encoding as c_char).try_into().unwrap(), + info.encoding as _, cnt_samples_ptr, flags.bits(), 0, @@ -289,7 +289,7 @@ where unsafe { let sid_len = info.sid().as_bytes_with_nul().len(); ptr::copy_nonoverlapping(info.sid().as_ptr(), (*msr).sid.as_mut_ptr(), sid_len); - (*msr).encoding = (info.encoding as c_char).try_into().unwrap(); + (*msr).encoding = info.encoding as _; (*msr).sampletype = { use MSDataEncoding::*; match info.encoding { @@ -306,7 +306,7 @@ where (*msr).formatversion = info.format_version; (*msr).numsamples = c_long::try_from(data_samples.len()) .map_err(|e| MSError::from_str(&format!("invalid data sample length ({})", e)))? - .into(); + as _; (*msr).datasamples = data_samples.as_mut_ptr() as *mut _ as *mut c_void; (*msr).datasize = mem::size_of_val(data_samples); (*msr).extralength = 0; @@ -323,7 +323,7 @@ where } let cnt_samples: c_long = 0; - let cnt_samples_ptr = &mut cnt_samples.into(); + let cnt_samples_ptr = (&mut cnt_samples.into()) as *mut _; let cnt_records = unsafe { check(raw::msr3_pack( @@ -382,7 +382,7 @@ where F: FnMut(&[u8]), { let cnt_samples: c_long = 0; - let cnt_samples_ptr = &mut cnt_samples.into(); + let cnt_samples_ptr = (&mut cnt_samples.into()) as *mut _; let cnt_records = unsafe { check(raw::msr3_pack( diff --git a/src/record.rs b/src/record.rs index 4299ca7..cab4023 100644 --- a/src/record.rs +++ b/src/record.rs @@ -1,4 +1,4 @@ -use std::ffi::{c_char, c_double, c_long, c_uchar, c_uint, c_ulong, c_ushort, CStr}; +use std::ffi::{c_char, c_double, c_long, c_uchar, c_uint, c_ushort, CStr}; use std::fmt; use std::ptr; use std::slice::from_raw_parts; @@ -32,7 +32,7 @@ pub fn detect>(buf: T) -> MSResult { let rec_len = unsafe { check(raw::ms3_detect( buf.as_ptr() as *const _, - (buf.len() as c_ulong).into(), + buf.len() as _, format_version_ptr, )) }?; @@ -180,7 +180,7 @@ impl MSRecord { let buf = &*(buf as *const [_] as *const [c_char]); check(raw::msr3_parse( buf.as_ptr(), - (buf.len() as c_ulong).into(), + buf.len() as _, (&mut msr) as *mut *mut MS3Record, flags.bits(), 0, @@ -213,7 +213,7 @@ impl MSRecord { if !self.ptr().datasamples.is_null() { return Ok(self.num_samples()); } - unsafe { check(raw::msr3_unpack_data(self.0, 0).try_into().unwrap()) } + unsafe { check(raw::msr3_unpack_data(self.0, 0) as _) } } /// Returns the [FDSN source identifier](https://docs.fdsn.org/projects/source-identifiers/). @@ -278,12 +278,12 @@ impl MSRecord { /// Returns the start time of the record (i.e. the time of the first sample). pub fn start_time(&self) -> MSResult { - util::nstime_to_time(self.ptr().starttime.try_into().unwrap()) + util::nstime_to_time(self.ptr().starttime as _) } /// Calculates the end time of the last sample in the record. pub fn end_time(&self) -> MSResult { - unsafe { util::nstime_to_time(check_nst(raw::msr3_endtime(self.0).try_into().unwrap())?) } + unsafe { util::nstime_to_time(check_nst(raw::msr3_endtime(self.0) as _)?) } } /// Returns the nominal sample rate as samples per second (`Hz`) @@ -303,7 +303,7 @@ impl MSRecord { /// Returns the number of data samples as indicated by the raw record. pub fn sample_cnt(&self) -> c_long { - self.ptr().samplecnt.try_into().unwrap() + self.ptr().samplecnt as _ } /// Returns the CRC of the record. @@ -352,7 +352,7 @@ impl MSRecord { /// Returns the number of (unpacked) data samples. pub fn num_samples(&self) -> c_long { - self.ptr().numsamples.try_into().unwrap() + self.ptr().numsamples as _ } /// Returns the record sample type. @@ -411,7 +411,7 @@ impl fmt::Display for MSRecord { v.samplecnt, self.sample_rate_hz(), util::nstime_to_string( - v.starttime.try_into().unwrap(), + v.starttime as _, MSTimeFormat::IsoMonthDayDoyZ, MSSubSeconds::NanoMicro ) @@ -470,7 +470,7 @@ impl fmt::Display for RecordDisplay<'_> { )?; let start_time = unsafe { (*self.rec.get_raw()).starttime }; let start_time = util::nstime_to_string( - start_time.try_into().unwrap(), + start_time as _, MSTimeFormat::IsoMonthDayDoyZ, MSSubSeconds::NanoMicro, ) diff --git a/src/trace.rs b/src/trace.rs index 057cebe..1c103ea 100644 --- a/src/trace.rs +++ b/src/trace.rs @@ -1,4 +1,4 @@ -use std::ffi::{c_char, c_double, c_float, c_int, c_long, c_uchar, c_uint, c_ulong}; +use std::ffi::{c_double, c_float, c_int, c_long, c_uchar, c_uint}; use std::fmt; use std::ptr; use std::slice::from_raw_parts; @@ -43,12 +43,12 @@ impl MSTraceId { /// Returns the time of the the first sample. pub fn start_time(&self) -> MSResult { - util::nstime_to_time(self.ptr().earliest.try_into().unwrap()) + util::nstime_to_time(self.ptr().earliest as _) } /// Returns the time of the the last sample. pub fn end_time(&self) -> MSResult { - util::nstime_to_time(self.ptr().latest.try_into().unwrap()) + util::nstime_to_time(self.ptr().latest as _) } /// Returns the number of [`MSTraceSegment`]s for this trace identifier. @@ -106,12 +106,12 @@ impl<'id> MSTraceSegment<'id> { /// Returns the time of the the first sample. pub fn start_time(&self) -> MSResult { - util::nstime_to_time(self.ptr().starttime.try_into().unwrap()) + util::nstime_to_time(self.ptr().starttime as _) } /// Returns the time of the the last sample. pub fn end_time(&self) -> MSResult { - util::nstime_to_time(self.ptr().endtime.try_into().unwrap()) + util::nstime_to_time(self.ptr().endtime as _) } /// Returns the nominal sample rate as samples per second (`Hz`) @@ -121,7 +121,7 @@ impl<'id> MSTraceSegment<'id> { /// Returns the number of samples in trace coverage. pub fn sample_cnt(&self) -> c_long { - self.ptr().samplecnt.try_into().unwrap() + self.ptr().samplecnt as _ } /// Returns the data samples of the trace segment. @@ -151,7 +151,7 @@ impl<'id> MSTraceSegment<'id> { /// Returns the number of (unpacked) data samples. pub fn num_samples(&self) -> c_long { - self.ptr().numsamples.try_into().unwrap() + self.ptr().numsamples as _ } /// Returns the trace segment sample type. @@ -390,7 +390,7 @@ impl MSTraceList { check(raw::mstl3_readbuffer( (&mut rv.get_raw_mut()) as *mut *mut _, buf.as_ptr(), - (buf.len() as c_ulong).into(), + buf.len() as _, 0, flags.bits(), ptr::null_mut(), @@ -430,7 +430,7 @@ impl MSTraceList { rec.into_raw(), ptr::null_mut(), 0, - (autoheal as c_char).try_into().unwrap(), + autoheal as _, MSControlFlags::empty().bits(), ptr::null_mut(), ) @@ -522,7 +522,7 @@ impl fmt::Display for TraceListDisplay<'_> { for tseg in tid.iter() { let start_time = unsafe { (*tseg.inner).starttime }; let start_time_str = util::nstime_to_string( - start_time.try_into().unwrap(), + start_time as _, self.time_format, MSSubSeconds::NanoMicro, ) @@ -530,7 +530,7 @@ impl fmt::Display for TraceListDisplay<'_> { let end_time = unsafe { (*tseg.inner).endtime }; let end_time_str = util::nstime_to_string( - end_time.try_into().unwrap(), + end_time as _, self.time_format, MSSubSeconds::NanoMicro, ) diff --git a/src/util.rs b/src/util.rs index 14e3042..f8580cf 100644 --- a/src/util.rs +++ b/src/util.rs @@ -73,13 +73,7 @@ pub fn nstime_to_time(nst: c_long) -> MSResult { let mut nsec = 0; unsafe { check(raw::ms_nstime2time( - nst.into(), - &mut year, - &mut yday, - &mut hour, - &mut min, - &mut sec, - &mut nsec, + nst as _, &mut year, &mut yday, &mut hour, &mut min, &mut sec, &mut nsec, ))? }; @@ -102,7 +96,7 @@ pub fn nstime_to_string( .into_raw(); unsafe { if raw::ms_nstime2timestr( - nst.into(), + nst as _, time, time_format.as_raw(), subsecond_format.as_raw(), From d1ae718a5d82207927d66d52692b351f6f820e05 Mon Sep 17 00:00:00 2001 From: bibin Date: Thu, 24 Aug 2023 16:08:10 -0400 Subject: [PATCH 3/3] fix complier error: casting `&mut i32` as `*mut i64` is invalid --- src/pack.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/pack.rs b/src/pack.rs index e4f12f1..ddd52ec 100644 --- a/src/pack.rs +++ b/src/pack.rs @@ -68,8 +68,8 @@ where extra_ptr = cloned.into_raw(); } - let cnt_samples: c_long = 0; - let cnt_samples_ptr = (&mut cnt_samples.into()) as *mut _; + let mut cnt_samples: i64 = 0; + let cnt_samples_ptr: *mut i64 = &mut cnt_samples; let cnt_records = unsafe { check(raw::mstl3_pack( mstl.get_raw_mut(), @@ -322,8 +322,8 @@ where } } - let cnt_samples: c_long = 0; - let cnt_samples_ptr = (&mut cnt_samples.into()) as *mut _; + let mut cnt_samples: i64 = 0; + let cnt_samples_ptr: *mut i64 = &mut cnt_samples; let cnt_records = unsafe { check(raw::msr3_pack( @@ -381,8 +381,8 @@ pub fn pack_record( where F: FnMut(&[u8]), { - let cnt_samples: c_long = 0; - let cnt_samples_ptr = (&mut cnt_samples.into()) as *mut _; + let mut cnt_samples: i64 = 0; + let cnt_samples_ptr: *mut i64 = &mut cnt_samples; let cnt_records = unsafe { check(raw::msr3_pack(