fix: Update for more recent Nix API

(cherry picked from commit 55355f03ab86dfa15972681d9a51d333739f6d10)
This commit is contained in:
Robert Hensing 2024-08-29 15:52:16 +02:00
parent cf6bedde14
commit ee1d591e1a
3 changed files with 16 additions and 7 deletions

View file

@ -33,7 +33,7 @@ impl Context {
/// We recommend to use `check_call!` if possible.
pub fn check_err(&self) -> Result<()> {
let err = unsafe { raw::err_code(self.inner.as_ptr()) };
if err != raw::NIX_OK.try_into().unwrap() {
if err != raw::err_NIX_OK.try_into().unwrap() {
// msgp is a borrowed pointer (pointing into the context), so we don't need to free it
let msgp = unsafe { raw::err_msg(null_mut(), self.inner.as_ptr(), null_mut()) };
// Turn the i8 pointer into a Rust string by copying
@ -47,7 +47,7 @@ impl Context {
unsafe {
raw::set_err_msg(
self.inner.as_ptr(),
raw::NIX_OK.try_into().unwrap(),
raw::err_NIX_OK.try_into().unwrap(),
b"\0".as_ptr() as *const i8,
);
}
@ -66,7 +66,7 @@ impl Context {
f: F,
) -> Result<Option<T>> {
let t = f(self.ptr());
if unsafe { raw::err_code(self.inner.as_ptr()) == raw::NIX_ERR_KEY } {
if unsafe { raw::err_code(self.inner.as_ptr()) == raw::err_NIX_ERR_KEY } {
self.clear();
return Ok(None);
}
@ -109,7 +109,7 @@ macro_rules! check_call_opt_key {
{
let ctx : &mut $crate::context::Context = $ctx;
let ret = $($f)::*(ctx.ptr(), $($arg,)*);
if unsafe { raw::err_code(ctx.ptr()) == raw::NIX_ERR_KEY } {
if unsafe { raw::err_code(ctx.ptr()) == raw::err_NIX_ERR_KEY } {
ctx.clear();
return Ok(None);
}
@ -140,7 +140,7 @@ mod tests {
unsafe {
raw::set_err_msg(
ctx_ptr,
raw::NIX_ERR_UNKNOWN.try_into().unwrap(),
raw::err_NIX_ERR_UNKNOWN.try_into().unwrap(),
b"dummy error message\0".as_ptr() as *const i8,
);
}