This is an automated email from the ASF dual-hosted git repository. plat1ko pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push: new 5aab04bbf51 [chore](cloud) Use c++20 and unleash endian check (#34735) 5aab04bbf51 is described below commit 5aab04bbf51e6878a5a9e5b2d11533b8ef453b19 Author: Gavin Chou <gavineaglec...@gmail.com> AuthorDate: Sat May 25 13:36:57 2024 +0800 [chore](cloud) Use c++20 and unleash endian check (#34735) Use c++20 and unleash endian check to prevent misuse. --- cloud/CMakeLists.txt | 2 +- cloud/src/meta-service/doris_txn.cpp | 5 ++++- cloud/src/meta-service/txn_kv.cpp | 8 ++++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/cloud/CMakeLists.txt b/cloud/CMakeLists.txt index 9b9929ae1d5..22469ef4d37 100644 --- a/cloud/CMakeLists.txt +++ b/cloud/CMakeLists.txt @@ -137,7 +137,7 @@ check_function_exists(sched_getcpu HAVE_SCHED_GETCPU) # -fno-omit-frame-pointers: Keep frame pointer for functions in register set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Wall -Wno-sign-compare -pthread -Werror") set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -fstrict-aliasing -fno-omit-frame-pointer") -set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -std=gnu++17 -D__STDC_FORMAT_MACROS") +set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -std=gnu++20 -D__STDC_FORMAT_MACROS") set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -DBOOST_DATE_TIME_POSIX_TIME_STD_CONFIG") set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -DBOOST_SYSTEM_NO_DEPRECATED") # Enable the cpu and heap profile of brpc diff --git a/cloud/src/meta-service/doris_txn.cpp b/cloud/src/meta-service/doris_txn.cpp index 7c185bbeb4a..eb01dd4d874 100644 --- a/cloud/src/meta-service/doris_txn.cpp +++ b/cloud/src/meta-service/doris_txn.cpp @@ -17,6 +17,8 @@ #include "doris_txn.h" +#include <bit> + namespace doris::cloud { int get_txn_id_from_fdb_ts(std::string_view fdb_vts, int64_t* txn_id) { @@ -29,7 +31,8 @@ int get_txn_id_from_fdb_ts(std::string_view fdb_vts, int64_t* txn_id) { // byte addr 0 1 2 3 4 5 6 7 8 9 int64_t ver = *reinterpret_cast<const int64_t*>(fdb_vts.data()); - // static_assert(std::endian::little); // Since c++20 + // TODO(gavin): implementation for big-endian or make it endian-independent + static_assert(std::endian::native == std::endian::little); // Since c++20 // Convert big endian to little endian static auto to_little = [](int64_t v) { v = ((v & 0xffffffff00000000) >> 32) | ((v & 0x00000000ffffffff) << 32); diff --git a/cloud/src/meta-service/txn_kv.cpp b/cloud/src/meta-service/txn_kv.cpp index 4c732892be1..ebb63d095f8 100644 --- a/cloud/src/meta-service/txn_kv.cpp +++ b/cloud/src/meta-service/txn_kv.cpp @@ -19,11 +19,11 @@ #include <bthread/countdown_event.h> #include <byteswap.h> -#include <endian.h> #include <foundationdb/fdb_c_types.h> #include <algorithm> #include <atomic> +#include <bit> #include <cstring> #include <memory> #include <optional> @@ -420,9 +420,9 @@ bool Transaction::decode_atomic_int(std::string_view data, int64_t* val) { // ATTN: The FDB_MUTATION_TYPE_ADD stores integers in a little-endian representation. std::memcpy(val, data.data(), sizeof(*val)); -#if __BYTE_ORDER == __BIG_ENDIAN - *val = bswap_64(*val); -#endif + if constexpr (std::endian::native == std::endian::big) { + *val = bswap_64(*val); + } return true; } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org