diff options
Diffstat (limited to 'absl/random')
-rw-r--r-- | absl/random/CMakeLists.txt | 3 | ||||
-rw-r--r-- | absl/random/internal/BUILD.bazel | 7 | ||||
-rw-r--r-- | absl/random/internal/explicit_seed_seq.h | 3 | ||||
-rw-r--r-- | absl/random/internal/randen_engine.h | 8 | ||||
-rw-r--r-- | absl/random/internal/randen_slow_test.cc | 3 |
5 files changed, 18 insertions, 6 deletions
diff --git a/absl/random/CMakeLists.txt b/absl/random/CMakeLists.txt index 7d7bec83..13093d6d 100644 --- a/absl/random/CMakeLists.txt +++ b/absl/random/CMakeLists.txt @@ -611,6 +611,7 @@ absl_cc_library( ${ABSL_DEFAULT_LINKOPTS} DEPS absl::config + absl::endian TESTONLY ) @@ -758,6 +759,7 @@ absl_cc_library( LINKOPTS ${ABSL_DEFAULT_LINKOPTS} DEPS + absl::endian absl::random_internal_iostream_state_saver absl::random_internal_randen absl::raw_logging_internal @@ -1119,6 +1121,7 @@ absl_cc_test( LINKOPTS ${ABSL_DEFAULT_LINKOPTS} DEPS + absl::endian absl::random_internal_randen_slow gtest_main ) diff --git a/absl/random/internal/BUILD.bazel b/absl/random/internal/BUILD.bazel index 2c1a5f4a..4e778aee 100644 --- a/absl/random/internal/BUILD.bazel +++ b/absl/random/internal/BUILD.bazel @@ -124,7 +124,10 @@ cc_library( ], copts = ABSL_DEFAULT_COPTS, linkopts = ABSL_DEFAULT_LINKOPTS, - deps = ["//absl/base:config"], + deps = [ + "//absl/base:config", + "//absl/base:endian", + ], ) cc_library( @@ -242,6 +245,7 @@ cc_library( deps = [ ":iostream_state_saver", ":randen", + "//absl/base:endian", "//absl/meta:type_traits", ], ) @@ -606,6 +610,7 @@ cc_test( deps = [ ":platform", ":randen_slow", + "//absl/base:endian", "@com_google_googletest//:gtest_main", ], ) diff --git a/absl/random/internal/explicit_seed_seq.h b/absl/random/internal/explicit_seed_seq.h index 6a743eaf..e3aa31a1 100644 --- a/absl/random/internal/explicit_seed_seq.h +++ b/absl/random/internal/explicit_seed_seq.h @@ -23,6 +23,7 @@ #include <vector> #include "absl/base/config.h" +#include "absl/base/internal/endian.h" namespace absl { ABSL_NAMESPACE_BEGIN @@ -73,7 +74,7 @@ class ExplicitSeedSeq { template <typename OutIterator> void generate(OutIterator begin, OutIterator end) { for (size_t index = 0; begin != end; begin++) { - *begin = state_.empty() ? 0 : state_[index++]; + *begin = state_.empty() ? 0 : little_endian::FromHost32(state_[index++]); if (index >= state_.size()) { index = 0; } diff --git a/absl/random/internal/randen_engine.h b/absl/random/internal/randen_engine.h index 6b337313..92bb8905 100644 --- a/absl/random/internal/randen_engine.h +++ b/absl/random/internal/randen_engine.h @@ -23,6 +23,7 @@ #include <limits> #include <type_traits> +#include "absl/base/internal/endian.h" #include "absl/meta/type_traits.h" #include "absl/random/internal/iostream_state_saver.h" #include "absl/random/internal/randen.h" @@ -76,7 +77,7 @@ class alignas(16) randen_engine { impl_.Generate(state_); } - return state_[next_++]; + return little_endian::ToHost(state_[next_++]); } template <class SeedSequence> @@ -181,7 +182,8 @@ class alignas(16) randen_engine { // In the case that `elem` is `uint8_t`, it must be cast to something // larger so that it prints as an integer rather than a character. For // simplicity, apply the cast all circumstances. - os << static_cast<numeric_type>(elem) << os.fill(); + os << static_cast<numeric_type>(little_endian::FromHost(elem)) + << os.fill(); } os << engine.next_; return os; @@ -200,7 +202,7 @@ class alignas(16) randen_engine { // necessary to read a wider type and then cast it to uint8_t. numeric_type value; is >> value; - elem = static_cast<result_type>(value); + elem = little_endian::ToHost(static_cast<result_type>(value)); } is >> next; if (is.fail()) { diff --git a/absl/random/internal/randen_slow_test.cc b/absl/random/internal/randen_slow_test.cc index 4a535837..4861ffa4 100644 --- a/absl/random/internal/randen_slow_test.cc +++ b/absl/random/internal/randen_slow_test.cc @@ -17,6 +17,7 @@ #include <cstring> #include "gtest/gtest.h" +#include "absl/base/internal/endian.h" #include "absl/random/internal/randen_traits.h" namespace { @@ -56,7 +57,7 @@ TEST(RandenSlowTest, Default) { uint64_t* id = d.state; for (const auto& elem : kGolden) { - EXPECT_EQ(elem, *id++); + EXPECT_EQ(absl::little_endian::FromHost64(elem), *id++); } } |