Skip to content

Commit

Permalink
Ensure code compiles and tests pass
Browse files Browse the repository at this point in the history
This mostly revolved around changing pointer types which were hard coded
to cast to libc::c_void, whereas in `fitsio-sys-bindgen` they were
`std::os::raw::c_void`. By using a wildcard cast (`_`) the code
automatically casts to the correct value for both libraries.

The other change was to move `MAX_VALUE_LENGTH` to `fitsio` rather than
the low level library.
  • Loading branch information
simonrw committed May 7, 2017
1 parent fef61b2 commit 7d48bf3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
2 changes: 0 additions & 2 deletions fitsio-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ extern crate libc;

use self::libc::*;

pub static MAX_VALUE_LENGTH: usize = 71;

pub type LONGLONG = c_longlong;

#[repr(C)]
Expand Down
14 changes: 10 additions & 4 deletions fitsio/src/fitsfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ use std::ffi;
use std::ptr;
use std::ops::Range;

pub static MAX_VALUE_LENGTH: usize = 71;

/// Macro to return a fits error if the fits file is not open in readwrite mode
macro_rules! fits_check_readwrite {
($fitsfile: expr) => (
Expand Down Expand Up @@ -755,7 +757,7 @@ impl ReadsKey for String {
fn read_key(f: &FitsFile, name: &str) -> FitsResult<Self> {
let c_name = ffi::CString::new(name).unwrap();
let mut status = 0;
let mut value: Vec<libc::c_char> = vec![0; sys::MAX_VALUE_LENGTH];
let mut value: Vec<libc::c_char> = vec![0; MAX_VALUE_LENGTH];

unsafe {
sys::ffgkys(f.fptr as *mut _,
Expand Down Expand Up @@ -908,7 +910,7 @@ macro_rules! read_write_image_impl {
(start + 1) as i64,
nelements as i64,
ptr::null_mut(),
out.as_mut_ptr() as *mut libc::c_void,
out.as_mut_ptr() as *mut _,
ptr::null_mut(),
&mut status);
}
Expand Down Expand Up @@ -984,7 +986,7 @@ macro_rules! read_write_image_impl {
lpixel.as_mut_ptr(),
inc.as_mut_ptr(),
ptr::null_mut(),
out.as_mut_ptr() as *mut libc::c_void,
out.as_mut_ptr() as *mut _,
ptr::null_mut(),
&mut status);

Expand Down Expand Up @@ -1051,7 +1053,7 @@ macro_rules! read_write_image_impl {
$data_type.into(),
fpixel.as_mut_ptr(),
lpixel.as_mut_ptr(),
data.as_ptr() as *mut libc::c_void,
data.as_ptr() as *mut _,
&mut status);
}

Expand Down Expand Up @@ -1376,7 +1378,11 @@ impl<'open> FitsHdu<'open> {

#[cfg(test)]
mod test {
#[cfg(feature = "default")]
extern crate fitsio_sys as sys;
#[cfg(feature = "bindgen")]
extern crate fitsio_sys_bindgen as sys;

extern crate tempdir;

use FitsHdu;
Expand Down
5 changes: 4 additions & 1 deletion fitsio/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@
//!
//! ```rust
//! # extern crate fitsio;
//! # extern crate fitsio_sys;
//! #[cfg(feature = "default")]
//! # extern crate fitsio_sys as sys;
//! #[cfg(feature = "bindgen")]
//! # extern crate fitsio_sys_bindgen as sys;
//! # use fitsio::{FitsFile, HduInfo};
//! #
//! # fn main() {
Expand Down

0 comments on commit 7d48bf3

Please sign in to comment.