Skip to content

Commit

Permalink
fix type mismatch error for arm
Browse files Browse the repository at this point in the history
  • Loading branch information
bibin committed Aug 23, 2023
1 parent 6d8d3e0 commit af8665f
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 64 deletions.
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: PartialOrd + AsPrimitive<c_long>>(code: T) -> MSResult<T> {
Expand Down
2 changes: 1 addition & 1 deletion src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ impl<W: Write> MSWriter<W> {
Some(record_handler::<W>),
(&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,
Expand Down
18 changes: 9 additions & 9 deletions src/pack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<F>),
(&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,
Expand Down Expand Up @@ -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 {
Expand All @@ -305,7 +305,7 @@ 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;
Expand All @@ -321,8 +321,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(
Expand Down Expand Up @@ -380,8 +380,8 @@ pub fn pack_record<F>(
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(
Expand Down
62 changes: 31 additions & 31 deletions src/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub fn detect<T: AsRef<[u8]>>(buf: T) -> MSResult<RecordDetection> {
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,
))
}?;
Expand All @@ -50,7 +50,7 @@ pub fn detect<T: AsRef<[u8]>>(buf: T) -> MSResult<RecordDetection> {
}

/// An enumeration of possible sample types.
#[repr(i8)]
#[repr(u8)]
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
pub enum MSSampleType {
/// Unknown data sample type.
Expand All @@ -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
Expand All @@ -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<Self> {
match ch as c_uint {
pub fn from_char(ch: u8) -> MSResult<Self> {
match ch as u32 {
raw::DE_TEXT => Ok(Self::Text),
raw::DE_INT16 => Ok(Self::Integer16),
raw::DE_INT32 => Ok(Self::Integer32),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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/).
Expand All @@ -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.
Expand Down Expand Up @@ -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<time::OffsetDateTime> {
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<time::OffsetDateTime> {
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`)
Expand All @@ -293,7 +293,7 @@ impl MSRecord {

/// Returns the data encoding format of the record.
pub fn encoding(&self) -> MSResult<MSDataEncoding> {
MSDataEncoding::from_char(self.ptr().encoding)
MSDataEncoding::from_char(self.ptr().encoding as _)
}

/// Returns the record publication version.
Expand All @@ -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.
Expand Down Expand Up @@ -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<Self> {
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"));
Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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,
)
Expand Down
34 changes: 17 additions & 17 deletions src/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ impl MSTraceId {

/// Returns the time of the the first sample.
pub fn start_time(&self) -> MSResult<OffsetDateTime> {
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<OffsetDateTime> {
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.
Expand Down Expand Up @@ -106,12 +106,12 @@ impl<'id> MSTraceSegment<'id> {

/// Returns the time of the the first sample.
pub fn start_time(&self) -> MSResult<OffsetDateTime> {
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<OffsetDateTime> {
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`)
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 _,
))
};

Expand All @@ -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 _,
))
};

Expand All @@ -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 _,
))
};

Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
)
Expand Down Expand Up @@ -522,12 +522,12 @@ 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)
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)
util::nstime_to_string(end_time.try_into().unwrap(), self.time_format, MSSubSeconds::NanoMicro)
.map_err(|_| fmt::Error)?;

if self.gap > 0 {
Expand Down
Loading

0 comments on commit af8665f

Please sign in to comment.