refact: Clean up Context interface to be safer

The mutation-based methods had some pitfalls, and we don't really
need them.

We could re-add them if we need to.

(cherry picked from commit ca92b8491d87cebf54dd2468599168fc7a16c07f)
This commit is contained in:
Robert Hensing 2024-06-14 19:58:44 +02:00
parent 93a2db836a
commit 2f3a5fb039
4 changed files with 38 additions and 35 deletions

View file

@ -74,9 +74,10 @@ impl Drop for Value {
impl Clone for Value {
fn clone(&self) -> Self {
let context = Context::new();
unsafe { raw::gc_incref(context.ptr(), self.inner.as_ptr()) };
context
.check_one_call(|ctx_ptr| unsafe { raw::gc_incref(ctx_ptr, 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
context.check_err().unwrap();
Value { inner: self.inner }
}
}