From 863f185970eff21e826e5fe1164a6215a515c23b Mon Sep 17 00:00:00 2001 From: Victor Costan Date: Tue, 28 May 2019 10:17:03 -0700 Subject: [PATCH] unsigned char -> uint8_t PiperOrigin-RevId: 250309603 --- db/c.cc | 30 +++++++++++++----------------- db/c_test.c | 8 +++----- db/dbformat.h | 8 +++++--- include/leveldb/c.h | 20 ++++++++++---------- table/block.cc | 7 ++++--- util/coding.cc | 10 +++++----- util/coding.h | 2 +- util/crc32c_test.cc | 2 +- util/hash.cc | 6 +++--- util/hash_test.cc | 10 +++++----- util/logging.cc | 11 +++++------ 11 files changed, 55 insertions(+), 59 deletions(-) diff --git a/db/c.cc b/db/c.cc index 1f6fd64..3a492f9 100644 --- a/db/c.cc +++ b/db/c.cc @@ -4,7 +4,8 @@ #include "leveldb/c.h" -#include +#include +#include #include "leveldb/cache.h" #include "leveldb/comparator.h" @@ -132,8 +133,8 @@ struct leveldb_filterpolicy_t : public FilterPolicy { char* (*create_)(void*, const char* const* key_array, const size_t* key_length_array, int num_keys, size_t* filter_length); - unsigned char (*key_match_)(void*, const char* key, size_t length, - const char* filter, size_t filter_length); + uint8_t (*key_match_)(void*, const char* key, size_t length, + const char* filter, size_t filter_length); }; struct leveldb_env_t { @@ -281,7 +282,7 @@ void leveldb_iter_destroy(leveldb_iterator_t* iter) { delete iter; } -unsigned char leveldb_iter_valid(const leveldb_iterator_t* iter) { +uint8_t leveldb_iter_valid(const leveldb_iterator_t* iter) { return iter->rep->Valid(); } @@ -378,18 +379,15 @@ void leveldb_options_set_filter_policy(leveldb_options_t* opt, opt->rep.filter_policy = policy; } -void leveldb_options_set_create_if_missing(leveldb_options_t* opt, - unsigned char v) { +void leveldb_options_set_create_if_missing(leveldb_options_t* opt, uint8_t v) { opt->rep.create_if_missing = v; } -void leveldb_options_set_error_if_exists(leveldb_options_t* opt, - unsigned char v) { +void leveldb_options_set_error_if_exists(leveldb_options_t* opt, uint8_t v) { opt->rep.error_if_exists = v; } -void leveldb_options_set_paranoid_checks(leveldb_options_t* opt, - unsigned char v) { +void leveldb_options_set_paranoid_checks(leveldb_options_t* opt, uint8_t v) { opt->rep.paranoid_checks = v; } @@ -449,8 +447,8 @@ leveldb_filterpolicy_t* leveldb_filterpolicy_create( char* (*create_filter)(void*, const char* const* key_array, const size_t* key_length_array, int num_keys, size_t* filter_length), - unsigned char (*key_may_match)(void*, const char* key, size_t length, - const char* filter, size_t filter_length), + uint8_t (*key_may_match)(void*, const char* key, size_t length, + const char* filter, size_t filter_length), const char* (*name)(void*)) { leveldb_filterpolicy_t* result = new leveldb_filterpolicy_t; result->state_ = state; @@ -497,12 +495,11 @@ leveldb_readoptions_t* leveldb_readoptions_create() { void leveldb_readoptions_destroy(leveldb_readoptions_t* opt) { delete opt; } void leveldb_readoptions_set_verify_checksums(leveldb_readoptions_t* opt, - unsigned char v) { + uint8_t v) { opt->rep.verify_checksums = v; } -void leveldb_readoptions_set_fill_cache(leveldb_readoptions_t* opt, - unsigned char v) { +void leveldb_readoptions_set_fill_cache(leveldb_readoptions_t* opt, uint8_t v) { opt->rep.fill_cache = v; } @@ -517,8 +514,7 @@ leveldb_writeoptions_t* leveldb_writeoptions_create() { void leveldb_writeoptions_destroy(leveldb_writeoptions_t* opt) { delete opt; } -void leveldb_writeoptions_set_sync(leveldb_writeoptions_t* opt, - unsigned char v) { +void leveldb_writeoptions_set_sync(leveldb_writeoptions_t* opt, uint8_t v) { opt->rep.sync = v; } diff --git a/db/c_test.c b/db/c_test.c index ae14b99..16c77ee 100644 --- a/db/c_test.c +++ b/db/c_test.c @@ -120,7 +120,7 @@ static const char* CmpName(void* arg) { } // Custom filter policy -static unsigned char fake_filter_result = 1; +static uint8_t fake_filter_result = 1; static void FilterDestroy(void* arg) { } static const char* FilterName(void* arg) { return "TestFilter"; @@ -135,10 +135,8 @@ static char* FilterCreate( memcpy(result, "fake", 4); return result; } -unsigned char FilterKeyMatch( - void* arg, - const char* key, size_t length, - const char* filter, size_t filter_length) { +uint8_t FilterKeyMatch(void* arg, const char* key, size_t length, + const char* filter, size_t filter_length) { CheckCondition(filter_length == 4); CheckCondition(memcmp(filter, "fake", 4) == 0); return fake_filter_result; diff --git a/db/dbformat.h b/db/dbformat.h index abcb489..a1c30ed 100644 --- a/db/dbformat.h +++ b/db/dbformat.h @@ -5,7 +5,9 @@ #ifndef STORAGE_LEVELDB_DB_DBFORMAT_H_ #define STORAGE_LEVELDB_DB_DBFORMAT_H_ -#include +#include +#include +#include #include "leveldb/comparator.h" #include "leveldb/db.h" @@ -171,11 +173,11 @@ inline bool ParseInternalKey(const Slice& internal_key, const size_t n = internal_key.size(); if (n < 8) return false; uint64_t num = DecodeFixed64(internal_key.data() + n - 8); - unsigned char c = num & 0xff; + uint8_t c = num & 0xff; result->sequence = num >> 8; result->type = static_cast(c); result->user_key = Slice(internal_key.data(), n - 8); - return (c <= static_cast(kTypeValue)); + return (c <= static_cast(kTypeValue)); } // A helper class useful for DBImpl::Get() diff --git a/include/leveldb/c.h b/include/leveldb/c.h index 04e383c..02c79ba 100644 --- a/include/leveldb/c.h +++ b/include/leveldb/c.h @@ -32,7 +32,7 @@ On failure, leveldb frees the old value of *errptr and set *errptr to a malloc()ed error message. - (4) Bools have the type unsigned char (0 == false; rest == true) + (4) Bools have the type uint8_t (0 == false; rest == true) (5) All of the pointer arguments must be non-NULL. */ @@ -131,7 +131,7 @@ LEVELDB_EXPORT void leveldb_repair_db(const leveldb_options_t* options, /* Iterator */ LEVELDB_EXPORT void leveldb_iter_destroy(leveldb_iterator_t*); -LEVELDB_EXPORT unsigned char leveldb_iter_valid(const leveldb_iterator_t*); +LEVELDB_EXPORT uint8_t leveldb_iter_valid(const leveldb_iterator_t*); LEVELDB_EXPORT void leveldb_iter_seek_to_first(leveldb_iterator_t*); LEVELDB_EXPORT void leveldb_iter_seek_to_last(leveldb_iterator_t*); LEVELDB_EXPORT void leveldb_iter_seek(leveldb_iterator_t*, const char* k, @@ -171,11 +171,11 @@ LEVELDB_EXPORT void leveldb_options_set_comparator(leveldb_options_t*, LEVELDB_EXPORT void leveldb_options_set_filter_policy(leveldb_options_t*, leveldb_filterpolicy_t*); LEVELDB_EXPORT void leveldb_options_set_create_if_missing(leveldb_options_t*, - unsigned char); + uint8_t); LEVELDB_EXPORT void leveldb_options_set_error_if_exists(leveldb_options_t*, - unsigned char); + uint8_t); LEVELDB_EXPORT void leveldb_options_set_paranoid_checks(leveldb_options_t*, - unsigned char); + uint8_t); LEVELDB_EXPORT void leveldb_options_set_env(leveldb_options_t*, leveldb_env_t*); LEVELDB_EXPORT void leveldb_options_set_info_log(leveldb_options_t*, leveldb_logger_t*); @@ -209,8 +209,8 @@ LEVELDB_EXPORT leveldb_filterpolicy_t* leveldb_filterpolicy_create( char* (*create_filter)(void*, const char* const* key_array, const size_t* key_length_array, int num_keys, size_t* filter_length), - unsigned char (*key_may_match)(void*, const char* key, size_t length, - const char* filter, size_t filter_length), + uint8_t (*key_may_match)(void*, const char* key, size_t length, + const char* filter, size_t filter_length), const char* (*name)(void*)); LEVELDB_EXPORT void leveldb_filterpolicy_destroy(leveldb_filterpolicy_t*); @@ -222,9 +222,9 @@ LEVELDB_EXPORT leveldb_filterpolicy_t* leveldb_filterpolicy_create_bloom( LEVELDB_EXPORT leveldb_readoptions_t* leveldb_readoptions_create(void); LEVELDB_EXPORT void leveldb_readoptions_destroy(leveldb_readoptions_t*); LEVELDB_EXPORT void leveldb_readoptions_set_verify_checksums( - leveldb_readoptions_t*, unsigned char); + leveldb_readoptions_t*, uint8_t); LEVELDB_EXPORT void leveldb_readoptions_set_fill_cache(leveldb_readoptions_t*, - unsigned char); + uint8_t); LEVELDB_EXPORT void leveldb_readoptions_set_snapshot(leveldb_readoptions_t*, const leveldb_snapshot_t*); @@ -233,7 +233,7 @@ LEVELDB_EXPORT void leveldb_readoptions_set_snapshot(leveldb_readoptions_t*, LEVELDB_EXPORT leveldb_writeoptions_t* leveldb_writeoptions_create(void); LEVELDB_EXPORT void leveldb_writeoptions_destroy(leveldb_writeoptions_t*); LEVELDB_EXPORT void leveldb_writeoptions_set_sync(leveldb_writeoptions_t*, - unsigned char); + uint8_t); /* Cache */ diff --git a/table/block.cc b/table/block.cc index 05c600f..2fe89ea 100644 --- a/table/block.cc +++ b/table/block.cc @@ -7,6 +7,7 @@ #include "table/block.h" #include +#include #include #include "leveldb/comparator.h" @@ -55,9 +56,9 @@ static inline const char* DecodeEntry(const char* p, const char* limit, uint32_t* shared, uint32_t* non_shared, uint32_t* value_length) { if (limit - p < 3) return nullptr; - *shared = reinterpret_cast(p)[0]; - *non_shared = reinterpret_cast(p)[1]; - *value_length = reinterpret_cast(p)[2]; + *shared = reinterpret_cast(p)[0]; + *non_shared = reinterpret_cast(p)[1]; + *value_length = reinterpret_cast(p)[2]; if ((*shared | *non_shared | *value_length) < 128) { // Fast path: all three values are encoded in one byte each p += 3; diff --git a/util/coding.cc b/util/coding.cc index 55be020..df3fa10 100644 --- a/util/coding.cc +++ b/util/coding.cc @@ -20,7 +20,7 @@ void PutFixed64(std::string* dst, uint64_t value) { char* EncodeVarint32(char* dst, uint32_t v) { // Operate on characters as unsigneds - unsigned char* ptr = reinterpret_cast(dst); + uint8_t* ptr = reinterpret_cast(dst); static const int B = 128; if (v < (1 << 7)) { *(ptr++) = v; @@ -54,12 +54,12 @@ void PutVarint32(std::string* dst, uint32_t v) { char* EncodeVarint64(char* dst, uint64_t v) { static const int B = 128; - unsigned char* ptr = reinterpret_cast(dst); + uint8_t* ptr = reinterpret_cast(dst); while (v >= B) { *(ptr++) = v | B; v >>= 7; } - *(ptr++) = static_cast(v); + *(ptr++) = static_cast(v); return reinterpret_cast(ptr); } @@ -87,7 +87,7 @@ const char* GetVarint32PtrFallback(const char* p, const char* limit, uint32_t* value) { uint32_t result = 0; for (uint32_t shift = 0; shift <= 28 && p < limit; shift += 7) { - uint32_t byte = *(reinterpret_cast(p)); + uint32_t byte = *(reinterpret_cast(p)); p++; if (byte & 128) { // More bytes are present @@ -116,7 +116,7 @@ bool GetVarint32(Slice* input, uint32_t* value) { const char* GetVarint64Ptr(const char* p, const char* limit, uint64_t* value) { uint64_t result = 0; for (uint32_t shift = 0; shift <= 63 && p < limit; shift += 7) { - uint64_t byte = *(reinterpret_cast(p)); + uint64_t byte = *(reinterpret_cast(p)); p++; if (byte & 128) { // More bytes are present diff --git a/util/coding.h b/util/coding.h index 92a961f..1983ae7 100644 --- a/util/coding.h +++ b/util/coding.h @@ -150,7 +150,7 @@ const char* GetVarint32PtrFallback(const char* p, const char* limit, inline const char* GetVarint32Ptr(const char* p, const char* limit, uint32_t* value) { if (p < limit) { - uint32_t result = *(reinterpret_cast(p)); + uint32_t result = *(reinterpret_cast(p)); if ((result & 128) == 0) { *value = result; return p + 1; diff --git a/util/crc32c_test.cc b/util/crc32c_test.cc index dbd2ba4..18a8494 100644 --- a/util/crc32c_test.cc +++ b/util/crc32c_test.cc @@ -30,7 +30,7 @@ TEST(CRC, StandardResults) { } ASSERT_EQ(0x113fdb5c, Value(buf, sizeof(buf))); - unsigned char data[48] = { + uint8_t data[48] = { 0x01, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x18, 0x28, 0x00, 0x00, 0x00, diff --git a/util/hash.cc b/util/hash.cc index 67dc134..dd47c11 100644 --- a/util/hash.cc +++ b/util/hash.cc @@ -38,13 +38,13 @@ uint32_t Hash(const char* data, size_t n, uint32_t seed) { // Pick up remaining bytes switch (limit - data) { case 3: - h += static_cast(data[2]) << 16; + h += static_cast(data[2]) << 16; FALLTHROUGH_INTENDED; case 2: - h += static_cast(data[1]) << 8; + h += static_cast(data[1]) << 8; FALLTHROUGH_INTENDED; case 1: - h += static_cast(data[0]); + h += static_cast(data[0]); h *= m; h ^= (h >> r); break; diff --git a/util/hash_test.cc b/util/hash_test.cc index 8f579cc..21f8171 100644 --- a/util/hash_test.cc +++ b/util/hash_test.cc @@ -10,11 +10,11 @@ namespace leveldb { class HASH {}; TEST(HASH, SignedUnsignedIssue) { - const unsigned char data1[1] = {0x62}; - const unsigned char data2[2] = {0xc3, 0x97}; - const unsigned char data3[3] = {0xe2, 0x99, 0xa5}; - const unsigned char data4[4] = {0xe1, 0x80, 0xb9, 0x32}; - const unsigned char data5[48] = { + const uint8_t data1[1] = {0x62}; + const uint8_t data2[2] = {0xc3, 0x97}; + const uint8_t data3[3] = {0xe2, 0x99, 0xa5}; + const uint8_t data4[4] = {0xe1, 0x80, 0xb9, 0x32}; + const uint8_t data5[48] = { 0x01, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x18, 0x28, 0x00, 0x00, 0x00, diff --git a/util/logging.cc b/util/logging.cc index 1ad8f1c..75e9d03 100644 --- a/util/logging.cc +++ b/util/logging.cc @@ -56,14 +56,13 @@ bool ConsumeDecimalNumber(Slice* in, uint64_t* val) { uint64_t value = 0; - // reinterpret_cast-ing from char* to unsigned char* to avoid signedness. - const unsigned char* start = - reinterpret_cast(in->data()); + // reinterpret_cast-ing from char* to uint8_t* to avoid signedness. + const uint8_t* start = reinterpret_cast(in->data()); - const unsigned char* end = start + in->size(); - const unsigned char* current = start; + const uint8_t* end = start + in->size(); + const uint8_t* current = start; for (; current != end; ++current) { - const unsigned char ch = *current; + const uint8_t ch = *current; if (ch < '0' || ch > '9') break; // Overflow check.