check_call!() macro to use () not []
(cherry picked from commit 66d255af0a5d331782dc24c89bb45d3434f3c109)
This commit is contained in:
parent
da26721bea
commit
cc2e640e7f
5 changed files with 64 additions and 39 deletions
|
|
@ -85,10 +85,10 @@ impl Drop for Context {
|
|||
|
||||
#[macro_export]
|
||||
macro_rules! check_call {
|
||||
($f:path[$ctx:expr $(, $arg:expr)*]) => {
|
||||
($($f:ident)::+($ctx:expr $(, $arg:expr)*)) => {
|
||||
{
|
||||
let ctx : &mut $crate::context::Context = $ctx;
|
||||
let ret = $f(ctx.ptr() $(, $arg)*);
|
||||
let ret = $($f)::*(ctx.ptr() $(, $arg)*);
|
||||
match ctx.check_err() {
|
||||
Ok(_) => Ok(ret),
|
||||
Err(e) => {
|
||||
|
|
@ -148,7 +148,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn check_call_dynamic_context() {
|
||||
let r = check_call!(set_dummy_err[&mut Context::new()]);
|
||||
let r = check_call!(set_dummy_err(&mut Context::new()));
|
||||
assert!(r.is_err());
|
||||
assert_eq!(r.unwrap_err().to_string(), "dummy error message");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ pub fn set(key: &str, value: &str) -> Result<()> {
|
|||
let key = std::ffi::CString::new(key)?;
|
||||
let value = std::ffi::CString::new(value)?;
|
||||
unsafe {
|
||||
check_call!(raw::setting_set[&mut ctx, key.as_ptr(), value.as_ptr()])?;
|
||||
check_call!(raw::setting_set(&mut ctx, key.as_ptr(), value.as_ptr()))?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -21,7 +21,12 @@ pub fn get(key: &str) -> Result<String> {
|
|||
let key = std::ffi::CString::new(key)?;
|
||||
let mut r: Result<String> = result_string_init!();
|
||||
unsafe {
|
||||
check_call!(raw::setting_get[&mut ctx, key.as_ptr(), Some(callback_get_result_string), callback_get_result_string_data(&mut r)])?;
|
||||
check_call!(raw::setting_get(
|
||||
&mut ctx,
|
||||
key.as_ptr(),
|
||||
Some(callback_get_result_string),
|
||||
callback_get_result_string_data(&mut r)
|
||||
))?;
|
||||
}
|
||||
r
|
||||
}
|
||||
|
|
@ -36,7 +41,7 @@ mod tests {
|
|||
fn setup() {
|
||||
let mut ctx = context::Context::new();
|
||||
unsafe {
|
||||
check_call!(raw::libstore_init[&mut ctx]).unwrap();
|
||||
check_call!(raw::libstore_init(&mut ctx)).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue