Fix image property accessor to copy C string
cargo test passes
This commit is contained in:
parent
19377db422
commit
7bc3f274d2
|
@ -3,6 +3,10 @@
|
||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
This project adheres to [Semantic Versioning](http://semver.org/).
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
||||||
|
|
||||||
|
## [0.3.1] - 2016-01-02
|
||||||
|
### Changed
|
||||||
|
- Fix bug `get_image_property()` to ensure C string is copied.
|
||||||
|
|
||||||
## [0.3.0] - 2016-01-02
|
## [0.3.0] - 2016-01-02
|
||||||
### Changed
|
### Changed
|
||||||
- Add `get_image_property()` function to retrieve, for example, EXIF data.
|
- Add `get_image_property()` function to retrieve, for example, EXIF data.
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "magick_rust"
|
name = "magick_rust"
|
||||||
version = "0.3.0"
|
version = "0.3.1"
|
||||||
authors = ["Nathan Fiedler <nathanfiedler@fastmail.fm>"]
|
authors = ["Nathan Fiedler <nathanfiedler@fastmail.fm>"]
|
||||||
description = "Selection of Rust bindings for the ImageMagick library."
|
description = "Selection of Rust bindings for the ImageMagick library."
|
||||||
homepage = "https://github.com/nlfiedler/magick-rust"
|
homepage = "https://github.com/nlfiedler/magick-rust"
|
||||||
|
|
|
@ -99,7 +99,7 @@ impl MagickWand {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Retrieve the named image property value.
|
/// Retrieve the named image property value.
|
||||||
pub fn get_image_property(&self, name: &str) -> Result<&str, &'static str> {
|
pub fn get_image_property(&self, name: &str) -> Result<String, &'static str> {
|
||||||
let c_name = CString::new(name).unwrap();
|
let c_name = CString::new(name).unwrap();
|
||||||
let result = unsafe {
|
let result = unsafe {
|
||||||
bindings::MagickGetImageProperty(self.wand, c_name.as_ptr())
|
bindings::MagickGetImageProperty(self.wand, c_name.as_ptr())
|
||||||
|
@ -107,11 +107,9 @@ impl MagickWand {
|
||||||
let value = if result.is_null() {
|
let value = if result.is_null() {
|
||||||
Err("missing property")
|
Err("missing property")
|
||||||
} else {
|
} else {
|
||||||
|
// convert (and copy) the C string to a Rust string
|
||||||
let cstr = unsafe { CStr::from_ptr(result) };
|
let cstr = unsafe { CStr::from_ptr(result) };
|
||||||
match cstr.to_str() {
|
Ok(cstr.to_string_lossy().into_owned())
|
||||||
Ok(v) => Ok(v),
|
|
||||||
Err(_) => Err("invalid value")
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
unsafe {
|
unsafe {
|
||||||
bindings::MagickRelinquishMemory(result as *mut c_void);
|
bindings::MagickRelinquishMemory(result as *mut c_void);
|
||||||
|
|
Loading…
Reference in a new issue