Add some std:: qualifiers to types and functions.

PiperOrigin-RevId: 309110343
This commit is contained in:
Victor Costan
2020-04-29 22:31:17 +00:00
parent 5417da69b7
commit 63620c06d2
3 changed files with 48 additions and 46 deletions

View File

@@ -69,9 +69,9 @@ std::string ReadTestDataFile(const std::string& base) {
std::string StrFormat(const char* format, ...) { std::string StrFormat(const char* format, ...) {
char buf[4096]; char buf[4096];
va_list ap; std::va_list ap;
va_start(ap, format); va_start(ap, format);
vsnprintf(buf, sizeof(buf), format, ap); std::vsnprintf(buf, sizeof(buf), format, ap);
va_end(ap); va_end(ap);
return buf; return buf;
} }
@@ -104,8 +104,8 @@ void StartBenchmarkTiming() {
#else #else
gettimeofday(&benchmark_start_real, NULL); gettimeofday(&benchmark_start_real, NULL);
if (getrusage(RUSAGE_SELF, &benchmark_start_cpu) == -1) { if (getrusage(RUSAGE_SELF, &benchmark_start_cpu) == -1) {
perror("getrusage(RUSAGE_SELF)"); std::perror("getrusage(RUSAGE_SELF)");
exit(1); std::exit(1);
} }
#endif #endif
benchmark_running = true; benchmark_running = true;
@@ -151,8 +151,8 @@ void StopBenchmarkTiming() {
struct rusage benchmark_stop_cpu; struct rusage benchmark_stop_cpu;
if (getrusage(RUSAGE_SELF, &benchmark_stop_cpu) == -1) { if (getrusage(RUSAGE_SELF, &benchmark_stop_cpu) == -1) {
perror("getrusage(RUSAGE_SELF)"); std::perror("getrusage(RUSAGE_SELF)");
exit(1); std::exit(1);
} }
benchmark_cpu_time_us += 1000000 * (benchmark_stop_cpu.ru_utime.tv_sec - benchmark_cpu_time_us += 1000000 * (benchmark_stop_cpu.ru_utime.tv_sec -
benchmark_start_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 #ifdef WIN32
"%-18s %10I64d %10I64d %10d %s %s\n", "%-18s %10I64d %10I64d %10d %s %s\n",
#else #else

View File

@@ -119,10 +119,10 @@ namespace file {
DummyStatus GetContents( DummyStatus GetContents(
const std::string& filename, std::string* data, int unused) { 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) { if (fp == NULL) {
perror(filename.c_str()); std::perror(filename.c_str());
exit(1); std::exit(1);
} }
data->clear(); data->clear();
@@ -130,32 +130,32 @@ namespace file {
char buf[4096]; char buf[4096];
size_t ret = fread(buf, 1, 4096, fp); size_t ret = fread(buf, 1, 4096, fp);
if (ret == 0 && ferror(fp)) { if (ret == 0 && ferror(fp)) {
perror("fread"); std::perror("fread");
exit(1); std::exit(1);
} }
data->append(std::string(buf, ret)); data->append(std::string(buf, ret));
} }
fclose(fp); std::fclose(fp);
return DummyStatus(); return DummyStatus();
} }
inline DummyStatus SetContents( inline DummyStatus SetContents(
const std::string& filename, const std::string& str, int unused) { 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) { if (fp == NULL) {
perror(filename.c_str()); std::perror(filename.c_str());
exit(1); 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) { if (ret != 1) {
perror("fwrite"); std::std::perror("fwrite");
exit(1); std::exit(1);
} }
fclose(fp); std::fclose(fp);
return DummyStatus(); return DummyStatus();
} }
@@ -184,7 +184,7 @@ std::string ReadTestDataFile(const std::string& base, size_t size_limit);
std::string ReadTestDataFile(const std::string& base); 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. // Not safe for general use due to truncation issues.
std::string StrFormat(const char* format, ...); std::string StrFormat(const char* format, ...);
@@ -403,15 +403,17 @@ static inline void RunSpecifiedBenchmarks() {
return; return;
} }
fprintf(stderr, "Running microbenchmarks.\n"); std::fprintf(stderr, "Running microbenchmarks.\n");
#ifndef NDEBUG #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 #endif
#ifndef __OPTIMIZE__ #ifndef __OPTIMIZE__
fprintf(stderr, "WARNING: Compiled without optimization, will be slow.\n"); std::fprintf(stderr,
"WARNING: Compiled without optimization, will be slow.\n");
#endif #endif
fprintf(stderr, "Benchmark Time(ns) CPU(ns) Iterations\n"); std::fprintf(stderr, "Benchmark Time(ns) CPU(ns) Iterations\n");
fprintf(stderr, "---------------------------------------------------\n"); std::fprintf(stderr, "---------------------------------------------------\n");
snappy::Benchmark_BM_UFlat->Run(); snappy::Benchmark_BM_UFlat->Run();
snappy::Benchmark_BM_UIOVec->Run(); snappy::Benchmark_BM_UIOVec->Run();
@@ -420,13 +422,13 @@ static inline void RunSpecifiedBenchmarks() {
snappy::Benchmark_BM_ZFlatAll->Run(); snappy::Benchmark_BM_ZFlatAll->Run();
snappy::Benchmark_BM_ZFlatIncreasingTableSize->Run(); snappy::Benchmark_BM_ZFlatIncreasingTableSize->Run();
fprintf(stderr, "\n"); std::fprintf(stderr, "\n");
} }
#ifndef HAVE_GTEST #ifndef HAVE_GTEST
static inline int RUN_ALL_TESTS() { 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_CorruptedTest_VerifyCorrupted();
snappy::Test_Snappy_SimpleTests(); snappy::Test_Snappy_SimpleTests();
snappy::Test_Snappy_MaxBlowup(); snappy::Test_Snappy_MaxBlowup();
@@ -438,7 +440,7 @@ static inline int RUN_ALL_TESTS() {
snappy::Test_Snappy_ReadPastEndOfBuffer(); snappy::Test_Snappy_ReadPastEndOfBuffer();
snappy::Test_Snappy_FindMatchLength(); snappy::Test_Snappy_FindMatchLength();
snappy::Test_Snappy_FindMatchLengthRandom(); snappy::Test_Snappy_FindMatchLengthRandom();
fprintf(stderr, "All tests passed.\n"); std::fprintf(stderr, "All tests passed.\n");
return 0; return 0;
} }
@@ -479,8 +481,8 @@ class LogMessage {
snappy::LogMessageVoidify() & snappy::LogMessageCrash() snappy::LogMessageVoidify() & snappy::LogMessageCrash()
#ifdef _MSC_VER #ifdef _MSC_VER
// ~LogMessageCrash calls abort() and therefore never exits. This is by design // ~LogMessageCrash calls std::abort() and therefore never exits. This is by
// so temporarily disable warning C4722. // design, so temporarily disable warning C4722.
#pragma warning(push) #pragma warning(push)
#pragma warning(disable:4722) #pragma warning(disable:4722)
#endif #endif
@@ -490,7 +492,7 @@ class LogMessageCrash : public LogMessage {
LogMessageCrash() { } LogMessageCrash() { }
~LogMessageCrash() { ~LogMessageCrash() {
std::cerr << std::endl; std::cerr << std::endl;
abort(); std::abort();
} }
}; };

View File

@@ -348,14 +348,14 @@ static void Measure(const char* data,
x += ":"; x += ":";
std::string urate = (uncomp_rate >= 0) ? StrFormat("%.1f", uncomp_rate) std::string urate = (uncomp_rate >= 0) ? StrFormat("%.1f", uncomp_rate)
: std::string("?"); : std::string("?");
printf("%-7s [b %dM] bytes %6d -> %6d %4.1f%% " std::printf("%-7s [b %dM] bytes %6d -> %6d %4.1f%% "
"comp %5.1f MB/s uncomp %5s MB/s\n", "comp %5.1f MB/s uncomp %5s MB/s\n",
x.c_str(), x.c_str(),
block_size/(1<<20), block_size/(1<<20),
static_cast<int>(length), static_cast<uint32_t>(compressed_size), static_cast<int>(length), static_cast<uint32_t>(compressed_size),
(compressed_size * 100.0) / std::max<int>(1, length), (compressed_size * 100.0) / std::max<int>(1, length),
comp_rate, comp_rate,
urate.c_str()); urate.c_str());
} }
static int VerifyString(const std::string& input) { static int VerifyString(const std::string& input) {
@@ -1164,13 +1164,13 @@ TEST(Snappy, VerifyCharTable) {
} }
if (FLAGS_snappy_dump_decompression_table) { 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++) { for (int i = 0; i < 256; i++) {
printf("0x%04x%s", std::printf("0x%04x%s",
dst[i], dst[i],
((i == 255) ? "\n" : (((i%8) == 7) ? ",\n " : ", "))); ((i == 255) ? "\n" : (((i%8) == 7) ? ",\n " : ", ")));
} }
printf("};\n"); std::printf("};\n");
} }
// Check that computed table matched recorded table. // Check that computed table matched recorded table.
@@ -1208,7 +1208,7 @@ static void UncompressFile(const char* fname) {
static void MeasureFile(const char* fname) { static void MeasureFile(const char* fname) {
std::string fullinput; std::string fullinput;
CHECK_OK(file::GetContents(fname, &fullinput, file::Defaults())); 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 start_len = (FLAGS_start_len < 0) ? fullinput.size() : FLAGS_start_len;
int end_len = fullinput.size(); int end_len = fullinput.size();