chromium/third_party/abseil-cpp/absl/flags/internal/flag.cc

//
// Copyright 2019 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/flag.h"

#include <assert.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>

#include <array>
#include <atomic>
#include <cstring>
#include <memory>
#include <string>
#include <typeinfo>
#include <vector>

#include "absl/base/attributes.h"
#include "absl/base/call_once.h"
#include "absl/base/casts.h"
#include "absl/base/config.h"
#include "absl/base/const_init.h"
#include "absl/base/dynamic_annotations.h"
#include "absl/base/optimization.h"
#include "absl/flags/config.h"
#include "absl/flags/internal/commandlineflag.h"
#include "absl/flags/usage_config.h"
#include "absl/memory/memory.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "absl/synchronization/mutex.h"

namespace absl {
ABSL_NAMESPACE_BEGIN
namespace flags_internal {

// The help message indicating that the commandline flag has been stripped. It
// will not show up when doing "-help" and its variants. The flag is stripped
// if ABSL_FLAGS_STRIP_HELP is set to 1 before including absl/flags/flag.h
const char kStrippedFlagHelp[] =;

namespace {

// Currently we only validate flag values for user-defined flag types.
bool ShouldValidateFlagValue(FlagFastTypeId flag_type_id) {}

// RAII helper used to temporarily unlock and relock `absl::Mutex`.
// This is used when we need to ensure that locks are released while
// invoking user supplied callbacks and then reacquired, since callbacks may
// need to acquire these locks themselves.
class MutexRelock {};

// This is a freelist of leaked flag values and guard for its access.
// When we can't guarantee it is safe to reuse the memory for flag values,
// we move the memory to the freelist where it lives indefinitely, so it can
// still be safely accessed. This also prevents leak checkers from complaining
// about the leaked memory that can no longer be accessed through any pointer.
ABSL_CONST_INIT absl::Mutex s_freelist_guard(absl::kConstInit);
ABSL_CONST_INIT std::vector<void*>* s_freelist =;

void AddToFreelist(void* p) {}

}  // namespace

///////////////////////////////////////////////////////////////////////////////

uint64_t NumLeakedFlagValues() {}

///////////////////////////////////////////////////////////////////////////////
// Persistent state of the flag data.

class FlagImpl;

class FlagState : public flags_internal::FlagStateInterface {};

///////////////////////////////////////////////////////////////////////////////
// Flag implementation, which does not depend on flag value type.

DynValueDeleter::DynValueDeleter(FlagOpFn op_arg) :{}

void DynValueDeleter::operator()(void* ptr) const {}

MaskedPointer::MaskedPointer(ptr_t rhs, bool is_candidate) :{}

bool MaskedPointer::IsUnprotectedReadCandidate() const {}

bool MaskedPointer::HasBeenRead() const {}

void MaskedPointer::Set(FlagOpFn op, const void* src, bool is_candidate) {}
void MaskedPointer::MarkAsRead() {}

void MaskedPointer::ApplyMask(mask_t mask) {}
bool MaskedPointer::CheckMask(mask_t mask) const {}

void FlagImpl::Init() {}

absl::Mutex* FlagImpl::DataGuard() const {}

void FlagImpl::AssertValidType(FlagFastTypeId rhs_type_id,
                               const std::type_info* (*gen_rtti)()) const {}

std::unique_ptr<void, DynValueDeleter> FlagImpl::MakeInitValue() const {}

void FlagImpl::StoreValue(const void* src, ValueSource source) {}

absl::string_view FlagImpl::Name() const {}

std::string FlagImpl::Filename() const {}

std::string FlagImpl::Help() const {}

FlagFastTypeId FlagImpl::TypeId() const {}

int64_t FlagImpl::ModificationCount() const {}

bool FlagImpl::IsSpecifiedOnCommandLine() const {}

std::string FlagImpl::DefaultValue() const {}

std::string FlagImpl::CurrentValue() const {}

void FlagImpl::SetCallback(const FlagCallbackFunc mutation_callback) {}

void FlagImpl::InvokeCallback() const {}

std::unique_ptr<FlagStateInterface> FlagImpl::SaveState() {}

bool FlagImpl::RestoreState(const FlagState& flag_state) {}

template <typename StorageT>
StorageT* FlagImpl::OffsetValue() const {}

std::atomic<uint64_t>* FlagImpl::AtomicBufferValue() const {}

std::atomic<int64_t>& FlagImpl::OneWordValue() const {}

std::atomic<MaskedPointer>& FlagImpl::PtrStorage() const {}

// Attempts to parse supplied `value` string using parsing routine in the `flag`
// argument. If parsing successful, this function replaces the dst with newly
// parsed value. In case if any error is encountered in either step, the error
// message is stored in 'err'
std::unique_ptr<void, DynValueDeleter> FlagImpl::TryParse(
    absl::string_view value, std::string& err) const {}

void FlagImpl::Read(void* dst) const {}

int64_t FlagImpl::ReadOneWord() const {}

bool FlagImpl::ReadOneBool() const {}

void FlagImpl::ReadSequenceLockedData(void* dst) const {}

void FlagImpl::Write(const void* src) {}

// Sets the value of the flag based on specified string `value`. If the flag
// was successfully set to new value, it returns true. Otherwise, sets `err`
// to indicate the error, leaves the flag unchanged, and returns false. There
// are three ways to set the flag's value:
//  * Update the current flag value
//  * Update the flag's default value
//  * Update the current flag value if it was never set before
// The mode is selected based on 'set_mode' parameter.
bool FlagImpl::ParseFrom(absl::string_view value, FlagSettingMode set_mode,
                         ValueSource source, std::string& err) {}

void FlagImpl::CheckDefaultValueParsingRoundtrip() const {}

bool FlagImpl::ValidateInputValue(absl::string_view value) const {}

}  // namespace flags_internal
ABSL_NAMESPACE_END
}  // namespace absl