fix: Require mutable Context, as it should be

This spreads out transitively to many places and requires that
we use `check_call!` instead of `check_one_call` in a number of
places.

(cherry picked from commit 6bc31dcf206518a7be7f0ac6e773d5dfe25531ea)
This commit is contained in:
Robert Hensing 2024-06-15 12:40:45 +02:00
parent 226639939f
commit a6dbf17778
5 changed files with 143 additions and 129 deletions

View file

@ -47,7 +47,7 @@ impl Context {
Ok(())
}
fn clear(&self) {
pub fn clear(&mut self) {
unsafe {
raw::set_err_msg(
self.inner.as_ptr(),
@ -57,7 +57,7 @@ impl Context {
}
}
pub fn check_err_and_clear(&self) -> Result<()> {
pub fn check_err_and_clear(&mut self) -> Result<()> {
let r = self.check_err();
if r.is_err() {
self.clear();
@ -68,14 +68,14 @@ impl Context {
/// Run the function, and check the error, then reset the error.
/// Make at most one call to a Nix function in `f`.
/// Do not use if the context isn't fresh or cleared (e.g. with `check_err_and_clear`).
pub fn check_one_call<T, F: FnOnce(*mut raw::c_context) -> T>(&self, f: F) -> Result<T> {
pub fn check_one_call<T, F: FnOnce(*mut raw::c_context) -> T>(&mut self, f: F) -> Result<T> {
let t = f(self.ptr());
self.check_err_and_clear()?;
Ok(t)
}
pub fn check_one_call_or_key_none<T, F: FnOnce(*mut raw::c_context) -> T>(
&self,
&mut self,
f: F,
) -> Result<Option<T>> {
let t = f(self.ptr());