Skip to content

Commit af6e89e

Browse files
chrsoosimonrw
authored andcommitted
#374 fixed cros-platform issues related to FFI
1 parent 8ceb6fe commit af6e89e

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

fitsio/src/hdu.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,7 @@ pub struct CardIter {
10831083

10841084
impl CardIter {
10851085
fn new(file: &mut FitsFile, hdu: &FitsHdu) -> Result<CardIter> {
1086-
file.make_current(&hdu)?;
1086+
file.make_current(hdu)?;
10871087

10881088
let mut iter = CardIter {
10891089
fptr: unsafe { file.as_raw() },
@@ -1113,17 +1113,17 @@ impl CardIter {
11131113
}
11141114
fn next_header(&mut self) -> Result<Card> {
11151115
self.status = 0; // reset the status before calling
1116-
let mut card = Card::new();
1116+
let mut card = Card::default();
11171117
unsafe {
11181118
ffgkyn(
11191119
self.fptr,
11201120
self.current,
11211121
// self.name.as_mut_ptr(),
11221122
// self.value.as_mut_ptr(),
11231123
// self.comment.as_mut_ptr(),
1124-
card.name.as_mut_ptr(),
1125-
card.value.as_mut_ptr(),
1126-
card.comment.as_mut_ptr(),
1124+
card.name.as_mut_ptr() as *mut c_char,
1125+
card.value.as_mut_ptr() as *mut c_char,
1126+
card.comment.as_mut_ptr() as *mut c_char,
11271127
ptr::addr_of_mut!(self.status)
11281128
)
11291129
};
@@ -1143,7 +1143,7 @@ impl Iterator for CardIter {
11431143
match self.next_header() {
11441144
Ok(card) => Some(card),
11451145
Err(e) => {
1146-
let mut card = Card::new();
1146+
let mut card = Card::default();
11471147
card.set_comment(format!("{e}"));
11481148
Some(card)
11491149
},

fitsio/src/headers/card.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use fitsio_sys::{FLEN_COMMENT, FLEN_KEYWORD, FLEN_VALUE};
44

55
use crate::errors::Result;
6-
use std::ffi::CStr;
6+
use std::ffi::{c_char, CStr};
77

88
/// Wraps a single header card
99
#[derive(Debug)]
@@ -14,28 +14,19 @@ pub struct Card {
1414
}
1515

1616
impl Card {
17-
/// Create a new empty card.
18-
pub fn new() -> Card {
19-
Card {
20-
name: [0i8;FLEN_KEYWORD as usize],
21-
value: [0i8;FLEN_VALUE as usize],
22-
comment: [0i8;FLEN_COMMENT as usize],
23-
}
24-
}
25-
2617
/// Header keyword.
2718
pub fn name(&self) -> Result<&str> {
28-
Ok(unsafe { CStr::from_ptr(self.name.as_ptr()) }.to_str()?)
19+
Ok(unsafe { CStr::from_ptr(self.name.as_ptr() as *mut c_char) }.to_str()?)
2920
}
3021

3122
/// Header comment.
3223
pub fn comment(&self) -> Result<&str> {
33-
Ok(unsafe { CStr::from_ptr(self.comment.as_ptr()) }.to_str()?)
24+
Ok(unsafe { CStr::from_ptr(self.comment.as_ptr() as *mut c_char) }.to_str()?)
3425
}
3526

3627
/// Header value as a &str.
3728
pub fn str_value(&self) -> Result<&str> {
38-
Ok(unsafe { CStr::from_ptr(self.value.as_ptr()) }.to_str()?)
29+
Ok(unsafe { CStr::from_ptr(self.value.as_ptr() as *mut c_char) }.to_str()?)
3930
}
4031

4132
pub(crate) fn set_comment(&mut self, comment: String) {
@@ -50,3 +41,13 @@ impl Card {
5041
}
5142
}
5243
}
44+
45+
impl Default for Card {
46+
fn default() -> Self {
47+
Card {
48+
name: [0i8;FLEN_KEYWORD as usize],
49+
value: [0i8;FLEN_VALUE as usize],
50+
comment: [0i8;FLEN_COMMENT as usize],
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)