Skip to content

Commit 5e16c77

Browse files
committed
Fix compilation issue with rustc 1.10.0
After the fix, error module compiles fine with both 1.9.0 and 1.10.0 versions.
1 parent 7a7d453 commit 5e16c77

File tree

3 files changed

+38
-13
lines changed

3 files changed

+38
-13
lines changed

src/error.rs

+29-4
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,48 @@ unsafe impl<'cblifetime> Send for Callback<'cblifetime> {}
2222
unsafe impl<'cblifetime> Sync for Callback<'cblifetime> {}
2323

2424

25-
pub static DEFAULT_HANDLE_ERROR: &'static ErrorCallback = &handle_error_general;
25+
pub const DEFAULT_HANDLE_ERROR: Callback<'static> = Callback{cb: &handle_error_general};
2626

2727

2828
lazy_static! {
2929
static ref ERROR_HANDLER_LOCK: RwLock< Callback<'static> > =
30-
RwLock::new(Callback{cb: DEFAULT_HANDLE_ERROR});
30+
RwLock::new(DEFAULT_HANDLE_ERROR);
3131
}
3232

3333

34+
/// Register user provided error handler
35+
///
36+
/// # Examples
37+
/// ```
38+
/// #[macro_use]
39+
/// extern crate arrayfire;
40+
///
41+
/// use arrayfire::{AfError, Callback, info, register_error_handler};
42+
/// use std::error::Error;
43+
///
44+
/// fn handleError(error_code: AfError) {
45+
/// match error_code {
46+
/// AfError::SUCCESS => {}, /* No-op */
47+
/// _ => panic!("Error message: {}", error_code.description()),
48+
/// }
49+
/// }
50+
///
51+
/// pub const ERR_HANDLE: Callback<'static> = Callback{ cb: &handleError};
52+
///
53+
/// fn main() {
54+
/// register_error_handler(ERR_HANDLE);
55+
///
56+
/// info();
57+
/// }
58+
/// ```
3459
#[allow(unused_must_use)]
35-
pub fn register_error_handler(cb_value: &'static ErrorCallback) {
60+
pub fn register_error_handler(cb_value: Callback<'static>) {
3661
let mut gaurd = match ERROR_HANDLER_LOCK.write() {
3762
Ok(g) => g,
3863
Err(_)=> panic!("Failed to acquire lock to register error handler"),
3964
};
4065

41-
*gaurd.deref_mut() = Callback{cb:cb_value};
66+
*gaurd.deref_mut() = cb_value;
4267
}
4368

4469
pub fn handle_error_general(error_code: AfError) {

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ mod defines;
5353
pub use dim4::Dim4;
5454
mod dim4;
5555

56-
pub use error::{ErrorCallback, register_error_handler, handle_error_general};
56+
pub use error::{Callback, ErrorCallback, register_error_handler, handle_error_general};
5757
mod error;
5858

5959
pub use index::{Indexer, index, row, rows, col, cols, slice, slices,

tests/lib.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ implement_handler!(handler_sample2, "Error Handler Sample2");
2525
implement_handler!(handler_sample3, "Error Handler Sample3");
2626
implement_handler!(handler_sample4, "Error Handler Sample4");
2727

28-
pub static HANDLE1: &'static ErrorCallback = &handler_sample1;
29-
pub static HANDLE2: &'static ErrorCallback = &handler_sample2;
30-
pub static HANDLE3: &'static ErrorCallback = &handler_sample3;
31-
pub static HANDLE4: &'static ErrorCallback = &handler_sample4;
28+
pub const HANDLE1: Callback<'static> = Callback{ cb: &handler_sample1};
29+
pub const HANDLE2: Callback<'static> = Callback{ cb: &handler_sample2};
30+
pub const HANDLE3: Callback<'static> = Callback{ cb: &handler_sample3};
31+
pub const HANDLE4: Callback<'static> = Callback{ cb: &handler_sample4};
3232

3333
#[allow(unused_must_use)]
3434
#[test]
@@ -38,10 +38,10 @@ fn check_error_handler_mutation() {
3838
thread::Builder::new().name(format!("child {}",i+1).to_string()).spawn(move || {
3939
println!("{:?}", thread::current());
4040
match i {
41-
0 => register_error_handler(HANDLE1.clone()),
42-
1 => register_error_handler(HANDLE2.clone()),
43-
2 => register_error_handler(HANDLE3.clone()),
44-
3 => register_error_handler(HANDLE4.clone()),
41+
0 => register_error_handler(HANDLE1),
42+
1 => register_error_handler(HANDLE2),
43+
2 => register_error_handler(HANDLE3),
44+
3 => register_error_handler(HANDLE4),
4545
_ => panic!("Impossible scenario"),
4646
}
4747
});

0 commit comments

Comments
 (0)