Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix usage of local_protect() #279

Merged
merged 1 commit into from
Jul 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/altrep/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub(crate) fn create_altrep_instance<T: IntoExtPtrSexp>(
class_name: &'static str,
) -> crate::Result<SEXP> {
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",
Expand All @@ -47,7 +47,7 @@ pub(crate) fn create_altrep_instance<T: IntoExtPtrSexp>(
.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) };

Expand Down
4 changes: 2 additions & 2 deletions src/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub fn eval_parse_text<T: AsRef<str>>(text: T) -> crate::error::Result<EvalResul

unsafe {
let charsxp = str_to_charsxp(text.as_ref())?;
local_protect(charsxp);
let _charsxp_guard = local_protect(charsxp);
let text_sexp = crate::unwind_protect(|| savvy_ffi::Rf_ScalarString(charsxp))?;

// According to WRE (https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Parsing-R-code-from-C),
Expand All @@ -76,7 +76,7 @@ pub fn eval_parse_text<T: AsRef<str>>(text: T) -> crate::error::Result<EvalResul
let parsed = unwind_protect(|| {
savvy_ffi::R_ParseVector(text_sexp, -1, parse_status.as_ptr(), R_NilValue)
})?;
local_protect(parsed);
let _parsed_guard = local_protect(parsed);

if parse_status.get() != savvy_ffi::ParseStatus_PARSE_OK {
return Err(crate::error::Error::InvalidRCode(text.as_ref().to_string()));
Expand Down
4 changes: 2 additions & 2 deletions src/protect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub fn insert_to_preserved_list(obj: SEXP) -> 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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/sexp/complex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/sexp/external_pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/sexp/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/sexp/integer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
/// }
/// }
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/sexp/logical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
/// }
/// }
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/sexp/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
/// }
/// }
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/sexp/real.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
/// }
/// }
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/sexp/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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)
Expand Down
Loading