-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
msys2 cannot find cfitsio version #198
Comments
@art-den: if you run |
New error now
|
This is in your code right? Windows uses.32-bit pointers even on 64-bit systems, or at least cfitsio does. Can you change the |
int ffomem
(fitsfile **fptr, const char *filename, int mode, void **memptr,
size_t *memsize, size_t deltasize,
void *(*mem_realloc)(void *p, size_t newsize), int *status)
|
Edit: my misunderstanding, I'm wrong about this, but my next comment is right |
Right: I found out why this is happening. It's not the size of a pointer, it's the size of a use fitsio_sys::size_t;
fn main() {
dbg!(std::mem::size_of::<libc::c_int>());
dbg!(std::mem::size_of::<libc::size_t>());
dbg!(std::mem::size_of::<libc::c_long>());
dbg!(std::mem::size_of::<*mut libc::size_t>());
dbg!(std::mem::size_of::<usize>());
dbg!(std::mem::size_of::<size_t>());
dbg!(std::mem::size_of::<*mut size_t>());
} On windows this prints
On linux this prints
The differences being $ diff /tmp/windows.txt /tmp/linux.txt
3c3
< std::mem::size_of::<libc::c_long>() = 4
---
> std::mem::size_of::<libc::c_long>() = 8
6c6
< std::mem::size_of::<size_t>() = 4
---
> std::mem::size_of::<size_t>() = 8 This explains why you are experiencing a difference on windows. You can probably cast the |
Yes, if to change your example to let (bytes, mut ptr_size) = {
let filename = "../testdata/full_example.fits";
let mut f = std::fs::File::open(filename).unwrap();
let mut bytes = Vec::new();
let num_bytes = f.read_to_end(&mut bytes).unwrap();
(bytes, num_bytes as sys::size_t) // <---here. Not good if FITS file is larger than 4 GB
};
let mut ptr = bytes.as_ptr();
let mut fptr = std::ptr::null_mut();
let mut status = 0;
let c_filename = std::ffi::CString::new("full_example.fits").unwrap();
unsafe {
sys::ffomem(
&mut fptr as *mut *mut _,
c_filename.as_ptr(),
sys::READONLY as _,
&mut ptr as *const _ as *mut *mut libc::c_void,
&mut ptr_size as *mut sys::size_t, // <---here
0,
None,
&mut status,
);
} it compiles but I see link error too |
|
In the short term I can get around the link error by calling To be clear, I'm using this code: // `fitsio` does not currently support opening files from memory, `cfitsio` _does_. This means we
// can use `Fitsfile::from_raw` to load a `FitsFile` from a file that was opened via
// `fits_open_memfile` in `cfitsio`.
use fitsio::errors::check_status;
use fitsio::{sys, FileOpenMode, FitsFile};
use std::io::Read;
fn main() {
// read the bytes into memory and return a pointer and length to the file
let (bytes, mut ptr_size) = {
let filename = "./testdata/full_example.fits";
let mut f = std::fs::File::open(filename).unwrap();
let mut bytes = Vec::new();
let num_bytes = f.read_to_end(&mut bytes).unwrap();
(bytes, num_bytes as u32)
};
let mut ptr = bytes.as_ptr();
// now we have a pointer to the data, let's open this in `fitsio_sys`
let mut fptr = std::ptr::null_mut();
let mut status = 0;
let c_filename = std::ffi::CString::new("full_example.fits").unwrap();
unsafe {
sys::ffomem(
&mut fptr as *mut *mut _,
c_filename.as_ptr(),
sys::READONLY as _,
&mut ptr as *const _ as *mut *mut libc::c_void,
&mut ptr_size as *mut u32,
0,
None,
&mut status,
);
}
check_status(status).unwrap();
let mut f = unsafe { FitsFile::from_raw(fptr, FileOpenMode::READONLY) }.unwrap();
f.pretty_print().expect("pretty printing fits file");
} |
Er... it's inconsistent. I can run the code multiple times and get different answers 🤦 That's going to be really hard to debug on windows (for me anyway)! |
Another option for you could be to use the fitsio = { version = "*", features = ["bindgen"], default-features = false } This requires the additional dependency clang (on |
Right. I've made some updates to the crate. I've mostly updated the bindings, which makes more sense for For the time being you have to use the # in Cargo.toml
fitsio = { git = "https://github.com/simonrw/rust-fitsio" } |
Build under msys is broken:
Info about my cfitsio package:
cc @art-den, originally reported in #194
The text was updated successfully, but these errors were encountered: