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
|
|
@ -16,7 +16,7 @@ lazy_static! {
|
|||
static ref INIT: Result<()> = {
|
||||
unsafe {
|
||||
raw::GC_allow_register_threads();
|
||||
check_call!(raw::libexpr_init[&mut Context::new()])?;
|
||||
check_call!(raw::libexpr_init(&mut Context::new()))?;
|
||||
Ok(())
|
||||
}
|
||||
};
|
||||
|
|
@ -67,7 +67,11 @@ impl EvalState {
|
|||
init()?;
|
||||
|
||||
let eval_state = unsafe {
|
||||
check_call!(raw::state_create[&mut context, lookup_path.as_mut_ptr(), store.raw_ptr()])
|
||||
check_call!(raw::state_create(
|
||||
&mut context,
|
||||
lookup_path.as_mut_ptr(),
|
||||
store.raw_ptr()
|
||||
))
|
||||
}?;
|
||||
Ok(EvalState {
|
||||
eval_state: NonNull::new(eval_state).unwrap_or_else(|| {
|
||||
|
|
@ -109,30 +113,29 @@ impl EvalState {
|
|||
CString::new(path).with_context(|| "eval_from_string: path contains null byte")?;
|
||||
unsafe {
|
||||
let value = self.new_value_uninitialized()?;
|
||||
check_call!(raw::expr_eval_from_string[
|
||||
check_call!(raw::expr_eval_from_string(
|
||||
&mut self.context,
|
||||
self.eval_state.as_ptr(),
|
||||
expr_ptr.as_ptr(),
|
||||
path_ptr.as_ptr(),
|
||||
value.raw_ptr()
|
||||
])?;
|
||||
))?;
|
||||
Ok(value)
|
||||
}
|
||||
}
|
||||
/// 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[&mut self.context, self.eval_state.as_ptr(), v.raw_ptr()])
|
||||
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> {
|
||||
let r = unsafe {
|
||||
check_call!(raw::get_type[
|
||||
&mut self.context,
|
||||
value.raw_ptr()
|
||||
])
|
||||
};
|
||||
let r = unsafe { check_call!(raw::get_type(&mut self.context, value.raw_ptr())) };
|
||||
// .unwrap(): no reason for this to fail, as it does not evaluate
|
||||
ValueType::from_raw(r.unwrap())
|
||||
}
|
||||
|
|
@ -155,7 +158,7 @@ impl EvalState {
|
|||
if t != ValueType::Int {
|
||||
bail!("expected an int, but got a {:?}", t);
|
||||
}
|
||||
unsafe { check_call!(raw::get_int[&mut self.context, v.raw_ptr()]) }
|
||||
unsafe { check_call!(raw::get_int(&mut self.context, v.raw_ptr())) }
|
||||
}
|
||||
/// Evaluate, and require that the value is an attrset.
|
||||
/// Returns a list of the keys in the attrset.
|
||||
|
|
@ -164,16 +167,16 @@ impl EvalState {
|
|||
if t != ValueType::AttrSet {
|
||||
bail!("expected an attrset, but got a {:?}", t);
|
||||
}
|
||||
let n = unsafe { check_call!(raw::get_attrs_size[&mut self.context, v.raw_ptr()]) }?;
|
||||
let n = unsafe { check_call!(raw::get_attrs_size(&mut self.context, v.raw_ptr())) }?;
|
||||
let mut attrs = Vec::with_capacity(n as usize);
|
||||
for i in 0..n {
|
||||
let cstr_ptr: *const i8 = unsafe {
|
||||
check_call!(raw::get_attr_name_byidx[
|
||||
check_call!(raw::get_attr_name_byidx(
|
||||
&mut self.context,
|
||||
v.raw_ptr(),
|
||||
self.eval_state.as_ptr(),
|
||||
i as c_uint
|
||||
])
|
||||
))
|
||||
}?;
|
||||
let cstr = unsafe { std::ffi::CStr::from_ptr(cstr_ptr) };
|
||||
let s = cstr
|
||||
|
|
@ -193,12 +196,12 @@ impl EvalState {
|
|||
let attr_name = CString::new(attr_name)
|
||||
.with_context(|| "require_attrs_select: attrName contains null byte")?;
|
||||
let v2 = unsafe {
|
||||
check_call!(raw::get_attr_byname[
|
||||
check_call!(raw::get_attr_byname(
|
||||
&mut self.context,
|
||||
v.raw_ptr(),
|
||||
self.eval_state.as_ptr(),
|
||||
attr_name.as_ptr()
|
||||
])
|
||||
))
|
||||
}?;
|
||||
Ok(Value::new(v2))
|
||||
}
|
||||
|
|
@ -238,7 +241,11 @@ impl EvalState {
|
|||
let s = CString::new(s).with_context(|| "new_value_str: contains null byte")?;
|
||||
let v = unsafe {
|
||||
let value = self.new_value_uninitialized()?;
|
||||
check_call!(raw::init_string[&mut self.context, value.raw_ptr(), s.as_ptr()])?;
|
||||
check_call!(raw::init_string(
|
||||
&mut self.context,
|
||||
value.raw_ptr(),
|
||||
s.as_ptr()
|
||||
))?;
|
||||
value
|
||||
};
|
||||
Ok(v)
|
||||
|
|
@ -247,7 +254,7 @@ impl EvalState {
|
|||
pub fn new_value_int(&mut self, i: Int) -> Result<Value> {
|
||||
let v = unsafe {
|
||||
let value = self.new_value_uninitialized()?;
|
||||
check_call!(raw::init_int[&mut self.context, value.raw_ptr(), i])?;
|
||||
check_call!(raw::init_int(&mut self.context, value.raw_ptr(), i))?;
|
||||
value
|
||||
};
|
||||
Ok(v)
|
||||
|
|
@ -257,12 +264,12 @@ impl EvalState {
|
|||
fn get_string(&mut self, value: &Value) -> Result<String> {
|
||||
let mut r = result_string_init!();
|
||||
unsafe {
|
||||
check_call!(raw::get_string[
|
||||
check_call!(raw::get_string(
|
||||
&mut self.context,
|
||||
value.raw_ptr(),
|
||||
Some(callback_get_result_string),
|
||||
callback_get_result_string_data(&mut r)
|
||||
])?;
|
||||
))?;
|
||||
};
|
||||
r
|
||||
}
|
||||
|
|
@ -285,12 +292,12 @@ impl EvalState {
|
|||
}
|
||||
|
||||
let rs = unsafe {
|
||||
check_call!(raw::string_realise[
|
||||
check_call!(raw::string_realise(
|
||||
&mut self.context,
|
||||
self.eval_state.as_ptr(),
|
||||
value.raw_ptr(),
|
||||
is_import_from_derivation
|
||||
])
|
||||
))
|
||||
}?;
|
||||
|
||||
let s = unsafe {
|
||||
|
|
@ -325,13 +332,13 @@ impl EvalState {
|
|||
pub fn call(&mut self, f: Value, a: Value) -> Result<Value> {
|
||||
let value = self.new_value_uninitialized()?;
|
||||
unsafe {
|
||||
check_call!(raw::value_call[
|
||||
check_call!(raw::value_call(
|
||||
&mut self.context,
|
||||
self.eval_state.as_ptr(),
|
||||
f.raw_ptr(),
|
||||
a.raw_ptr(),
|
||||
value.raw_ptr()
|
||||
])
|
||||
))
|
||||
}?;
|
||||
Ok(value)
|
||||
}
|
||||
|
|
@ -342,19 +349,23 @@ impl EvalState {
|
|||
pub fn new_value_apply(&mut self, f: &Value, a: &Value) -> Result<Value> {
|
||||
let value = self.new_value_uninitialized()?;
|
||||
unsafe {
|
||||
check_call!(raw::init_apply[
|
||||
check_call!(raw::init_apply(
|
||||
&mut self.context,
|
||||
value.raw_ptr(),
|
||||
f.raw_ptr(),
|
||||
a.raw_ptr()
|
||||
])
|
||||
))
|
||||
}?;
|
||||
Ok(value)
|
||||
}
|
||||
|
||||
fn new_value_uninitialized(&mut self) -> Result<Value> {
|
||||
let value =
|
||||
unsafe { check_call!(raw::alloc_value[&mut self.context, self.eval_state.as_ptr()]) }?;
|
||||
let value = unsafe {
|
||||
check_call!(raw::alloc_value(
|
||||
&mut self.context,
|
||||
self.eval_state.as_ptr()
|
||||
))
|
||||
}?;
|
||||
Ok(Value::new(value))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ impl Clone for Value {
|
|||
// this is very unlikely to error, and it is not recoverable
|
||||
// Maybe try without, and try again with context to report details?
|
||||
unsafe {
|
||||
check_call!(raw::gc_incref[&mut Context::new(), self.inner.as_ptr()]).unwrap();
|
||||
check_call!(raw::gc_incref(&mut Context::new(), self.inner.as_ptr())).unwrap();
|
||||
}
|
||||
// can't return an error here, but we don't want to ignore the error either as it means we could use-after-free
|
||||
Value { inner: self.inner }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue