summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorVictor Costan <costan@google.com>2020-04-29 22:31:41 +0000
committerVictor Costan <costan@google.com>2020-04-29 22:33:14 +0000
commita6b3a2012e9c598258a295aef74d88b796c47a2b (patch)
tree2ce49183e6a860db3e29909409ea884a4bec56d0 /util
parent3f934e3705444a3df80b128ddefc4cf440441ffe (diff)
downloadleveldb-a6b3a2012e9c598258a295aef74d88b796c47a2b.tar.gz
Add some std:: qualifiers to types and functions.
PiperOrigin-RevId: 309110431
Diffstat (limited to 'util')
-rw-r--r--util/bloom_test.cc15
-rw-r--r--util/cache.cc2
-rw-r--r--util/env.cc4
-rw-r--r--util/env_posix_test.cc6
-rw-r--r--util/env_windows_test.cc4
-rw-r--r--util/histogram.cc20
-rw-r--r--util/logging.cc6
-rw-r--r--util/posix_logger.h8
-rw-r--r--util/status.cc16
-rw-r--r--util/windows_logger.h8
10 files changed, 46 insertions, 43 deletions
diff --git a/util/bloom_test.cc b/util/bloom_test.cc
index bcf14dc..520473e 100644
--- a/util/bloom_test.cc
+++ b/util/bloom_test.cc
@@ -45,14 +45,14 @@ class BloomTest : public testing::Test {
size_t FilterSize() const { return filter_.size(); }
void DumpFilter() {
- fprintf(stderr, "F(");
+ std::fprintf(stderr, "F(");
for (size_t i = 0; i + 1 < filter_.size(); i++) {
const unsigned int c = static_cast<unsigned int>(filter_[i]);
for (int j = 0; j < 8; j++) {
- fprintf(stderr, "%c", (c & (1 << j)) ? '1' : '.');
+ std::fprintf(stderr, "%c", (c & (1 << j)) ? '1' : '.');
}
}
- fprintf(stderr, ")\n");
+ std::fprintf(stderr, ")\n");
}
bool Matches(const Slice& s) {
@@ -132,8 +132,9 @@ TEST_F(BloomTest, VaryingLengths) {
// Check false positive rate
double rate = FalsePositiveRate();
if (kVerbose >= 1) {
- fprintf(stderr, "False positives: %5.2f%% @ length = %6d ; bytes = %6d\n",
- rate * 100.0, length, static_cast<int>(FilterSize()));
+ std::fprintf(stderr,
+ "False positives: %5.2f%% @ length = %6d ; bytes = %6d\n",
+ rate * 100.0, length, static_cast<int>(FilterSize()));
}
ASSERT_LE(rate, 0.02); // Must not be over 2%
if (rate > 0.0125)
@@ -142,8 +143,8 @@ TEST_F(BloomTest, VaryingLengths) {
good_filters++;
}
if (kVerbose >= 1) {
- fprintf(stderr, "Filters: %d good, %d mediocre\n", good_filters,
- mediocre_filters);
+ std::fprintf(stderr, "Filters: %d good, %d mediocre\n", good_filters,
+ mediocre_filters);
}
ASSERT_LE(mediocre_filters, good_filters / 5);
}
diff --git a/util/cache.cc b/util/cache.cc
index 509e5eb..ad1e9a2 100644
--- a/util/cache.cc
+++ b/util/cache.cc
@@ -279,7 +279,7 @@ Cache::Handle* LRUCache::Insert(const Slice& key, uint32_t hash, void* value,
e->hash = hash;
e->in_cache = false;
e->refs = 1; // for the returned handle.
- memcpy(e->key_data, key.data(), key.size());
+ std::memcpy(e->key_data, key.data(), key.size());
if (capacity_ > 0) {
e->refs++; // for the cache's reference.
diff --git a/util/env.cc b/util/env.cc
index 40e6071..a53b230 100644
--- a/util/env.cc
+++ b/util/env.cc
@@ -4,6 +4,8 @@
#include "leveldb/env.h"
+#include <cstdarg>
+
// This workaround can be removed when leveldb::Env::DeleteFile is removed.
// See env.h for justification.
#if defined(_WIN32) && defined(LEVELDB_DELETEFILE_UNDEFINED)
@@ -38,7 +40,7 @@ FileLock::~FileLock() = default;
void Log(Logger* info_log, const char* format, ...) {
if (info_log != nullptr) {
- va_list ap;
+ std::va_list ap;
va_start(ap, format);
info_log->Logv(format, ap);
va_end(ap);
diff --git a/util/env_posix_test.cc b/util/env_posix_test.cc
index 36f226f..29f973f 100644
--- a/util/env_posix_test.cc
+++ b/util/env_posix_test.cc
@@ -149,7 +149,7 @@ void CheckCloseOnExecDoesNotLeakFDs(
if (child_pid == kForkInChildProcessReturnValue) {
::execv(child_argv[0], child_argv);
std::fprintf(stderr, "Error spawning child process: %s\n", strerror(errno));
- std::exit(kTextCloseOnExecHelperExecFailedCode);
+ std::std::exit(kTextCloseOnExecHelperExecFailedCode);
}
int child_status = 0;
@@ -187,11 +187,11 @@ TEST_F(EnvPosixTest, TestOpenOnRead) {
ASSERT_LEVELDB_OK(env_->GetTestDirectory(&test_dir));
std::string test_file = test_dir + "/open_on_read.txt";
- FILE* f = fopen(test_file.c_str(), "we");
+ FILE* f = std::fopen(test_file.c_str(), "we");
ASSERT_TRUE(f != nullptr);
const char kFileData[] = "abcdefghijklmnopqrstuvwxyz";
fputs(kFileData, f);
- fclose(f);
+ std::fclose(f);
// Open test file some number above the sum of the two limits to force
// open-on-read behavior of POSIX Env leveldb::RandomAccessFile.
diff --git a/util/env_windows_test.cc b/util/env_windows_test.cc
index 15c0274..d6822d2 100644
--- a/util/env_windows_test.cc
+++ b/util/env_windows_test.cc
@@ -29,11 +29,11 @@ TEST_F(EnvWindowsTest, TestOpenOnRead) {
ASSERT_LEVELDB_OK(env_->GetTestDirectory(&test_dir));
std::string test_file = test_dir + "/open_on_read.txt";
- FILE* f = fopen(test_file.c_str(), "w");
+ FILE* f = std::fopen(test_file.c_str(), "w");
ASSERT_TRUE(f != nullptr);
const char kFileData[] = "abcdefghijklmnopqrstuvwxyz";
fputs(kFileData, f);
- fclose(f);
+ std::fclose(f);
// Open test file some number above the sum of the two limits to force
// leveldb::WindowsEnv to switch from mapping the file into memory
diff --git a/util/histogram.cc b/util/histogram.cc
index d110d28..7af4030 100644
--- a/util/histogram.cc
+++ b/util/histogram.cc
@@ -241,11 +241,11 @@ double Histogram::StandardDeviation() const {
std::string Histogram::ToString() const {
std::string r;
char buf[200];
- snprintf(buf, sizeof(buf), "Count: %.0f Average: %.4f StdDev: %.2f\n", num_,
- Average(), StandardDeviation());
+ std::snprintf(buf, sizeof(buf), "Count: %.0f Average: %.4f StdDev: %.2f\n",
+ num_, Average(), StandardDeviation());
r.append(buf);
- snprintf(buf, sizeof(buf), "Min: %.4f Median: %.4f Max: %.4f\n",
- (num_ == 0.0 ? 0.0 : min_), Median(), max_);
+ std::snprintf(buf, sizeof(buf), "Min: %.4f Median: %.4f Max: %.4f\n",
+ (num_ == 0.0 ? 0.0 : min_), Median(), max_);
r.append(buf);
r.append("------------------------------------------------------\n");
const double mult = 100.0 / num_;
@@ -253,12 +253,12 @@ std::string Histogram::ToString() const {
for (int b = 0; b < kNumBuckets; b++) {
if (buckets_[b] <= 0.0) continue;
sum += buckets_[b];
- snprintf(buf, sizeof(buf), "[ %7.0f, %7.0f ) %7.0f %7.3f%% %7.3f%% ",
- ((b == 0) ? 0.0 : kBucketLimit[b - 1]), // left
- kBucketLimit[b], // right
- buckets_[b], // count
- mult * buckets_[b], // percentage
- mult * sum); // cumulative percentage
+ std::snprintf(buf, sizeof(buf), "[ %7.0f, %7.0f ) %7.0f %7.3f%% %7.3f%% ",
+ ((b == 0) ? 0.0 : kBucketLimit[b - 1]), // left
+ kBucketLimit[b], // right
+ buckets_[b], // count
+ mult * buckets_[b], // percentage
+ mult * sum); // cumulative percentage
r.append(buf);
// Add hash marks based on percentage; 20 marks for 100%.
diff --git a/util/logging.cc b/util/logging.cc
index 39d8551..8d6fb5b 100644
--- a/util/logging.cc
+++ b/util/logging.cc
@@ -16,7 +16,7 @@ namespace leveldb {
void AppendNumberTo(std::string* str, uint64_t num) {
char buf[30];
- snprintf(buf, sizeof(buf), "%llu", (unsigned long long)num);
+ std::snprintf(buf, sizeof(buf), "%llu", static_cast<unsigned long long>(num));
str->append(buf);
}
@@ -27,8 +27,8 @@ void AppendEscapedStringTo(std::string* str, const Slice& value) {
str->push_back(c);
} else {
char buf[10];
- snprintf(buf, sizeof(buf), "\\x%02x",
- static_cast<unsigned int>(c) & 0xff);
+ std::snprintf(buf, sizeof(buf), "\\x%02x",
+ static_cast<unsigned int>(c) & 0xff);
str->append(buf);
}
}
diff --git a/util/posix_logger.h b/util/posix_logger.h
index 28e15d1..6bbc1a0 100644
--- a/util/posix_logger.h
+++ b/util/posix_logger.h
@@ -30,7 +30,7 @@ class PosixLogger final : public Logger {
~PosixLogger() override { std::fclose(fp_); }
- void Logv(const char* format, va_list arguments) override {
+ void Logv(const char* format, std::va_list arguments) override {
// Record the time as close to the Logv() call as possible.
struct ::timeval now_timeval;
::gettimeofday(&now_timeval, nullptr);
@@ -62,7 +62,7 @@ class PosixLogger final : public Logger {
(iteration == 0) ? stack_buffer : new char[dynamic_buffer_size];
// Print the header into the buffer.
- int buffer_offset = snprintf(
+ int buffer_offset = std::snprintf(
buffer, buffer_size, "%04d/%02d/%02d-%02d:%02d:%02d.%06d %s ",
now_components.tm_year + 1900, now_components.tm_mon + 1,
now_components.tm_mday, now_components.tm_hour, now_components.tm_min,
@@ -98,8 +98,8 @@ class PosixLogger final : public Logger {
}
// The dynamically-allocated buffer was incorrectly sized. This should
- // not happen, assuming a correct implementation of (v)snprintf. Fail
- // in tests, recover by truncating the log message in production.
+ // not happen, assuming a correct implementation of std::(v)snprintf.
+ // Fail in tests, recover by truncating the log message in production.
assert(false);
buffer_offset = buffer_size - 1;
}
diff --git a/util/status.cc b/util/status.cc
index 6b6528b..0559f5b 100644
--- a/util/status.cc
+++ b/util/status.cc
@@ -12,9 +12,9 @@ namespace leveldb {
const char* Status::CopyState(const char* state) {
uint32_t size;
- memcpy(&size, state, sizeof(size));
+ std::memcpy(&size, state, sizeof(size));
char* result = new char[size + 5];
- memcpy(result, state, size + 5);
+ std::memcpy(result, state, size + 5);
return result;
}
@@ -24,13 +24,13 @@ Status::Status(Code code, const Slice& msg, const Slice& msg2) {
const uint32_t len2 = static_cast<uint32_t>(msg2.size());
const uint32_t size = len1 + (len2 ? (2 + len2) : 0);
char* result = new char[size + 5];
- memcpy(result, &size, sizeof(size));
+ std::memcpy(result, &size, sizeof(size));
result[4] = static_cast<char>(code);
- memcpy(result + 5, msg.data(), len1);
+ std::memcpy(result + 5, msg.data(), len1);
if (len2) {
result[5 + len1] = ':';
result[6 + len1] = ' ';
- memcpy(result + 7 + len1, msg2.data(), len2);
+ std::memcpy(result + 7 + len1, msg2.data(), len2);
}
state_ = result;
}
@@ -61,14 +61,14 @@ std::string Status::ToString() const {
type = "IO error: ";
break;
default:
- snprintf(tmp, sizeof(tmp),
- "Unknown code(%d): ", static_cast<int>(code()));
+ std::snprintf(tmp, sizeof(tmp),
+ "Unknown code(%d): ", static_cast<int>(code()));
type = tmp;
break;
}
std::string result(type);
uint32_t length;
- memcpy(&length, state_, sizeof(length));
+ std::memcpy(&length, state_, sizeof(length));
result.append(state_ + 5, length);
return result;
}
diff --git a/util/windows_logger.h b/util/windows_logger.h
index 9296063..26e6c7b 100644
--- a/util/windows_logger.h
+++ b/util/windows_logger.h
@@ -27,7 +27,7 @@ class WindowsLogger final : public Logger {
~WindowsLogger() override { std::fclose(fp_); }
- void Logv(const char* format, va_list arguments) override {
+ void Logv(const char* format, std::va_list arguments) override {
// Record the time as close to the Logv() call as possible.
SYSTEMTIME now_components;
::GetLocalTime(&now_components);
@@ -56,7 +56,7 @@ class WindowsLogger final : public Logger {
(iteration == 0) ? stack_buffer : new char[dynamic_buffer_size];
// Print the header into the buffer.
- int buffer_offset = snprintf(
+ int buffer_offset = std::snprintf(
buffer, buffer_size, "%04d/%02d/%02d-%02d:%02d:%02d.%06d %s ",
now_components.wYear, now_components.wMonth, now_components.wDay,
now_components.wHour, now_components.wMinute, now_components.wSecond,
@@ -92,8 +92,8 @@ class WindowsLogger final : public Logger {
}
// The dynamically-allocated buffer was incorrectly sized. This should
- // not happen, assuming a correct implementation of (v)snprintf. Fail
- // in tests, recover by truncating the log message in production.
+ // not happen, assuming a correct implementation of std::(v)snprintf.
+ // Fail in tests, recover by truncating the log message in production.
assert(false);
buffer_offset = buffer_size - 1;
}