Use the rust-bindgen crate properly

Using the changes from @gadomski along with some additional work, to get the
generated bindings working again. Works on macOS and FreeBSD 11. A couple of
hacks are needed for FreeBSD, but nothing too serious.

Changed to use the libc prefix, and changed to use the generated enums.

Fixes #22, #15, and #14

cargo test passes
This commit is contained in:
Nathan Fiedler
2017-04-08 16:03:58 -07:00
parent 4507d07c9c
commit e7054d3e35
14 changed files with 152 additions and 8244 deletions

View File

@ -35,17 +35,17 @@ macro_rules! wand_common {
fn clear_exception(&mut self) -> Result<(), &'static str> {
match unsafe { ::bindings::$clear_exc(self.wand) } {
::bindings::MagickTrue => Ok(()),
::bindings::MagickBooleanType::MagickTrue => Ok(()),
_ => Err(concat!("failed to clear", stringify!($wand), "exception"))
}
}
fn get_exception_type(&self) -> u32 {
fn get_exception_type(&self) -> ::bindings::ExceptionType {
unsafe { ::bindings::$get_exc_type(self.wand) }
}
fn get_exception(&self) -> Result<(String, u32), &'static str> {
let mut severity: u32 = 0;
fn get_exception(&self) -> Result<(String, ::bindings::ExceptionType), &'static str> {
let mut severity: ::bindings::ExceptionType = ::bindings::ExceptionType::UndefinedException;
// TODO: memory management
let ptr = unsafe { ::bindings::$get_exc(self.wand, &mut severity as *mut _) };
if ptr.is_null() {
@ -58,7 +58,7 @@ macro_rules! wand_common {
pub fn is_wand(&self) -> Result<(), &'static str> {
match unsafe { ::bindings::$is_wand(self.wand) } {
::bindings::MagickTrue => Ok(()),
::bindings::MagickBooleanType::MagickTrue => Ok(()),
_ => Err(concat!(stringify!($wand), " not a wand"))
}
}
@ -91,7 +91,7 @@ macro_rules! set_get {
}
pub fn $set(&mut self, v: $typ) -> Result<(), &'static str> {
match unsafe { ::bindings::$c_set(self.wand, v) } {
::bindings::MagickTrue => Ok(()),
::bindings::MagickBooleanType::MagickTrue => Ok(()),
_ => Err(concat!(stringify!($set), " returned false"))
}
}
@ -142,7 +142,7 @@ macro_rules! string_set_get {
pub fn $set(&mut self, s: &str) -> Result<(), &'static str> {
let c_string = try!(::std::ffi::CString::new(s).map_err(|_| "could not convert to cstring"));
match unsafe { ::bindings::$c_set(self.wand, c_string.as_ptr()) } {
::bindings::MagickTrue => Ok(()),
::bindings::MagickBooleanType::MagickTrue => Ok(()),
_ => Err(concat!(stringify!($set), " returned false"))
}
}