fix: Do not duplicate ctx expr in check_call!
(cherry picked from commit 9b6f0c1e66d80ec2e92ce079152edb22c05e9b1e)
This commit is contained in:
parent
870c03ee4d
commit
bf6dbd3f1e
3 changed files with 38 additions and 17 deletions
|
|
@ -96,11 +96,12 @@ impl Drop for Context {
|
|||
macro_rules! check_call {
|
||||
($f:path[$ctx:expr $(, $arg:expr)*]) => {
|
||||
{
|
||||
let ret = $f($ctx.ptr() $(, $arg)*);
|
||||
match $ctx.check_err() {
|
||||
let ctx : &mut $crate::context::Context = $ctx;
|
||||
let ret = $f(ctx.ptr() $(, $arg)*);
|
||||
match ctx.check_err() {
|
||||
Ok(_) => Ok(ret),
|
||||
Err(e) => {
|
||||
$ctx.clear();
|
||||
ctx.clear();
|
||||
Err(e)
|
||||
}
|
||||
}
|
||||
|
|
@ -142,4 +143,21 @@ mod tests {
|
|||
// don't crash
|
||||
let _c = Context::new();
|
||||
}
|
||||
|
||||
fn set_dummy_err(ctx_ptr: *mut raw::c_context) {
|
||||
unsafe {
|
||||
raw::set_err_msg(
|
||||
ctx_ptr,
|
||||
raw::NIX_ERR_UNKNOWN.try_into().unwrap(),
|
||||
b"dummy error message\0".as_ptr() as *const i8,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn check_call_dynamic_context() {
|
||||
let r = check_call!(set_dummy_err[&mut Context::new()]);
|
||||
assert!(r.is_err());
|
||||
assert_eq!(r.unwrap_err().to_string(), "dummy error message");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ mod tests {
|
|||
fn setup() {
|
||||
let mut ctx = context::Context::new();
|
||||
unsafe {
|
||||
check_call!(raw::libstore_init[ctx]).unwrap();
|
||||
check_call!(raw::libstore_init[&mut ctx]).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue