From 41c4a7b27c2f975c069af7cce7aeae06f0089c19 Mon Sep 17 00:00:00 2001 From: Peter Griess Date: Mon, 23 Sep 2013 16:38:05 -0500 Subject: [PATCH] Clean up platform-dependant format strings. Summary: - Use PRIu64 and friends from to handle uint64_t requiring different format strings on different platforms. - Fix lint errors. Test Plan: - fbconfig -r folly && fbmake runtests - ./configure && make check on Ubuntu/FC/Mac Reviewed By: simpkins@fb.com FB internal diff: D998512 --- folly/build/GenerateFingerprintTables.cpp | 10 ++++- folly/test/SpookyHashV1Test.cpp | 40 +++++++++++------ folly/test/SpookyHashV2Test.cpp | 55 ++++++++++++++--------- 3 files changed, 70 insertions(+), 35 deletions(-) diff --git a/folly/build/GenerateFingerprintTables.cpp b/folly/build/GenerateFingerprintTables.cpp index 3b330f2a..b39c168b 100644 --- a/folly/build/GenerateFingerprintTables.cpp +++ b/folly/build/GenerateFingerprintTables.cpp @@ -14,7 +14,12 @@ * limitations under the License. */ +#ifndef __STDC_FORMAT_MACROS +#define __STDC_FORMAT_MACROS 1 +#endif + #include +#include #include @@ -84,7 +89,7 @@ void computeTables(FILE* file, const FingerprintPolynomial& poly) { "const uint64_t FingerprintTable<%d>::poly[%d] = {", DEG+1, FingerprintPolynomial::size())); for (int j = 0; j < FingerprintPolynomial::size(); j++) { - CHECK_ERR(fprintf(file, "%s%luLU", j ? ", " : "", poly_val[j])); + CHECK_ERR(fprintf(file, "%s%" PRIu64 "LU", j ? ", " : "", poly_val[j])); } CHECK_ERR(fprintf(file, "};\n\n")); @@ -101,7 +106,8 @@ void computeTables(FILE* file, const FingerprintPolynomial& poly) { for (int x = 0; x < 256; x++) { CHECK_ERR(fprintf(file, " {")); for (int j = 0; j < FingerprintPolynomial::size(); j++) { - CHECK_ERR(fprintf(file, "%s%luLU", (j ? ", " : ""), table[i][x][j])); + CHECK_ERR(fprintf( + file, "%s%" PRIu64 "LU", (j ? ", " : ""), table[i][x][j])); } CHECK_ERR(fprintf(file, "},\n")); } diff --git a/folly/test/SpookyHashV1Test.cpp b/folly/test/SpookyHashV1Test.cpp index cdaae438..2896c461 100644 --- a/folly/test/SpookyHashV1Test.cpp +++ b/folly/test/SpookyHashV1Test.cpp @@ -15,8 +15,15 @@ */ // SpookyHash: a 128-bit noncryptographic hash function // By Bob Jenkins, public domain + +#ifndef __STDC_FORMAT_MACROS +#define __STDC_FORMAT_MACROS 1 +#endif + #include "folly/SpookyHashV1.h" +#include "folly/Benchmark.h" +#include #include #include #include @@ -271,7 +278,8 @@ void DoTimingBig(int seed) SpookyHashV1::Hash128(buf[i], BUFSIZE, &hash1, &hash2); } uint64_t z = GetTickCount(); - printf("SpookyHashV1::Hash128, uncached: time is %4lu milliseconds\n", z-a); + printf("SpookyHashV1::Hash128, uncached: time is " + "%4" PRIu64 " milliseconds\n", z-a); a = GetTickCount(); for (uint64_t i=0; i #include #include #include @@ -167,7 +174,8 @@ void TestResults() saw[i] = SpookyHashV2::Hash32(buf, i, 0); if (saw[i] != expected[i]) { - printf("%3d: saw 0x%.8x, expected 0x%.8lx\n", i, saw[i], expected[i]); + printf("%3d: saw 0x%.8x, expected 0x%.8" PRIx64 "\n", i, saw[i], + expected[i]); failed = true; } } @@ -193,34 +201,38 @@ void DoTimingBig(int seed) uint64_t hash2 = seed; for (uint64_t i=0; i