about summary refs log tree commit diff
path: root/absl/flags/internal/flag.h
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2020-03-18T08·31-0700
committervslashg <gfalcon@google.com>2020-03-18T21·29-0400
commit2d2a8aea291c4877e75c7991a61e57d7e12b5373 (patch)
tree7768eaea5cde0d3f6e5e861222122d0ae5f4ea99 /absl/flags/internal/flag.h
parent7853a7586c492ce8905c9e49f8679dada6354f2c (diff)
Export of internal Abseil changes
--
a85860e450815776c8753f34348f41ab0e918d36 by Gennadiy Rozental <rogeeff@google.com>:

Rename ComamndLineFlag's interface SetFromString as ParseFrom.

This is the name approved by C++ API review.

PiperOrigin-RevId: 301543521

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

Internal change

PiperOrigin-RevId: 301524919

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

Introduce absl::base_internal::StrError, a portability wrapper around the various thread-safe alternatives to C89's strerror.

PiperOrigin-RevId: 301513962

--
92ccac3b6eb18cb41cddedbfdab53b9ad481505d by Andy Getzendanner <durandal@google.com>:

Introduce absl::base_internal::StrError, a portability wrapper around the various thread-safe alternatives to C89's strerror.

PiperOrigin-RevId: 301493389

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

Internal change

PiperOrigin-RevId: 301363394

--
dd1dcffa6c47675ba4d198730a301bd408142298 by Gennadiy Rozental <rogeeff@google.com>:

Add validation for size of void* to match the size of free function pointer.

PiperOrigin-RevId: 301341331
GitOrigin-RevId: a85860e450815776c8753f34348f41ab0e918d36
Change-Id: I27c9d1365d3c9b4328d1587ab3ac38e2d09a6ec2
Diffstat (limited to 'absl/flags/internal/flag.h')
-rw-r--r--absl/flags/internal/flag.h23
1 files changed, 16 insertions, 7 deletions
diff --git a/absl/flags/internal/flag.h b/absl/flags/internal/flag.h
index 0ef0ee745641..2c4aba680a6e 100644
--- a/absl/flags/internal/flag.h
+++ b/absl/flags/internal/flag.h
@@ -76,8 +76,17 @@ void* FlagOps(FlagOp op, const void* v1, void* v2, void* v3) {
       return nullptr;
     case FlagOp::kSizeof:
       return reinterpret_cast<void*>(sizeof(T));
-    case FlagOp::kStaticTypeId:
-      return reinterpret_cast<void*>(&FlagStaticTypeIdGen<T>);
+    case FlagOp::kStaticTypeId: {
+      auto* static_id = &FlagStaticTypeIdGen<T>;
+
+      // Cast from function pointer to void* is not portable.
+      // We don't have an easy way to work around this, but it works fine
+      // on all the platforms we test and as long as size of pointers match
+      // we should be fine to do reinterpret cast.
+      static_assert(sizeof(void*) == sizeof(static_id),
+                    "Flag's static type id does not work on this platform");
+      return reinterpret_cast<void*>(static_id);
+    }
     case FlagOp::kParse: {
       // Initialize the temporary instance of type T based on current value in
       // destination (which is going to be flag's default value).
@@ -395,8 +404,8 @@ class FlagImpl {
 
   // Mutating access methods
   void Write(const void* src) ABSL_LOCKS_EXCLUDED(*DataGuard());
-  bool SetFromString(absl::string_view value, FlagSettingMode set_mode,
-                     ValueSource source, std::string* err)
+  bool ParseFrom(absl::string_view value, FlagSettingMode set_mode,
+                 ValueSource source, std::string* err)
       ABSL_LOCKS_EXCLUDED(*DataGuard());
 
   // Interfaces to operate on callbacks.
@@ -586,9 +595,9 @@ class Flag final : public flags_internal::CommandLineFlag {
     return impl_.RestoreState(&flag_state.cur_value_, flag_state.modified_,
                               flag_state.on_command_line_, flag_state.counter_);
   }
-  bool SetFromString(absl::string_view value, FlagSettingMode set_mode,
-                     ValueSource source, std::string* error) override {
-    return impl_.SetFromString(value, set_mode, source, error);
+  bool ParseFrom(absl::string_view value, FlagSettingMode set_mode,
+                 ValueSource source, std::string* error) override {
+    return impl_.ParseFrom(value, set_mode, source, error);
   }
   void CheckDefaultValueParsingRoundtrip() const override {
     impl_.CheckDefaultValueParsingRoundtrip();