diff options
author | Victor Costan <costan@google.com> | 2020-04-29 22:31:17 +0000 |
---|---|---|
committer | Victor Costan <costan@google.com> | 2020-04-29 22:31:55 +0000 |
commit | 63620c06d20f4ccac6e5c85c607f4e8698428ec8 (patch) | |
tree | a22668df8a329748cdda3f14e4a599993fd033f2 | |
parent | 5417da69b7e150bcfb9c18304c0aa95d8caf7f34 (diff) | |
download | snappy-git-63620c06d20f4ccac6e5c85c607f4e8698428ec8.tar.gz |
Add some std:: qualifiers to types and functions.
PiperOrigin-RevId: 309110343
-rw-r--r-- | snappy-test.cc | 14 | ||||
-rw-r--r-- | snappy-test.h | 52 | ||||
-rw-r--r-- | snappy_unittest.cc | 28 |
3 files changed, 48 insertions, 46 deletions
diff --git a/snappy-test.cc b/snappy-test.cc index 7149f2e..e7762a3 100644 --- a/snappy-test.cc +++ b/snappy-test.cc @@ -69,9 +69,9 @@ std::string ReadTestDataFile(const std::string& base) { std::string StrFormat(const char* format, ...) { char buf[4096]; - va_list ap; + std::va_list ap; va_start(ap, format); - vsnprintf(buf, sizeof(buf), format, ap); + std::vsnprintf(buf, sizeof(buf), format, ap); va_end(ap); return buf; } @@ -104,8 +104,8 @@ void StartBenchmarkTiming() { #else gettimeofday(&benchmark_start_real, NULL); if (getrusage(RUSAGE_SELF, &benchmark_start_cpu) == -1) { - perror("getrusage(RUSAGE_SELF)"); - exit(1); + std::perror("getrusage(RUSAGE_SELF)"); + std::exit(1); } #endif benchmark_running = true; @@ -151,8 +151,8 @@ void StopBenchmarkTiming() { struct rusage benchmark_stop_cpu; if (getrusage(RUSAGE_SELF, &benchmark_stop_cpu) == -1) { - perror("getrusage(RUSAGE_SELF)"); - exit(1); + std::perror("getrusage(RUSAGE_SELF)"); + std::exit(1); } benchmark_cpu_time_us += 1000000 * (benchmark_stop_cpu.ru_utime.tv_sec - benchmark_start_cpu.ru_utime.tv_sec); @@ -246,7 +246,7 @@ void Benchmark::Run() { } } - fprintf(stderr, + std::fprintf(stderr, #ifdef WIN32 "%-18s %10I64d %10I64d %10d %s %s\n", #else diff --git a/snappy-test.h b/snappy-test.h index 682998b..633c69b 100644 --- a/snappy-test.h +++ b/snappy-test.h @@ -119,10 +119,10 @@ namespace file { DummyStatus GetContents( const std::string& filename, std::string* data, int unused) { - FILE* fp = fopen(filename.c_str(), "rb"); + FILE* fp = std::fopen(filename.c_str(), "rb"); if (fp == NULL) { - perror(filename.c_str()); - exit(1); + std::perror(filename.c_str()); + std::exit(1); } data->clear(); @@ -130,32 +130,32 @@ namespace file { char buf[4096]; size_t ret = fread(buf, 1, 4096, fp); if (ret == 0 && ferror(fp)) { - perror("fread"); - exit(1); + std::perror("fread"); + std::exit(1); } data->append(std::string(buf, ret)); } - fclose(fp); + std::fclose(fp); return DummyStatus(); } inline DummyStatus SetContents( const std::string& filename, const std::string& str, int unused) { - FILE* fp = fopen(filename.c_str(), "wb"); + FILE* fp = std::fopen(filename.c_str(), "wb"); if (fp == NULL) { - perror(filename.c_str()); - exit(1); + std::perror(filename.c_str()); + std::exit(1); } - int ret = fwrite(str.data(), str.size(), 1, fp); + int ret = std::fwrite(str.data(), str.size(), 1, fp); if (ret != 1) { - perror("fwrite"); - exit(1); + std::std::perror("fwrite"); + std::exit(1); } - fclose(fp); + std::fclose(fp); return DummyStatus(); } @@ -184,7 +184,7 @@ std::string ReadTestDataFile(const std::string& base, size_t size_limit); std::string ReadTestDataFile(const std::string& base); -// A sprintf() variant that returns a std::string. +// A std::sprintf() variant that returns a std::string. // Not safe for general use due to truncation issues. std::string StrFormat(const char* format, ...); @@ -403,15 +403,17 @@ static inline void RunSpecifiedBenchmarks() { return; } - fprintf(stderr, "Running microbenchmarks.\n"); + std::fprintf(stderr, "Running microbenchmarks.\n"); #ifndef NDEBUG - fprintf(stderr, "WARNING: Compiled with assertions enabled, will be slow.\n"); + std::fprintf(stderr, + "WARNING: Compiled with assertions enabled, will be slow.\n"); #endif #ifndef __OPTIMIZE__ - fprintf(stderr, "WARNING: Compiled without optimization, will be slow.\n"); + std::fprintf(stderr, + "WARNING: Compiled without optimization, will be slow.\n"); #endif - fprintf(stderr, "Benchmark Time(ns) CPU(ns) Iterations\n"); - fprintf(stderr, "---------------------------------------------------\n"); + std::fprintf(stderr, "Benchmark Time(ns) CPU(ns) Iterations\n"); + std::fprintf(stderr, "---------------------------------------------------\n"); snappy::Benchmark_BM_UFlat->Run(); snappy::Benchmark_BM_UIOVec->Run(); @@ -420,13 +422,13 @@ static inline void RunSpecifiedBenchmarks() { snappy::Benchmark_BM_ZFlatAll->Run(); snappy::Benchmark_BM_ZFlatIncreasingTableSize->Run(); - fprintf(stderr, "\n"); + std::fprintf(stderr, "\n"); } #ifndef HAVE_GTEST static inline int RUN_ALL_TESTS() { - fprintf(stderr, "Running correctness tests.\n"); + std::fprintf(stderr, "Running correctness tests.\n"); snappy::Test_CorruptedTest_VerifyCorrupted(); snappy::Test_Snappy_SimpleTests(); snappy::Test_Snappy_MaxBlowup(); @@ -438,7 +440,7 @@ static inline int RUN_ALL_TESTS() { snappy::Test_Snappy_ReadPastEndOfBuffer(); snappy::Test_Snappy_FindMatchLength(); snappy::Test_Snappy_FindMatchLengthRandom(); - fprintf(stderr, "All tests passed.\n"); + std::fprintf(stderr, "All tests passed.\n"); return 0; } @@ -479,8 +481,8 @@ class LogMessage { snappy::LogMessageVoidify() & snappy::LogMessageCrash() #ifdef _MSC_VER -// ~LogMessageCrash calls abort() and therefore never exits. This is by design -// so temporarily disable warning C4722. +// ~LogMessageCrash calls std::abort() and therefore never exits. This is by +// design, so temporarily disable warning C4722. #pragma warning(push) #pragma warning(disable:4722) #endif @@ -490,7 +492,7 @@ class LogMessageCrash : public LogMessage { LogMessageCrash() { } ~LogMessageCrash() { std::cerr << std::endl; - abort(); + std::abort(); } }; diff --git a/snappy_unittest.cc b/snappy_unittest.cc index c4c85fd..2ca35f6 100644 --- a/snappy_unittest.cc +++ b/snappy_unittest.cc @@ -348,14 +348,14 @@ static void Measure(const char* data, x += ":"; std::string urate = (uncomp_rate >= 0) ? StrFormat("%.1f", uncomp_rate) : std::string("?"); - printf("%-7s [b %dM] bytes %6d -> %6d %4.1f%% " - "comp %5.1f MB/s uncomp %5s MB/s\n", - x.c_str(), - block_size/(1<<20), - static_cast<int>(length), static_cast<uint32_t>(compressed_size), - (compressed_size * 100.0) / std::max<int>(1, length), - comp_rate, - urate.c_str()); + std::printf("%-7s [b %dM] bytes %6d -> %6d %4.1f%% " + "comp %5.1f MB/s uncomp %5s MB/s\n", + x.c_str(), + block_size/(1<<20), + static_cast<int>(length), static_cast<uint32_t>(compressed_size), + (compressed_size * 100.0) / std::max<int>(1, length), + comp_rate, + urate.c_str()); } static int VerifyString(const std::string& input) { @@ -1164,13 +1164,13 @@ TEST(Snappy, VerifyCharTable) { } if (FLAGS_snappy_dump_decompression_table) { - printf("static const uint16_t char_table[256] = {\n "); + std::printf("static const uint16_t char_table[256] = {\n "); for (int i = 0; i < 256; i++) { - printf("0x%04x%s", - dst[i], - ((i == 255) ? "\n" : (((i%8) == 7) ? ",\n " : ", "))); + std::printf("0x%04x%s", + dst[i], + ((i == 255) ? "\n" : (((i%8) == 7) ? ",\n " : ", "))); } - printf("};\n"); + std::printf("};\n"); } // Check that computed table matched recorded table. @@ -1208,7 +1208,7 @@ static void UncompressFile(const char* fname) { static void MeasureFile(const char* fname) { std::string fullinput; CHECK_OK(file::GetContents(fname, &fullinput, file::Defaults())); - printf("%-40s :\n", fname); + std::printf("%-40s :\n", fname); int start_len = (FLAGS_start_len < 0) ? fullinput.size() : FLAGS_start_len; int end_len = fullinput.size(); |