Skip to content
Open
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
30 changes: 20 additions & 10 deletions src/assign.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ static void finalizer(SEXP p)
return;
}

void setselfref(SEXP x) {
void setselfref(SEXP x)
{
if(!INHERITS(x, char_datatable)) return; // #5286
SEXP p;
// Store pointer to itself so we can detect if the object has been copied. See
Expand Down Expand Up @@ -106,7 +107,8 @@ Moved out of ?setkey Details section in 1.12.2 (Mar 2019). Revisit this w.r.t. t
\code{identical()} and \code{object.size()}.
*/

static int _selfrefok(SEXP x, Rboolean checkNames, Rboolean verbose) {
static int _selfrefok(SEXP x, Rboolean checkNames, Rboolean verbose)
{
SEXP v, p, tag, prot, names;
v = getAttrib(x, SelfRefSymbol);
if (v==R_NilValue || TYPEOF(v)!=EXTPTRSXP) {
Expand Down Expand Up @@ -138,10 +140,12 @@ static int _selfrefok(SEXP x, Rboolean checkNames, Rboolean verbose) {
return checkNames ? names==tag : x==R_ExternalPtrAddr(prot);
}

static Rboolean selfrefok(SEXP x, Rboolean verbose) { // for readability
static Rboolean selfrefok(SEXP x, Rboolean verbose) // for readability
{
return(_selfrefok(x, FALSE, verbose)==1);
}
static Rboolean selfrefnamesok(SEXP x, Rboolean verbose) {
static Rboolean selfrefnamesok(SEXP x, Rboolean verbose)
{
return(_selfrefok(x, TRUE, verbose)==1);
}

Expand Down Expand Up @@ -199,7 +203,8 @@ static SEXP shallow(SEXP dt, SEXP cols, R_len_t n)
}

// Wrapped in a function so the same message is issued for the data.frame case at the R level
void warn_matrix_column(/* 1-indexed */ int i) {
void warn_matrix_column(/* 1-indexed */ int i)
{
warning(_("Some columns are a multi-column type (such as a matrix column), for example column %d. setDT will retain these columns as-is but subsequent operations like grouping and joining may fail. Please consider as.data.table() instead which will create a new column for each embedded column."), i);
}

Expand Down Expand Up @@ -285,7 +290,8 @@ int checkOverAlloc(SEXP x)
return ans;
}

SEXP alloccolwrapper(SEXP dt, SEXP overAllocArg, SEXP verbose) {
SEXP alloccolwrapper(SEXP dt, SEXP overAllocArg, SEXP verbose)
{
if (!IS_TRUE_OR_FALSE(verbose))
error(_("%s must be TRUE or FALSE"), "verbose");
int overAlloc = checkOverAlloc(overAllocArg);
Expand All @@ -305,7 +311,8 @@ SEXP alloccolwrapper(SEXP dt, SEXP overAllocArg, SEXP verbose) {
return ans;
}

SEXP shallowwrapper(SEXP dt, SEXP cols) {
SEXP shallowwrapper(SEXP dt, SEXP cols)
{
// selfref will be FALSE on manually created data.table, e.g., via dput() or structure()
if (!selfrefok(dt, FALSE)) {
int n = isNull(cols) ? length(dt) : length(cols);
Expand Down Expand Up @@ -1258,7 +1265,8 @@ SEXP allocNAVector(SEXPTYPE type, R_len_t n)
return(v);
}

SEXP allocNAVectorLike(SEXP x, R_len_t n) {
SEXP allocNAVectorLike(SEXP x, R_len_t n)
{
// writeNA needs the attribute retained to write NA_INTEGER64, #3723
// TODO: remove allocNAVector above when usage in fastmean.c, fcast.c and fmelt.c can be adjusted; see comments in PR3724
SEXP v = PROTECT(allocVector(TYPEOF(x), n));
Expand All @@ -1271,7 +1279,8 @@ SEXP allocNAVectorLike(SEXP x, R_len_t n) {
static SEXP *saveds=NULL;
static R_len_t *savedtl=NULL, nalloc=0, nsaved=0;

void savetl_init(void) {
void savetl_init(void)
{
if (nsaved || nalloc || saveds || savedtl) {
internal_error(__func__, "savetl_init checks failed (%d %d %p %p)", nsaved, nalloc, (void *)saveds, (void *)savedtl); // # nocov
}
Expand Down Expand Up @@ -1313,7 +1322,8 @@ void savetl(SEXP s)
nsaved++;
}

void savetl_end(void) {
void savetl_end(void)
{
// Can get called if nothing has been saved yet (nsaved==0), or even if _init() hasn't been called yet (pointers NULL). Such
// as to clear up before error. Also, it might be that nothing needed to be saved anyway.
for (int i=0; i<nsaved; i++) SET_TRUELENGTH(saveds[i],savedtl[i]);
Expand Down
3 changes: 2 additions & 1 deletion src/between.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
the specified lower and upper bounds, for INTSXP and REALSXP types
- The checking and handling of undefined values (such as NaNs)
*/
SEXP between(SEXP x, SEXP lower, SEXP upper, SEXP incbounds, SEXP NAboundsArg, SEXP checkArg) {
SEXP between(SEXP x, SEXP lower, SEXP upper, SEXP incbounds, SEXP NAboundsArg, SEXP checkArg)
{
int nprotect = 0;
R_len_t nx = length(x), nl = length(lower), nu = length(upper);
if (!nx || !nl || !nu)
Expand Down
3 changes: 2 additions & 1 deletion src/bmerge.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ static Rboolean rollToNearest=FALSE;

void bmerge_r(int xlowIn, int xuppIn, int ilowIn, int iuppIn, int col, int thisgrp, int lowmax, int uppmax);

SEXP bmerge(SEXP idt, SEXP xdt, SEXP icolsArg, SEXP xcolsArg, SEXP xoArg, SEXP rollarg, SEXP rollendsArg, SEXP nomatchArg, SEXP multArg, SEXP opArg, SEXP nqgrpArg, SEXP nqmaxgrpArg) {
SEXP bmerge(SEXP idt, SEXP xdt, SEXP icolsArg, SEXP xcolsArg, SEXP xoArg, SEXP rollarg, SEXP rollendsArg, SEXP nomatchArg, SEXP multArg, SEXP opArg, SEXP nqgrpArg, SEXP nqmaxgrpArg)
{
const bool verbose = GetVerbose();
double tic=0.0, tic0=0.0;
if (verbose)
Expand Down
21 changes: 15 additions & 6 deletions src/chmatch.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "data.table.h"

static SEXP chmatchMain(SEXP x, SEXP table, int nomatch, bool chin, bool chmatchdup) {
static SEXP chmatchMain(SEXP x, SEXP table, int nomatch, bool chin, bool chmatchdup)
{
if (!isString(table) && !isNull(table))
error(_("table is type '%s' (must be 'character' or NULL)"), type2char(TYPEOF(table)));
if (chin && chmatchdup)
Expand Down Expand Up @@ -140,21 +141,29 @@ static SEXP chmatchMain(SEXP x, SEXP table, int nomatch, bool chin, bool chmatch
}

// for internal use from C :
SEXP chmatch(SEXP x, SEXP table, int nomatch) { // chin= chmatchdup=
SEXP chmatch(SEXP x, SEXP table, int nomatch) // chin= chmatchdup=
{
return chmatchMain(x, table, nomatch, false, false);
}
SEXP chin(SEXP x, SEXP table) {

SEXP chin(SEXP x, SEXP table)
{
return chmatchMain(x, table, 0, true, false);
}

// for use from internals at R level; chmatch and chin are exported too but not chmatchdup yet
SEXP chmatch_R(SEXP x, SEXP table, SEXP nomatch) {
SEXP chmatch_R(SEXP x, SEXP table, SEXP nomatch)
{
return chmatchMain(x, table, INTEGER(nomatch)[0], false, false);
}
SEXP chin_R(SEXP x, SEXP table) {

SEXP chin_R(SEXP x, SEXP table)
{
return chmatchMain(x, table, 0, true, false);
}
SEXP chmatchdup_R(SEXP x, SEXP table, SEXP nomatch) {

SEXP chmatchdup_R(SEXP x, SEXP table, SEXP nomatch)
{
return chmatchMain(x, table, INTEGER(nomatch)[0], false, true);
}

Expand Down
3 changes: 2 additions & 1 deletion src/cj.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
- The memory copying operations (blockwise replication of data using memcpy)
- The creation of all combinations of the input vectors over the cross-product space
*/
SEXP cj(SEXP base_list) {
SEXP cj(SEXP base_list)
{
int ncol = LENGTH(base_list);
SEXP out = PROTECT(allocVector(VECSXP, ncol));
int nrow = 1;
Expand Down
3 changes: 2 additions & 1 deletion src/coalesce.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
- The replacement of NAs with non-NA values from subsequent vectors
- The conditional checks within parallelized loops
*/
SEXP coalesce(SEXP x, SEXP inplaceArg, SEXP nan_is_na_arg) {
SEXP coalesce(SEXP x, SEXP inplaceArg, SEXP nan_is_na_arg)
{
if (TYPEOF(x)!=VECSXP) internal_error(__func__, "input is list(...) at R level"); // # nocov
if (!IS_TRUE_OR_FALSE(inplaceArg)) internal_error(__func__, "argument 'inplaceArg' must be TRUE or FALSE"); // # nocov
if (!IS_TRUE_OR_FALSE(nan_is_na_arg)) internal_error(__func__, "argument 'nan_is_na_arg' must be TRUE or FALSE"); // # nocov
Expand Down
3 changes: 2 additions & 1 deletion src/dogroups.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
#include <fcntl.h>
#include <time.h>

static bool anySpecialStatic(SEXP x) {
static bool anySpecialStatic(SEXP x)
{
// Special refers to special symbols .BY, .I, .N, and .GRP; see special-symbols.Rd
// Static because these are like C static arrays which are the same memory for each group; e.g., dogroups
// creates .SD for the largest group once up front, overwriting the contents for each group. Their
Expand Down
3 changes: 2 additions & 1 deletion src/fcast.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
// raise(SIGINT);

// TO DO: margins
SEXP fcast(SEXP lhs, SEXP val, SEXP nrowArg, SEXP ncolArg, SEXP idxArg, SEXP fill, SEXP fill_d, SEXP is_agg, SEXP some_fillArg) {
SEXP fcast(SEXP lhs, SEXP val, SEXP nrowArg, SEXP ncolArg, SEXP idxArg, SEXP fill, SEXP fill_d, SEXP is_agg, SEXP some_fillArg)
{
int nrows=INTEGER(nrowArg)[0], ncols=INTEGER(ncolArg)[0];
int nlhs=length(lhs), nval=length(val), *idx = INTEGER(idxArg);
SEXP target;
Expand Down
6 changes: 4 additions & 2 deletions src/fifelse.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
supplied logical vector based on the condition (test) and values
provided for the remaining arguments (yes, no, and na).
*/
SEXP fifelseR(SEXP l, SEXP a, SEXP b, SEXP na) {
SEXP fifelseR(SEXP l, SEXP a, SEXP b, SEXP na)
{
if (!isLogical(l)) {
error(_("Argument 'test' must be logical."));
}
Expand Down Expand Up @@ -207,7 +208,8 @@ SEXP fifelseR(SEXP l, SEXP a, SEXP b, SEXP na) {
return ans;
}

SEXP fcaseR(SEXP rho, SEXP args) {
SEXP fcaseR(SEXP rho, SEXP args)
{
const int narg=length(args); // `default` will take the last two positions
if (narg % 2) {
error(_("Received %d inputs; please supply an even number of arguments in ..., "
Expand Down
56 changes: 36 additions & 20 deletions src/fmelt.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
// raise(SIGINT);

// generate from 1 to n (a simple fun for melt, vecseq is convenient from R due to SEXP inputs)
SEXP seq_int(int n, int start) {
SEXP seq_int(int n, int start)
{
if (n <= 0) return(R_NilValue);
SEXP ans = PROTECT(allocVector(INTSXP, n));
int *ians = INTEGER(ans);
Expand All @@ -14,7 +15,8 @@ SEXP seq_int(int n, int start) {
}

// very specific "set_diff" for integers
SEXP set_diff(SEXP x, int n) {
SEXP set_diff(SEXP x, int n)
{
if (TYPEOF(x) != INTSXP) error(_("'x' must be an integer"));
if (n <= 0) error(_("'n' must be a positive integer"));
SEXP table = PROTECT(seq_int(n, 1)); // TODO: using match to 1:n seems odd here, why use match at all
Expand All @@ -34,8 +36,8 @@ SEXP set_diff(SEXP x, int n) {
return(ans);
}

SEXP which(SEXP x, Rboolean val) {

SEXP which(SEXP x, Rboolean val)
{
int j=0, n = length(x);
SEXP ans;
if (!isLogical(x)) error(_("Argument to 'which' must be logical"));
Expand All @@ -55,13 +57,15 @@ SEXP which(SEXP x, Rboolean val) {
}

// whichwrapper for R
SEXP whichwrapper(SEXP x, SEXP val) {
SEXP whichwrapper(SEXP x, SEXP val)
{
// if (LOGICAL(val)[0] == NA_LOGICAL)
// error(_("val should be logical TRUE/FALSE"));
return which(x, LOGICAL(val)[0]);
}

static const char *concat(SEXP vec, SEXP idx) {
static const char *concat(SEXP vec, SEXP idx)
{
if (!isString(vec)) error(_("concat: 'vec' must be a character vector"));
if (!isInteger(idx))
error(_("concat: 'idx' must be an integer vector"));
Expand Down Expand Up @@ -118,7 +122,8 @@ SEXP chmatch_na(SEXP x, SEXP table)
}

// deal with measure.vars of type VECSXP
SEXP measurelist(SEXP measure, SEXP dtnames) {
SEXP measurelist(SEXP measure, SEXP dtnames)
{
const int n=length(measure);
SEXP ans = PROTECT(allocVector(VECSXP, n));
for (int i=0; i<n; ++i) {
Expand All @@ -142,7 +147,8 @@ SEXP measurelist(SEXP measure, SEXP dtnames) {
}

// internal function just to unlist integer lists
static SEXP unlist_(SEXP xint) {
static SEXP unlist_(SEXP xint)
{
int totn=0, n=length(xint);
for (int i=0; i<n; ++i)
totn += length(VECTOR_ELT(xint, i));
Expand All @@ -160,7 +166,8 @@ static SEXP unlist_(SEXP xint) {

// convert NA in user-supplied integer vector input to -1 in order to
// trigger error in uniq_diff().
SEXP na_to_negative(SEXP vec_with_NA){
SEXP na_to_negative(SEXP vec_with_NA)
{
SEXP vec_with_negatives = PROTECT(allocVector(INTSXP, length(vec_with_NA)));
for (int i=0; i<length(vec_with_NA); i++) {
int input_i = INTEGER(vec_with_NA)[i];
Expand All @@ -172,12 +179,14 @@ SEXP na_to_negative(SEXP vec_with_NA){

// If neither id.vars nor measure.vars is provided by user, then this
// function decides which input columns are default measure.vars.
bool is_default_measure(SEXP vec) {
bool is_default_measure(SEXP vec)
{
return (isInteger(vec) || isNumeric(vec) || isLogical(vec)) && !isFactor(vec);
}

// maybe unlist, then unique, then set_diff.
SEXP uniq_diff(SEXP int_or_list, int ncol, bool is_measure) {
SEXP uniq_diff(SEXP int_or_list, int ncol, bool is_measure)
{
SEXP int_vec = PROTECT(isNewList(int_or_list) ? unlist_(int_or_list) : int_or_list);
SEXP is_duplicated = PROTECT(duplicated(int_vec, FALSE));
int n_unique_cols = 0;
Expand Down Expand Up @@ -205,7 +214,8 @@ SEXP uniq_diff(SEXP int_or_list, int ncol, bool is_measure) {
return out;
}

SEXP cols_to_int_or_list(SEXP cols, SEXP dtnames, bool is_measure) {
SEXP cols_to_int_or_list(SEXP cols, SEXP dtnames, bool is_measure)
{
switch(TYPEOF(cols)) {
case STRSXP : return chmatch(cols, dtnames, 0);
case REALSXP : return coerceVector(cols, INTSXP);
Expand All @@ -220,7 +230,8 @@ SEXP cols_to_int_or_list(SEXP cols, SEXP dtnames, bool is_measure) {
}
}

SEXP checkVars(SEXP DT, SEXP id, SEXP measure, Rboolean verbose) {
SEXP checkVars(SEXP DT, SEXP id, SEXP measure, Rboolean verbose)
{
int ncol=LENGTH(DT), n_target_cols=0, protecti=0, target_col_i=0, id_col_i=0;
SEXP thiscol, idcols = R_NilValue, valuecols = R_NilValue, ans;
SEXP dtnames = PROTECT(getAttrib(DT, R_NamesSymbol)); protecti++;
Expand Down Expand Up @@ -301,8 +312,8 @@ struct processData {
bool narm; // remove missing values?
};

static void preprocess(SEXP DT, SEXP id, SEXP measure, SEXP varnames, SEXP valnames, Rboolean narm, Rboolean verbose, struct processData *data) {

static void preprocess(SEXP DT, SEXP id, SEXP measure, SEXP varnames, SEXP valnames, Rboolean narm, Rboolean verbose, struct processData *data)
{
SEXP vars,tmp,thiscol;
SEXPTYPE type;
data->lmax = 0; data->totlen = 0; data->nrow = length(VECTOR_ELT(DT, 0));
Expand Down Expand Up @@ -449,7 +460,8 @@ static SEXP combineFactorLevels(SEXP factorLevels, SEXP target, int * factorType
return ans;
}

SEXP input_col_or_NULL(SEXP DT, struct processData* data, SEXP thisvaluecols, int out_col, int in_col) {
SEXP input_col_or_NULL(SEXP DT, struct processData* data, SEXP thisvaluecols, int out_col, int in_col)
{
if (in_col < data->leach[out_col]) {
int input_column_num = INTEGER(thisvaluecols)[in_col];
if (input_column_num != NA_INTEGER) {
Expand All @@ -459,7 +471,8 @@ SEXP input_col_or_NULL(SEXP DT, struct processData* data, SEXP thisvaluecols, in
return R_NilValue;
}

SEXP getvaluecols(SEXP DT, SEXP dtnames, Rboolean valfactor, Rboolean verbose, struct processData *data) {
SEXP getvaluecols(SEXP DT, SEXP dtnames, Rboolean valfactor, Rboolean verbose, struct processData *data)
{
for (int i=0; i<data->lvalues; ++i) {
SEXP thisvaluecols = VECTOR_ELT(data->valuecols, i);
if (!data->isidentical[i])
Expand Down Expand Up @@ -589,7 +602,8 @@ SEXP getvaluecols(SEXP DT, SEXP dtnames, Rboolean valfactor, Rboolean verbose, s
return(ansvals);
}

SEXP getvarcols(SEXP DT, SEXP dtnames, Rboolean varfactor, Rboolean verbose, struct processData *data) {
SEXP getvarcols(SEXP DT, SEXP dtnames, Rboolean varfactor, Rboolean verbose, struct processData *data)
{
// reworked in PR#3455 to create character/factor directly for efficiency, and handle duplicates (#1754)
// data->nrow * data->lmax == data->totlen
int protecti=0;
Expand Down Expand Up @@ -691,7 +705,8 @@ SEXP getvarcols(SEXP DT, SEXP dtnames, Rboolean varfactor, Rboolean verbose, str
return(ansvars);
}

SEXP getidcols(SEXP DT, SEXP dtnames, Rboolean verbose, struct processData *data) {
SEXP getidcols(SEXP DT, SEXP dtnames, Rboolean verbose, struct processData *data)
{
SEXP ansids = PROTECT(allocVector(VECSXP, data->lids));
for (int i=0; i<data->lids; ++i) {
int counter = 0;
Expand Down Expand Up @@ -783,7 +798,8 @@ SEXP getidcols(SEXP DT, SEXP dtnames, Rboolean verbose, struct processData *data
return (ansids);
}

SEXP fmelt(SEXP DT, SEXP id, SEXP measure, SEXP varfactor, SEXP valfactor, SEXP varnames, SEXP valnames, SEXP narmArg, SEXP verboseArg) {
SEXP fmelt(SEXP DT, SEXP id, SEXP measure, SEXP varfactor, SEXP valfactor, SEXP varnames, SEXP valnames, SEXP narmArg, SEXP verboseArg)
{
SEXP dtnames, ansvals, ansvars, ansids, ansnames, ans;
Rboolean narm=FALSE, verbose=FALSE;

Expand Down
Loading
Loading