From 279626a06684004eb91fa4304a9c7b992f38930d Mon Sep 17 00:00:00 2001 From: Tomasz Kalinowski Date: Fri, 19 Jul 2024 10:58:31 -0400 Subject: [PATCH] fix usage of `local_protect()` closes #278 --- src/altrep/mod.rs | 4 ++-- src/eval.rs | 4 ++-- src/protect.rs | 4 ++-- src/sexp/complex.rs | 2 +- src/sexp/external_pointer.rs | 2 +- src/sexp/function.rs | 2 +- src/sexp/integer.rs | 4 ++-- src/sexp/logical.rs | 4 ++-- src/sexp/raw.rs | 4 ++-- src/sexp/real.rs | 4 ++-- src/sexp/string.rs | 4 ++-- 11 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/altrep/mod.rs b/src/altrep/mod.rs index 0ba8ba1e..c1c9f45e 100644 --- a/src/altrep/mod.rs +++ b/src/altrep/mod.rs @@ -34,7 +34,7 @@ pub(crate) fn create_altrep_instance( class_name: &'static str, ) -> crate::Result { let sexp = x.into_external_pointer().0; - local_protect(sexp); + let _sexp_guard = local_protect(sexp); let catalogue_mutex = ALTREP_CLASS_CATALOGUE.get().ok_or(crate::Error::new( "ALTREP_CLASS_CATALOGUE is not initialized", @@ -47,7 +47,7 @@ pub(crate) fn create_altrep_instance( .ok_or(crate::Error::new("Failed to get the ALTREP class"))?; let altrep = unsafe { R_new_altrep(*class, sexp, R_NilValue) }; - local_protect(altrep); + let _altrep_guard = local_protect(altrep); unsafe { MARK_NOT_MUTABLE(altrep) }; diff --git a/src/eval.rs b/src/eval.rs index 1df04364..b60457de 100644 --- a/src/eval.rs +++ b/src/eval.rs @@ -49,7 +49,7 @@ pub fn eval_parse_text>(text: T) -> crate::error::Result>(text: T) -> crate::error::Result SEXP { } // Protect the object until the operation finishes - local_protect(obj); + let _obj_guard = local_protect(obj); let preserved = PRESERVED_LIST.get_or_init(|| { let r = Rf_cons(R_NilValue, R_NilValue); @@ -87,7 +87,7 @@ pub fn insert_to_preserved_list(obj: SEXP) -> SEXP { }); let token = Rf_cons(preserved.0, CDR(preserved.0)); - local_protect(token); + let _token_guard = local_protect(token); SET_TAG(token, obj); SETCDR(preserved.0, token); diff --git a/src/sexp/complex.rs b/src/sexp/complex.rs index c55d2e05..7c477853 100644 --- a/src/sexp/complex.rs +++ b/src/sexp/complex.rs @@ -199,7 +199,7 @@ impl OwnedComplexSexp { // truncated to the actual length at last. let inner = crate::alloc_vector(CPLXSXP, upper as _)?; - local_protect(inner); + let _inner_guard = local_protect(inner); let raw = unsafe { COMPLEX(inner) }; let mut last_index = 0; diff --git a/src/sexp/external_pointer.rs b/src/sexp/external_pointer.rs index 7f6cdf75..ab1e3e29 100644 --- a/src/sexp/external_pointer.rs +++ b/src/sexp/external_pointer.rs @@ -60,7 +60,7 @@ pub trait IntoExtPtrSexp: Sized { let external_pointer = R_MakeExternalPtr(ptr as *mut std::os::raw::c_void, R_NilValue, R_NilValue); - local_protect(external_pointer); + let _external_pointer_guard = local_protect(external_pointer); // Use R_RegisterCFinalizerEx(..., TRUE) instead of // R_RegisterCFinalizer() in order to make the cleanup happen during diff --git a/src/sexp/function.rs b/src/sexp/function.rs index 10e5c27d..7a318030 100644 --- a/src/sexp/function.rs +++ b/src/sexp/function.rs @@ -125,7 +125,7 @@ impl FunctionSexp { Rf_lcons(self.inner(), args.inner()) }; - local_protect(call); + let _call_guard = local_protect(call); // Note: here, probably the environment doesn't matter at all // because the first argument is the function, which preserves the diff --git a/src/sexp/integer.rs b/src/sexp/integer.rs index 89668031..0061cf0c 100644 --- a/src/sexp/integer.rs +++ b/src/sexp/integer.rs @@ -224,7 +224,7 @@ impl OwnedIntegerSexp { /// let mut out = unsafe { OwnedIntegerSexp::new_without_init(2)? }; /// out[0] = value.x; /// out[1] = value.y; - /// + /// /// Ok(out) /// } /// } @@ -285,7 +285,7 @@ impl OwnedIntegerSexp { // truncated to the actual length at last. let inner = crate::alloc_vector(INTSXP, upper as _)?; - local_protect(inner); + let _inner_guard = local_protect(inner); let raw = unsafe { INTEGER(inner) }; let mut last_index = 0; diff --git a/src/sexp/logical.rs b/src/sexp/logical.rs index b9c73809..9dd9b6b8 100644 --- a/src/sexp/logical.rs +++ b/src/sexp/logical.rs @@ -199,7 +199,7 @@ impl OwnedLogicalSexp { /// let mut out = unsafe { OwnedLogicalSexp::new_without_init(2)? }; /// out.set_elt(0, value.x)?; /// out.set_elt(1, value.y)?; - /// + /// /// Ok(out) /// } /// } @@ -259,7 +259,7 @@ impl OwnedLogicalSexp { // truncated to the actual length at last. let inner = crate::alloc_vector(LGLSXP, upper as _)?; - local_protect(inner); + let _inner_guard = local_protect(inner); let raw = unsafe { LOGICAL(inner) }; let mut last_index = 0; diff --git a/src/sexp/raw.rs b/src/sexp/raw.rs index 0bdbba6f..617f38c8 100644 --- a/src/sexp/raw.rs +++ b/src/sexp/raw.rs @@ -203,7 +203,7 @@ impl OwnedRawSexp { /// let mut out = unsafe { OwnedRawSexp::new_without_init(2)? }; /// out[0] = value.x; /// out[1] = value.y; - /// + /// /// Ok(out) /// } /// } @@ -264,7 +264,7 @@ impl OwnedRawSexp { // truncated to the actual length at last. let inner = crate::alloc_vector(RAWSXP, upper as _)?; - local_protect(inner); + let _inner_guard = local_protect(inner); let raw = unsafe { RAW(inner) }; let mut last_index = 0; diff --git a/src/sexp/real.rs b/src/sexp/real.rs index e4d87e53..cb42a37d 100644 --- a/src/sexp/real.rs +++ b/src/sexp/real.rs @@ -227,7 +227,7 @@ impl OwnedRealSexp { /// let mut out = unsafe { OwnedRealSexp::new_without_init(2)? }; /// out[0] = value.x; /// out[1] = value.y; - /// + /// /// Ok(out) /// } /// } @@ -288,7 +288,7 @@ impl OwnedRealSexp { // truncated to the actual length at last. let inner = crate::alloc_vector(REALSXP, upper as _)?; - local_protect(inner); + let _inner_guard = local_protect(inner); let raw = unsafe { REAL(inner) }; let mut last_index = 0; diff --git a/src/sexp/string.rs b/src/sexp/string.rs index 3dcc2d3a..f22edb52 100644 --- a/src/sexp/string.rs +++ b/src/sexp/string.rs @@ -186,7 +186,7 @@ impl OwnedStringSexp { // truncated to the actual length at last. let inner = crate::alloc_vector(STRSXP, upper as _)?; - local_protect(inner); + let _inner_guard = local_protect(inner); let mut last_index = 0; for (i, v) in iter.enumerate() { @@ -260,7 +260,7 @@ impl OwnedStringSexp { // Note: unlike `new()`, this allocates a STRSXP after creating a // CHARSXP. So, the `CHARSXP` needs to be protected. let charsxp = str_to_charsxp(value.as_ref())?; - local_protect(charsxp); + let _charsxp_guard = local_protect(charsxp); crate::unwind_protect(|| savvy_ffi::Rf_ScalarString(charsxp))? }; Self::new_from_raw_sexp(sexp, 1)