From 70b5fa948d920ccca86d143057497132f63a44f3 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Mon, 26 Mar 2018 15:15:40 -0700 Subject: Changes imported from Abseil "staging" branch: - f2c4c517f14afa7a3fac6b35588381462f02dec3 Rollback release of algorithm benchmark. by Alex Strelnikov - ec8a9569ac36d58a4fff2f9fc851e5a9474d274a Change AllocInspector to ConstructorTracker by Jon Cohen - 6f94f3d65a29b11c692948d23c0fc530f015cd53 Update WORKSPACE for C++ microbenchmarks and release algo... by Alex Strelnikov - 79187dd7cec821e47cdd751db71bb23be2b8cef7 Define copy assignment operator for ThrowingAllocator. by Xiaoyi Zhang - 8bf5e1048dd7788f4bce60376f5c3992f8525d88 Fix incorrect format string used in str_cat_test.cc code,... by Jorg Brown - 19c51194e6638f05cbb364c6684f14dc7ed1a323 Fix symbolize_test under sanitizers. by Derek Mauro - d68119cfb845a9d460fc3fd4aae1d2ea7d79ee21 Internal change. by Derek Mauro - 4ca54d336c7a18050c95c6c1a859f2a0530e1cde Internal change. by Shaindel Schwartz GitOrigin-RevId: f2c4c517f14afa7a3fac6b35588381462f02dec3 Change-Id: If61a65d65f03b26d6776710040780ddd1c52c4de --- absl/base/exception_safety_testing_test.cc | 23 ++++++++++------ absl/base/internal/exception_safety_testing.h | 21 ++++++++++----- absl/debugging/BUILD.bazel | 1 - absl/debugging/symbolize_test.cc | 16 +++++------ absl/strings/str_cat_test.cc | 2 +- absl/time/time.h | 38 +++++++++++++++------------ absl/types/any_exception_safety_test.cc | 2 +- 7 files changed, 59 insertions(+), 44 deletions(-) diff --git a/absl/base/exception_safety_testing_test.cc b/absl/base/exception_safety_testing_test.cc index f8baf20c9360..9c52f249ee16 100644 --- a/absl/base/exception_safety_testing_test.cc +++ b/absl/base/exception_safety_testing_test.cc @@ -44,7 +44,7 @@ class ThrowingValueTest : public ::testing::Test { void SetUp() override { UnsetCountdown(); } private: - AllocInspector clouseau_; + ConstructorTracker clouseau_; }; TEST_F(ThrowingValueTest, Throws) { @@ -279,7 +279,7 @@ class ThrowingAllocatorTest : public ::testing::Test { void SetUp() override { UnsetCountdown(); } private: - AllocInspector borlu_; + ConstructorTracker borlu_; }; TEST_F(ThrowingAllocatorTest, MemoryManagement) { @@ -652,22 +652,22 @@ struct Tracked : private exceptions_internal::TrackedObject { Tracked() : TrackedObject(ABSL_PRETTY_FUNCTION) {} }; -TEST(AllocInspectorTest, Pass) { - AllocInspector javert; +TEST(ConstructorTrackerTest, Pass) { + ConstructorTracker javert; Tracked t; } -TEST(AllocInspectorTest, NotDestroyed) { +TEST(ConstructorTrackerTest, NotDestroyed) { absl::aligned_storage_t storage; EXPECT_NONFATAL_FAILURE( { - AllocInspector gadget; + ConstructorTracker gadget; new (&storage) Tracked; }, "not destroyed"); } -TEST(AllocInspectorTest, DestroyedTwice) { +TEST(ConstructorTrackerTest, DestroyedTwice) { EXPECT_NONFATAL_FAILURE( { Tracked t; @@ -676,7 +676,7 @@ TEST(AllocInspectorTest, DestroyedTwice) { "destroyed improperly"); } -TEST(AllocInspectorTest, ConstructedTwice) { +TEST(ConstructorTrackerTest, ConstructedTwice) { absl::aligned_storage_t storage; EXPECT_NONFATAL_FAILURE( { @@ -697,5 +697,12 @@ TEST(ThrowingValueTraitsTest, RelationalOperators) { EXPECT_TRUE((std::is_convertible= b), bool>::value)); } +TEST(ThrowingAllocatorTraitsTest, Assignablility) { + EXPECT_TRUE(std::is_move_assignable>::value); + EXPECT_TRUE(std::is_copy_assignable>::value); + EXPECT_TRUE(std::is_nothrow_move_assignable>::value); + EXPECT_TRUE(std::is_nothrow_copy_assignable>::value); +} + } // namespace } // namespace absl diff --git a/absl/base/internal/exception_safety_testing.h b/absl/base/internal/exception_safety_testing.h index adee848b2e90..a0cd33b4d00a 100644 --- a/absl/base/internal/exception_safety_testing.h +++ b/absl/base/internal/exception_safety_testing.h @@ -37,7 +37,7 @@ namespace absl { struct InternalAbslNamespaceFinder {}; -struct AllocInspector; +struct ConstructorTracker; // A configuration enum for Throwing*. Operations whose flags are set will // throw, everything else won't. This isn't meant to be exhaustive, more flags @@ -125,7 +125,7 @@ class TrackedObject { } } - friend struct ::absl::AllocInspector; + friend struct ::absl::ConstructorTracker; }; template @@ -594,6 +594,8 @@ class ThrowingAllocator : private exceptions_internal::TrackedObject { const ThrowingAllocator& other) noexcept : TrackedObject(ABSL_PRETTY_FUNCTION), dummy_(other.State()) {} + // According to C++11 standard [17.6.3.5], Table 28, the move/copy ctors of + // allocator shall not exit via an exception, thus they are marked noexcept. ThrowingAllocator(const ThrowingAllocator& other) noexcept : TrackedObject(ABSL_PRETTY_FUNCTION), dummy_(other.State()) {} @@ -607,6 +609,11 @@ class ThrowingAllocator : private exceptions_internal::TrackedObject { ~ThrowingAllocator() noexcept = default; + ThrowingAllocator& operator=(const ThrowingAllocator& other) noexcept { + dummy_ = other.State(); + return *this; + } + template ThrowingAllocator& operator=( const ThrowingAllocator& other) noexcept { @@ -704,11 +711,11 @@ int ThrowingAllocator::next_id_ = 0; // Inspects the constructions and destructions of anything inheriting from // TrackedObject. Place this as a member variable in a test fixture to ensure // that every ThrowingValue was constructed and destroyed correctly. This also -// allows us to safely "leak" TrackedObjects, as AllocInspector will destroy +// allows us to safely "leak" TrackedObjects, as ConstructorTracker will destroy // everything left over in its destructor. -struct AllocInspector { - AllocInspector() = default; - ~AllocInspector() { +struct ConstructorTracker { + ConstructorTracker() = default; + ~ConstructorTracker() { auto& allocs = exceptions_internal::TrackedObject::GetAllocs(); for (const auto& kv : allocs) { ADD_FAILURE() << "Object at address " << static_cast(kv.first) @@ -720,7 +727,7 @@ struct AllocInspector { // Tests for resource leaks by attempting to construct a T using args repeatedly // until successful, using the countdown method. Side effects can then be -// tested for resource leaks. If an AllocInspector is present in the test +// tested for resource leaks. If a ConstructorTracker is present in the test // fixture, then this will also test that memory resources are not leaked as // long as T allocates TrackedObjects. template diff --git a/absl/debugging/BUILD.bazel b/absl/debugging/BUILD.bazel index d62a781dc66e..f6859093ddc7 100644 --- a/absl/debugging/BUILD.bazel +++ b/absl/debugging/BUILD.bazel @@ -70,7 +70,6 @@ cc_test( ":symbolize", "//absl/base", "//absl/base:core_headers", - "//absl/base:malloc_extension", "//absl/memory", "@com_google_googletest//:gtest", ], diff --git a/absl/debugging/symbolize_test.cc b/absl/debugging/symbolize_test.cc index 8b28e5c53951..b23a8011990b 100644 --- a/absl/debugging/symbolize_test.cc +++ b/absl/debugging/symbolize_test.cc @@ -27,7 +27,6 @@ #include "gtest/gtest.h" #include "absl/base/attributes.h" #include "absl/base/casts.h" -#include "absl/base/internal/malloc_extension.h" #include "absl/base/internal/per_thread_tls.h" #include "absl/base/internal/raw_logging.h" #include "absl/base/optimization.h" @@ -192,14 +191,13 @@ static const char *SymbolizeStackConsumption(void *pc, int *stack_consumed) { static int GetStackConsumptionUpperLimit() { // Symbolize stack consumption should be within 2kB. - const int kStackConsumptionUpperLimit = 2048; - // Account for ASan/TSan instrumentation requiring additional stack space. - size_t multiplier = 0; - if (absl::base_internal::MallocExtension::instance()->GetNumericProperty( - "dynamic_tool.stack_size_multiplier", &multiplier)) { - return kStackConsumptionUpperLimit * multiplier; - } - return kStackConsumptionUpperLimit; + int stack_consumption_upper_limit = 2048; +#if defined(ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER) || \ + defined(THREAD_SANITIZER) + // Account for sanitizer instrumentation requiring additional stack space. + stack_consumption_upper_limit *= 5; +#endif + return stack_consumption_upper_limit; } TEST(Symbolize, SymbolizeStackConsumption) { diff --git a/absl/strings/str_cat_test.cc b/absl/strings/str_cat_test.cc index c5a3526d7a6a..58ab743ac13b 100644 --- a/absl/strings/str_cat_test.cc +++ b/absl/strings/str_cat_test.cc @@ -486,7 +486,7 @@ void CheckHexDec32(uint32_t uv) { if (sizeof(v) == sizeof(&v)) { auto uintptr = static_cast(v); void* ptr = reinterpret_cast(uintptr); - CheckHex(ptr, "%llx", "%0*llx", "%*llx"); + CheckHex(ptr, "%x", "%0*x", "%*x"); } } diff --git a/absl/time/time.h b/absl/time/time.h index 2cbe94376f09..daf0b1559f58 100644 --- a/absl/time/time.h +++ b/absl/time/time.h @@ -854,7 +854,7 @@ Time FromChrono(const std::chrono::system_clock::time_point& tp); // absl::Time t = absl::FromTimeT(123); // auto tp = absl::ToChronoTime(t); // // tp == std::chrono::system_clock::from_time_t(123); -std::chrono::system_clock::time_point ToChronoTime(absl::Time); +std::chrono::system_clock::time_point ToChronoTime(Time); // RFC3339_full // RFC3339_sec @@ -1070,13 +1070,16 @@ inline bool LoadTimeZone(const std::string& name, TimeZone* tz) { // Note: If the absolute value of the offset is greater than 24 hours // you'll get UTC (i.e., no offset) instead. inline TimeZone FixedTimeZone(int seconds) { - return TimeZone(cctz::fixed_time_zone(std::chrono::seconds(seconds))); + return TimeZone( + cctz::fixed_time_zone(std::chrono::seconds(seconds))); } // UTCTimeZone() // // Convenience method returning the UTC time zone. -inline TimeZone UTCTimeZone() { return TimeZone(cctz::utc_time_zone()); } +inline TimeZone UTCTimeZone() { + return TimeZone(cctz::utc_time_zone()); +} // LocalTimeZone() // @@ -1084,7 +1087,9 @@ inline TimeZone UTCTimeZone() { return TimeZone(cctz::utc_time_zone()); } // no configured local zone. Warning: Be wary of using LocalTimeZone(), // and particularly so in a server process, as the zone configured for the // local machine should be irrelevant. Prefer an explicit zone name. -inline TimeZone LocalTimeZone() { return TimeZone(cctz::local_time_zone()); } +inline TimeZone LocalTimeZone() { + return TimeZone(cctz::local_time_zone()); +} // ============================================================================ // Implementation Details Follow @@ -1139,16 +1144,16 @@ constexpr Time FromUnixDuration(Duration d) { return Time(d); } constexpr Duration ToUnixDuration(Time t) { return t.rep_; } template -constexpr absl::Duration FromInt64(int64_t v, std::ratio<1, N>) { +constexpr Duration FromInt64(int64_t v, std::ratio<1, N>) { static_assert(0 < N && N <= 1000 * 1000 * 1000, "Unsupported ratio"); // Subsecond ratios cannot overflow. return MakeNormalizedDuration( v / N, v % N * kTicksPerNanosecond * 1000 * 1000 * 1000 / N); } -constexpr absl::Duration FromInt64(int64_t v, std::ratio<60>) { +constexpr Duration FromInt64(int64_t v, std::ratio<60>) { return Minutes(v); } -constexpr absl::Duration FromInt64(int64_t v, std::ratio<3600>) { +constexpr Duration FromInt64(int64_t v, std::ratio<3600>) { return Hours(v); } @@ -1166,41 +1171,40 @@ constexpr auto IsValidRep64(char) -> bool { // Converts a std::chrono::duration to an absl::Duration. template -constexpr absl::Duration FromChrono( - const std::chrono::duration& d) { +constexpr Duration FromChrono(const std::chrono::duration& d) { static_assert(IsValidRep64(0), "duration::rep is invalid"); return FromInt64(int64_t{d.count()}, Period{}); } template -int64_t ToInt64(absl::Duration d, Ratio) { +int64_t ToInt64(Duration d, Ratio) { // Note: This may be used on MSVC, which may have a system_clock period of // std::ratio<1, 10 * 1000 * 1000> return ToInt64Seconds(d * Ratio::den / Ratio::num); } // Fastpath implementations for the 6 common duration units. -inline int64_t ToInt64(absl::Duration d, std::nano) { +inline int64_t ToInt64(Duration d, std::nano) { return ToInt64Nanoseconds(d); } -inline int64_t ToInt64(absl::Duration d, std::micro) { +inline int64_t ToInt64(Duration d, std::micro) { return ToInt64Microseconds(d); } -inline int64_t ToInt64(absl::Duration d, std::milli) { +inline int64_t ToInt64(Duration d, std::milli) { return ToInt64Milliseconds(d); } -inline int64_t ToInt64(absl::Duration d, std::ratio<1>) { +inline int64_t ToInt64(Duration d, std::ratio<1>) { return ToInt64Seconds(d); } -inline int64_t ToInt64(absl::Duration d, std::ratio<60>) { +inline int64_t ToInt64(Duration d, std::ratio<60>) { return ToInt64Minutes(d); } -inline int64_t ToInt64(absl::Duration d, std::ratio<3600>) { +inline int64_t ToInt64(Duration d, std::ratio<3600>) { return ToInt64Hours(d); } // Converts an absl::Duration to a chrono duration of type T. template -T ToChronoDuration(absl::Duration d) { +T ToChronoDuration(Duration d) { using Rep = typename T::rep; using Period = typename T::period; static_assert(IsValidRep64(0), "duration::rep is invalid"); diff --git a/absl/types/any_exception_safety_test.cc b/absl/types/any_exception_safety_test.cc index eadba3080437..f4ca52eba3b0 100644 --- a/absl/types/any_exception_safety_test.cc +++ b/absl/types/any_exception_safety_test.cc @@ -75,7 +75,7 @@ namespace { class AnyExceptionSafety : public ::testing::Test { private: - absl::AllocInspector inspector_; + absl::ConstructorTracker inspector_; }; testing::AssertionResult AnyIsEmpty(absl::any* a) { -- cgit 1.4.1