diff --git a/.travis.yml b/.travis.yml index 3bd6a20cb..b366da251 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,8 +15,17 @@ cache: - apt addons: - apt: - packages: ['zlib1g-dev', 'libbz2-dev', 'libsnappy-dev', 'curl', 'libgflags-dev', 'mingw-w64'] + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - curl + - g++-8 + - libbz2-dev + - libgflags-dev + - libsnappy-dev + - mingw-w64 + - zlib1g-dev env: - TEST_GROUP=platform_dependent # 16-18 minutes - TEST_GROUP=1 # 33-35 minutes @@ -30,6 +39,7 @@ env: # Build examples - JOB_NAME=examples # 5-7 minutes - JOB_NAME=cmake # 3-5 minutes + - JOB_NAME=cmake-gcc8 # 3-5 minutes - JOB_NAME=cmake-mingw # 3 minutes matrix: @@ -42,6 +52,8 @@ matrix: env: TEST_GROUP=3 - os: osx env: TEST_GROUP=4 + - os: osx + env: JOB_NAME=cmake-gcc8 - os : osx env: JOB_NAME=cmake-mingw - os : linux @@ -55,6 +67,9 @@ install: brew install ccache zstd lz4 snappy xz; PATH=$PATH:/usr/local/opt/ccache/libexec; fi + - if [ "${JOB_NAME}" == cmake-gcc8 ]; then + CC=gcc-8 && CXX=g++-8; + fi - if [[ "${JOB_NAME}" == cmake* ]] && [ "${TRAVIS_OS_NAME}" == linux ]; then mkdir cmake-dist && curl -sfSL https://cmake.org/files/v3.8/cmake-3.8.1-Linux-x86_64.tar.gz | tar --strip-components=1 -C cmake-dist -xz && export PATH=$PWD/cmake-dist/bin:$PATH; fi @@ -67,16 +82,40 @@ before_script: script: - ${CXX} --version - if [ `command -v ccache` ]; then ccache -C; fi - - if [ "${TEST_GROUP}" == 'platform_dependent' ]; then OPT=-DTRAVIS V=1 ROCKSDBTESTS_END=db_block_cache_test make -j4 all_but_some_tests check_some; fi - - if [ "${TEST_GROUP}" == '1' ]; then OPT=-DTRAVIS V=1 ROCKSDBTESTS_START=db_block_cache_test ROCKSDBTESTS_END=full_filter_block_test make -j4 check_some; fi - - if [ "${TEST_GROUP}" == '2' ]; then OPT=-DTRAVIS V=1 ROCKSDBTESTS_START=full_filter_block_test ROCKSDBTESTS_END=write_batch_with_index_test make -j4 check_some; fi - - if [ "${TEST_GROUP}" == '3' ]; then OPT=-DTRAVIS V=1 ROCKSDBTESTS_START=write_batch_with_index_test ROCKSDBTESTS_END=write_prepared_transaction_test make -j4 check_some; fi - - if [ "${TEST_GROUP}" == '4' ]; then OPT=-DTRAVIS V=1 ROCKSDBTESTS_START=write_prepared_transaction_test make -j4 check_some; fi - - if [ "${JOB_NAME}" == 'java_test' ]; then OPT=-DTRAVIS V=1 make clean jclean && make rocksdbjava jtest; fi - - if [ "${JOB_NAME}" == 'lite_build' ]; then OPT="-DTRAVIS -DROCKSDB_LITE" V=1 make -j4 static_lib tools; fi - - if [ "${JOB_NAME}" == 'examples' ]; then OPT=-DTRAVIS V=1 make -j4 static_lib; cd examples; make -j4; fi - - if [ "${JOB_NAME}" == 'cmake' ]; then mkdir build && cd build && cmake -DJNI=1 .. && make -j4 rocksdb rocksdbjni; fi - - if [ "${JOB_NAME}" == 'cmake-mingw' ]; then mkdir build && cd build && cmake -DJNI=1 .. -DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc -DCMAKE_CXX_COMPILER=x86_64-w64-mingw32-g++ -DCMAKE_SYSTEM_NAME=Windows && make -j4 rocksdb rocksdbjni; fi + - case $TEST_GROUP in + platform_dependent) + OPT=-DTRAVIS V=1 ROCKSDBTESTS_END=db_block_cache_test make -j4 all_but_some_tests check_some + ;; + 1) + OPT=-DTRAVIS V=1 ROCKSDBTESTS_START=db_block_cache_test ROCKSDBTESTS_END=full_filter_block_test make -j4 check_some + ;; + 2) + OPT=-DTRAVIS V=1 ROCKSDBTESTS_START=full_filter_block_test ROCKSDBTESTS_END=write_batch_with_index_test make -j4 check_some + ;; + 3) + OPT=-DTRAVIS V=1 ROCKSDBTESTS_START=write_batch_with_index_test ROCKSDBTESTS_END=write_prepared_transaction_test make -j4 check_some + ;; + 4) + OPT=-DTRAVIS V=1 ROCKSDBTESTS_START=write_prepared_transaction_test make -j4 check_some + ;; + esac + - case $JOB_NAME in + java_test) + OPT=-DTRAVIS V=1 make clean jclean && make rocksdbjava jtest + ;; + lite_build) + OPT='-DTRAVIS -DROCKSDB_LITE' V=1 make -j4 static_lib tools + ;; + examples) + OPT=-DTRAVIS V=1 make -j4 static_lib && cd examples && make -j4 + ;; + cmake-mingw) + mkdir build && cd build && cmake -DJNI=1 .. -DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc -DCMAKE_CXX_COMPILER=x86_64-w64-mingw32-g++ -DCMAKE_SYSTEM_NAME=Windows && make -j4 rocksdb rocksdbjni + ;; + cmake*) + mkdir build && cd build && cmake -DJNI=1 .. -DCMAKE_BUILD_TYPE=Release && make -j4 rocksdb rocksdbjni + ;; + esac notifications: email: - leveldb@fb.com diff --git a/CMakeLists.txt b/CMakeLists.txt index ad7c7a0f8..06f34e9a2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -170,7 +170,7 @@ else() endif() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -fno-omit-frame-pointer") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer") include(CheckCXXCompilerFlag) CHECK_CXX_COMPILER_FLAG("-momit-leaf-frame-pointer" HAVE_OMIT_LEAF_FRAME_POINTER) if(HAVE_OMIT_LEAF_FRAME_POINTER) diff --git a/WINDOWS_PORT.md b/WINDOWS_PORT.md index a0fe1fe11..7eee29567 100644 --- a/WINDOWS_PORT.md +++ b/WINDOWS_PORT.md @@ -45,7 +45,7 @@ We plan to use this port for our business purposes here at Bing and this provide * All posix specific headers were replaced to port/port.h which worked well * Replaced `dirent.h` for `port/dirent.h` (very few places) with the implementation of the relevant interfaces within `rocksdb::port` namespace * Replaced `sys/time.h` to `port/sys_time.h` (few places) implemented equivalents within `rocksdb::port` -* `printf %z` specification is not supported on Windows. To imitate existing standards we came up with a string macro `ROCKSDB_PRIszt` which expands to `%z` on posix systems and to Iu on windows. +* `printf %z` specification is not supported on Windows. To imitate existing standards we came up with a string macro `ROCKSDB_PRIszt` which expands to `zu` on posix systems and to `Iu` on windows. * in class member initialization were moved to a __ctors in some cases * `constexpr` is not supported. We had to replace `std::numeric_limits<>::max/min()` to its C macros for constants. Sometimes we had to make class members `static const` and place a definition within a .cc file. * `constexpr` for functions was replaced to a template specialization (1 place) diff --git a/db/log_reader.cc b/db/log_reader.cc index cae5d8ea0..0db96a75c 100644 --- a/db/log_reader.cc +++ b/db/log_reader.cc @@ -14,6 +14,7 @@ #include "util/coding.h" #include "util/crc32c.h" #include "util/file_reader_writer.h" +#include "util/util.h" namespace rocksdb { namespace log { @@ -151,7 +152,7 @@ bool Reader::ReadRecord(Slice* record, std::string* scratch, // in clean shutdown we don't expect any error in the log files ReportCorruption(drop_size, "truncated header"); } - // fall-thru + FALLTHROUGH_INTENDED; case kEof: if (in_fragmented_record) { @@ -181,7 +182,7 @@ bool Reader::ReadRecord(Slice* record, std::string* scratch, } return false; } - // fall-thru + FALLTHROUGH_INTENDED; case kBadRecord: if (in_fragmented_record) { diff --git a/db/memtable.cc b/db/memtable.cc index c68827ad9..6be872881 100644 --- a/db/memtable.cc +++ b/db/memtable.cc @@ -36,6 +36,7 @@ #include "util/memory_usage.h" #include "util/murmurhash.h" #include "util/mutexlock.h" +#include "util/util.h" namespace rocksdb { @@ -639,7 +640,7 @@ static bool SaveValue(void* arg, const char* entry) { *(s->found_final_value) = true; return false; } - // intentional fallthrough + FALLTHROUGH_INTENDED; case kTypeValue: { if (s->inplace_update_support) { s->mem->GetLock(s->key->user_key())->ReadLock(); diff --git a/db/write_batch.cc b/db/write_batch.cc index 5c9378f56..aa78d45cd 100644 --- a/db/write_batch.cc +++ b/db/write_batch.cc @@ -55,6 +55,7 @@ #include "util/coding.h" #include "util/duplicate_detector.h" #include "util/string_util.h" +#include "util/util.h" namespace rocksdb { @@ -307,7 +308,7 @@ Status ReadRecordFromWriteBatch(Slice* input, char* tag, if (!GetVarint32(input, column_family)) { return Status::Corruption("bad WriteBatch Put"); } - // intentional fallthrough + FALLTHROUGH_INTENDED; case kTypeValue: if (!GetLengthPrefixedSlice(input, key) || !GetLengthPrefixedSlice(input, value)) { @@ -319,7 +320,7 @@ Status ReadRecordFromWriteBatch(Slice* input, char* tag, if (!GetVarint32(input, column_family)) { return Status::Corruption("bad WriteBatch Delete"); } - // intentional fallthrough + FALLTHROUGH_INTENDED; case kTypeDeletion: case kTypeSingleDeletion: if (!GetLengthPrefixedSlice(input, key)) { @@ -330,7 +331,7 @@ Status ReadRecordFromWriteBatch(Slice* input, char* tag, if (!GetVarint32(input, column_family)) { return Status::Corruption("bad WriteBatch DeleteRange"); } - // intentional fallthrough + FALLTHROUGH_INTENDED; case kTypeRangeDeletion: // for range delete, "key" is begin_key, "value" is end_key if (!GetLengthPrefixedSlice(input, key) || @@ -342,7 +343,7 @@ Status ReadRecordFromWriteBatch(Slice* input, char* tag, if (!GetVarint32(input, column_family)) { return Status::Corruption("bad WriteBatch Merge"); } - // intentional fallthrough + FALLTHROUGH_INTENDED; case kTypeMerge: if (!GetLengthPrefixedSlice(input, key) || !GetLengthPrefixedSlice(input, value)) { @@ -353,7 +354,7 @@ Status ReadRecordFromWriteBatch(Slice* input, char* tag, if (!GetVarint32(input, column_family)) { return Status::Corruption("bad WriteBatch BlobIndex"); } - // intentional fallthrough + FALLTHROUGH_INTENDED; case kTypeBlobIndex: if (!GetLengthPrefixedSlice(input, key) || !GetLengthPrefixedSlice(input, value)) { diff --git a/include/rocksdb/status.h b/include/rocksdb/status.h index e3576b2aa..ea0fb467a 100644 --- a/include/rocksdb/status.h +++ b/include/rocksdb/status.h @@ -26,7 +26,7 @@ class Status { public: // Create a success status. Status() : code_(kOk), subcode_(kNone), sev_(kNoError), state_(nullptr) {} - ~Status() { free((void *) state_); } + ~Status() { delete[] state_; } // Copy the specified status. Status(const Status& s); @@ -308,7 +308,7 @@ inline Status& Status::operator=(const Status& s) { code_ = s.code_; subcode_ = s.subcode_; sev_ = s.sev_; - free((void *) state_); + delete[] state_; state_ = (s.state_ == nullptr) ? nullptr : CopyState(s.state_); } return *this; @@ -334,7 +334,7 @@ inline Status& Status::operator=(Status&& s) s.subcode_ = kNone; sev_ = std::move(s.sev_); s.sev_ = kNoError; - free((void *)state_); + delete[] state_; state_ = nullptr; std::swap(state_, s.state_); } diff --git a/table/table_test.cc b/table/table_test.cc index f696942d3..312b0bfcd 100644 --- a/table/table_test.cc +++ b/table/table_test.cc @@ -996,7 +996,7 @@ class HarnessTest : public testing::Test { std::vector args = GenerateArgList(); assert(part); assert(part <= total); - for (unsigned int i = 0; i < args.size(); i++) { + for (size_t i = 0; i < args.size(); i++) { if ((i % total) + 1 != part) { continue; } diff --git a/third-party/fbson/FbsonJsonParser.h b/third-party/fbson/FbsonJsonParser.h index 2c936d675..47bff77fe 100644 --- a/third-party/fbson/FbsonJsonParser.h +++ b/third-party/fbson/FbsonJsonParser.h @@ -456,7 +456,11 @@ class FbsonJsonParserT { } case '+': in.ignore(); - // fall through +#if defined(__clang__) + [[clang::fallthrough]]; +#elif defined(__GNUC__) && __GNUC__ >= 7 + [[gnu::fallthrough]]; +#endif default: ret = parseDecimal(in, 1); break; diff --git a/util/crc32c.cc b/util/crc32c.cc index a7647ca9d..9e4b65e66 100644 --- a/util/crc32c.cc +++ b/util/crc32c.cc @@ -16,6 +16,7 @@ #include #endif #include "util/coding.h" +#include "util/util.h" #ifdef __powerpc64__ #include "util/crc32c_ppc.h" @@ -704,386 +705,386 @@ uint32_t crc32c_3way(uint32_t crc, const char* buf, size_t len) { do { // jumps here for a full block of len 128 CRCtriplet(crc, next, -128); - // FALLTHRU + FALLTHROUGH_INTENDED; case 127: // jumps here or below for the first block smaller CRCtriplet(crc, next, -127); - // FALLTHRU + FALLTHROUGH_INTENDED; case 126: CRCtriplet(crc, next, -126); // than 128 - // FALLTHRU + FALLTHROUGH_INTENDED; case 125: CRCtriplet(crc, next, -125); - // FALLTHRU + FALLTHROUGH_INTENDED; case 124: CRCtriplet(crc, next, -124); - // FALLTHRU + FALLTHROUGH_INTENDED; case 123: CRCtriplet(crc, next, -123); - // FALLTHRU + FALLTHROUGH_INTENDED; case 122: CRCtriplet(crc, next, -122); - // FALLTHRU + FALLTHROUGH_INTENDED; case 121: CRCtriplet(crc, next, -121); - // FALLTHRU + FALLTHROUGH_INTENDED; case 120: CRCtriplet(crc, next, -120); - // FALLTHRU + FALLTHROUGH_INTENDED; case 119: CRCtriplet(crc, next, -119); - // FALLTHRU + FALLTHROUGH_INTENDED; case 118: CRCtriplet(crc, next, -118); - // FALLTHRU + FALLTHROUGH_INTENDED; case 117: CRCtriplet(crc, next, -117); - // FALLTHRU + FALLTHROUGH_INTENDED; case 116: CRCtriplet(crc, next, -116); - // FALLTHRU + FALLTHROUGH_INTENDED; case 115: CRCtriplet(crc, next, -115); - // FALLTHRU + FALLTHROUGH_INTENDED; case 114: CRCtriplet(crc, next, -114); - // FALLTHRU + FALLTHROUGH_INTENDED; case 113: CRCtriplet(crc, next, -113); - // FALLTHRU + FALLTHROUGH_INTENDED; case 112: CRCtriplet(crc, next, -112); - // FALLTHRU + FALLTHROUGH_INTENDED; case 111: CRCtriplet(crc, next, -111); - // FALLTHRU + FALLTHROUGH_INTENDED; case 110: CRCtriplet(crc, next, -110); - // FALLTHRU + FALLTHROUGH_INTENDED; case 109: CRCtriplet(crc, next, -109); - // FALLTHRU + FALLTHROUGH_INTENDED; case 108: CRCtriplet(crc, next, -108); - // FALLTHRU + FALLTHROUGH_INTENDED; case 107: CRCtriplet(crc, next, -107); - // FALLTHRU + FALLTHROUGH_INTENDED; case 106: CRCtriplet(crc, next, -106); - // FALLTHRU + FALLTHROUGH_INTENDED; case 105: CRCtriplet(crc, next, -105); - // FALLTHRU + FALLTHROUGH_INTENDED; case 104: CRCtriplet(crc, next, -104); - // FALLTHRU + FALLTHROUGH_INTENDED; case 103: CRCtriplet(crc, next, -103); - // FALLTHRU + FALLTHROUGH_INTENDED; case 102: CRCtriplet(crc, next, -102); - // FALLTHRU + FALLTHROUGH_INTENDED; case 101: CRCtriplet(crc, next, -101); - // FALLTHRU + FALLTHROUGH_INTENDED; case 100: CRCtriplet(crc, next, -100); - // FALLTHRU + FALLTHROUGH_INTENDED; case 99: CRCtriplet(crc, next, -99); - // FALLTHRU + FALLTHROUGH_INTENDED; case 98: CRCtriplet(crc, next, -98); - // FALLTHRU + FALLTHROUGH_INTENDED; case 97: CRCtriplet(crc, next, -97); - // FALLTHRU + FALLTHROUGH_INTENDED; case 96: CRCtriplet(crc, next, -96); - // FALLTHRU + FALLTHROUGH_INTENDED; case 95: CRCtriplet(crc, next, -95); - // FALLTHRU + FALLTHROUGH_INTENDED; case 94: CRCtriplet(crc, next, -94); - // FALLTHRU + FALLTHROUGH_INTENDED; case 93: CRCtriplet(crc, next, -93); - // FALLTHRU + FALLTHROUGH_INTENDED; case 92: CRCtriplet(crc, next, -92); - // FALLTHRU + FALLTHROUGH_INTENDED; case 91: CRCtriplet(crc, next, -91); - // FALLTHRU + FALLTHROUGH_INTENDED; case 90: CRCtriplet(crc, next, -90); - // FALLTHRU + FALLTHROUGH_INTENDED; case 89: CRCtriplet(crc, next, -89); - // FALLTHRU + FALLTHROUGH_INTENDED; case 88: CRCtriplet(crc, next, -88); - // FALLTHRU + FALLTHROUGH_INTENDED; case 87: CRCtriplet(crc, next, -87); - // FALLTHRU + FALLTHROUGH_INTENDED; case 86: CRCtriplet(crc, next, -86); - // FALLTHRU + FALLTHROUGH_INTENDED; case 85: CRCtriplet(crc, next, -85); - // FALLTHRU + FALLTHROUGH_INTENDED; case 84: CRCtriplet(crc, next, -84); - // FALLTHRU + FALLTHROUGH_INTENDED; case 83: CRCtriplet(crc, next, -83); - // FALLTHRU + FALLTHROUGH_INTENDED; case 82: CRCtriplet(crc, next, -82); - // FALLTHRU + FALLTHROUGH_INTENDED; case 81: CRCtriplet(crc, next, -81); - // FALLTHRU + FALLTHROUGH_INTENDED; case 80: CRCtriplet(crc, next, -80); - // FALLTHRU + FALLTHROUGH_INTENDED; case 79: CRCtriplet(crc, next, -79); - // FALLTHRU + FALLTHROUGH_INTENDED; case 78: CRCtriplet(crc, next, -78); - // FALLTHRU + FALLTHROUGH_INTENDED; case 77: CRCtriplet(crc, next, -77); - // FALLTHRU + FALLTHROUGH_INTENDED; case 76: CRCtriplet(crc, next, -76); - // FALLTHRU + FALLTHROUGH_INTENDED; case 75: CRCtriplet(crc, next, -75); - // FALLTHRU + FALLTHROUGH_INTENDED; case 74: CRCtriplet(crc, next, -74); - // FALLTHRU + FALLTHROUGH_INTENDED; case 73: CRCtriplet(crc, next, -73); - // FALLTHRU + FALLTHROUGH_INTENDED; case 72: CRCtriplet(crc, next, -72); - // FALLTHRU + FALLTHROUGH_INTENDED; case 71: CRCtriplet(crc, next, -71); - // FALLTHRU + FALLTHROUGH_INTENDED; case 70: CRCtriplet(crc, next, -70); - // FALLTHRU + FALLTHROUGH_INTENDED; case 69: CRCtriplet(crc, next, -69); - // FALLTHRU + FALLTHROUGH_INTENDED; case 68: CRCtriplet(crc, next, -68); - // FALLTHRU + FALLTHROUGH_INTENDED; case 67: CRCtriplet(crc, next, -67); - // FALLTHRU + FALLTHROUGH_INTENDED; case 66: CRCtriplet(crc, next, -66); - // FALLTHRU + FALLTHROUGH_INTENDED; case 65: CRCtriplet(crc, next, -65); - // FALLTHRU + FALLTHROUGH_INTENDED; case 64: CRCtriplet(crc, next, -64); - // FALLTHRU + FALLTHROUGH_INTENDED; case 63: CRCtriplet(crc, next, -63); - // FALLTHRU + FALLTHROUGH_INTENDED; case 62: CRCtriplet(crc, next, -62); - // FALLTHRU + FALLTHROUGH_INTENDED; case 61: CRCtriplet(crc, next, -61); - // FALLTHRU + FALLTHROUGH_INTENDED; case 60: CRCtriplet(crc, next, -60); - // FALLTHRU + FALLTHROUGH_INTENDED; case 59: CRCtriplet(crc, next, -59); - // FALLTHRU + FALLTHROUGH_INTENDED; case 58: CRCtriplet(crc, next, -58); - // FALLTHRU + FALLTHROUGH_INTENDED; case 57: CRCtriplet(crc, next, -57); - // FALLTHRU + FALLTHROUGH_INTENDED; case 56: CRCtriplet(crc, next, -56); - // FALLTHRU + FALLTHROUGH_INTENDED; case 55: CRCtriplet(crc, next, -55); - // FALLTHRU + FALLTHROUGH_INTENDED; case 54: CRCtriplet(crc, next, -54); - // FALLTHRU + FALLTHROUGH_INTENDED; case 53: CRCtriplet(crc, next, -53); - // FALLTHRU + FALLTHROUGH_INTENDED; case 52: CRCtriplet(crc, next, -52); - // FALLTHRU + FALLTHROUGH_INTENDED; case 51: CRCtriplet(crc, next, -51); - // FALLTHRU + FALLTHROUGH_INTENDED; case 50: CRCtriplet(crc, next, -50); - // FALLTHRU + FALLTHROUGH_INTENDED; case 49: CRCtriplet(crc, next, -49); - // FALLTHRU + FALLTHROUGH_INTENDED; case 48: CRCtriplet(crc, next, -48); - // FALLTHRU + FALLTHROUGH_INTENDED; case 47: CRCtriplet(crc, next, -47); - // FALLTHRU + FALLTHROUGH_INTENDED; case 46: CRCtriplet(crc, next, -46); - // FALLTHRU + FALLTHROUGH_INTENDED; case 45: CRCtriplet(crc, next, -45); - // FALLTHRU + FALLTHROUGH_INTENDED; case 44: CRCtriplet(crc, next, -44); - // FALLTHRU + FALLTHROUGH_INTENDED; case 43: CRCtriplet(crc, next, -43); - // FALLTHRU + FALLTHROUGH_INTENDED; case 42: CRCtriplet(crc, next, -42); - // FALLTHRU + FALLTHROUGH_INTENDED; case 41: CRCtriplet(crc, next, -41); - // FALLTHRU + FALLTHROUGH_INTENDED; case 40: CRCtriplet(crc, next, -40); - // FALLTHRU + FALLTHROUGH_INTENDED; case 39: CRCtriplet(crc, next, -39); - // FALLTHRU + FALLTHROUGH_INTENDED; case 38: CRCtriplet(crc, next, -38); - // FALLTHRU + FALLTHROUGH_INTENDED; case 37: CRCtriplet(crc, next, -37); - // FALLTHRU + FALLTHROUGH_INTENDED; case 36: CRCtriplet(crc, next, -36); - // FALLTHRU + FALLTHROUGH_INTENDED; case 35: CRCtriplet(crc, next, -35); - // FALLTHRU + FALLTHROUGH_INTENDED; case 34: CRCtriplet(crc, next, -34); - // FALLTHRU + FALLTHROUGH_INTENDED; case 33: CRCtriplet(crc, next, -33); - // FALLTHRU + FALLTHROUGH_INTENDED; case 32: CRCtriplet(crc, next, -32); - // FALLTHRU + FALLTHROUGH_INTENDED; case 31: CRCtriplet(crc, next, -31); - // FALLTHRU + FALLTHROUGH_INTENDED; case 30: CRCtriplet(crc, next, -30); - // FALLTHRU + FALLTHROUGH_INTENDED; case 29: CRCtriplet(crc, next, -29); - // FALLTHRU + FALLTHROUGH_INTENDED; case 28: CRCtriplet(crc, next, -28); - // FALLTHRU + FALLTHROUGH_INTENDED; case 27: CRCtriplet(crc, next, -27); - // FALLTHRU + FALLTHROUGH_INTENDED; case 26: CRCtriplet(crc, next, -26); - // FALLTHRU + FALLTHROUGH_INTENDED; case 25: CRCtriplet(crc, next, -25); - // FALLTHRU + FALLTHROUGH_INTENDED; case 24: CRCtriplet(crc, next, -24); - // FALLTHRU + FALLTHROUGH_INTENDED; case 23: CRCtriplet(crc, next, -23); - // FALLTHRU + FALLTHROUGH_INTENDED; case 22: CRCtriplet(crc, next, -22); - // FALLTHRU + FALLTHROUGH_INTENDED; case 21: CRCtriplet(crc, next, -21); - // FALLTHRU + FALLTHROUGH_INTENDED; case 20: CRCtriplet(crc, next, -20); - // FALLTHRU + FALLTHROUGH_INTENDED; case 19: CRCtriplet(crc, next, -19); - // FALLTHRU + FALLTHROUGH_INTENDED; case 18: CRCtriplet(crc, next, -18); - // FALLTHRU + FALLTHROUGH_INTENDED; case 17: CRCtriplet(crc, next, -17); - // FALLTHRU + FALLTHROUGH_INTENDED; case 16: CRCtriplet(crc, next, -16); - // FALLTHRU + FALLTHROUGH_INTENDED; case 15: CRCtriplet(crc, next, -15); - // FALLTHRU + FALLTHROUGH_INTENDED; case 14: CRCtriplet(crc, next, -14); - // FALLTHRU + FALLTHROUGH_INTENDED; case 13: CRCtriplet(crc, next, -13); - // FALLTHRU + FALLTHROUGH_INTENDED; case 12: CRCtriplet(crc, next, -12); - // FALLTHRU + FALLTHROUGH_INTENDED; case 11: CRCtriplet(crc, next, -11); - // FALLTHRU + FALLTHROUGH_INTENDED; case 10: CRCtriplet(crc, next, -10); - // FALLTHRU + FALLTHROUGH_INTENDED; case 9: CRCtriplet(crc, next, -9); - // FALLTHRU + FALLTHROUGH_INTENDED; case 8: CRCtriplet(crc, next, -8); - // FALLTHRU + FALLTHROUGH_INTENDED; case 7: CRCtriplet(crc, next, -7); - // FALLTHRU + FALLTHROUGH_INTENDED; case 6: CRCtriplet(crc, next, -6); - // FALLTHRU + FALLTHROUGH_INTENDED; case 5: CRCtriplet(crc, next, -5); - // FALLTHRU + FALLTHROUGH_INTENDED; case 4: CRCtriplet(crc, next, -4); - // FALLTHRU + FALLTHROUGH_INTENDED; case 3: CRCtriplet(crc, next, -3); - // FALLTHRU + FALLTHROUGH_INTENDED; case 2: CRCtriplet(crc, next, -2); - // FALLTHRU + FALLTHROUGH_INTENDED; case 1: CRCduplet(crc, next, -1); // the final triplet is actually only 2 //{ CombineCRC(); } @@ -1096,7 +1097,7 @@ uint32_t crc32c_3way(uint32_t crc, const char* buf, size_t len) { next1 = next0 + 128; // from here on all blocks are 128 long next2 = next1 + 128; } - // FALLTHRU + FALLTHROUGH_INTENDED; case 0:; } while (n > 0); } @@ -1108,85 +1109,85 @@ uint32_t crc32c_3way(uint32_t crc, const char* buf, size_t len) { switch (count2) { case 27: CRCsinglet(crc0, next, -27 * 8); - // FALLTHRU + FALLTHROUGH_INTENDED; case 26: CRCsinglet(crc0, next, -26 * 8); - // FALLTHRU + FALLTHROUGH_INTENDED; case 25: CRCsinglet(crc0, next, -25 * 8); - // FALLTHRU + FALLTHROUGH_INTENDED; case 24: CRCsinglet(crc0, next, -24 * 8); - // FALLTHRU + FALLTHROUGH_INTENDED; case 23: CRCsinglet(crc0, next, -23 * 8); - // FALLTHRU + FALLTHROUGH_INTENDED; case 22: CRCsinglet(crc0, next, -22 * 8); - // FALLTHRU + FALLTHROUGH_INTENDED; case 21: CRCsinglet(crc0, next, -21 * 8); - // FALLTHRU + FALLTHROUGH_INTENDED; case 20: CRCsinglet(crc0, next, -20 * 8); - // FALLTHRU + FALLTHROUGH_INTENDED; case 19: CRCsinglet(crc0, next, -19 * 8); - // FALLTHRU + FALLTHROUGH_INTENDED; case 18: CRCsinglet(crc0, next, -18 * 8); - // FALLTHRU + FALLTHROUGH_INTENDED; case 17: CRCsinglet(crc0, next, -17 * 8); - // FALLTHRU + FALLTHROUGH_INTENDED; case 16: CRCsinglet(crc0, next, -16 * 8); - // FALLTHRU + FALLTHROUGH_INTENDED; case 15: CRCsinglet(crc0, next, -15 * 8); - // FALLTHRU + FALLTHROUGH_INTENDED; case 14: CRCsinglet(crc0, next, -14 * 8); - // FALLTHRU + FALLTHROUGH_INTENDED; case 13: CRCsinglet(crc0, next, -13 * 8); - // FALLTHRU + FALLTHROUGH_INTENDED; case 12: CRCsinglet(crc0, next, -12 * 8); - // FALLTHRU + FALLTHROUGH_INTENDED; case 11: CRCsinglet(crc0, next, -11 * 8); - // FALLTHRU + FALLTHROUGH_INTENDED; case 10: CRCsinglet(crc0, next, -10 * 8); - // FALLTHRU + FALLTHROUGH_INTENDED; case 9: CRCsinglet(crc0, next, -9 * 8); - // FALLTHRU + FALLTHROUGH_INTENDED; case 8: CRCsinglet(crc0, next, -8 * 8); - // FALLTHRU + FALLTHROUGH_INTENDED; case 7: CRCsinglet(crc0, next, -7 * 8); - // FALLTHRU + FALLTHROUGH_INTENDED; case 6: CRCsinglet(crc0, next, -6 * 8); - // FALLTHRU + FALLTHROUGH_INTENDED; case 5: CRCsinglet(crc0, next, -5 * 8); - // FALLTHRU + FALLTHROUGH_INTENDED; case 4: CRCsinglet(crc0, next, -4 * 8); - // FALLTHRU + FALLTHROUGH_INTENDED; case 3: CRCsinglet(crc0, next, -3 * 8); - // FALLTHRU + FALLTHROUGH_INTENDED; case 2: CRCsinglet(crc0, next, -2 * 8); - // FALLTHRU + FALLTHROUGH_INTENDED; case 1: CRCsinglet(crc0, next, -1 * 8); - // FALLTHRU + FALLTHROUGH_INTENDED; case 0:; } } diff --git a/util/hash.cc b/util/hash.cc index a0660c60a..852710d73 100644 --- a/util/hash.cc +++ b/util/hash.cc @@ -10,6 +10,7 @@ #include #include "util/coding.h" #include "util/hash.h" +#include "util/util.h" namespace rocksdb { @@ -40,10 +41,10 @@ uint32_t Hash(const char* data, size_t n, uint32_t seed) { // are unsigned we first cast the char to int8_t. case 3: h += static_cast(static_cast(data[2])) << 16; - // fall through + FALLTHROUGH_INTENDED; case 2: h += static_cast(static_cast(data[1])) << 8; - // fall through + FALLTHROUGH_INTENDED; case 1: h += static_cast(static_cast(data[0])); h *= m; diff --git a/util/murmurhash.cc b/util/murmurhash.cc index 8491a83bf..3b759c5e6 100644 --- a/util/murmurhash.cc +++ b/util/murmurhash.cc @@ -10,6 +10,7 @@ is under the MIT license. */ #include "murmurhash.h" +#include "util/util.h" #if defined(__x86_64__) @@ -53,12 +54,12 @@ uint64_t MurmurHash64A ( const void * key, int len, unsigned int seed ) switch(len & 7) { - case 7: h ^= ((uint64_t)data2[6]) << 48; // fallthrough - case 6: h ^= ((uint64_t)data2[5]) << 40; // fallthrough - case 5: h ^= ((uint64_t)data2[4]) << 32; // fallthrough - case 4: h ^= ((uint64_t)data2[3]) << 24; // fallthrough - case 3: h ^= ((uint64_t)data2[2]) << 16; // fallthrough - case 2: h ^= ((uint64_t)data2[1]) << 8; // fallthrough + case 7: h ^= ((uint64_t)data2[6]) << 48; FALLTHROUGH_INTENDED; + case 6: h ^= ((uint64_t)data2[5]) << 40; FALLTHROUGH_INTENDED; + case 5: h ^= ((uint64_t)data2[4]) << 32; FALLTHROUGH_INTENDED; + case 4: h ^= ((uint64_t)data2[3]) << 24; FALLTHROUGH_INTENDED; + case 3: h ^= ((uint64_t)data2[2]) << 16; FALLTHROUGH_INTENDED; + case 2: h ^= ((uint64_t)data2[1]) << 8; FALLTHROUGH_INTENDED; case 1: h ^= ((uint64_t)data2[0]); h *= m; }; @@ -120,8 +121,8 @@ unsigned int MurmurHash2 ( const void * key, int len, unsigned int seed ) switch(len) { - case 3: h ^= data[2] << 16; // fallthrough - case 2: h ^= data[1] << 8; // fallthrough + case 3: h ^= data[2] << 16; FALLTHROUGH_INTENDED; + case 2: h ^= data[1] << 8; FALLTHROUGH_INTENDED; case 1: h ^= data[0]; h *= m; }; @@ -174,8 +175,8 @@ unsigned int MurmurHashNeutral2 ( const void * key, int len, unsigned int seed ) switch(len) { - case 3: h ^= data[2] << 16; // fallthrough - case 2: h ^= data[1] << 8; // fallthrough + case 3: h ^= data[2] << 16; FALLTHROUGH_INTENDED; + case 2: h ^= data[1] << 8; FALLTHROUGH_INTENDED; case 1: h ^= data[0]; h *= m; }; diff --git a/util/status.cc b/util/status.cc index aaad67367..f3f03d24e 100644 --- a/util/status.cc +++ b/util/status.cc @@ -10,17 +10,14 @@ #include "rocksdb/status.h" #include #include -#include #include "port/port.h" namespace rocksdb { const char* Status::CopyState(const char* state) { -#ifdef OS_WIN - return _strdup(state); -#else - return strdup(state); -#endif + const size_t cch = + std::strlen(state) + 1; // +1 for the null terminator + return std::strncpy(new char[cch], state, cch); } Status::Status(Code _code, SubCode _subcode, const Slice& msg, const Slice& msg2) @@ -30,7 +27,7 @@ Status::Status(Code _code, SubCode _subcode, const Slice& msg, const Slice& msg2 const size_t len1 = msg.size(); const size_t len2 = msg2.size(); const size_t size = len1 + (len2 ? (2 + len2) : 0); - char* const result = (char*) malloc(size + 1); // +1 for null terminator + char* const result = new char[size + 1]; // +1 for null terminator memcpy(result, msg.data(), len1); if (len2) { result[len1] = ':'; diff --git a/util/util.h b/util/util.h new file mode 100644 index 000000000..a5fd36490 --- /dev/null +++ b/util/util.h @@ -0,0 +1,16 @@ +// Copyright (c) 2011-present, Facebook, Inc. All rights reserved. +// This source code is licensed under both the GPLv2 (found in the +// COPYING file in the root directory) and Apache 2.0 License +// (found in the LICENSE.Apache file in the root directory). + +#pragma once + +#ifndef FALLTHROUGH_INTENDED +#if defined(__clang__) +#define FALLTHROUGH_INTENDED [[clang::fallthrough]] +#elif defined(__GNUC__) && __GNUC__ >= 7 +#define FALLTHROUGH_INTENDED [[gnu::fallthrough]] +#else +#define FALLTHROUGH_INTENDED do {} while (0) +#endif +#endif