Skip to content

Commit

Permalink
Merge pull request ruabmbua#9 from ruabmbua/fix-5-segfault
Browse files Browse the repository at this point in the history
Fixed issue paritytech#5 & some minor changes
  • Loading branch information
Osspial authored Jul 21, 2017
2 parents ac52cb0 + c73246c commit 901cc1b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hidapi"
version = "0.4.0"
version = "0.4.1"
authors = [
"Roland Ruckerbauer <[email protected]>",
"Osspial <[email protected]>",
Expand All @@ -12,7 +12,7 @@ license = "MIT"
keywords = ["hid", "api", "usb","binding", "wrapper"]
build = "build.rs"
links = "hidapi"
documentation = "https://beta.docs.rs/hidapi"
documentation = "https://docs.rs/hidapi"

[dependencies]
libc = "0.2.15"
Expand Down
25 changes: 11 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//!
//! ```toml
//! [dependencies]
//! hidapi = "0.3"
//! hidapi = "0.4"
//! ```
//! # Example
//!
Expand Down Expand Up @@ -59,19 +59,19 @@ pub struct HidApi {
devices: Vec<HidDeviceInfo>,
}

static mut hid_api_lock: bool = false;
static mut HID_API_LOCK: bool = false;

impl HidApi {
/// Initializes the HID
pub fn new() -> HidResult<Self> {
if unsafe { !hid_api_lock } {
if unsafe { !HID_API_LOCK } {

// Initialize the HID and prevent other HIDs from being created
unsafe {
if ffi::hid_init() == -1 {
return Err("Failed to init hid");
}
hid_api_lock = true;
HID_API_LOCK = true;
}


Expand All @@ -95,19 +95,16 @@ impl HidApi {
{
let mut current_device = enumeration;

'do_while: loop {

while !current_device.is_null() {
device_vector.push(conv_hid_device_info(current_device));

if (*current_device).next.is_null() {
break 'do_while;
} else {
current_device = (*current_device).next;
}
current_device = (*current_device).next;
}

}

ffi::hid_free_enumeration(enumeration);
if !enumeration.is_null() {
ffi::hid_free_enumeration(enumeration);
}

device_vector
}
Expand Down Expand Up @@ -165,7 +162,7 @@ impl Drop for HidApi {
fn drop(&mut self) {
unsafe {
ffi::hid_exit();
hid_api_lock = false;
HID_API_LOCK = false;
}
}
}
Expand Down

0 comments on commit 901cc1b

Please sign in to comment.