Merge pull request #66 from npajkovsky/master
fix build issues and try! warnings
This commit is contained in:
@ -14,5 +14,5 @@ build = "build.rs"
|
|||||||
libc = ">=0.2"
|
libc = ">=0.2"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
bindgen = "0.31"
|
bindgen = "0.52.0"
|
||||||
pkg-config = ">=0.3"
|
pkg-config = ">=0.3"
|
||||||
|
|||||||
45
build.rs
45
build.rs
@ -87,6 +87,37 @@ fn main() {
|
|||||||
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
|
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
|
||||||
let bindings_path_str = out_dir.join("bindings.rs");
|
let bindings_path_str = out_dir.join("bindings.rs");
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct IgnoreMacros(HashSet<String>);
|
||||||
|
|
||||||
|
impl bindgen::callbacks::ParseCallbacks for IgnoreMacros {
|
||||||
|
fn will_parse_macro(&self, name: &str) -> bindgen::callbacks::MacroParsingBehavior {
|
||||||
|
if self.0.contains(name) {
|
||||||
|
bindgen::callbacks::MacroParsingBehavior::Ignore
|
||||||
|
} else {
|
||||||
|
bindgen::callbacks::MacroParsingBehavior::Default
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let ignored_macros = IgnoreMacros(
|
||||||
|
vec![
|
||||||
|
"FP_INFINITE".into(),
|
||||||
|
"FP_NAN".into(),
|
||||||
|
"FP_NORMAL".into(),
|
||||||
|
"FP_SUBNORMAL".into(),
|
||||||
|
"FP_ZERO".into(),
|
||||||
|
"IPPORT_RESERVED".into(),
|
||||||
|
"FP_INT_UPWARD".into(),
|
||||||
|
"FP_INT_DOWNWARD".into(),
|
||||||
|
"FP_INT_TOWARDZERO".into(),
|
||||||
|
"FP_INT_TONEARESTFROMZERO".into(),
|
||||||
|
"FP_INT_TONEAREST".into(),
|
||||||
|
]
|
||||||
|
.into_iter()
|
||||||
|
.collect(),
|
||||||
|
);
|
||||||
|
|
||||||
if !Path::new(&bindings_path_str).exists() {
|
if !Path::new(&bindings_path_str).exists() {
|
||||||
// Create the header file that rust-bindgen needs as input.
|
// Create the header file that rust-bindgen needs as input.
|
||||||
let gen_h_path = out_dir.join("gen.h");
|
let gen_h_path = out_dir.join("gen.h");
|
||||||
@ -101,17 +132,9 @@ fn main() {
|
|||||||
.ctypes_prefix("libc")
|
.ctypes_prefix("libc")
|
||||||
.raw_line("extern crate libc;")
|
.raw_line("extern crate libc;")
|
||||||
.header(gen_h_path.to_str().unwrap())
|
.header(gen_h_path.to_str().unwrap())
|
||||||
// https://github.com/rust-lang-nursery/rust-bindgen/issues/687
|
.parse_callbacks(Box::new(ignored_macros))
|
||||||
.blacklist_type("FP_NAN")
|
.blacklist_type("timex")
|
||||||
.blacklist_type("FP_INFINITE")
|
.blacklist_function("clock_adjtime");
|
||||||
.blacklist_type("FP_ZERO")
|
|
||||||
.blacklist_type("FP_SUBNORMAL")
|
|
||||||
.blacklist_type("FP_NORMAL")
|
|
||||||
.blacklist_type("FP_INT_UPWARD")
|
|
||||||
.blacklist_type("FP_INT_DOWNWARD")
|
|
||||||
.blacklist_type("FP_INT_TOWARDZERO")
|
|
||||||
.blacklist_type("FP_INT_TONEARESTFROMZERO")
|
|
||||||
.blacklist_type("FP_INT_TONEAREST");
|
|
||||||
|
|
||||||
for d in include_dirs {
|
for d in include_dirs {
|
||||||
builder = builder.clang_arg(format!("-I{}", d.to_string_lossy()));
|
builder = builder.clang_arg(format!("-I{}", d.to_string_lossy()));
|
||||||
|
|||||||
@ -69,8 +69,7 @@ pub fn magick_wand_terminus() {
|
|||||||
|
|
||||||
pub fn magick_query_fonts(pattern: &str) -> Result<Vec<String>, &'static str> {
|
pub fn magick_query_fonts(pattern: &str) -> Result<Vec<String>, &'static str> {
|
||||||
let mut number_fonts: size_t = 0;
|
let mut number_fonts: size_t = 0;
|
||||||
let c_string =
|
let c_string = ::std::ffi::CString::new(pattern).map_err(|_| "could not convert to cstring")?;
|
||||||
try!(::std::ffi::CString::new(pattern).map_err(|_| "could not convert to cstring"));
|
|
||||||
let ptr =
|
let ptr =
|
||||||
unsafe { bindings::MagickQueryFonts(c_string.as_ptr(), &mut number_fonts as *mut size_t) };
|
unsafe { bindings::MagickQueryFonts(c_string.as_ptr(), &mut number_fonts as *mut size_t) };
|
||||||
if ptr.is_null() {
|
if ptr.is_null() {
|
||||||
|
|||||||
@ -35,7 +35,7 @@ wand_common!(
|
|||||||
|
|
||||||
impl DrawingWand {
|
impl DrawingWand {
|
||||||
pub fn draw_annotation(&mut self, x: f64, y: f64, text: &str) -> Result<(), &'static str> {
|
pub fn draw_annotation(&mut self, x: f64, y: f64, text: &str) -> Result<(), &'static str> {
|
||||||
let c_string = try!(CString::new(text).map_err(|_| "could not convert to cstring"));
|
let c_string = CString::new(text).map_err(|_| "could not convert to cstring")?;
|
||||||
unsafe { bindings::DrawAnnotation(self.wand, x, y, c_string.as_ptr() as *const _) };
|
unsafe { bindings::DrawAnnotation(self.wand, x, y, c_string.as_ptr() as *const _) };
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -94,13 +94,13 @@ impl DrawingWand {
|
|||||||
|
|
||||||
impl fmt::Debug for DrawingWand {
|
impl fmt::Debug for DrawingWand {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
try!(writeln!(f, "DrawingWand {{"));
|
writeln!(f, "DrawingWand {{")?;
|
||||||
try!(writeln!(f, " Exception: {:?}", self.get_exception()));
|
writeln!(f, " Exception: {:?}", self.get_exception())?;
|
||||||
try!(writeln!(f, " IsWand: {:?}", self.is_wand()));
|
writeln!(f, " IsWand: {:?}", self.is_wand())?;
|
||||||
try!(self.fmt_unchecked_settings(f, " "));
|
self.fmt_unchecked_settings(f, " ")?;
|
||||||
try!(self.fmt_string_settings(f, " "));
|
self.fmt_string_settings(f, " ")?;
|
||||||
try!(self.fmt_string_unchecked_settings(f, " "));
|
self.fmt_string_unchecked_settings(f, " ")?;
|
||||||
try!(self.fmt_pixel_settings(f, " "));
|
self.fmt_pixel_settings(f, " ")?;
|
||||||
writeln!(f, "}}")
|
writeln!(f, "}}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -118,7 +118,7 @@ macro_rules! set_get {
|
|||||||
}
|
}
|
||||||
)*
|
)*
|
||||||
pub fn fmt_checked_settings(&self, f: &mut ::std::fmt::Formatter, prefix: &str) -> ::std::fmt::Result {
|
pub fn fmt_checked_settings(&self, f: &mut ::std::fmt::Formatter, prefix: &str) -> ::std::fmt::Result {
|
||||||
$( try!(writeln!(f, "{}{:<50}: {:?}", prefix, stringify!($c_get), self.$get())); )*
|
$( writeln!(f, "{}{:<50}: {:?}", prefix, stringify!($c_get), self.$get())?; )*
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -135,7 +135,7 @@ macro_rules! set_get_unchecked {
|
|||||||
}
|
}
|
||||||
)*
|
)*
|
||||||
pub fn fmt_unchecked_settings(&self, f: &mut ::std::fmt::Formatter, prefix: &str) -> ::std::fmt::Result {
|
pub fn fmt_unchecked_settings(&self, f: &mut ::std::fmt::Formatter, prefix: &str) -> ::std::fmt::Result {
|
||||||
$( try!(writeln!(f, "{}{:<50}: {:?}", prefix, stringify!($c_get), self.$get())); )*
|
$( writeln!(f, "{}{:<50}: {:?}", prefix, stringify!($c_get), self.$get()); )*
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -154,7 +154,7 @@ macro_rules! string_get {
|
|||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! string_set_get {
|
macro_rules! string_set_get {
|
||||||
@ -162,7 +162,7 @@ macro_rules! string_set_get {
|
|||||||
$(
|
$(
|
||||||
string_get!($get, $c_get);
|
string_get!($get, $c_get);
|
||||||
pub fn $set(&mut self, s: &str) -> Result<(), &'static str> {
|
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"));
|
let c_string = std::ffi::CString::new(s).map_err(|_| "could not convert to cstring")?;
|
||||||
match unsafe { ::bindings::$c_set(self.wand, c_string.as_ptr()) } {
|
match unsafe { ::bindings::$c_set(self.wand, c_string.as_ptr()) } {
|
||||||
::bindings::MagickBooleanType_MagickTrue => Ok(()),
|
::bindings::MagickBooleanType_MagickTrue => Ok(()),
|
||||||
_ => Err(concat!(stringify!($set), " returned false"))
|
_ => Err(concat!(stringify!($set), " returned false"))
|
||||||
@ -170,7 +170,7 @@ macro_rules! string_set_get {
|
|||||||
}
|
}
|
||||||
)*
|
)*
|
||||||
pub fn fmt_string_settings(&self, f: &mut ::std::fmt::Formatter, prefix: &str) -> ::std::fmt::Result {
|
pub fn fmt_string_settings(&self, f: &mut ::std::fmt::Formatter, prefix: &str) -> ::std::fmt::Result {
|
||||||
$( try!(writeln!(f, "{}{:<50}: {:?}", prefix, stringify!($c_get), self.$get())); )*
|
$( writeln!(f, "{}{:<50}: {:?}", prefix, stringify!($c_get), self.$get())?; )*
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -181,13 +181,13 @@ macro_rules! string_set_get_unchecked {
|
|||||||
$(
|
$(
|
||||||
string_get!($get, $c_get);
|
string_get!($get, $c_get);
|
||||||
pub fn $set(&mut self, s: &str) -> Result<(), &'static str> {
|
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"));
|
let c_string = ::std::ffi::CString::new(s).map_err(|_| "could not convert to cstring")?;
|
||||||
unsafe { ::bindings::$c_set(self.wand, c_string.as_ptr()) };
|
unsafe { ::bindings::$c_set(self.wand, c_string.as_ptr()) };
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
)*
|
)*
|
||||||
pub fn fmt_string_unchecked_settings(&self, f: &mut ::std::fmt::Formatter, prefix: &str) -> ::std::fmt::Result {
|
pub fn fmt_string_unchecked_settings(&self, f: &mut ::std::fmt::Formatter, prefix: &str) -> ::std::fmt::Result {
|
||||||
$( try!(writeln!(f, "{}{:<50}: {:?}", prefix, stringify!($c_get), self.$get())); )*
|
$( writeln!(f, "{}{:<50}: {:?}", prefix, stringify!($c_get), self.$get())?; )*
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -207,8 +207,8 @@ macro_rules! pixel_set_get {
|
|||||||
)*
|
)*
|
||||||
pub fn fmt_pixel_settings(&self, f: &mut ::std::fmt::Formatter, prefix: &str) -> ::std::fmt::Result {
|
pub fn fmt_pixel_settings(&self, f: &mut ::std::fmt::Formatter, prefix: &str) -> ::std::fmt::Result {
|
||||||
$(
|
$(
|
||||||
try!(writeln!(f, "{}{:<50}: ", prefix, stringify!($c_get)));
|
writeln!(f, "{}{:<50}: ", prefix, stringify!($c_get))?;
|
||||||
try!(self.$get().fmt_w_prefix(f, &format!("{}{:<53}", prefix, " ") ));
|
self.$get().fmt_w_prefix(f, &format!("{}{:<53}", prefix, " ") )?;
|
||||||
)*
|
)*
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -235,14 +235,14 @@ macro_rules! color_set_get {
|
|||||||
}
|
}
|
||||||
)*
|
)*
|
||||||
pub fn fmt_color_settings(&self, f: &mut ::std::fmt::Formatter, prefix: &str) -> ::std::fmt::Result {
|
pub fn fmt_color_settings(&self, f: &mut ::std::fmt::Formatter, prefix: &str) -> ::std::fmt::Result {
|
||||||
try!(writeln!(f, "{}Color: {:?}, normalized: {:?}\n{}hsl: {:?}",
|
writeln!(f, "{}Color: {:?}, normalized: {:?}\n{}hsl: {:?}",
|
||||||
prefix,
|
prefix,
|
||||||
self.get_color_as_string(),
|
self.get_color_as_string(),
|
||||||
self.get_color_as_normalized_string(),
|
self.get_color_as_normalized_string(),
|
||||||
prefix,
|
prefix,
|
||||||
self.get_hsl()
|
self.get_hsl()
|
||||||
));
|
)?;
|
||||||
$( try!(writeln!(f, "{}{:<10}: {:>} quantum: {}", prefix, stringify!($c_get).split_at(8).1, self.$get(), self.$get_quantum())); )*
|
$( writeln!(f, "{}{:<10}: {:>} quantum: {}", prefix, stringify!($c_get).split_at(8).1, self.$get(), self.$get_quantum())?; )*
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -75,7 +75,7 @@ impl MagickWand {
|
|||||||
angle: f64,
|
angle: f64,
|
||||||
text: &str,
|
text: &str,
|
||||||
) -> Result<(), &'static str> {
|
) -> Result<(), &'static str> {
|
||||||
let c_string = try!(CString::new(text).map_err(|_| "could not convert to cstring"));
|
let c_string = CString::new(text).map_err(|_| "could not convert to cstring")?;
|
||||||
match unsafe {
|
match unsafe {
|
||||||
bindings::MagickAnnotateImage(
|
bindings::MagickAnnotateImage(
|
||||||
self.wand,
|
self.wand,
|
||||||
@ -335,6 +335,16 @@ impl MagickWand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn negate_image(&self) -> Result<(), &'static str> {
|
||||||
|
let result = unsafe {
|
||||||
|
bindings::MagickNegateImage(self.wand, bindings::MagickBooleanType_MagickTrue)
|
||||||
|
};
|
||||||
|
match result {
|
||||||
|
bindings::MagickBooleanType_MagickTrue => Ok(()),
|
||||||
|
_ => Err("failed to flip image"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn flop_image(&self) -> Result<(), &'static str> {
|
pub fn flop_image(&self) -> Result<(), &'static str> {
|
||||||
let result = unsafe { bindings::MagickFlopImage(self.wand) };
|
let result = unsafe { bindings::MagickFlopImage(self.wand) };
|
||||||
match result {
|
match result {
|
||||||
@ -831,11 +841,11 @@ impl MagickWand {
|
|||||||
|
|
||||||
impl fmt::Debug for MagickWand {
|
impl fmt::Debug for MagickWand {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
try!(writeln!(f, "MagickWand {{"));
|
writeln!(f, "MagickWand {{")?;
|
||||||
try!(writeln!(f, " Exception: {:?}", self.get_exception()));
|
writeln!(f, " Exception: {:?}", self.get_exception())?;
|
||||||
try!(writeln!(f, " IsWand: {:?}", self.is_wand()));
|
writeln!(f, " IsWand: {:?}", self.is_wand())?;
|
||||||
try!(self.fmt_string_settings(f, " "));
|
self.fmt_string_settings(f, " ")?;
|
||||||
try!(self.fmt_checked_settings(f, " "));
|
self.fmt_checked_settings(f, " ")?;
|
||||||
writeln!(f, "}}")
|
writeln!(f, "}}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -70,16 +70,16 @@ impl PixelWand {
|
|||||||
pub fn fmt_w_prefix(&self, f: &mut fmt::Formatter, prefix: &str) -> fmt::Result {
|
pub fn fmt_w_prefix(&self, f: &mut fmt::Formatter, prefix: &str) -> fmt::Result {
|
||||||
let mut prf = prefix.to_string();
|
let mut prf = prefix.to_string();
|
||||||
prf.push_str(" ");
|
prf.push_str(" ");
|
||||||
try!(writeln!(f, "{}PixelWand {{", prefix));
|
writeln!(f, "{}PixelWand {{", prefix)?;
|
||||||
try!(writeln!(f, "{}Exception: {:?}", prf, self.get_exception()));
|
writeln!(f, "{}Exception: {:?}", prf, self.get_exception())?;
|
||||||
try!(writeln!(f, "{}IsWand: {:?}", prf, self.is_wand()));
|
writeln!(f, "{}IsWand: {:?}", prf, self.is_wand())?;
|
||||||
try!(self.fmt_unchecked_settings(f, &prf));
|
self.fmt_unchecked_settings(f, &prf)?;
|
||||||
try!(self.fmt_color_settings(f, &prf));
|
self.fmt_color_settings(f, &prf)?;
|
||||||
writeln!(f, "{}}}", prefix)
|
writeln!(f, "{}}}", prefix)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_color(&mut self, s: &str) -> Result<(), &'static str> {
|
pub fn set_color(&mut self, s: &str) -> Result<(), &'static str> {
|
||||||
let c_string = try!(CString::new(s).map_err(|_| "could not convert to cstring"));
|
let c_string = CString::new(s).map_err(|_| "could not convert to cstring")?;
|
||||||
match unsafe { bindings::PixelSetColor(self.wand, c_string.as_ptr()) } {
|
match unsafe { bindings::PixelSetColor(self.wand, c_string.as_ptr()) } {
|
||||||
bindings::MagickBooleanType_MagickTrue => Ok(()),
|
bindings::MagickBooleanType_MagickTrue => Ok(()),
|
||||||
_ => Err("failed to set color"),
|
_ => Err("failed to set color"),
|
||||||
|
|||||||
15
tests/lib.rs
15
tests/lib.rs
@ -346,3 +346,18 @@ fn test_clut_image() {
|
|||||||
)
|
)
|
||||||
.is_ok());
|
.is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_negate_image() {
|
||||||
|
START.call_once(|| {
|
||||||
|
magick_wand_genesis();
|
||||||
|
});
|
||||||
|
let wand = MagickWand::new();
|
||||||
|
assert!(wand.read_image("tests/data/rust.png").is_ok());
|
||||||
|
wand.negate_image().unwrap();
|
||||||
|
let pixel_color = wand.get_image_pixel_color(0, 0).unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
"srgb(255,255,255)",
|
||||||
|
pixel_color.get_color_as_string().unwrap()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user