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

PROTECT() as= input to coerceAs() #6249

Merged
merged 5 commits into from
Jul 13, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
9 changes: 6 additions & 3 deletions src/frollR.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ SEXP coerceToRealListR(SEXP obj) {
SEXP this_obj = VECTOR_ELT(obj, i);
if (!(isReal(this_obj) || isInteger(this_obj) || isLogical(this_obj)))
error(_("x must be of type numeric or logical, or a list, data.frame or data.table of such"));
SET_VECTOR_ELT(x, i, coerceAs(this_obj, ScalarReal(NA_REAL), /*copyArg=*/ScalarLogical(false))); // copyArg=false will make type-class match to return as-is, no copy
SET_VECTOR_ELT(x, i, coerceAs(this_obj, PROTECT(ScalarReal(NA_REAL)), /*copyArg=*/ScalarLogical(false))); // copyArg=false will make type-class match to return as-is, no copy
UNPROTECT(1); // as= input to coerceAs()
}
UNPROTECT(protecti);
return x;
Expand Down Expand Up @@ -145,7 +146,8 @@ SEXP frollfunR(SEXP fun, SEXP obj, SEXP k, SEXP fill, SEXP algo, SEXP align, SEX
error(_("fill must be a vector of length 1"));
if (!isInteger(fill) && !isReal(fill) && !isLogical(fill))
error(_("fill must be numeric or logical"));
double dfill = REAL(PROTECT(coerceAs(fill, ScalarReal(NA_REAL), ScalarLogical(true))))[0]; protecti++;
double dfill = REAL(PROTECT(coerceAs(fill, PROTECT(ScalarReal(NA_REAL)), ScalarLogical(true))))[0]; protecti++;
UNPROTECT(1); // as= input to coerceAs()

bool bnarm = LOGICAL(narm)[0];

Expand Down Expand Up @@ -257,7 +259,8 @@ SEXP frollapplyR(SEXP fun, SEXP obj, SEXP k, SEXP fill, SEXP align, SEXP rho) {
error(_("fill must be a vector of length 1"));
if (!isInteger(fill) && !isReal(fill) && !isLogical(fill))
error(_("fill must be numeric or logical"));
double dfill = REAL(PROTECT(coerceAs(fill, ScalarReal(NA_REAL), ScalarLogical(true))))[0]; protecti++;
double dfill = REAL(PROTECT(coerceAs(fill, PROTECT(ScalarReal(NA_REAL)), ScalarLogical(true))))[0]; protecti++;
UNPROTECT(1); // as= input to coerceAs()

SEXP ans = PROTECT(allocVector(VECSXP, nk * nx)); protecti++;
if (verbose)
Expand Down
3 changes: 2 additions & 1 deletion src/gsumm.c
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,8 @@ SEXP gmean(SEXP x, SEXP narmArg)
x = PROTECT(coerceVector(x, REALSXP)); protecti++;
case REALSXP: {
if (INHERITS(x, char_integer64)) {
x = PROTECT(coerceAs(x, /*as=*/ScalarReal(1), /*copyArg=*/ScalarLogical(TRUE))); protecti++;
x = PROTECT(coerceAs(x, /*as=*/PROTECT(ScalarReal(1)), /*copyArg=*/ScalarLogical(TRUE))); protecti++;
UNPROTECT(1); // as= input to coerceAs()
}
const double *restrict gx = gather(x, &anyNA);
ans = PROTECT(allocVector(REALSXP, ngrp)); protecti++;
Expand Down
Loading