about summary refs log tree commit diff
path: root/absl
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2019-08-08T17·56-0700
committerCJ Johnson <johnsoncj@google.com>2019-08-08T18·07-0400
commit9ee91d3e430fb33a4590486573792eb0fa146c2d (patch)
treee71e204df2efe0845c853013e4e3748e721fa91b /absl
parent8efba58a3b656e9b41fb0471ae6453425a61c520 (diff)
Export of internal Abseil changes
--
f51743aa96e19aa3dda96d09d313b4390f1d61e7 by CJ Johnson <johnsoncj@google.com>:

Minor touchup on the InlinedVector/Storage internal header file

PiperOrigin-RevId: 262389640

--
e2f54c1f7142e40d30ff0fda43bef050625821a5 by Abseil Team <absl-team@google.com>:

Update the absl codebase to use proper marketing names for macOS and Xcode

PiperOrigin-RevId: 262389450

--
f29aae774edd0d00e2daa1fb96694a6dc3565a55 by CJ Johnson <johnsoncj@google.com>:

Blocks code generator script from being affected by LTS inline namespaces

PiperOrigin-RevId: 262376791
GitOrigin-RevId: f51743aa96e19aa3dda96d09d313b4390f1d61e7
Change-Id: I33be7f5a708ce8a2b7111b00151e43d73c5e0009
Diffstat (limited to 'absl')
-rw-r--r--absl/base/config.h4
-rw-r--r--absl/base/internal/endian.h2
-rw-r--r--absl/container/internal/inlined_vector.h158
-rw-r--r--absl/debugging/internal/stacktrace_powerpc-inl.inc2
-rw-r--r--absl/random/internal/gaussian_distribution_gentables.cc14
-rw-r--r--absl/random/internal/platform.h2
-rw-r--r--absl/strings/numbers_test.cc2
-rw-r--r--absl/time/format_test.cc2
8 files changed, 105 insertions, 81 deletions
diff --git a/absl/base/config.h b/absl/base/config.h
index 181d840e1488..1c3cb08e746d 100644
--- a/absl/base/config.h
+++ b/absl/base/config.h
@@ -260,7 +260,7 @@
 //   Linux and Linux-derived           __linux__
 //   Android                           __ANDROID__ (implies __linux__)
 //   Linux (non-Android)               __linux__ && !__ANDROID__
-//   Darwin (Mac OS X and iOS)         __APPLE__
+//   Darwin (macOS and iOS)            __APPLE__
 //   Akaros (http://akaros.org)        __ros__
 //   Windows                           _WIN32
 //   NaCL                              __native_client__
@@ -370,7 +370,7 @@
 #error "absl endian detection needs to be set up for your compiler"
 #endif
 
-// MacOS 10.13 and iOS 10.11 don't let you use <any>, <optional>, or <variant>
+// macOS 10.13 and iOS 10.11 don't let you use <any>, <optional>, or <variant>
 // even though the headers exist and are publicly noted to work.  See
 // https://github.com/abseil/abseil-cpp/issues/207 and
 // https://developer.apple.com/documentation/xcode_release_notes/xcode_10_release_notes
diff --git a/absl/base/internal/endian.h b/absl/base/internal/endian.h
index 6b828b6e6e61..296e92d9e550 100644
--- a/absl/base/internal/endian.h
+++ b/absl/base/internal/endian.h
@@ -20,7 +20,7 @@
 #ifdef _MSC_VER
 #include <stdlib.h>  // NOLINT(build/include)
 #elif defined(__APPLE__)
-// Mac OS X / Darwin features
+// macOS / Darwin features
 #include <libkern/OSByteOrder.h>
 #elif defined(__FreeBSD__)
 #include <sys/endian.h>
diff --git a/absl/container/internal/inlined_vector.h b/absl/container/internal/inlined_vector.h
index 17e203e51f5e..61c4f6ebfccc 100644
--- a/absl/container/internal/inlined_vector.h
+++ b/absl/container/internal/inlined_vector.h
@@ -19,6 +19,7 @@
 #include <cstddef>
 #include <cstring>
 #include <iterator>
+#include <limits>
 #include <memory>
 #include <utility>
 
@@ -270,6 +271,19 @@ class Storage {
   using ConstructionTransaction =
       inlined_vector_internal::ConstructionTransaction<allocator_type>;
 
+  static size_type NextCapacity(size_type current_capacity) {
+    return current_capacity * 2;
+  }
+
+  static size_type ComputeCapacity(size_type current_capacity,
+                                   size_type requested_capacity) {
+    return (std::max)(NextCapacity(current_capacity), requested_capacity);
+  }
+
+  // ---------------------------------------------------------------------------
+  // Storage Constructors and Destructor
+  // ---------------------------------------------------------------------------
+
   Storage() : metadata_() {}
 
   explicit Storage(const allocator_type& alloc)
@@ -281,10 +295,26 @@ class Storage {
     DeallocateIfAllocated();
   }
 
+  // ---------------------------------------------------------------------------
+  // Storage Member Accessors
+  // ---------------------------------------------------------------------------
+
+  size_type& GetSizeAndIsAllocated() { return metadata_.template get<1>(); }
+
+  const size_type& GetSizeAndIsAllocated() const {
+    return metadata_.template get<1>();
+  }
+
   size_type GetSize() const { return GetSizeAndIsAllocated() >> 1; }
 
   bool GetIsAllocated() const { return GetSizeAndIsAllocated() & 1; }
 
+  pointer GetAllocatedData() { return data_.allocated.allocated_data; }
+
+  const_pointer GetAllocatedData() const {
+    return data_.allocated.allocated_data;
+  }
+
   pointer GetInlinedData() {
     return reinterpret_cast<pointer>(
         std::addressof(data_.inlined.inlined_data[0]));
@@ -295,18 +325,12 @@ class Storage {
         std::addressof(data_.inlined.inlined_data[0]));
   }
 
-  pointer GetAllocatedData() { return data_.allocated.allocated_data; }
-
-  const_pointer GetAllocatedData() const {
-    return data_.allocated.allocated_data;
-  }
-
-  size_type GetInlinedCapacity() const { return static_cast<size_type>(N); }
-
   size_type GetAllocatedCapacity() const {
     return data_.allocated.allocated_capacity;
   }
 
+  size_type GetInlinedCapacity() const { return static_cast<size_type>(N); }
+
   StorageView MakeStorageView() {
     return GetIsAllocated()
                ? StorageView{GetAllocatedData(), GetSize(),
@@ -322,30 +346,63 @@ class Storage {
     return std::addressof(metadata_.template get<0>());
   }
 
-  void SetIsAllocated() { GetSizeAndIsAllocated() |= 1; }
+  // ---------------------------------------------------------------------------
+  // Storage Member Mutators
+  // ---------------------------------------------------------------------------
 
-  void UnsetIsAllocated() {
-    SetIsAllocated();
-    GetSizeAndIsAllocated() -= 1;
-  }
+  template <typename ValueAdapter>
+  void Initialize(ValueAdapter values, size_type new_size);
 
-  void SetAllocatedSize(size_type size) {
-    GetSizeAndIsAllocated() = (size << 1) | static_cast<size_type>(1);
+  template <typename ValueAdapter>
+  void Assign(ValueAdapter values, size_type new_size);
+
+  template <typename ValueAdapter>
+  void Resize(ValueAdapter values, size_type new_size);
+
+  template <typename ValueAdapter>
+  iterator Insert(const_iterator pos, ValueAdapter values,
+                  size_type insert_count);
+
+  template <typename... Args>
+  reference EmplaceBack(Args&&... args);
+
+  iterator Erase(const_iterator from, const_iterator to);
+
+  void Reserve(size_type requested_capacity);
+
+  void ShrinkToFit();
+
+  void Swap(Storage* other_storage_ptr);
+
+  void SetIsAllocated() {
+    GetSizeAndIsAllocated() |= static_cast<size_type>(1);
   }
 
-  void SetInlinedSize(size_type size) { GetSizeAndIsAllocated() = size << 1; }
+  void UnsetIsAllocated() {
+    GetSizeAndIsAllocated() &= ((std::numeric_limits<size_type>::max)() - 1);
+  }
 
   void SetSize(size_type size) {
     GetSizeAndIsAllocated() =
         (size << 1) | static_cast<size_type>(GetIsAllocated());
   }
 
-  void AddSize(size_type count) { GetSizeAndIsAllocated() += count << 1; }
+  void SetAllocatedSize(size_type size) {
+    GetSizeAndIsAllocated() = (size << 1) | static_cast<size_type>(1);
+  }
+
+  void SetInlinedSize(size_type size) {
+    GetSizeAndIsAllocated() = size << static_cast<size_type>(1);
+  }
+
+  void AddSize(size_type count) {
+    GetSizeAndIsAllocated() += count << static_cast<size_type>(1);
+  }
 
   void SubtractSize(size_type count) {
     assert(count <= GetSize());
 
-    GetSizeAndIsAllocated() -= count << 1;
+    GetSizeAndIsAllocated() -= count << static_cast<size_type>(1);
   }
 
   void SetAllocatedData(pointer data, size_type capacity) {
@@ -353,14 +410,7 @@ class Storage {
     data_.allocated.allocated_capacity = capacity;
   }
 
-  void DeallocateIfAllocated() {
-    if (GetIsAllocated()) {
-      AllocatorTraits::deallocate(*GetAllocPtr(), GetAllocatedData(),
-                                  GetAllocatedCapacity());
-    }
-  }
-
-  void AcquireAllocation(AllocationTransaction* allocation_tx_ptr) {
+  void AcquireAllocatedData(AllocationTransaction* allocation_tx_ptr) {
     SetAllocatedData(allocation_tx_ptr->GetData(),
                      allocation_tx_ptr->GetCapacity());
     allocation_tx_ptr->GetData() = nullptr;
@@ -374,46 +424,14 @@ class Storage {
     data_ = other_storage.data_;
   }
 
-  template <typename ValueAdapter>
-  void Initialize(ValueAdapter values, size_type new_size);
-
-  template <typename ValueAdapter>
-  void Assign(ValueAdapter values, size_type new_size);
-
-  template <typename ValueAdapter>
-  void Resize(ValueAdapter values, size_type new_size);
-
-  template <typename ValueAdapter>
-  iterator Insert(const_iterator pos, ValueAdapter values,
-                  size_type insert_count);
-
-  template <typename... Args>
-  reference EmplaceBack(Args&&... args);
-
-  iterator Erase(const_iterator from, const_iterator to);
-
-  void Reserve(size_type requested_capacity);
-
-  void ShrinkToFit();
-
-  void Swap(Storage* other_storage_ptr);
-
- private:
-  size_type& GetSizeAndIsAllocated() { return metadata_.template get<1>(); }
-
-  const size_type& GetSizeAndIsAllocated() const {
-    return metadata_.template get<1>();
-  }
-
-  static size_type NextCapacity(size_type current_capacity) {
-    return current_capacity * 2;
-  }
-
-  static size_type ComputeCapacity(size_type current_capacity,
-                                   size_type requested_capacity) {
-    return (std::max)(NextCapacity(current_capacity), requested_capacity);
+  void DeallocateIfAllocated() {
+    if (GetIsAllocated()) {
+      AllocatorTraits::deallocate(*GetAllocPtr(), GetAllocatedData(),
+                                  GetAllocatedCapacity());
+    }
   }
 
+ private:
   using Metadata =
       container_internal::CompressedTuple<allocator_type, size_type>;
 
@@ -508,7 +526,7 @@ auto Storage<T, N, A>::Assign(ValueAdapter values, size_type new_size) -> void {
 
   if (allocation_tx.DidAllocate()) {
     DeallocateIfAllocated();
-    AcquireAllocation(&allocation_tx);
+    AcquireAllocatedData(&allocation_tx);
     SetIsAllocated();
   }
 
@@ -557,7 +575,7 @@ auto Storage<T, N, A>::Resize(ValueAdapter values, size_type new_size) -> void {
   construction_tx.Commit();
   if (allocation_tx.DidAllocate()) {
     DeallocateIfAllocated();
-    AcquireAllocation(&allocation_tx);
+    AcquireAllocatedData(&allocation_tx);
     SetIsAllocated();
   }
 
@@ -600,7 +618,7 @@ auto Storage<T, N, A>::Insert(const_iterator pos, ValueAdapter values,
     construction_tx.Commit();
     move_construciton_tx.Commit();
     DeallocateIfAllocated();
-    AcquireAllocation(&allocation_tx);
+    AcquireAllocatedData(&allocation_tx);
 
     SetAllocatedSize(new_size);
     return iterator(new_data + insert_index);
@@ -697,7 +715,7 @@ auto Storage<T, N, A>::EmplaceBack(Args&&... args) -> reference {
                                              storage_view.size);
 
     DeallocateIfAllocated();
-    AcquireAllocation(&allocation_tx);
+    AcquireAllocatedData(&allocation_tx);
     SetIsAllocated();
   }
 
@@ -754,7 +772,7 @@ auto Storage<T, N, A>::Reserve(size_type requested_capacity) -> void {
                                            storage_view.size);
 
   DeallocateIfAllocated();
-  AcquireAllocation(&allocation_tx);
+  AcquireAllocatedData(&allocation_tx);
   SetIsAllocated();
 }
 
@@ -800,7 +818,7 @@ auto Storage<T, N, A>::ShrinkToFit() -> void {
                               storage_view.capacity);
 
   if (allocation_tx.DidAllocate()) {
-    AcquireAllocation(&allocation_tx);
+    AcquireAllocatedData(&allocation_tx);
   } else {
     UnsetIsAllocated();
   }
diff --git a/absl/debugging/internal/stacktrace_powerpc-inl.inc b/absl/debugging/internal/stacktrace_powerpc-inl.inc
index 9e0f2aad3fc1..3a070ee45d4b 100644
--- a/absl/debugging/internal/stacktrace_powerpc-inl.inc
+++ b/absl/debugging/internal/stacktrace_powerpc-inl.inc
@@ -162,7 +162,7 @@ ABSL_ATTRIBUTE_NO_SANITIZE_MEMORY   // May read random elements from stack.
 static int UnwindImpl(void** result, int* sizes, int max_depth, int skip_count,
                       const void *ucp, int *min_dropped_frames) {
   void **sp;
-  // Apple OS X uses an old version of gnu as -- both Darwin 7.9.0 (Panther)
+  // Apple macOS uses an old version of gnu as -- both Darwin 7.9.0 (Panther)
   // and Darwin 8.8.1 (Tiger) use as 1.38.  This means we have to use a
   // different asm syntax.  I don't know quite the best way to discriminate
   // systems using the old as from the new one; I've gone with __APPLE__.
diff --git a/absl/random/internal/gaussian_distribution_gentables.cc b/absl/random/internal/gaussian_distribution_gentables.cc
index 85247966f51b..16a23cb2f91f 100644
--- a/absl/random/internal/gaussian_distribution_gentables.cc
+++ b/absl/random/internal/gaussian_distribution_gentables.cc
@@ -110,8 +110,12 @@ void TableGenerator::Print(std::ostream* os) {
          "\n"
          "#include \"absl/random/gaussian_distribution.h\"\n"
          "\n"
-         "namespace absl {\n"
-         "namespace random_internal {\n"
+         // "namespace " and "absl" are broken apart so as not to conflict with
+         // script that adds the LTS inline namespace.
+         "namespace "
+         "absl {\n"
+         "namespace "
+         "random_internal {\n"
          "\n"
          "const gaussian_distribution_base::Tables\n"
          "    gaussian_distribution_base::zg_ = {\n";
@@ -120,8 +124,10 @@ void TableGenerator::Print(std::ostream* os) {
   FormatArrayContents(os, tables_.f);
   *os << "};\n"
          "\n"
-         "}  // namespace random_internal\n"
-         "}  // namespace absl\n"
+         "}  // namespace "
+         "random_internal\n"
+         "}  // namespace "
+         "absl\n"
          "\n"
          "// clang-format on\n"
          "// END GENERATED CODE";
diff --git a/absl/random/internal/platform.h b/absl/random/internal/platform.h
index d1ef5c249032..a5a42cbb80ea 100644
--- a/absl/random/internal/platform.h
+++ b/absl/random/internal/platform.h
@@ -30,7 +30,7 @@
 //   Linux and Linux-derived           __linux__
 //   Android                           __ANDROID__ (implies __linux__)
 //   Linux (non-Android)               __linux__ && !__ANDROID__
-//   Darwin (Mac OS X and iOS)         __APPLE__
+//   Darwin (macOS and iOS)            __APPLE__
 //   Akaros (http://akaros.org)        __ros__
 //   Windows                           _WIN32
 //   NaCL                              __native_client__
diff --git a/absl/strings/numbers_test.cc b/absl/strings/numbers_test.cc
index ca2ee485d84e..77d7e7835b8b 100644
--- a/absl/strings/numbers_test.cc
+++ b/absl/strings/numbers_test.cc
@@ -713,7 +713,7 @@ TEST(stringtest, safe_strtou64_base_length_delimited) {
   }
 }
 
-// feenableexcept() and fedisableexcept() are missing on Mac OS X, MSVC,
+// feenableexcept() and fedisableexcept() are missing on macOS, MSVC,
 // and WebAssembly.
 #if defined(_MSC_VER) || defined(__APPLE__) || defined(__EMSCRIPTEN__)
 #define ABSL_MISSING_FEENABLEEXCEPT 1
diff --git a/absl/time/format_test.cc b/absl/time/format_test.cc
index 4a1f1aa2cd42..ab1f30594ea9 100644
--- a/absl/time/format_test.cc
+++ b/absl/time/format_test.cc
@@ -201,7 +201,7 @@ TEST(ParseTime, ErrorCases) {
   err.clear();
   EXPECT_FALSE(absl::ParseTime("%Q", "x", &t, &err)) << err;
   // Exact contents of "err" are platform-dependent because of
-  // differences in the strptime implementation between OSX and Linux.
+  // differences in the strptime implementation between macOS and Linux.
   EXPECT_FALSE(err.empty());
 
   // Fails because of trailing, unparsed data "blah".