Skip to content

Commit

Permalink
# nocov for recent missed lines
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelChirico authored Sep 26, 2024
1 parent 11a44bd commit 091859c
Show file tree
Hide file tree
Showing 21 changed files with 81 additions and 68 deletions.
6 changes: 3 additions & 3 deletions R/data.table.R
Original file line number Diff line number Diff line change
Expand Up @@ -2256,8 +2256,8 @@ tail.data.table = function(x, n=6L, ...) {

"$<-.data.table" = function(x, name, value) {
if (!cedta()) {
ans = `$<-.data.frame`(x, name, value)
return(setalloccol(ans)) # over-allocate (again)
ans = `$<-.data.frame`(x, name, value) # nocov
return(setalloccol(ans)) # nocov. over-allocate (again)
}
x = copy(x)
set(x,j=name,value=value) # important i is missing here
Expand Down Expand Up @@ -2430,7 +2430,7 @@ which_ = function(x, bool = TRUE) {
}

is.na.data.table = function(x) {
if (!cedta()) return(is.na.data.frame(x))
if (!cedta()) return(is.na.data.frame(x)) # nocov
do.call(cbind, lapply(x, is.na))
}

Expand Down
4 changes: 3 additions & 1 deletion R/fread.R
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ yaml=FALSE, autostart=NA, tmpdir=tempdir(), tz="UTC")
}
# whitespace at the beginning or end of na.strings is checked at C level and is an error there; test 1804
}
# nocov start. Tested in other.Rraw tests 16, not in the main suite.
if (yaml) {
if (!requireNamespace('yaml', quietly = TRUE))
stopf("'data.table' relies on the package 'yaml' to parse the file header; please add this to your library with install.packages('yaml') and try again.") # nocov
Expand Down Expand Up @@ -267,6 +268,7 @@ yaml=FALSE, autostart=NA, tmpdir=tempdir(), tz="UTC")
}
if (is.integer(skip)) skip = skip + n_read
}
# nocov end
warnings2errors = getOption("warn") >= 2
stopifnot(identical(tz,"UTC") || identical(tz,""))
if (tz=="") {
Expand Down Expand Up @@ -341,7 +343,7 @@ yaml=FALSE, autostart=NA, tmpdir=tempdir(), tz="UTC")
key = cols_from_csv(key)
setkeyv(ans, key)
}
if (yaml) setattr(ans, 'yaml_metadata', yaml_header)
if (yaml) setattr(ans, 'yaml_metadata', yaml_header) # nocov
if (!is.null(index) && data.table) {
if (!all(vapply_1b(index, is.character)))
stopf("index argument of data.table() must be a character vector naming columns (NB: col.names are applied before this)")
Expand Down
2 changes: 2 additions & 0 deletions R/fwrite.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ fwrite = function(x, file="", append=FALSE, quote="auto",
return(invisible())
}
}
# nocov start. See test 17 in other.Rraw, not tested in the main suite.
yaml = if (!yaml) "" else {
if (!requireNamespace('yaml', quietly=TRUE))
stopf("'data.table' relies on the package 'yaml' to write the file header; please add this to your library with install.packages('yaml') and try again.") # nocov
Expand All @@ -114,6 +115,7 @@ fwrite = function(x, file="", append=FALSE, quote="auto",
)
paste0('---', eol, yaml::as.yaml(yaml_header, line.sep=eol), '---', eol) # NB: as.yaml adds trailing newline
}
# nocov end
file = enc2native(file) # CfwriteR cannot handle UTF-8 if that is not the native encoding, see #3078.
.Call(CfwriteR, x, file, sep, sep2, eol, na, dec, quote, qmethod=="escape", append,
row.names, col.names, logical01, scipen, dateTimeAs, buffMB, nThread,
Expand Down
2 changes: 2 additions & 0 deletions R/last.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# data.table defined last(x) with no arguments, just for last. If you need the last 10 then use tail(x,10).
# for xts class objects it will dispatch to xts::last
# reworked to avoid loading xts namespace (#3857) then again to fix dispatching of xts class (#4053)
# nocov start. Tests 19.* in other.Rraw, not in the main suite.
last = function(x, n=1L, ...) {
verbose = isTRUE(getOption("datatable.verbose", FALSE))
if (!inherits(x, "xts")) {
Expand Down Expand Up @@ -82,3 +83,4 @@ first = function(x, n=1L, ...) {
xts::first(x, n=n, ...)
}
}
# nocov end
2 changes: 2 additions & 0 deletions R/xts.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# nocov start. See tests 18.* in other.Rraw, not in the main suite.
as.data.table.xts = function(x, keep.rownames = TRUE, key=NULL, ...) {
stopifnot(requireNamespace("xts"), !missing(x), xts::is.xts(x))
if (length(keep.rownames) != 1L) stopf("keep.rownames must be length 1")
Expand Down Expand Up @@ -26,3 +27,4 @@ as.xts.data.table = function(x, numeric.only = TRUE, ...) {
}
return(xts::xts(as.matrix(r), order.by = if (inherits(x[[1L]], "IDate")) as.Date(x[[1L]]) else x[[1L]]))
}
# nocov end
8 changes: 4 additions & 4 deletions src/assign.c
Original file line number Diff line number Diff line change
Expand Up @@ -1190,7 +1190,7 @@ const char *memrecycle(const SEXP target, const SEXP where, const int start, con
}
}
} break;
default :
default : // # nocov
error(_("Unsupported column type in assign.c:memrecycle '%s'"), type2char(TYPEOF(target))); // # nocov
}
UNPROTECT(protecti);
Expand Down Expand Up @@ -1244,7 +1244,7 @@ void writeNA(SEXP v, const int from, const int n, const bool listNA)
case EXPRSXP :
for (int i=from; i<=to; ++i) SET_VECTOR_ELT(v, i, R_NilValue);
break;
default :
default : // # nocov
internal_error(__func__, "Unsupported type '%s' for v", type2char(TYPEOF(v))); // # nocov
}
}
Expand Down Expand Up @@ -1283,8 +1283,8 @@ void savetl_init(void) {
saveds = (SEXP *)malloc(nalloc * sizeof(SEXP));
savedtl = (R_len_t *)malloc(nalloc * sizeof(R_len_t));
if (!saveds || !savedtl) {
free(saveds); free(savedtl);
savetl_end(); // # nocov
free(saveds); free(savedtl); // # nocov
savetl_end(); // # nocov
error(_("Failed to allocate initial %d items in savetl_init"), nalloc); // # nocov
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/between.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ SEXP between(SEXP x, SEXP lower, SEXP upper, SEXP incbounds, SEXP NAboundsArg, S
}
if (verbose) Rprintf(_("between non-parallel processing of character took %8.3fs\n"), omp_get_wtime()-tic);
} break;
default:
default: // # nocov
internal_error(__func__, "unsupported type '%s' should have been caught at R level", type2char(TYPEOF(x))); // # nocov
}
UNPROTECT(nprotect);
Expand Down
4 changes: 2 additions & 2 deletions src/bmerge.c
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,8 @@ void bmerge_r(int xlowIn, int xuppIn, int ilowIn, int iuppIn, int col, int thisg
}
break;
// supported types were checked up front to avoid handling an error here in (future) parallel region
default:
error(_("Type '%s' is not supported for joining/merging"), type2char(TYPEOF(xc)));
default: // # nocov
internal_error("Invalid join/merge type '%s' should have been caught earlier", type2char(TYPEOF(xc))); // # nocov
}

if (xlow<xupp-1 || rollLow || rollUpp) { // if value found, xlow and xupp surround it, unlike standard binary search where low falls on it
Expand Down
2 changes: 1 addition & 1 deletion src/chmatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ static SEXP chmatchMain(SEXP x, SEXP table, int nomatch, bool chin, bool chmatch
int *counts = (int *)calloc(nuniq, sizeof(int));
int *map = (int *)calloc(mapsize, sizeof(int));
if (!counts || !map) {
free(counts); free(map);
// # nocov start
free(counts); free(map);
for (int i=0; i<tablelen; i++) SET_TRUELENGTH(td[i], 0);
savetl_end();
error(_("Failed to allocate %"PRIu64" bytes working memory in chmatchdup: length(table)=%d length(unique(table))=%d"), ((uint64_t)tablelen*2+nuniq)*sizeof(int), tablelen, nuniq);
Expand Down
6 changes: 3 additions & 3 deletions src/dogroups.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ SEXP dogroups(SEXP dt, SEXP dtcols, SEXP groups, SEXP grpcols, SEXP jiscols, SEX
// using <- in j (which is valid, useful and tested), they are repointed to the .SD cols for each group.
SEXP names = PROTECT(getAttrib(SDall, R_NamesSymbol)); nprotect++;
if (length(names) != length(SDall))
error("length(names)!=length(SD)"); // # notranslate
internal_error("length(names)!=length(SD)");
SEXP *nameSyms = (SEXP *)R_alloc(length(names), sizeof(SEXP));

for(int i=0; i<length(SDall); ++i) {
Expand All @@ -154,7 +154,7 @@ SEXP dogroups(SEXP dt, SEXP dtcols, SEXP groups, SEXP grpcols, SEXP jiscols, SEX

SEXP xknames = PROTECT(getAttrib(xSD, R_NamesSymbol)); nprotect++;
if (length(xknames) != length(xSD))
error("length(xknames)!=length(xSD)"); // # notranslate
internal_error("length(xknames)!=length(xSD)");
SEXP *xknameSyms = (SEXP *)R_alloc(length(xknames), sizeof(SEXP));
for(int i=0; i<length(xSD); ++i) {
if (SIZEOF(VECTOR_ELT(xSD, i))==0)
Expand Down Expand Up @@ -544,7 +544,7 @@ SEXP growVector(SEXP x, const R_len_t newlen)
for (int i=0; i<len; ++i)
SET_VECTOR_ELT(newx, i, xd[i]);
} break;
default :
default : // # nocov
internal_error(__func__, "type '%s' not supported", type2char(TYPEOF(x))); // # nocov
}
// if (verbose) Rprintf(_("Growing vector from %d to %d items of type '%s'\n"), len, newlen, type2char(TYPEOF(x)));
Expand Down
4 changes: 2 additions & 2 deletions src/fastmean.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ SEXP fastmean(SEXP args)
}
REAL(ans)[0] = (double) s;
break;
default:
default: // # nocov
internal_error(__func__, "type '%s' not caught earlier in fastmean", type2char(TYPEOF(x))); // # nocov
}
} else { // narm==FALSE
Expand Down Expand Up @@ -107,7 +107,7 @@ SEXP fastmean(SEXP args)
}
REAL(ans)[0] = (double) s;
break;
default:
default: // # nocov
internal_error(__func__, "type '%s' not caught earlier in fastmean", type2char(TYPEOF(x))); // # nocov
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/fmelt.c
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ SEXP fmelt(SEXP DT, SEXP id, SEXP measure, SEXP varfactor, SEXP valfactor, SEXP
int protecti=0;
dtnames = PROTECT(getAttrib(DT, R_NamesSymbol)); protecti++;
if (isNull(dtnames))
internal_error(__func__, "names(data) is NULL");
internal_error(__func__, "names(data) is NULL"); // # nocov
if (LOGICAL(narmArg)[0] == TRUE) narm = TRUE;
if (LOGICAL(verboseArg)[0] == TRUE) verbose = TRUE;
struct processData data;
Expand Down
41 changes: 20 additions & 21 deletions src/forder.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,8 @@ static void cradix(SEXP *x, int n)
cradix_counts = (int *)calloc(ustr_maxlen*256, sizeof(int)); // counts for the letters of left-aligned strings
cradix_xtmp = (SEXP *)malloc(ustr_n*sizeof(SEXP));
if (!cradix_counts || !cradix_xtmp) {
free(cradix_counts); free(cradix_xtmp);
STOP(_("Failed to alloc cradix_counts and/or cradix_tmp"));
free(cradix_counts); free(cradix_xtmp); // # nocov
STOP(_("Failed to alloc cradix_counts and/or cradix_tmp")); // # nocov
}
cradix_r(x, n, 0);
free(cradix_counts); cradix_counts=NULL;
Expand Down Expand Up @@ -772,12 +772,11 @@ SEXP forder(SEXP DT, SEXP by, SEXP retGrpArg, SEXP retStatsArg, SEXP sortGroupsA
}}
free_ustr(); // ustr could be left allocated and reused, but free now in case large and we're tight on ram
break;
default:
internal_error_with_cleanup(__func__, "column not supported, not caught earlier"); // # nocov
default: // # nocov
internal_error_with_cleanup(__func__, "column not supported, not caught earlier"); // # nocov
}
nradix += nbyte-1+(spare==0);
TEND(4)
// Rprintf(_("Written key for column %d\n"), col);
}
if (key[nradix]!=NULL) nradix++; // nradix now number of bytes in key
#ifdef TIMING_ON
Expand All @@ -789,17 +788,17 @@ SEXP forder(SEXP DT, SEXP by, SEXP retGrpArg, SEXP retStatsArg, SEXP sortGroupsA
TMP = (int *)malloc(nth*UINT16_MAX*sizeof(int)); // used by counting sort (my_n<=65536) in radix_r()
UGRP = (uint8_t *)malloc(nth*256); // TODO: align TMP and UGRP to cache lines (and do the same for stack allocations too)
if (!TMP || !UGRP /*|| TMP%64 || UGRP%64*/) {
free(TMP); free(UGRP);
STOP(_("Failed to allocate TMP or UGRP or they weren't cache line aligned: nth=%d"), nth);
free(TMP); free(UGRP); // # nocov
STOP(_("Failed to allocate TMP or UGRP or they weren't cache line aligned: nth=%d"), nth); // # nocov
}

if (retgrp) {
gs_thread = calloc(nth, sizeof(int *)); // thread private group size buffers
gs_thread_alloc = calloc(nth, sizeof(int));
gs_thread_n = calloc(nth, sizeof(int));
if (!gs_thread || !gs_thread_alloc || !gs_thread_n) {
free(gs_thread); free(gs_thread_alloc); free(gs_thread_n);
STOP(_("Could not allocate (very tiny) group size thread buffers"));
free(gs_thread); free(gs_thread_alloc); free(gs_thread_n); // # nocov
STOP(_("Could not allocate (very tiny) group size thread buffers")); // # nocov
}
}
if (nradix) {
Expand Down Expand Up @@ -917,7 +916,7 @@ void radix_r(const int from, const int to, const int radix) {
uint8_t *restrict my_key = key[radix]+from; // safe to write as we don't use this radix again
uint8_t *o = (uint8_t *)malloc(my_n * sizeof(uint8_t));
if (!o)
STOP(_("Failed to allocate %d bytes for '%s'."), (int)(my_n * sizeof(uint8_t)), "o");
STOP(_("Failed to allocate %d bytes for '%s'."), (int)(my_n * sizeof(uint8_t)), "o"); // # nocov
// if last key (i.e. radix+1==nradix) there are no more keys to reorder so we could reorder osub by reference directly and save allocating and populating o just
// to use it once. However, o's type is uint8_t so many moves within this max-256 vector should be faster than many moves in osub (4 byte or 8 byte ints) [1 byte
// type is always aligned]
Expand Down Expand Up @@ -986,8 +985,8 @@ void radix_r(const int from, const int to, const int radix) {
// reorder osub and each remaining ksub
int *TMP = malloc(my_n * sizeof(int));
if (!TMP) {
free(o);
STOP(_("Failed to allocate %d bytes for '%s'."), (int)(my_n * sizeof(int)), "TMP");
free(o); // # nocov
STOP(_("Failed to allocate %d bytes for '%s'."), (int)(my_n * sizeof(int)), "TMP"); // # nocov
}
const int *restrict osub = anso+from;
for (int i=0; i<my_n; i++) TMP[i] = osub[o[i]];
Expand All @@ -1009,7 +1008,7 @@ void radix_r(const int from, const int to, const int radix) {
int ngrp=0; //minor TODO: could know number of groups with certainty up above
int *my_gs = malloc(my_n * sizeof(int));
if (!my_gs)
STOP(_("Failed to allocate %d bytes for '%s'."), (int)(my_n * sizeof(int)), "my_gs");
STOP(_("Failed to allocate %d bytes for '%s'."), (int)(my_n * sizeof(int)), "my_gs"); // # nocov
my_gs[ngrp]=1;
for (int i=1; i<my_n; i++) {
if (my_key[i]!=my_key[i-1]) my_gs[++ngrp] = 1;
Expand Down Expand Up @@ -1111,7 +1110,7 @@ void radix_r(const int from, const int to, const int radix) {
}
int *my_gs = malloc((ngrp==0 ? 256 : ngrp) * sizeof(int)); // ngrp==0 when sort and skip==true; we didn't count the non-zeros in my_counts yet in that case
if (!my_gs)
STOP(_("Failed to allocate %d bytes for '%s'."), (int)((ngrp==0 ? 256 : ngrp) * sizeof(int)), "my_gs");
STOP(_("Failed to allocate %d bytes for '%s'."), (int)((ngrp==0 ? 256 : ngrp) * sizeof(int)), "my_gs"); // # nocov
if (sortType!=0) {
ngrp=0;
for (int i=0; i<256; i++) if (my_counts[i]) my_gs[ngrp++]=my_counts[i]; // this casts from uint16_t to int32, too
Expand Down Expand Up @@ -1141,8 +1140,8 @@ void radix_r(const int from, const int to, const int radix) {
uint8_t *ugrps = malloc(nBatch*256*sizeof(uint8_t));
int *ngrps = calloc(nBatch ,sizeof(int));
if (!counts || !ugrps || !ngrps) {
free(counts); free(ugrps); free(ngrps);
STOP(_("Failed to allocate parallel counts. my_n=%d, nBatch=%d"), my_n, nBatch);
free(counts); free(ugrps); free(ngrps); // # nocov
STOP(_("Failed to allocate parallel counts. my_n=%d, nBatch=%d"), my_n, nBatch); // # nocov
}

bool skip=true;
Expand Down Expand Up @@ -1242,7 +1241,7 @@ void radix_r(const int from, const int to, const int radix) {

int *starts = calloc(nBatch*256, sizeof(int)); // keep starts the same shape and ugrp order as counts
if (!starts)
STOP(_("Failed to allocate %d bytes for '%s'."), (int)(nBatch*256*sizeof(int)), "starts");
STOP(_("Failed to allocate %d bytes for '%s'."), (int)(nBatch*256*sizeof(int)), "starts"); // # nocov
for (int j=0, sum=0; j<ngrp; j++) { // iterate through columns (ngrp bytes)
uint16_t *tmp1 = counts+ugrp[j];
int *tmp2 = starts+ugrp[j];
Expand All @@ -1259,7 +1258,7 @@ void radix_r(const int from, const int to, const int radix) {
if (!skip) {
int *TMP = malloc(my_n * sizeof(int));
if (!TMP)
STOP(_("Unable to allocate TMP for my_n=%d items in parallel batch counting"), my_n);
STOP(_("Unable to allocate TMP for my_n=%d items in parallel batch counting"), my_n); // # nocov
#pragma omp parallel for num_threads(getDTthreads(nBatch, false))
for (int batch=0; batch<nBatch; batch++) {
const int *restrict my_starts = starts + batch*256;
Expand Down Expand Up @@ -1298,7 +1297,7 @@ void radix_r(const int from, const int to, const int radix) {

int *my_gs = malloc(ngrp * sizeof(int));
if (!my_gs)
STOP(_("Failed to allocate %d bytes for '%s'."), (int)(ngrp * sizeof(int)), "my_gs");
STOP(_("Failed to allocate %d bytes for '%s'."), (int)(ngrp * sizeof(int)), "my_gs"); // # nocov
for (int i=1; i<ngrp; i++) my_gs[i-1] = starts[ugrp[i]] - starts[ugrp[i-1]]; // use the first row of starts to get totals
my_gs[ngrp-1] = my_n - starts[ugrp[ngrp-1]];

Expand Down Expand Up @@ -1441,7 +1440,7 @@ SEXP issorted(SEXP x, SEXP by)
types[j] = 3;
ptrs[j] = (const char *)STRING_PTR_RO(col);
break;
default:
default: // # nocov
STOP(_("type '%s' is not yet supported"), type2char(TYPEOF(col))); // # nocov
}
}
Expand Down Expand Up @@ -1475,7 +1474,7 @@ SEXP issorted(SEXP x, SEXP by)
strcmp(CHAR(p[0]), CHAR(p[-1]))) >= 0;
}
} break;
default :
default : // # nocov
STOP(_("type '%s' is not yet supported"), type2char(TYPEOF(x))); // # nocov
}
if (!ok) return ScalarLogical(FALSE); // not sorted so return early
Expand Down
Loading

0 comments on commit 091859c

Please sign in to comment.