summaryrefslogtreecommitdiff
path: root/absl/flags
diff options
context:
space:
mode:
authorGravatar Abseil Team <absl-team@google.com>2020-06-30 13:08:50 -0700
committerGravatar Derek Mauro <dmauro@google.com>2020-06-30 16:12:34 -0400
commit81f34df8347a73c617f244f49cb916238857dc34 (patch)
tree44d8278f3102055ab0c41059259bb3eacf112323 /absl/flags
parentb86fff162e15ad8ee534c25e58bf522330e8376d (diff)
Export of internal Abseil changes
-- 739f9fb80212c21c015fec473e9e29803a156ef9 by Derek Mauro <dmauro@google.com>: Define FlagStateInterface::~FlagStateInterface() in the translation unit in which it is actually declared Fixes #717 PiperOrigin-RevId: 319083605 -- 913ef1f23113268b22d636d3ae3b992862efdb1a by Derek Mauro <dmauro@google.com>: Fix ABSL_LOCK_RETURNED statement PiperOrigin-RevId: 319078667 -- a43b1413da1770d638147c73e7e1693cfaf869c7 by Derek Mauro <dmauro@google.com>: Fix redeclaration ‘absl::Cord::InlineRep::kMaxInline’, which differs in ‘constexpr’ Fixes #725 PiperOrigin-RevId: 319060910 -- 1ad7d491a80f6c9de78a6fc20f09b7765d224503 by Abseil Team <absl-team@google.com>: Make absl SpinLock trivially destructible when possible PiperOrigin-RevId: 319049456 -- 659ecad3578dfa669854a82279fa590002bdb37f by Derek Mauro <dmauro@google.com>: Remove the static initialization of global variables used by absl::Mutex as requested by Chromium PiperOrigin-RevId: 319031204 -- 609c491d8bb4f8bb3b44c5a4c0bee51c583df24c by Abseil Team <absl-team@google.com>: Add implementation of %a and %A to absl::StrFormat. Prior to this it just fell back to sprintf. PiperOrigin-RevId: 318888039 -- 5e8ae6392bcd135248aac14c4b9f2a5116868678 by Abseil Team <absl-team@google.com>: Google-internal changes only. PiperOrigin-RevId: 318857077 -- 4a2578e33e8442954e29e5f0380ddfcf0f033f0d by Greg Falcon <gfalcon@google.com>: Change of enum constants to accommodate internal change. PiperOrigin-RevId: 318844716 -- 4b578b102816260c213675759f4c15911735578a by Abseil Team <absl-team@google.com>: Internal change PiperOrigin-RevId: 318704453 -- 0ee82fd24d548b260c9229fa1f54571dae1dfa24 by Gennadiy Rozental <rogeeff@google.com>: Allow lookup of retired flags. At the moment we issue warning on attempt to find a retired flag. This way we can't even check if flag is retired without issuing the warning. With this change we will only issue the warning if one tries to access any functionality of retired flag but it's name "is retired" status, and type. PiperOrigin-RevId: 318605017 -- 3e35fe9b4c79f636fa328c59e2aabb93e29b7c99 by Abseil Team <absl-team@google.com>: Fix error return from InstallSymbolDecorator(). PiperOrigin-RevId: 318490405 -- ae46063f3eb2998cb961f62a359d932e5908a4bc by Abseil Team <absl-team@google.com>: Do not make copies of iterated collection elements into the loop variable. PiperOrigin-RevId: 318423139 -- d06a075a12aab5f6ab98474677ce50d588b21de3 by Abseil Team <absl-team@google.com>: add missing word making the error code better English PiperOrigin-RevId: 318335052 GitOrigin-RevId: 739f9fb80212c21c015fec473e9e29803a156ef9 Change-Id: Id77a0a4b1959036b00555deef40e82d51884fbc1
Diffstat (limited to 'absl/flags')
-rw-r--r--absl/flags/BUILD.bazel3
-rw-r--r--absl/flags/CMakeLists.txt2
-rw-r--r--absl/flags/commandlineflag.cc4
-rw-r--r--absl/flags/commandlineflag.h4
-rw-r--r--absl/flags/internal/commandlineflag.cc26
-rw-r--r--absl/flags/internal/flag.h3
-rw-r--r--absl/flags/internal/usage.cc4
-rw-r--r--absl/flags/parse.cc7
-rw-r--r--absl/flags/reflection.cc48
9 files changed, 76 insertions, 25 deletions
diff --git a/absl/flags/BUILD.bazel b/absl/flags/BUILD.bazel
index 006911fd..524e7027 100644
--- a/absl/flags/BUILD.bazel
+++ b/absl/flags/BUILD.bazel
@@ -106,6 +106,9 @@ cc_library(
cc_library(
name = "commandlineflag_internal",
+ srcs = [
+ "internal/commandlineflag.cc",
+ ],
hdrs = [
"internal/commandlineflag.h",
],
diff --git a/absl/flags/CMakeLists.txt b/absl/flags/CMakeLists.txt
index ef75db8e..343774de 100644
--- a/absl/flags/CMakeLists.txt
+++ b/absl/flags/CMakeLists.txt
@@ -95,6 +95,8 @@ absl_cc_library(
absl_cc_library(
NAME
flags_commandlineflag_internal
+ SRCS
+ "internal/commandlineflag.cc"
HDRS
"internal/commandlineflag.h"
COPTS
diff --git a/absl/flags/commandlineflag.cc b/absl/flags/commandlineflag.cc
index 217b2d87..9f3b4a5a 100644
--- a/absl/flags/commandlineflag.cc
+++ b/absl/flags/commandlineflag.cc
@@ -30,9 +30,5 @@ bool CommandLineFlag::ParseFrom(absl::string_view value, std::string* error) {
flags_internal::kProgrammaticChange, *error);
}
-namespace flags_internal {
-FlagStateInterface::~FlagStateInterface() {}
-} // namespace flags_internal
ABSL_NAMESPACE_END
} // namespace absl
-
diff --git a/absl/flags/commandlineflag.h b/absl/flags/commandlineflag.h
index 7e21d05d..f2fa0897 100644
--- a/absl/flags/commandlineflag.h
+++ b/absl/flags/commandlineflag.h
@@ -108,6 +108,10 @@ class CommandLineFlag {
U u;
Read(&u.value);
+ // allow retired flags to be "read", so we can report invalid access.
+ if (IsRetired()) {
+ return absl::nullopt;
+ }
return std::move(u.value);
}
diff --git a/absl/flags/internal/commandlineflag.cc b/absl/flags/internal/commandlineflag.cc
new file mode 100644
index 00000000..4482955c
--- /dev/null
+++ b/absl/flags/internal/commandlineflag.cc
@@ -0,0 +1,26 @@
+//
+// Copyright 2020 The Abseil Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "absl/flags/internal/commandlineflag.h"
+
+namespace absl {
+ABSL_NAMESPACE_BEGIN
+namespace flags_internal {
+
+FlagStateInterface::~FlagStateInterface() {}
+
+} // namespace flags_internal
+ABSL_NAMESPACE_END
+} // namespace absl
diff --git a/absl/flags/internal/flag.h b/absl/flags/internal/flag.h
index 2cc44e00..89e43ad7 100644
--- a/absl/flags/internal/flag.h
+++ b/absl/flags/internal/flag.h
@@ -482,7 +482,8 @@ class FlagImpl final : public CommandLineFlag {
friend class FlagState;
// Ensures that `data_guard_` is initialized and returns it.
- absl::Mutex* DataGuard() const ABSL_LOCK_RETURNED((absl::Mutex*)&data_guard_);
+ absl::Mutex* DataGuard() const
+ ABSL_LOCK_RETURNED(reinterpret_cast<absl::Mutex*>(data_guard_));
// Returns heap allocated value of type T initialized with default value.
std::unique_ptr<void, DynValueDeleter> MakeInitValue() const
ABSL_EXCLUSIVE_LOCKS_REQUIRED(*DataGuard());
diff --git a/absl/flags/internal/usage.cc b/absl/flags/internal/usage.cc
index 35b6427b..0805df31 100644
--- a/absl/flags/internal/usage.cc
+++ b/absl/flags/internal/usage.cc
@@ -250,14 +250,14 @@ void FlagsHelpImpl(std::ostream& out, flags_internal::FlagKindFilter filter_cb,
matching_flags;
flags_internal::ForEachFlag([&](absl::CommandLineFlag& flag) {
- std::string flag_filename = flag.Filename();
-
// Ignore retired flags.
if (flag.IsRetired()) return;
// If the flag has been stripped, pretend that it doesn't exist.
if (flag.Help() == flags_internal::kStrippedFlagHelp) return;
+ std::string flag_filename = flag.Filename();
+
// Make sure flag satisfies the filter
if (!filter_cb || !filter_cb(flag_filename)) return;
diff --git a/absl/flags/parse.cc b/absl/flags/parse.cc
index e2c88ff8..4f4bb3d5 100644
--- a/absl/flags/parse.cc
+++ b/absl/flags/parse.cc
@@ -729,12 +729,13 @@ std::vector<char*> ParseCommandLineImpl(int argc, char* argv[],
}
// 100. Set the located flag to a new new value, unless it is retired.
- // Setting retired flag fails, but we ignoring it here.
- if (flag->IsRetired()) continue;
-
+ // Setting retired flag fails, but we ignoring it here while also reporting
+ // access to retired flag.
std::string error;
if (!flags_internal::PrivateHandleAccessor::ParseFrom(
*flag, value, SET_FLAGS_VALUE, kCommandLine, error)) {
+ if (flag->IsRetired()) continue;
+
flags_internal::ReportUsageError(error, true);
success = false;
} else {
diff --git a/absl/flags/reflection.cc b/absl/flags/reflection.cc
index 5fc945f2..02b7c06a 100644
--- a/absl/flags/reflection.cc
+++ b/absl/flags/reflection.cc
@@ -88,12 +88,6 @@ CommandLineFlag* FlagRegistry::FindFlagLocked(absl::string_view name) {
if (i == flags_.end()) {
return nullptr;
}
-
- if (i->second->IsRetired()) {
- flags_internal::ReportUsageError(
- absl::StrCat("Accessing retired flag '", name, "'"), false);
- }
-
return i->second;
}
@@ -155,7 +149,7 @@ void FlagRegistry::RegisterFlag(CommandLineFlag& flag) {
} else {
flags_internal::ReportUsageError(
absl::StrCat(
- "Something wrong with flag '", flag.Name(), "' in file '",
+ "Something is wrong with flag '", flag.Name(), "' in file '",
flag.Filename(), "'. One possibility: file '", flag.Filename(),
"' is being linked both statically and dynamically into this "
"executable. e.g. some files listed as srcs to a test and also "
@@ -206,16 +200,34 @@ class RetiredFlagObj final : public CommandLineFlag {
private:
absl::string_view Name() const override { return name_; }
- std::string Filename() const override { return "RETIRED"; }
+ std::string Filename() const override {
+ OnAccess();
+ return "RETIRED";
+ }
FlagFastTypeId TypeId() const override { return type_id_; }
- std::string Help() const override { return ""; }
+ std::string Help() const override {
+ OnAccess();
+ return "";
+ }
bool IsRetired() const override { return true; }
- bool IsSpecifiedOnCommandLine() const override { return false; }
- std::string DefaultValue() const override { return ""; }
- std::string CurrentValue() const override { return ""; }
+ bool IsSpecifiedOnCommandLine() const override {
+ OnAccess();
+ return false;
+ }
+ std::string DefaultValue() const override {
+ OnAccess();
+ return "";
+ }
+ std::string CurrentValue() const override {
+ OnAccess();
+ return "";
+ }
// Any input is valid
- bool ValidateInputValue(absl::string_view) const override { return true; }
+ bool ValidateInputValue(absl::string_view) const override {
+ OnAccess();
+ return true;
+ }
std::unique_ptr<flags_internal::FlagStateInterface> SaveState() override {
return nullptr;
@@ -223,12 +235,18 @@ class RetiredFlagObj final : public CommandLineFlag {
bool ParseFrom(absl::string_view, flags_internal::FlagSettingMode,
flags_internal::ValueSource, std::string&) override {
+ OnAccess();
return false;
}
- void CheckDefaultValueParsingRoundtrip() const override {}
+ void CheckDefaultValueParsingRoundtrip() const override { OnAccess(); }
- void Read(void*) const override {}
+ void Read(void*) const override { OnAccess(); }
+
+ void OnAccess() const {
+ flags_internal::ReportUsageError(
+ absl::StrCat("Accessing retired flag '", name_, "'"), false);
+ }
// Data members
const char* const name_;