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
|
|
@ -111,8 +111,8 @@ impl EvalState {
|
|||
unsafe {
|
||||
let value = self.new_value_uninitialized()?;
|
||||
check_call!(raw::expr_eval_from_string[
|
||||
self.context,
|
||||
self.raw_ptr(),
|
||||
&mut self.context,
|
||||
self.eval_state.as_ptr(),
|
||||
expr_ptr.as_ptr(),
|
||||
path_ptr.as_ptr(),
|
||||
value.raw_ptr()
|
||||
|
|
@ -122,7 +122,9 @@ impl EvalState {
|
|||
}
|
||||
/// Try turn any Value into a Value that isn't a Thunk.
|
||||
pub fn force(&mut self, v: &Value) -> Result<()> {
|
||||
unsafe { check_call!(raw::value_force[self.context, self.raw_ptr(), v.raw_ptr()]) }?;
|
||||
unsafe {
|
||||
check_call!(raw::value_force[&mut self.context, self.eval_state.as_ptr(), v.raw_ptr()])
|
||||
}?;
|
||||
Ok(())
|
||||
}
|
||||
pub fn value_type_unforced(&mut self, value: &Value) -> Option<ValueType> {
|
||||
|
|
@ -168,9 +170,9 @@ impl EvalState {
|
|||
for i in 0..n {
|
||||
let cstr_ptr: *const i8 = unsafe {
|
||||
check_call!(raw::get_attr_name_byidx[
|
||||
self.context,
|
||||
&mut self.context,
|
||||
v.raw_ptr(),
|
||||
self.raw_ptr(),
|
||||
self.eval_state.as_ptr(),
|
||||
i as c_uint
|
||||
])
|
||||
}?;
|
||||
|
|
@ -193,9 +195,9 @@ impl EvalState {
|
|||
.with_context(|| "require_attrs_select: attrName contains null byte")?;
|
||||
let v2 = unsafe {
|
||||
check_call!(raw::get_attr_byname[
|
||||
self.context,
|
||||
&mut self.context,
|
||||
v.raw_ptr(),
|
||||
self.raw_ptr(),
|
||||
self.eval_state.as_ptr(),
|
||||
attr_name.as_ptr()
|
||||
])
|
||||
}?;
|
||||
|
|
@ -289,8 +291,8 @@ impl EvalState {
|
|||
|
||||
let rs = unsafe {
|
||||
check_call!(raw::string_realise[
|
||||
self.context,
|
||||
self.raw_ptr(),
|
||||
&mut self.context,
|
||||
self.eval_state.as_ptr(),
|
||||
value.raw_ptr(),
|
||||
is_import_from_derivation
|
||||
])
|
||||
|
|
@ -329,8 +331,8 @@ impl EvalState {
|
|||
let value = self.new_value_uninitialized()?;
|
||||
unsafe {
|
||||
check_call!(raw::value_call[
|
||||
self.context,
|
||||
self.raw_ptr(),
|
||||
&mut self.context,
|
||||
self.eval_state.as_ptr(),
|
||||
f.raw_ptr(),
|
||||
a.raw_ptr(),
|
||||
value.raw_ptr()
|
||||
|
|
@ -346,7 +348,7 @@ impl EvalState {
|
|||
let value = self.new_value_uninitialized()?;
|
||||
unsafe {
|
||||
check_call!(raw::init_apply[
|
||||
self.context,
|
||||
&mut self.context,
|
||||
value.raw_ptr(),
|
||||
f.raw_ptr(),
|
||||
a.raw_ptr()
|
||||
|
|
@ -356,7 +358,8 @@ impl EvalState {
|
|||
}
|
||||
|
||||
fn new_value_uninitialized(&mut self) -> Result<Value> {
|
||||
let value = unsafe { check_call!(raw::alloc_value[self.context, self.raw_ptr()]) }?;
|
||||
let value =
|
||||
unsafe { check_call!(raw::alloc_value[&mut self.context, self.eval_state.as_ptr()]) }?;
|
||||
Ok(Value::new(value))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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