Skip to content

Commit

Permalink
Fix issues mixing 'const'-ness of STRING_PTR_RO
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelChirico committed Dec 12, 2024
1 parent a599557 commit 6d66b81
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/chmatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ static SEXP chmatchMain(SEXP x, SEXP table, int nomatch, bool chin, bool chmatch
return ans;
}
// Since non-ASCII strings may be marked with different encodings, it only make sense to compare
// the bytes under a same encoding (UTF-8) #3844 #3850
// the bytes under a same encoding (UTF-8) #3844 #3850.
// Not 'const' because we might SET_TRUELENGTH() below.
SEXP *xd;
if (isSymbol(x)) {
xd = &sym;
} else {
xd = STRING_PTR_RO(PROTECT(coerceUtf8IfNeeded(x))); nprotect++;
xd = (SEXP *)STRING_PTR_RO(PROTECT(coerceUtf8IfNeeded(x))); nprotect++;
}
const SEXP *td = STRING_PTR_RO(PROTECT(coerceUtf8IfNeeded(table))); nprotect++;
if (xlen==1) {
Expand Down
10 changes: 5 additions & 5 deletions src/coalesce.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ SEXP coalesce(SEXP x, SEXP inplaceArg) {
first = PROTECT(copyAsPlain(first)); nprotect++;
if (verbose) Rprintf(_("coalesce copied first item (inplace=FALSE)\n"));
}
void **valP = (void **)R_alloc(nval, sizeof(void *));
const void **valP = (const void **)R_alloc(nval, sizeof(void *));
switch(TYPEOF(first)) {
case LGLSXP:
case INTSXP: {
Expand All @@ -66,7 +66,7 @@ SEXP coalesce(SEXP x, SEXP inplaceArg) {
finalVal = tt;
break; // stop early on the first singleton that is not NA; minimizes deepest loop body below
}
valP[k++] = INTEGER(item);
valP[k++] = INTEGER_RO(item);
}
const bool final=(finalVal!=NA_INTEGER);
#pragma omp parallel for num_threads(getDTthreads(nrow, true))
Expand All @@ -89,7 +89,7 @@ SEXP coalesce(SEXP x, SEXP inplaceArg) {
finalVal = tt;
break;
}
valP[k++] = REAL(item);
valP[k++] = REAL_RO(item);
}
const bool final = (finalVal!=NA_INTEGER64);
#pragma omp parallel for num_threads(getDTthreads(nrow, true))
Expand All @@ -110,7 +110,7 @@ SEXP coalesce(SEXP x, SEXP inplaceArg) {
finalVal = tt;
break;
}
valP[k++] = REAL(item);
valP[k++] = REAL_RO(item);
}
const bool final = !ISNAN(finalVal);
#pragma omp parallel for num_threads(getDTthreads(nrow, true))
Expand All @@ -133,7 +133,7 @@ SEXP coalesce(SEXP x, SEXP inplaceArg) {
finalVal = tt;
break;
}
valP[k++] = COMPLEX(item);
valP[k++] = COMPLEX_RO(item);
}
const bool final = !ISNAN(finalVal.r) && !ISNAN(finalVal.i);
#pragma omp parallel for num_threads(getDTthreads(nrow, true))
Expand Down

0 comments on commit 6d66b81

Please sign in to comment.