diff --git a/src/assign.c b/src/assign.c index 9478c8745b..85979e2fb3 100644 --- a/src/assign.c +++ b/src/assign.c @@ -1,6 +1,4 @@ #include "data.table.h" -#include -#include static void finalizer(SEXP p) { diff --git a/src/data.table.h b/src/data.table.h index 062bbc8663..c7e4f0f7a9 100644 --- a/src/data.table.h +++ b/src/data.table.h @@ -1,10 +1,10 @@ +#include "dt_stdio.h" // PRId64 and PRIu64 #include #define USE_RINTERNALS #include // #include // the debugging machinery + breakpoint aidee // raise(SIGINT); #include // for uint64_t rather than unsigned long long -#include // for PRId64 and PRIu64 #include #include "myomp.h" #include "types.h" diff --git a/src/dt_stdio.h b/src/dt_stdio.h new file mode 100644 index 0000000000..4e69e0d87e --- /dev/null +++ b/src/dt_stdio.h @@ -0,0 +1,34 @@ + +// It seems that latest min64-w64 compiler needs some help to avoid warnings; #4064 +// It appears that its inttypes.h defines PRId64 to be I64 on Windows but then warns that +// I64 is not C99 too. Which is correct, but we know, and we don't want any warnings, and +// we can't control settings on CRAN. So here we try and isolate ourselves from all scenarios. +// There is a lot online about this, but these were a few that were most useful: +// https://stackoverflow.com/questions/23718110/error-unknown-conversion-type-character-l-in-format-scanning-long-long +// https://gitlab.freedesktop.org/nacho.garglez/cerbero/commit/4ec6bfdc1db1e4bc8d4278f53ad295af1efe89fb +// https://github.com/GNOME/glib/commit/98a0ab929d8c59ee27e5f470f11d077bb6a56749#diff-969b60ad3d206fd45c208e266ccfed38 +// https://sourceforge.net/p/mingw-w64/wiki2/gnu%20printf/ +// Warning that __USE_MINGW_ANSI_STDIO could be deprecated: +// https://mingw-w64-public.narkive.com/aQDJHqCv/how-to-printf-64-bit-integer-in-64-bit-compiler-in-strict-iso-mode-with-all-warnings-enabled +// and then actual deprecation (with complaints) earlier in 2019 here: +// https://osdn.net/projects/mingw/lists/archive/users/2019-January/000202.html +// But I can't find _mingw.h. I can find mingw.h but not advice within it: +// https://github.com/git/git/blob/master/compat/mingw.h#L448 +// The deprecation about I64 doesn't seem to take into account that lld throws the warning in MinGW: +// warning: unknown conversion type character 'l' in format [-Wformat=] +// So let's see if the approach below works for now. +// If we need to make changes in future, we can do it here in one place. + +#ifndef DT_STDIO_H +#define DT_STDIO_H +#if defined(__MINGW32__) || (defined __MINGW64__) + #define __USE_MINGW_ANSI_STDIO 1 + #include + #define PRId64 "lld" + #define PRIu64 "llu" +#else + #include + #include + // let inttypes.h decide: lld on Linux/C99; I64 on Windows Visual Studio for example +#endif +#endif diff --git a/src/fread.h b/src/fread.h index e70dbbe42f..ec230c6986 100644 --- a/src/fread.h +++ b/src/fread.h @@ -1,9 +1,9 @@ #ifndef dt_FREAD_H #define dt_FREAD_H -#include // uint32_t -#include // PRId64 -#include // size_t -#include // bool +#include "dt_stdio.h" // PRId64 +#include // uint32_t +#include // size_t +#include // bool #include "myomp.h" #ifdef DTPY #include "py_fread.h" diff --git a/src/froll.c b/src/froll.c index ef19255431..5116307393 100644 --- a/src/froll.c +++ b/src/froll.c @@ -1,7 +1,3 @@ -#include -#include -#include -#include #include "data.table.h" /* fast rolling mean - router @@ -49,7 +45,7 @@ void frollmean(unsigned int algo, double *x, uint64_t nx, ans_t *ans, int k, int */ void frollmeanFast(double *x, uint64_t nx, ans_t *ans, int k, double fill, bool narm, int hasna, bool verbose) { if (verbose) - snprintf(end(ans->message[0]), 500, "%s: running for input length %"PRIu64", window %d, hasna %d, narm %d\n", __func__, (uint64_t)nx, k, hasna, (int)narm); + snprintf(end(ans->message[0]), 500, "frollmeanFast: running for input length %"PRIu64", window %d, hasna %d, narm %d\n", (uint64_t)nx, k, hasna, (int)narm); long double w = 0.0; // sliding window aggregate bool truehasna = hasna>0; // flag to re-run with NA support if NAs detected if (!truehasna) { @@ -138,7 +134,7 @@ void frollmeanFast(double *x, uint64_t nx, ans_t *ans, int k, double fill, bool */ void frollmeanExact(double *x, uint64_t nx, ans_t *ans, int k, double fill, bool narm, int hasna, bool verbose) { if (verbose) - snprintf(end(ans->message[0]), 500, "%s: running in parallel for input length %"PRIu64", window %d, hasna %d, narm %d\n", __func__, (uint64_t)nx, k, hasna, (int)narm); + snprintf(end(ans->message[0]), 500, "frollmeanExact: running in parallel for input length %"PRIu64", window %d, hasna %d, narm %d\n", (uint64_t)nx, k, hasna, (int)narm); for (int i=0; idbl_v[i] = fill; } @@ -252,7 +248,7 @@ void frollsum(unsigned int algo, double *x, uint64_t nx, ans_t *ans, int k, int } void frollsumFast(double *x, uint64_t nx, ans_t *ans, int k, double fill, bool narm, int hasna, bool verbose) { if (verbose) - snprintf(end(ans->message[0]), 500, "%s: running for input length %"PRIu64", window %d, hasna %d, narm %d\n", __func__, (uint64_t)nx, k, hasna, (int)narm); + snprintf(end(ans->message[0]), 500, "frollsumFast: running for input length %"PRIu64", window %d, hasna %d, narm %d\n", (uint64_t)nx, k, hasna, (int)narm); long double w = 0.0; bool truehasna = hasna>0; if (!truehasna) { @@ -336,7 +332,7 @@ void frollsumFast(double *x, uint64_t nx, ans_t *ans, int k, double fill, bool n } void frollsumExact(double *x, uint64_t nx, ans_t *ans, int k, double fill, bool narm, int hasna, bool verbose) { if (verbose) - snprintf(end(ans->message[0]), 500, "%s: running in parallel for input length %"PRIu64", window %d, hasna %d, narm %d\n", __func__, (uint64_t)nx, k, hasna, (int)narm); + snprintf(end(ans->message[0]), 500, "frollsumExact: running in parallel for input length %"PRIu64", window %d, hasna %d, narm %d\n", (uint64_t)nx, k, hasna, (int)narm); for (int i=0; idbl_v[i] = fill; } diff --git a/src/frolladaptive.c b/src/frolladaptive.c index 9451e70e22..9521217593 100644 --- a/src/frolladaptive.c +++ b/src/frolladaptive.c @@ -1,7 +1,3 @@ -#include -#include -#include -#include #include "data.table.h" /* fast adaptive rolling mean - router @@ -30,7 +26,7 @@ void fadaptiverollmean(unsigned int algo, double *x, uint64_t nx, ans_t *ans, in */ void fadaptiverollmeanFast(double *x, uint64_t nx, ans_t *ans, int *k, double fill, bool narm, int hasna, bool verbose) { if (verbose) - snprintf(end(ans->message[0]), 500, "%s: running for input length %"PRIu64", hasna %d, narm %d\n", __func__, (uint64_t)nx, hasna, (int) narm); + snprintf(end(ans->message[0]), 500, "fadaptiverollmeanFast: running for input length %"PRIu64", hasna %d, narm %d\n", (uint64_t)nx, hasna, (int) narm); bool truehasna = hasna>0; // flag to re-run if NAs detected long double w = 0.0; double *cs = malloc(nx*sizeof(double)); // cumsum vector, same as double cs[nx] but no segfault @@ -115,7 +111,7 @@ void fadaptiverollmeanFast(double *x, uint64_t nx, ans_t *ans, int *k, double fi */ void fadaptiverollmeanExact(double *x, uint64_t nx, ans_t *ans, int *k, double fill, bool narm, int hasna, bool verbose) { if (verbose) - snprintf(end(ans->message[0]), 500, "%s: running in parallel for input length %"PRIu64", hasna %d, narm %d\n", __func__, (uint64_t)nx, hasna, (int) narm); + snprintf(end(ans->message[0]), 500, "fadaptiverollmeanExact: running in parallel for input length %"PRIu64", hasna %d, narm %d\n", (uint64_t)nx, hasna, (int) narm); bool truehasna = hasna>0; // flag to re-run if NAs detected if (!truehasna || !narm) { // narm=FALSE handled here as NAs properly propagated in exact algo #pragma omp parallel for num_threads(getDTthreads()) @@ -219,7 +215,7 @@ void fadaptiverollsum(unsigned int algo, double *x, uint64_t nx, ans_t *ans, int } void fadaptiverollsumFast(double *x, uint64_t nx, ans_t *ans, int *k, double fill, bool narm, int hasna, bool verbose) { if (verbose) - snprintf(end(ans->message[0]), 500, "%s: running for input length %"PRIu64", hasna %d, narm %d\n", __func__, (uint64_t)nx, hasna, (int) narm); + snprintf(end(ans->message[0]), 500, "fadaptiverollsumFast: running for input length %"PRIu64", hasna %d, narm %d\n", (uint64_t)nx, hasna, (int) narm); bool truehasna = hasna>0; long double w = 0.0; double *cs = malloc(nx*sizeof(double)); @@ -299,7 +295,7 @@ void fadaptiverollsumFast(double *x, uint64_t nx, ans_t *ans, int *k, double fil } void fadaptiverollsumExact(double *x, uint64_t nx, ans_t *ans, int *k, double fill, bool narm, int hasna, bool verbose) { if (verbose) - snprintf(end(ans->message[0]), 500, "%s: running in parallel for input length %"PRIu64", hasna %d, narm %d\n", __func__, (uint64_t)nx, hasna, (int) narm); + snprintf(end(ans->message[0]), 500, "fadaptiverollsumExact: running in parallel for input length %"PRIu64", hasna %d, narm %d\n", (uint64_t)nx, hasna, (int) narm); bool truehasna = hasna>0; if (!truehasna || !narm) { #pragma omp parallel for num_threads(getDTthreads()) diff --git a/src/fwrite.c b/src/fwrite.c index aa30ab8413..b5ff08cde6 100644 --- a/src/fwrite.c +++ b/src/fwrite.c @@ -1,9 +1,9 @@ +#include "dt_stdio.h" #include #include // for access() #include #include // true and false #include // INT32_MIN -#include // PRId64 #include // isfinite, isnan #include // abs #include // strlen, strerror