Blob Blame History Raw
From 79911aaf7cd877c0d25fccd5aaecdecd9a5d0204 Mon Sep 17 00:00:00 2001
From: Elliott Sales de Andrade <quantum.analyst@gmail.com>
Date: Thu, 30 Jan 2020 01:26:50 -0500
Subject: [PATCH 3/3] Use consistent types with fwriteMainArgs.nrow.

On armv7hl, test 1737.5 fails due to garbage in the column length
mismatch error message. This is because the message tries to format
`args.nrow` (an `int64_t`) using `%d` (i.e., `int`). Strangely, this
does not fail on any other architectures, but this is likely a fluke.

In all the other formatting calls, remove the unnecessary `(int64_t)`
type cast, since `fwriteMainArgs.nargs` already is one.

Signed-off-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
---
 src/fwrite.c  |  6 +++---
 src/fwriteR.c | 13 +++++++------
 2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/src/fwrite.c b/src/fwrite.c
index b5ff08cd..93cbaf62 100644
--- a/src/fwrite.c
+++ b/src/fwrite.c
@@ -620,7 +620,7 @@ void fwriteMain(fwriteMainArgs args)
       for (int j=args.ncol-10; j<args.ncol; j++) DTPRINT("%d ", args.whichFun[j]);
     }
     DTPRINT("\nargs.doRowNames=%d args.rowNames=%d doQuote=%d args.nrow=%"PRId64" args.ncol=%d eolLen=%d\n",
-          args.doRowNames, args.rowNames, doQuote, (int64_t)args.nrow, args.ncol, eolLen);
+          args.doRowNames, args.rowNames, doQuote, args.nrow, args.ncol, eolLen);
   }
 
   // Calculate upper bound for line length. Numbers use a fixed maximum (e.g. 12 for integer) while strings find the longest
@@ -777,7 +777,7 @@ void fwriteMain(fwriteMainArgs args)
   if (numBatches < nth) nth = numBatches;
   if (verbose) {
     DTPRINT("Writing %"PRId64" rows in %d batches of %d rows (each buffer size %dMB, showProgress=%d, nth=%d)\n",
-            (int64_t)args.nrow, numBatches, rowsPerBatch, args.buffMB, args.showProgress, nth);
+            args.nrow, numBatches, rowsPerBatch, args.buffMB, args.showProgress, nth);
   }
   t0 = wallclock();
 
@@ -905,7 +905,7 @@ void fwriteMain(fwriteMainArgs args)
               if (verbose && !hasPrinted) DTPRINT("\n");
               DTPRINT("\rWritten %.1f%% of %"PRId64" rows in %d secs using %d thread%s. "
                       "maxBuffUsed=%d%%. ETA %d secs.      ",
-                       (100.0*end)/args.nrow, (int64_t)args.nrow, (int)(now-startTime), nth, nth==1?"":"s",
+                       (100.0*end)/args.nrow, args.nrow, (int)(now-startTime), nth, nth==1?"":"s",
                        maxBuffUsedPC, ETA);
               // TODO: use progress() as in fread
               nextTime = now+1;
diff --git a/src/fwriteR.c b/src/fwriteR.c
index 8040631d..e3d36606 100644
--- a/src/fwriteR.c
+++ b/src/fwriteR.c
@@ -26,7 +26,7 @@ const int getStringLen(SEXP *col, int64_t row) {
 const int getMaxStringLen(const SEXP *col, const int64_t n) {
   int max=0;
   SEXP last=NULL;
-  for (int i=0; i<n; ++i) {
+  for (int64_t i=0; i<n; ++i) {
     SEXP this = *col++;
     if (this==last) continue; // no point calling LENGTH() again on the same string; LENGTH is unlikely as fast as single pointer compare
     int thisnchar = LENGTH(this);
@@ -90,17 +90,17 @@ void writeList(SEXP *col, int64_t row, char **pch) {
 const int getMaxListItemLen(const SEXP *col, const int64_t n) {
   int max=0;
   SEXP last=NULL;
-  for (int i=0; i<n; ++i) {
+  for (int64_t i=0; i<n; ++i) {
     SEXP this = *col++;
     if (this==last) continue; // no point calling LENGTH() again on the same string; LENGTH is unlikely as fast as single pointer compare
     int32_t wf = whichWriter(this);
     if (TYPEOF(this)==VECSXP || wf==INT32_MIN || isFactor(this)) {
-      error("Row %d of list column is type '%s' - not yet implemented. fwrite() can write list columns containing items which are atomic vectors of" \
+      error("Row %"PRId64" of list column is type '%s' - not yet implemented. fwrite() can write list columns containing items which are atomic vectors of" \
             " type logical, integer, integer64, double, complex and character.", i+1, isFactor(this) ? "factor" : type2char(TYPEOF(this)));
     }
     int width = writerMaxLen[wf];
     if (width==0) {
-      if (wf!=WF_String) STOP("Internal error: row %d of list column has no max length method implemented", i+1); // # nocov
+      if (wf!=WF_String) STOP("Internal error: row %"PRId64" of list column has no max length method implemented", i+1); // # nocov
       const int l = LENGTH(this);
       for (int j=0; j<l; ++j) width+=LENGTH(STRING_ELT(this, j));
     } else {
@@ -230,8 +230,9 @@ SEXP fwriteR(
   int firstListColumn = 0;
   for (int j=0; j<args.ncol; j++) {
     SEXP column = VECTOR_ELT(DFcoerced, j);
-    if (args.nrow != length(column))
-      error("Column %d's length (%d) is not the same as column 1's length (%d)", j+1, length(column), args.nrow);
+    if (args.nrow != length(column)) {
+      error("Column %d's length (%d) is not the same as column 1's length (%"PRId64")", j+1, length(column), args.nrow);
+    }
     int32_t wf = whichWriter(column);
     if (wf<0) {
       error("Column %d's type is '%s' - not yet implemented in fwrite.", j+1, type2char(TYPEOF(column)));
-- 
2.21.0