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 issues mixing 'const'-ness of STRING_PTR_RO #6659

Merged
merged 2 commits into from
Dec 13, 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
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
Loading