From 6d66b81ef4d221b1bd003f1ba68c4bdc90e6c73e Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Thu, 12 Dec 2024 02:07:59 +0000 Subject: [PATCH] Fix issues mixing 'const'-ness of STRING_PTR_RO --- src/chmatch.c | 5 +++-- src/coalesce.c | 10 +++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/chmatch.c b/src/chmatch.c index 2bad963f9..46e68c1d8 100644 --- a/src/chmatch.c +++ b/src/chmatch.c @@ -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) { diff --git a/src/coalesce.c b/src/coalesce.c index c6e18da9e..0f25c5c6d 100644 --- a/src/coalesce.c +++ b/src/coalesce.c @@ -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: { @@ -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)) @@ -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)) @@ -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)) @@ -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))