Skip to content

Commit

Permalink
cherry picked #5769 to master
Browse files Browse the repository at this point in the history
  • Loading branch information
jangorecki committed Dec 2, 2023
1 parent cbb0d07 commit 5533835
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 32 deletions.
7 changes: 4 additions & 3 deletions src/assign.c
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,8 @@ SEXP assign(SEXP dt, SEXP rows, SEXP cols, SEXP newcolnames, SEXP values)
// Can growVector at this point easily enough, but it shouldn't happen in first place so leave it as
// strong error message for now.
else if (TRUELENGTH(names) != oldtncol)
error(_("Internal error: selfrefnames is ok but tl names [%d] != tl [%d]"), TRUELENGTH(names), oldtncol); // # nocov
// Use (long long) to cast R_xlen_t to a fixed type to robustly avoid -Wformat compiler warnings, see #5768, PRId64 didnt work
error(_("Internal error: selfrefnames is ok but tl names [%ld] != tl [%d]"), TRUELENGTH(names), oldtncol); // # nocov
SETLENGTH(dt, oldncol+LENGTH(newcolnames));
SETLENGTH(names, oldncol+LENGTH(newcolnames));
for (int i=0; i<LENGTH(newcolnames); ++i)
Expand Down Expand Up @@ -658,7 +659,7 @@ SEXP assign(SEXP dt, SEXP rows, SEXP cols, SEXP newcolnames, SEXP values)
R_isort(tt, ndelete); // sort the column-numbers-to-delete into ascending order
for (int i=0; i<ndelete-1; ++i) {
if (tt[i]>=tt[i+1])
error(_("Internal error: %d column numbers to delete not now in strictly increasing order. No-dups were checked earlier.")); // # nocov
error(_("Internal error: %d column numbers to delete not now in strictly increasing order. No-dups were checked earlier."), i); // # nocov
}
for (int i=tt[0], j=1, k=tt[0]+1; i<ndt-ndelete; ++i, ++k) { // i moves up from the first non-deleted column and is the target of write
while (j<ndelete && k==tt[j]) { j++; k++; } // move k up to the next non-deleted column; j is the next position in tt
Expand Down Expand Up @@ -808,7 +809,7 @@ const char *memrecycle(const SEXP target, const SEXP where, const int start, con
// # nocov start
for (int k=0; k<nSourceLevels; ++k) SET_TRUELENGTH(sourceLevelsD[k], 0);
savetl_end();
error(_("Unable to allocate working memory of %d bytes to combine factor levels"), nAdd*sizeof(SEXP *));
error(_("Unable to allocate working memory of %lu bytes to combine factor levels"), nAdd*sizeof(SEXP *));
// # nocov end
}
for (int k=0, thisAdd=0; thisAdd<nAdd; ++k) { // thisAdd<nAdd to stop early when the added ones are all reached
Expand Down
2 changes: 1 addition & 1 deletion src/fread.c
Original file line number Diff line number Diff line change
Expand Up @@ -1894,7 +1894,7 @@ int freadMain(freadMainArgs _args) {
if (sampleLines>0) for (int j=0; j<ncol; j++) {
if (tmpType[j]==CT_STRING && type[j]<CT_STRING && type[j]>CT_EMPTY) {
args.header=true;
if (verbose) DTPRINT(_(" 'header' determined to be true due to column %d containing a string on row 1 and a lower type (%s) in the rest of the %d sample rows\n"),
if (verbose) DTPRINT(_(" 'header' determined to be true due to column %d containing a string on row 1 and a lower type (%s) in the rest of the %"PRId64" sample rows\n"),
j+1, typeName[type[j]], sampleLines);
break;
}
Expand Down
6 changes: 3 additions & 3 deletions src/fsort.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ SEXP fsort(SEXP x, SEXP verboseArg) {
int MSBNbits = maxBit > 15 ? 16 : maxBit+1; // how many bits make up the MSB
int shift = maxBit + 1 - MSBNbits; // the right shift to leave the MSB bits remaining
size_t MSBsize = 1LL<<MSBNbits; // the number of possible MSB values (16 bits => 65,536)
if (verbose) Rprintf(_("maxBit=%d; MSBNbits=%d; shift=%d; MSBsize=%d\n"), maxBit, MSBNbits, shift, MSBsize);
if (verbose) Rprintf(_("maxBit=%d; MSBNbits=%d; shift=%d; MSBsize=%zu\n"), maxBit, MSBNbits, shift, MSBsize);

uint64_t *counts = (uint64_t *)R_alloc(nBatch*MSBsize, sizeof(uint64_t));
memset(counts, 0, nBatch*MSBsize*sizeof(uint64_t));
Expand Down Expand Up @@ -242,11 +242,11 @@ SEXP fsort(SEXP x, SEXP verboseArg) {

if (verbose) {
Rprintf(_("Top 20 MSB counts: ")); for(int i=0; i<MIN(MSBsize,20); i++) Rprintf(_("%"PRId64" "), (int64_t)msbCounts[order[i]]); Rprintf(_("\n"));
Rprintf(_("Reduced MSBsize from %d to "), MSBsize);
Rprintf(_("Reduced MSBsize from %zu to "), MSBsize);
}
while (MSBsize>0 && msbCounts[order[MSBsize-1]] < 2) MSBsize--;
if (verbose) {
Rprintf(_("%d by excluding 0 and 1 counts\n"), MSBsize);
Rprintf(_("%zu by excluding 0 and 1 counts\n"), MSBsize);
}

bool failed=false, alloc_fail=false, non_monotonic=false; // shared bools only ever assigned true; no need for atomic or critical assign
Expand Down
8 changes: 4 additions & 4 deletions src/fwrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ void fwriteMain(fwriteMainArgs args)
}
if (headerLen) {
char *buff = malloc(headerLen);
if (!buff) STOP(_("Unable to allocate %d MiB for header: %s"), headerLen / 1024 / 1024, strerror(errno));
if (!buff) STOP(_("Unable to allocate %zu MiB for header: %s"), headerLen / 1024 / 1024, strerror(errno));
char *ch = buff;
if (args.bom) {*ch++=(char)0xEF; *ch++=(char)0xBB; *ch++=(char)0xBF; } // 3 appears above (search for "bom")
memcpy(ch, args.yaml, yamlLen);
Expand Down Expand Up @@ -753,7 +753,7 @@ void fwriteMain(fwriteMainArgs args)
char *zbuff = malloc(zbuffSize);
if (!zbuff) {
free(buff); // # nocov
STOP(_("Unable to allocate %d MiB for zbuffer: %s"), zbuffSize / 1024 / 1024, strerror(errno)); // # nocov
STOP(_("Unable to allocate %zu MiB for zbuffer: %s"), zbuffSize / 1024 / 1024, strerror(errno)); // # nocov
}
size_t zbuffUsed = zbuffSize;
ret1 = compressbuff(&stream, zbuff, &zbuffUsed, buff, (size_t)(ch-buff));
Expand Down Expand Up @@ -820,7 +820,7 @@ void fwriteMain(fwriteMainArgs args)
char *buffPool = malloc(nth*(size_t)buffSize);
if (!buffPool) {
// # nocov start
STOP(_("Unable to allocate %d MB * %d thread buffers; '%d: %s'. Please read ?fwrite for nThread, buffMB and verbose options."),
STOP(_("Unable to allocate %zu MB * %d thread buffers; '%d: %s'. Please read ?fwrite for nThread, buffMB and verbose options."),
(size_t)buffSize/(1024^2), nth, errno, strerror(errno));
// # nocov end
}
Expand All @@ -831,7 +831,7 @@ void fwriteMain(fwriteMainArgs args)
if (!zbuffPool) {
// # nocov start
free(buffPool);
STOP(_("Unable to allocate %d MB * %d thread compressed buffers; '%d: %s'. Please read ?fwrite for nThread, buffMB and verbose options."),
STOP(_("Unable to allocate %zu MB * %d thread compressed buffers; '%d: %s'. Please read ?fwrite for nThread, buffMB and verbose options."),
(size_t)zbuffSize/(1024^2), nth, errno, strerror(errno));
// # nocov end
}
Expand Down
6 changes: 3 additions & 3 deletions src/gsumm.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ SEXP gforce(SEXP env, SEXP jsub, SEXP o, SEXP f, SEXP l, SEXP irowsArg) {
// TODO: enable stress-test mode in tests only (#3205) which can be turned off by default in release to decrease overhead on small data
// if that is established to be biting (it may be fine).
if (nBatch<1 || batchSize<1 || lastBatchSize<1) {
error(_("Internal error: nrow=%d ngrp=%d nbit=%d bitshift=%d highSize=%d nBatch=%d batchSize=%d lastBatchSize=%d\n"), // # nocov
nrow, ngrp, nb, bitshift, highSize, nBatch, batchSize, lastBatchSize); // # nocov
error(_("Internal error: nrow=%d ngrp=%d nbit=%d bitshift=%d highSize=%zu nBatch=%zu batchSize=%zu lastBatchSize=%zu\n"), // # nocov
nrow, ngrp, nb, bitshift, highSize, nBatch, batchSize, lastBatchSize); // # nocov
}
// initial population of g:
#pragma omp parallel for num_threads(getDTthreads(ngrp, false))
Expand Down Expand Up @@ -1116,7 +1116,7 @@ SEXP gprod(SEXP x, SEXP narmArg) {
//clock_t start = clock();
if (nrow != n) error(_("nrow [%d] != length(x) [%d] in %s"), nrow, n, "gprod");
long double *s = malloc(ngrp * sizeof(long double));
if (!s) error(_("Unable to allocate %d * %d bytes for gprod"), ngrp, sizeof(long double));
if (!s) error(_("Unable to allocate %d * %lu bytes for gprod"), ngrp, sizeof(long double));
for (int i=0; i<ngrp; ++i) s[i] = 1.0;
switch(TYPEOF(x)) {
case LGLSXP: case INTSXP: {
Expand Down
31 changes: 16 additions & 15 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ static void setSizes(void) {
__sizes[CPLXSXP] = sizeof(Rcomplex); __typeorder[CPLXSXP] = 4;
__sizes[STRSXP] = sizeof(SEXP *); __typeorder[STRSXP] = 5;
__sizes[VECSXP] = sizeof(SEXP *); __typeorder[VECSXP] = 6; // list column
if (sizeof(char *)>8) error(_("Pointers are %d bytes, greater than 8. We have not tested on any architecture greater than 64bit yet."), sizeof(char *));
if (sizeof(char *)>8) error(_("Pointers are %lu bytes, greater than 8. We have not tested on any architecture greater than 64bit yet."), sizeof(char *));
// One place we need the largest sizeof is the working memory malloc in reorder.c
}

Expand All @@ -177,23 +177,24 @@ void attribute_visible R_init_data_table(DllInfo *info)
const char *msg = _("... failed. Please forward this message to maintainer('data.table').");
if ((int)NA_INTEGER != (int)INT_MIN) error(_("Checking NA_INTEGER [%d] == INT_MIN [%d] %s"), NA_INTEGER, INT_MIN, msg);
if ((int)NA_INTEGER != (int)NA_LOGICAL) error(_("Checking NA_INTEGER [%d] == NA_LOGICAL [%d] %s"), NA_INTEGER, NA_LOGICAL, msg);
if (sizeof(int) != 4) error(_("Checking sizeof(%s) [%d] is %d %s"), "int", sizeof(int), 4, msg);
if (sizeof(double) != 8) error(_("Checking sizeof(%s) [%d] is %d %s"), "double", sizeof(double), 8, msg); // 8 on both 32bit and 64bit
// alignof not available in C99: if (alignof(double) != 8) error(_("Checking alignof(double) [%d] is 8 %s"), alignof(double), msg); // 8 on both 32bit and 64bit
if (sizeof(long long) != 8) error(_("Checking sizeof(%s) [%d] is %d %s"), "long long", sizeof(long long), 8, msg);
if (sizeof(char *) != 4 && sizeof(char *) != 8) error(_("Checking sizeof(pointer) [%d] is 4 or 8 %s"), sizeof(char *), msg);
if (sizeof(SEXP) != sizeof(char *)) error(_("Checking sizeof(SEXP) [%d] == sizeof(pointer) [%d] %s"), sizeof(SEXP), sizeof(char *), msg);
if (sizeof(uint64_t) != 8) error(_("Checking sizeof(%s) [%d] is %d %s"), "uint64_t", sizeof(uint64_t), 8, msg);
if (sizeof(int64_t) != 8) error(_("Checking sizeof(%s) [%d] is %d %s"), "int64_t", sizeof(int64_t), 8, msg);
if (sizeof(signed char) != 1) error(_("Checking sizeof(%s) [%d] is %d %s"), "signed char", sizeof(signed char), 1, msg);
if (sizeof(int8_t) != 1) error(_("Checking sizeof(%s) [%d] is %d %s"), "int8_t", sizeof(int8_t), 1, msg);
if (sizeof(uint8_t) != 1) error(_("Checking sizeof(%s) [%d] is %d %s"), "uint8_t", sizeof(uint8_t), 1, msg);
if (sizeof(int16_t) != 2) error(_("Checking sizeof(%s) [%d] is %d %s"), "int16_t", sizeof(int16_t), 2, msg);
if (sizeof(uint16_t) != 2) error(_("Checking sizeof(%s) [%d] is %d %s"), "uint16_t", sizeof(uint16_t), 2 ,msg);
if (sizeof(int) != 4) error(_("Checking sizeof(%s) [%lu] is %d %s"), "int", sizeof(int), 4, msg);
if (sizeof(double) != 8) error(_("Checking sizeof(%s) [%lu] is %d %s"), "double", sizeof(double), 8, msg); // 8 on both 32bit and 64bit
// alignof not available in C99: if (alignof(double) != 8) error(_("Checking alignof(double) [%lu] is 8 %s"), alignof(double), msg); // 8 on both 32bit and 64bit
if (sizeof(long long) != 8) error(_("Checking sizeof(%s) [%lu] is %d %s"), "long long", sizeof(long long), 8, msg);
if (sizeof(char *) != 4 && sizeof(char *) != 8) error(_("Checking sizeof(pointer) [%lu] is 4 or 8 %s"), sizeof(char *), msg);
if (sizeof(SEXP) != sizeof(char *)) error(_("Checking sizeof(SEXP) [%lu] == sizeof(pointer) [%lu] %s"), sizeof(SEXP), sizeof(char *), msg);
if (sizeof(uint64_t) != 8) error(_("Checking sizeof(%s) [%lu] is %d %s"), "uint64_t", sizeof(uint64_t), 8, msg);
if (sizeof(int64_t) != 8) error(_("Checking sizeof(%s) [%lu] is %d %s"), "int64_t", sizeof(int64_t), 8, msg);
if (sizeof(signed char) != 1) error(_("Checking sizeof(%s) [%lu] is %d %s"), "signed char", sizeof(signed char), 1, msg);
if (sizeof(int8_t) != 1) error(_("Checking sizeof(%s) [%lu] is %d %s"), "int8_t", sizeof(int8_t), 1, msg);
if (sizeof(uint8_t) != 1) error(_("Checking sizeof(%s) [%lu] is %d %s"), "uint8_t", sizeof(uint8_t), 1, msg);
if (sizeof(int16_t) != 2) error(_("Checking sizeof(%s) [%lu] is %d %s"), "int16_t", sizeof(int16_t), 2, msg);
if (sizeof(uint16_t) != 2) error(_("Checking sizeof(%s) [%lu] is %d %s"), "uint16_t", sizeof(uint16_t), 2 ,msg);

SEXP tmp = PROTECT(allocVector(INTSXP,2));
if (LENGTH(tmp)!=2) error(_("Checking LENGTH(allocVector(INTSXP,2)) [%d] is 2 %s"), LENGTH(tmp), msg);
if (TRUELENGTH(tmp)!=0) error(_("Checking TRUELENGTH(allocVector(INTSXP,2)) [%d] is 0 %s"), TRUELENGTH(tmp), msg);
// Use (long long) to cast R_xlen_t to a fixed type to robustly avoid -Wformat compiler warnings, see #5768
if (TRUELENGTH(tmp)!=0) error(_("Checking TRUELENGTH(allocVector(INTSXP,2)) [%lld] is 0 %s"), (long long)TRUELENGTH(tmp), msg);
UNPROTECT(1);

// According to IEEE (http://en.wikipedia.org/wiki/IEEE_754-1985#Zero) we can rely on 0.0 being all 0 bits.
Expand Down
4 changes: 2 additions & 2 deletions src/reorder.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ SEXP reorder(SEXP x, SEXP order)
for (int i=0; i<ncol; i++) {
SEXP v = VECTOR_ELT(x,i);
if (SIZEOF(v)!=4 && SIZEOF(v)!=8 && SIZEOF(v)!=16 && SIZEOF(v)!=1)
error(_("Item %d of list is type '%s' which isn't yet supported (SIZEOF=%d)"), i+1, type2char(TYPEOF(v)), SIZEOF(v));
error(_("Item %d of list is type '%s' which isn't yet supported (SIZEOF=%zu)"), i+1, type2char(TYPEOF(v)), SIZEOF(v));
if (length(v)!=nrow)
error(_("Column %d is length %d which differs from length of column 1 (%d). Invalid data.table."), i+1, length(v), nrow);
if (SIZEOF(v) > maxSize)
Expand All @@ -24,7 +24,7 @@ SEXP reorder(SEXP x, SEXP order)
copySharedColumns(x); // otherwise two columns which point to the same vector would be reordered and then re-reordered, issues linked in PR#3768
} else {
if (SIZEOF(x)!=4 && SIZEOF(x)!=8 && SIZEOF(x)!=16 && SIZEOF(x)!=1)
error(_("reorder accepts vectors but this non-VECSXP is type '%s' which isn't yet supported (SIZEOF=%d)"), type2char(TYPEOF(x)), SIZEOF(x));
error(_("reorder accepts vectors but this non-VECSXP is type '%s' which isn't yet supported (SIZEOF=%zu)"), type2char(TYPEOF(x)), SIZEOF(x));
if (ALTREP(x)) error(_("Internal error in reorder.c: cannot reorder an ALTREP vector. Please see NEWS item 2 in v1.11.4 and report this as a bug.")); // # nocov
maxSize = SIZEOF(x);
nrow = length(x);
Expand Down
2 changes: 1 addition & 1 deletion src/snprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ SEXP test_dt_win_snprintf(void)

int res = dt_win_snprintf(buff, 10, "%4$d%2$d%3$d%5$d%1$d", 111, 222, 33, 44, 555); // fmt longer than n
if (strlen(buff)!=9 || strcmp(buff, "442223355")) error(_("dt_win_snprintf test %d failed: %s"), 9, buff);
if (res!=13) /* should return what would have been written if not chopped */ error(_("dt_win_snprintf test %d failed: %s"), 10, res);
if (res!=13) /* should return what would have been written if not chopped */ error(_("dt_win_snprintf test %d failed: %d"), 10, res);

dt_win_snprintf(buff, 39, "%l", 3);
if (strlen(buff)!=38 || strcmp(buff, "0 %l does not end with recognized t")) error(_("dt_win_snprintf test %d failed: %s"), 11, buff);
Expand Down

0 comments on commit 5533835

Please sign in to comment.