Skip to content

Commit 0e257a8

Browse files
aitapMichaelChiricorikivillalba
authored
Message fixes for the C code (#6504)
* Expand the fragmented sentence Otherwise it's very hard to translate without pgettext() in a language where "there is no <x>" is translated as "<x> is absent" * Combine the fragmented sentence This will avoid potential word order issues. * Correct internal error message .Last.value is a variable in the global environment. .Last.updated belongs to the data.table package. * data.table-help -> data.table issue tracker * Avoid templating on the known value of a variable * When '9'+1 != ':', say it's ASCII-incompatible * Don't check for length(.) < 0 * Use R capitalization for logical constants * newline->error for codecov * Use internal_error() instead of manual error handling Co-authored-by: Michael Chirico <[email protected]> * internal_error needs __func__ * Branch a previously templated translation * Combine a fragmented sentence * Recombine "gather took %.3fs\n" Co-authored-by: rikivillalba <[email protected]> * Split off the shrinkMSB helper Hopefully the compiler will be smart enough to inline it back. Co-authored-by: Michael Chirico <[email protected]> * Branch a fragmented verbose sentence in fread * Don't say we reduced MSBsize if it didn't change Forgot to take #6504 (comment) into account. * declaration style for pointer spacing * line bump for codecov + readability --------- Co-authored-by: Michael Chirico <[email protected]> Co-authored-by: rikivillalba <[email protected]>
1 parent 1c771e5 commit 0e257a8

File tree

5 files changed

+36
-21
lines changed

5 files changed

+36
-21
lines changed

src/fmelt.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ SEXP whichwrapper(SEXP x, SEXP val) {
6363

6464
static const char *concat(SEXP vec, SEXP idx) {
6565
if (!isString(vec)) error(_("concat: 'vec' must be a character vector"));
66-
if (!isInteger(idx) || length(idx) < 0) error(_("concat: 'idx' must be an integer vector of length >= 0"));
66+
if (!isInteger(idx))
67+
error(_("concat: 'idx' must be an integer vector"));
6768

6869
static char ans[1024]; // so only one call to concat() per calling warning/error
6970
int nidx=length(idx), nvec=length(vec);
@@ -802,7 +803,8 @@ SEXP fmelt(SEXP DT, SEXP id, SEXP measure, SEXP varfactor, SEXP valfactor, SEXP
802803
}
803804
int protecti=0;
804805
dtnames = PROTECT(getAttrib(DT, R_NamesSymbol)); protecti++;
805-
if (isNull(dtnames)) error(_("names(data) is NULL. Please report to data.table-help"));
806+
if (isNull(dtnames))
807+
internal_error(__func__, "names(data) is NULL");
806808
if (LOGICAL(narmArg)[0] == TRUE) narm = TRUE;
807809
if (LOGICAL(verboseArg)[0] == TRUE) verbose = TRUE;
808810
struct processData data;

src/fread.c

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1888,11 +1888,14 @@ int freadMain(freadMainArgs _args) {
18881888
// *2 to get a good spacing. We don't want overlaps resulting in double counting.
18891889
}
18901890
if (verbose) {
1891-
DTPRINT(_(" Number of sampling jump points = %d because "), nJumps);
1892-
if (nrowLimit<INT64_MAX) DTPRINT(_("nrow limit (%"PRIu64") supplied\n"), (uint64_t)nrowLimit);
1893-
else if (jump0size==0) DTPRINT(_("jump0size==0\n"));
1894-
else DTPRINT(_("(%"PRIu64" bytes from row 1 to eof) / (2 * %"PRIu64" jump0size) == %"PRIu64"\n"),
1895-
(uint64_t)sz, (uint64_t)jump0size, (uint64_t)(sz/(2*jump0size)));
1891+
if (nrowLimit<INT64_MAX) {
1892+
DTPRINT(_(" Number of sampling jump points = %d because nrow limit (%"PRIu64") supplied\n"), nJumps, (uint64_t)nrowLimit);
1893+
} else if (jump0size==0) {
1894+
DTPRINT(_(" Number of sampling jump points = %d because jump0size==0\n"), nJumps);
1895+
} else {
1896+
DTPRINT(_(" Number of sampling jump points = %d because (%"PRIu64" bytes from row 1 to eof) / (2 * %"PRIu64" jump0size) == %"PRIu64"\n"),
1897+
nJumps, (uint64_t)sz, (uint64_t)jump0size, (uint64_t)(sz/(2*jump0size)));
1898+
}
18961899
}
18971900
nJumps++; // the extra sample at the very end (up to eof) is sampled and format checked but not jumped to when reading
18981901
if (nrowLimit<INT64_MAX && nrowLimit>0) nJumps=1; // when nrows>0 supplied by user, no jumps (not even at the end) and single threaded
@@ -1930,8 +1933,10 @@ int freadMain(freadMainArgs _args) {
19301933
}
19311934
if ( (thisNcol<ncol && ncol>1 && !fill) ||
19321935
(!eol(&ch) && ch!=eof) ) {
1933-
if (verbose) DTPRINT(_(" A line with too-%s fields (%d/%d) was found on line %d of sample jump %d. %s\n"),
1934-
thisNcol<ncol ? _("few") : _("many"), thisNcol, ncol, jumpLine, jump, jump>0 ? _("Most likely this jump landed awkwardly so type bumps here will be skipped.") : "");
1936+
if (verbose)
1937+
DTPRINT(thisNcol<ncol ? _(" A line with too-few fields (%d/%d) was found on line %d of sample jump %d. %s\n")
1938+
: _(" A line with too-many fields (%d/%d) was found on line %d of sample jump %d. %s\n"),
1939+
thisNcol, ncol, jumpLine, jump, jump>0 ? _("Most likely this jump landed awkwardly so type bumps here will be skipped.") : "");
19351940
bumped = false;
19361941
if (jump==0) lastRowEnd=eof; // to prevent the end from being tested; e.g. a short file with blank line within first 100 like test 976
19371942
break;
@@ -2035,7 +2040,10 @@ int freadMain(freadMainArgs _args) {
20352040
}
20362041
if (verbose) {
20372042
if (sampleLines==0) {
2038-
DTPRINT(_(" 'header' determined to be %s because there are%s number fields in the first and only row\n"), args.header?"TRUE":"FALSE", args.header?_(" no"):"");
2043+
if (args.header)
2044+
DTPRINT(_(" 'header' determined to be TRUE because there are no number fields in the first and only row\n"));
2045+
else
2046+
DTPRINT(_(" 'header' determined to be FALSE because there are number fields in the first and only row\n"));
20392047
} else {
20402048
if (args.header)
20412049
DTPRINT(_(" 'header' determined to be true because all columns are type string and a better guess is not possible\n"));
@@ -2621,7 +2629,7 @@ int freadMain(freadMainArgs _args) {
26212629

26222630
if (stopTeam) {
26232631
if (internalErr[0]!='\0') {
2624-
STOP("%s %s: %s. %s", _("Internal error in"), __func__, internalErr, _("Please report to the data.table issues tracker")); // # nocov
2632+
STOP(_("Internal error in %s: %s. Please report to the data.table issues tracker"), __func__, internalErr); // # nocov
26252633
}
26262634
stopTeam = false;
26272635

src/fsort.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,16 @@ int qsort_cmp(const void *a, const void *b) {
9898
return (x<y)-(x>y); // largest first in a safe branchless way casting long to int
9999
}
100100

101+
static size_t shrinkMSB(size_t MSBsize, uint64_t *msbCounts, int *order, Rboolean verbose) {
102+
size_t oldMSBsize = MSBsize;
103+
while (MSBsize>0 && msbCounts[order[MSBsize-1]] < 2)
104+
MSBsize--;
105+
if (verbose && oldMSBsize != MSBsize) {
106+
Rprintf(_("Reduced MSBsize from %zu to %zu by excluding 0 and 1 counts\n"), oldMSBsize, MSBsize);
107+
}
108+
return MSBsize;
109+
}
110+
101111
/*
102112
OpenMP is used here to find the range and distribution of data for efficient
103113
grouping and sorting.
@@ -252,12 +262,8 @@ SEXP fsort(SEXP x, SEXP verboseArg) {
252262

253263
if (verbose) {
254264
Rprintf(_("Top 20 MSB counts: ")); for(int i=0; i<MIN(MSBsize,20); i++) Rprintf(_("%"PRId64" "), (int64_t)msbCounts[order[i]]); Rprintf(_("\n"));
255-
Rprintf(_("Reduced MSBsize from %zu to "), MSBsize);
256-
}
257-
while (MSBsize>0 && msbCounts[order[MSBsize-1]] < 2) MSBsize--;
258-
if (verbose) {
259-
Rprintf(_("%zu by excluding 0 and 1 counts\n"), MSBsize);
260265
}
266+
MSBsize = shrinkMSB(MSBsize, msbCounts, order, verbose);
261267

262268
bool failed=false, alloc_fail=false, non_monotonic=false; // shared bools only ever assigned true; no need for atomic or critical assign
263269
t[6] = wallclock();

src/gsumm.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@ void *gather(SEXP x, bool *anyNA)
221221
{
222222
double started=wallclock();
223223
const bool verbose = GetVerbose();
224-
if (verbose) Rprintf(_("gather took ... "));
225224
switch (TYPEOF(x)) {
226225
case LGLSXP: case INTSXP: {
227226
const int *restrict thisx = INTEGER(x);
@@ -341,7 +340,7 @@ void *gather(SEXP x, bool *anyNA)
341340
default :
342341
error(_("gather implemented for INTSXP, REALSXP, and CPLXSXP but not '%s'"), type2char(TYPEOF(x))); // # nocov
343342
}
344-
if (verbose) { Rprintf(_("%.3fs\n"), wallclock()-started); }
343+
if (verbose) { Rprintf(_("gather took %.3fs\n"), wallclock()-started); }
345344
return gx;
346345
}
347346

src/init.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,9 @@ void attribute_visible R_init_data_table(DllInfo *info)
222222
if (ld != 0.0) error(_("Checking memset(&ld, 0, sizeof(long double)); ld == (long double)0.0 %s"), msg);
223223

224224
// Check unsigned cast used in fread.c. This isn't overflow/underflow, just cast.
225-
if ((uint_fast8_t)('0'-'/') != 1) error(_("The ascii character '/' is not just before '0'"));
225+
if ((uint_fast8_t)('0'-'/') != 1) error(_("Unlike the very common case, e.g. ASCII, the character '/' is not just before '0'."));
226226
if ((uint_fast8_t)('/'-'0') < 10) error(_("The C expression (uint_fast8_t)('/'-'0')<10 is true. Should be false."));
227-
if ((uint_fast8_t)(':'-'9') != 1) error(_("The ascii character ':' is not just after '9'"));
227+
if ((uint_fast8_t)(':'-'9') != 1) error(_("Unlike the very common case, e.g. ASCII, the character ':' is not just after '9'."));
228228
if ((uint_fast8_t)('9'-':') < 10) error(_("The C expression (uint_fast8_t)('9'-':')<10 is true. Should be false."));
229229

230230
// Variables rather than #define for NA_INT64 to ensure correct usage; i.e. not casted
@@ -364,7 +364,7 @@ SEXP beforeR340(void) {
364364
extern int *_Last_updated; // assign.c
365365

366366
SEXP initLastUpdated(SEXP var) {
367-
if (!isInteger(var) || LENGTH(var)!=1) error(_(".Last.value in namespace is not a length 1 integer"));
367+
if (!isInteger(var) || LENGTH(var)!=1) error(_(".Last.updated in namespace is not a length 1 integer"));
368368
_Last_updated = INTEGER(var);
369369
return R_NilValue;
370370
}

0 commit comments

Comments
 (0)