Blame 0003-Use-consistent-types-with-fwriteMainArgs.nrow.patch

e82a4d6
From 79911aaf7cd877c0d25fccd5aaecdecd9a5d0204 Mon Sep 17 00:00:00 2001
e82a4d6
From: Elliott Sales de Andrade <quantum.analyst@gmail.com>
e82a4d6
Date: Thu, 30 Jan 2020 01:26:50 -0500
e82a4d6
Subject: [PATCH 3/3] Use consistent types with fwriteMainArgs.nrow.
e82a4d6
e82a4d6
On armv7hl, test 1737.5 fails due to garbage in the column length
e82a4d6
mismatch error message. This is because the message tries to format
e82a4d6
`args.nrow` (an `int64_t`) using `%d` (i.e., `int`). Strangely, this
e82a4d6
does not fail on any other architectures, but this is likely a fluke.
e82a4d6
e82a4d6
In all the other formatting calls, remove the unnecessary `(int64_t)`
e82a4d6
type cast, since `fwriteMainArgs.nargs` already is one.
e82a4d6
e82a4d6
Signed-off-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
e82a4d6
---
e82a4d6
 src/fwrite.c  |  6 +++---
e82a4d6
 src/fwriteR.c | 13 +++++++------
e82a4d6
 2 files changed, 10 insertions(+), 9 deletions(-)
e82a4d6
e82a4d6
diff --git a/src/fwrite.c b/src/fwrite.c
e82a4d6
index b5ff08cd..93cbaf62 100644
e82a4d6
--- a/src/fwrite.c
e82a4d6
+++ b/src/fwrite.c
e82a4d6
@@ -620,7 +620,7 @@ void fwriteMain(fwriteMainArgs args)
e82a4d6
       for (int j=args.ncol-10; j
e82a4d6
     }
e82a4d6
     DTPRINT("\nargs.doRowNames=%d args.rowNames=%d doQuote=%d args.nrow=%"PRId64" args.ncol=%d eolLen=%d\n",
e82a4d6
-          args.doRowNames, args.rowNames, doQuote, (int64_t)args.nrow, args.ncol, eolLen);
e82a4d6
+          args.doRowNames, args.rowNames, doQuote, args.nrow, args.ncol, eolLen);
e82a4d6
   }
e82a4d6
 
e82a4d6
   // Calculate upper bound for line length. Numbers use a fixed maximum (e.g. 12 for integer) while strings find the longest
e82a4d6
@@ -777,7 +777,7 @@ void fwriteMain(fwriteMainArgs args)
e82a4d6
   if (numBatches < nth) nth = numBatches;
e82a4d6
   if (verbose) {
e82a4d6
     DTPRINT("Writing %"PRId64" rows in %d batches of %d rows (each buffer size %dMB, showProgress=%d, nth=%d)\n",
e82a4d6
-            (int64_t)args.nrow, numBatches, rowsPerBatch, args.buffMB, args.showProgress, nth);
e82a4d6
+            args.nrow, numBatches, rowsPerBatch, args.buffMB, args.showProgress, nth);
e82a4d6
   }
e82a4d6
   t0 = wallclock();
e82a4d6
 
e82a4d6
@@ -905,7 +905,7 @@ void fwriteMain(fwriteMainArgs args)
e82a4d6
               if (verbose && !hasPrinted) DTPRINT("\n");
e82a4d6
               DTPRINT("\rWritten %.1f%% of %"PRId64" rows in %d secs using %d thread%s. "
e82a4d6
                       "maxBuffUsed=%d%%. ETA %d secs.      ",
e82a4d6
-                       (100.0*end)/args.nrow, (int64_t)args.nrow, (int)(now-startTime), nth, nth==1?"":"s",
e82a4d6
+                       (100.0*end)/args.nrow, args.nrow, (int)(now-startTime), nth, nth==1?"":"s",
e82a4d6
                        maxBuffUsedPC, ETA);
e82a4d6
               // TODO: use progress() as in fread
e82a4d6
               nextTime = now+1;
e82a4d6
diff --git a/src/fwriteR.c b/src/fwriteR.c
e82a4d6
index 8040631d..e3d36606 100644
e82a4d6
--- a/src/fwriteR.c
e82a4d6
+++ b/src/fwriteR.c
e82a4d6
@@ -26,7 +26,7 @@ const int getStringLen(SEXP *col, int64_t row) {
e82a4d6
 const int getMaxStringLen(const SEXP *col, const int64_t n) {
e82a4d6
   int max=0;
e82a4d6
   SEXP last=NULL;
e82a4d6
-  for (int i=0; i
e82a4d6
+  for (int64_t i=0; i
e82a4d6
     SEXP this = *col++;
e82a4d6
     if (this==last) continue; // no point calling LENGTH() again on the same string; LENGTH is unlikely as fast as single pointer compare
e82a4d6
     int thisnchar = LENGTH(this);
e82a4d6
@@ -90,17 +90,17 @@ void writeList(SEXP *col, int64_t row, char **pch) {
e82a4d6
 const int getMaxListItemLen(const SEXP *col, const int64_t n) {
e82a4d6
   int max=0;
e82a4d6
   SEXP last=NULL;
e82a4d6
-  for (int i=0; i
e82a4d6
+  for (int64_t i=0; i
e82a4d6
     SEXP this = *col++;
e82a4d6
     if (this==last) continue; // no point calling LENGTH() again on the same string; LENGTH is unlikely as fast as single pointer compare
e82a4d6
     int32_t wf = whichWriter(this);
e82a4d6
     if (TYPEOF(this)==VECSXP || wf==INT32_MIN || isFactor(this)) {
e82a4d6
-      error("Row %d of list column is type '%s' - not yet implemented. fwrite() can write list columns containing items which are atomic vectors of" \
e82a4d6
+      error("Row %"PRId64" of list column is type '%s' - not yet implemented. fwrite() can write list columns containing items which are atomic vectors of" \
e82a4d6
             " type logical, integer, integer64, double, complex and character.", i+1, isFactor(this) ? "factor" : type2char(TYPEOF(this)));
e82a4d6
     }
e82a4d6
     int width = writerMaxLen[wf];
e82a4d6
     if (width==0) {
e82a4d6
-      if (wf!=WF_String) STOP("Internal error: row %d of list column has no max length method implemented", i+1); // # nocov
e82a4d6
+      if (wf!=WF_String) STOP("Internal error: row %"PRId64" of list column has no max length method implemented", i+1); // # nocov
e82a4d6
       const int l = LENGTH(this);
e82a4d6
       for (int j=0; j
e82a4d6
     } else {
e82a4d6
@@ -230,8 +230,9 @@ SEXP fwriteR(
e82a4d6
   int firstListColumn = 0;
e82a4d6
   for (int j=0; j
e82a4d6
     SEXP column = VECTOR_ELT(DFcoerced, j);
e82a4d6
-    if (args.nrow != length(column))
e82a4d6
-      error("Column %d's length (%d) is not the same as column 1's length (%d)", j+1, length(column), args.nrow);
e82a4d6
+    if (args.nrow != length(column)) {
e82a4d6
+      error("Column %d's length (%d) is not the same as column 1's length (%"PRId64")", j+1, length(column), args.nrow);
e82a4d6
+    }
e82a4d6
     int32_t wf = whichWriter(column);
e82a4d6
     if (wf<0) {
e82a4d6
       error("Column %d's type is '%s' - not yet implemented in fwrite.", j+1, type2char(TYPEOF(column)));
e82a4d6
-- 
e82a4d6
2.21.0
e82a4d6