Skip to content

Commit

Permalink
Fix issues mixing 'const'-ness of STRING_PTR_RO (#6659)
Browse files Browse the repository at this point in the history
* Fix issues mixing 'const'-ness of STRING_PTR_RO

* Provide a few more *_RO accessors for R<3.5

---------

Co-authored-by: Ivan K <[email protected]>
  • Loading branch information
MichaelChirico and aitap authored Dec 13, 2024
1 parent a599557 commit a9cd0bf
Show file tree
Hide file tree
Showing 3 changed files with 11 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
3 changes: 3 additions & 0 deletions src/data.table.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
# define USE_RINTERNALS // #3301
# define DATAPTR_RO(x) ((const void *)DATAPTR(x))
# define STRING_PTR_RO STRING_PTR
# define INTEGER_RO INTEGER
# define REAL_RO REAL
# define COMPLEX_RO COMPLEX
# define R_Calloc(x, y) Calloc(x, y) // #6380
# define R_Realloc(x, y, z) Realloc(x, y, z)
# define R_Free(x) Free(x)
Expand Down

0 comments on commit a9cd0bf

Please sign in to comment.