Skip to content

Commit

Permalink
Export of internal Abseil changes
Browse files Browse the repository at this point in the history
--
167cd2647144583746311129b0cc98a89a9897e1 by Andy Soffer <[email protected]>:

Internal Changes

PiperOrigin-RevId: 268000987

--
ab44fea7dfdaf763c69609a08ddfac22480ce520 by Derek Mauro <[email protected]>:

Fix flags Cmake tests on Windows

PiperOrigin-RevId: 267859442

--
d7ec9f7611370b01bc9a5aed7e18460df2a15429 by Abseil Team <[email protected]>:

Fix undefined behavior in symbolize_elf.inc

PiperOrigin-RevId: 267684904

--
e7c5f8e472a91ed99bdf4876942f2bda5751aa6c by Abseil Team <[email protected]>:

Turn off ABSL_HAS_ALARM on Fuchsia.

PiperOrigin-RevId: 267666090

--
b7d25d5c71a49e697a8bf6440ed30f2e3f036420 by Chris Kennelly <[email protected]>:

Mark once initialization function as no inline.

We expect this code to run infrequently.

PiperOrigin-RevId: 267649713

--
dc2a5e5f1e39a03fff837d34a319033fde55d9ba by Derek Mauro <[email protected]>:

Fix the MSVC CMake random build

PiperOrigin-RevId: 267624074

--
ba2751b67fa17d1b6c53e5ba79f81a5371e4a03a by Abseil Team <[email protected]>:

Move "internal/flag.*" files to the "internal" build target.

PiperOrigin-RevId: 267588996

--
05b985a33eec4f8acff1809ad9218a1e22220f34 by Abseil Team <[email protected]>:

Move "internal/flag.*" files to the "internal" build target.

PiperOrigin-RevId: 267580412
GitOrigin-RevId: 167cd2647144583746311129b0cc98a89a9897e1
Change-Id: Ibd334f46a5671c7c1d3fcf5354029e2fbb7ba91f
  • Loading branch information
Abseil Team authored and shaindelschwartz committed Sep 9, 2019
1 parent 325fd7b commit 97c1664
Show file tree
Hide file tree
Showing 14 changed files with 154 additions and 62 deletions.
1 change: 1 addition & 0 deletions absl/base/call_once.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ enum {
};

template <typename Callable, typename... Args>
ABSL_ATTRIBUTE_NOINLINE
void CallOnceImpl(std::atomic<uint32_t>* control,
base_internal::SchedulingMode scheduling_mode, Callable&& fn,
Args&&... args) {
Expand Down
2 changes: 2 additions & 0 deletions absl/base/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,8 @@
// feature tests for Microsoft's library
#elif defined(__EMSCRIPTEN__)
// emscripten doesn't support signals
#elif defined(__Fuchsia__)
// Signals don't exist on fuchsia.
#elif defined(__native_client__)
#else
// other standard libraries
Expand Down
13 changes: 10 additions & 3 deletions absl/debugging/symbolize_elf.inc
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,13 @@ static bool InSection(const void *address, const ElfW(Shdr) * section) {
return start <= address && address < (start + size);
}

static const char *ComputeOffset(const char *base, ptrdiff_t offset) {
// Note: cast to uintptr_t to avoid undefined behavior when base evaluates to
// zero and offset is non-zero.
return reinterpret_cast<const char *>(
reinterpret_cast<uintptr_t>(base) + offset);
}

// Read a symbol table and look for the symbol containing the
// pc. Iterate over symbols in a symbol table and look for the symbol
// containing "pc". If the symbol is found, and its name fits in
Expand Down Expand Up @@ -676,7 +683,8 @@ static ABSL_ATTRIBUTE_NOINLINE FindSymbolResult FindSymbol(
// We keep the original address for opd redirection below.
const char *const original_start_address =
reinterpret_cast<const char *>(symbol.st_value);
const char *start_address = original_start_address + relocation;
const char *start_address =
ComputeOffset(original_start_address, relocation);

if (deref_function_descriptor_pointer &&
InSection(original_start_address, opd)) {
Expand All @@ -688,8 +696,7 @@ static ABSL_ATTRIBUTE_NOINLINE FindSymbolResult FindSymbol(

// If pc is inside the .opd section, it points to a function descriptor.
const size_t size = pc_in_opd ? kFunctionDescriptorSize : symbol.st_size;
const void *const end_address =
reinterpret_cast<const char *>(start_address) + size;
const void *const end_address = ComputeOffset(start_address, size);
if (symbol.st_value != 0 && // Skip null value symbols.
symbol.st_shndx != 0 && // Skip undefined symbols.
#ifdef STT_TLS
Expand Down
2 changes: 2 additions & 0 deletions absl/flags/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ cc_test(
copts = ABSL_TEST_COPTS,
linkopts = ABSL_DEFAULT_LINKOPTS,
deps = [
":config",
":flag",
":handle",
":registry",
Expand Down Expand Up @@ -264,6 +265,7 @@ cc_test(
copts = ABSL_TEST_COPTS,
linkopts = ABSL_DEFAULT_LINKOPTS,
deps = [
":config",
":flag",
"//absl/strings",
"@com_google_googletest//:gtest_main",
Expand Down
2 changes: 2 additions & 0 deletions absl/flags/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ absl_cc_test(
${ABSL_TEST_COPTS}
DEPS
absl::flags
absl::flags_config
absl::flags_handle
absl::flags_registry
absl::memory
Expand Down Expand Up @@ -242,6 +243,7 @@ absl_cc_test(
${ABSL_TEST_COPTS}
DEPS
absl::flags
absl::flags_config
absl::strings
gtest_main
)
Expand Down
92 changes: 58 additions & 34 deletions absl/flags/flag_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@

#include "absl/flags/flag.h"

#include <algorithm>
#include <string>

#include "gtest/gtest.h"
#include "absl/flags/usage_config.h"
#include "absl/strings/match.h"
#include "absl/strings/numbers.h"
#include "absl/strings/str_cat.h"
Expand Down Expand Up @@ -63,7 +67,27 @@ struct UDT {
bool AbslParseFlag(absl::string_view, UDT*, std::string*) { return true; }
std::string AbslUnparseFlag(const UDT&) { return ""; }

TEST(FlagTest, TestConstruction) {
class FlagTest : public testing::Test {
protected:
static void SetUpTestSuite() {
// Install a function to normalize filenames before this test is run.
absl::FlagsUsageConfig default_config;
default_config.normalize_filename = &FlagTest::NormalizeFileName;
absl::SetFlagsUsageConfig(default_config);
}

private:
static std::string NormalizeFileName(absl::string_view fname) {
#ifdef _WIN32
std::string normalized(fname);
std::replace(normalized.begin(), normalized.end(), '\\', '/');
fname = normalized;
#endif
return std::string(fname);
}
};

TEST_F(FlagTest, TestConstruction) {
TestConstructionFor<bool>();
TestConstructionFor<int16_t>();
TestConstructionFor<uint16_t>();
Expand Down Expand Up @@ -98,7 +122,7 @@ namespace {

#if !ABSL_FLAGS_STRIP_NAMES

TEST(FlagTest, TestFlagDeclaration) {
TEST_F(FlagTest, TestFlagDeclaration) {
// test that we can access flag objects.
EXPECT_EQ(FLAGS_test_flag_01.Name(), "test_flag_01");
EXPECT_EQ(FLAGS_test_flag_02.Name(), "test_flag_02");
Expand Down Expand Up @@ -133,69 +157,69 @@ ABSL_FLAG(std::string, test_flag_11, "", "test flag 11");
namespace {

#if !ABSL_FLAGS_STRIP_NAMES
TEST(FlagTest, TestFlagDefinition) {
TEST_F(FlagTest, TestFlagDefinition) {
absl::string_view expected_file_name = "absl/flags/flag_test.cc";

EXPECT_EQ(FLAGS_test_flag_01.Name(), "test_flag_01");
EXPECT_EQ(FLAGS_test_flag_01.Help(), "test flag 01");
EXPECT_TRUE(
absl::EndsWith(FLAGS_test_flag_01.Filename(), expected_file_name));
EXPECT_TRUE(absl::EndsWith(FLAGS_test_flag_01.Filename(), expected_file_name))
<< FLAGS_test_flag_01.Filename();

EXPECT_EQ(FLAGS_test_flag_02.Name(), "test_flag_02");
EXPECT_EQ(FLAGS_test_flag_02.Help(), "test flag 02");
EXPECT_TRUE(
absl::EndsWith(FLAGS_test_flag_02.Filename(), expected_file_name));
EXPECT_TRUE(absl::EndsWith(FLAGS_test_flag_02.Filename(), expected_file_name))
<< FLAGS_test_flag_02.Filename();

EXPECT_EQ(FLAGS_test_flag_03.Name(), "test_flag_03");
EXPECT_EQ(FLAGS_test_flag_03.Help(), "test flag 03");
EXPECT_TRUE(
absl::EndsWith(FLAGS_test_flag_03.Filename(), expected_file_name));
EXPECT_TRUE(absl::EndsWith(FLAGS_test_flag_03.Filename(), expected_file_name))
<< FLAGS_test_flag_03.Filename();

EXPECT_EQ(FLAGS_test_flag_04.Name(), "test_flag_04");
EXPECT_EQ(FLAGS_test_flag_04.Help(), "test flag 04");
EXPECT_TRUE(
absl::EndsWith(FLAGS_test_flag_04.Filename(), expected_file_name));
EXPECT_TRUE(absl::EndsWith(FLAGS_test_flag_04.Filename(), expected_file_name))
<< FLAGS_test_flag_04.Filename();

EXPECT_EQ(FLAGS_test_flag_05.Name(), "test_flag_05");
EXPECT_EQ(FLAGS_test_flag_05.Help(), "test flag 05");
EXPECT_TRUE(
absl::EndsWith(FLAGS_test_flag_05.Filename(), expected_file_name));
EXPECT_TRUE(absl::EndsWith(FLAGS_test_flag_05.Filename(), expected_file_name))
<< FLAGS_test_flag_05.Filename();

EXPECT_EQ(FLAGS_test_flag_06.Name(), "test_flag_06");
EXPECT_EQ(FLAGS_test_flag_06.Help(), "test flag 06");
EXPECT_TRUE(
absl::EndsWith(FLAGS_test_flag_06.Filename(), expected_file_name));
EXPECT_TRUE(absl::EndsWith(FLAGS_test_flag_06.Filename(), expected_file_name))
<< FLAGS_test_flag_06.Filename();

EXPECT_EQ(FLAGS_test_flag_07.Name(), "test_flag_07");
EXPECT_EQ(FLAGS_test_flag_07.Help(), "test flag 07");
EXPECT_TRUE(
absl::EndsWith(FLAGS_test_flag_07.Filename(), expected_file_name));
EXPECT_TRUE(absl::EndsWith(FLAGS_test_flag_07.Filename(), expected_file_name))
<< FLAGS_test_flag_07.Filename();

EXPECT_EQ(FLAGS_test_flag_08.Name(), "test_flag_08");
EXPECT_EQ(FLAGS_test_flag_08.Help(), "test flag 08");
EXPECT_TRUE(
absl::EndsWith(FLAGS_test_flag_08.Filename(), expected_file_name));
EXPECT_TRUE(absl::EndsWith(FLAGS_test_flag_08.Filename(), expected_file_name))
<< FLAGS_test_flag_08.Filename();

EXPECT_EQ(FLAGS_test_flag_09.Name(), "test_flag_09");
EXPECT_EQ(FLAGS_test_flag_09.Help(), "test flag 09");
EXPECT_TRUE(
absl::EndsWith(FLAGS_test_flag_09.Filename(), expected_file_name));
EXPECT_TRUE(absl::EndsWith(FLAGS_test_flag_09.Filename(), expected_file_name))
<< FLAGS_test_flag_09.Filename();

EXPECT_EQ(FLAGS_test_flag_10.Name(), "test_flag_10");
EXPECT_EQ(FLAGS_test_flag_10.Help(), "test flag 10");
EXPECT_TRUE(
absl::EndsWith(FLAGS_test_flag_10.Filename(), expected_file_name));
EXPECT_TRUE(absl::EndsWith(FLAGS_test_flag_10.Filename(), expected_file_name))
<< FLAGS_test_flag_10.Filename();

EXPECT_EQ(FLAGS_test_flag_11.Name(), "test_flag_11");
EXPECT_EQ(FLAGS_test_flag_11.Help(), "test flag 11");
EXPECT_TRUE(
absl::EndsWith(FLAGS_test_flag_11.Filename(), expected_file_name));
EXPECT_TRUE(absl::EndsWith(FLAGS_test_flag_11.Filename(), expected_file_name))
<< FLAGS_test_flag_11.Filename();
}
#endif // !ABSL_FLAGS_STRIP_NAMES

// --------------------------------------------------------------------

TEST(FlagTest, TestDefault) {
TEST_F(FlagTest, TestDefault) {
EXPECT_EQ(absl::GetFlag(FLAGS_test_flag_01), true);
EXPECT_EQ(absl::GetFlag(FLAGS_test_flag_02), 1234);
EXPECT_EQ(absl::GetFlag(FLAGS_test_flag_03), -34);
Expand All @@ -211,7 +235,7 @@ TEST(FlagTest, TestDefault) {

// --------------------------------------------------------------------

TEST(FlagTest, TestGetSet) {
TEST_F(FlagTest, TestGetSet) {
absl::SetFlag(&FLAGS_test_flag_01, false);
EXPECT_EQ(absl::GetFlag(FLAGS_test_flag_01), false);

Expand Down Expand Up @@ -258,7 +282,7 @@ ABSL_FLAG(std::string, test_flag_13, absl::StrCat("AAA", "BBB"),

namespace {

TEST(FlagTest, TestNonConstexprDefault) {
TEST_F(FlagTest, TestNonConstexprDefault) {
EXPECT_EQ(absl::GetFlag(FLAGS_test_flag_12), 1);
EXPECT_EQ(absl::GetFlag(FLAGS_test_flag_13), "AAABBB");
}
Expand All @@ -272,7 +296,7 @@ ABSL_FLAG(bool, test_flag_14, true, absl::StrCat("test ", "flag ", "14"));
namespace {

#if !ABSL_FLAGS_STRIP_HELP
TEST(FlagTest, TestNonConstexprHelp) {
TEST_F(FlagTest, TestNonConstexprHelp) {
EXPECT_EQ(FLAGS_test_flag_14.Help(), "test flag 14");
}
#endif //! ABSL_FLAGS_STRIP_HELP
Expand All @@ -296,7 +320,7 @@ namespace {
void TestFlagCB() { cb_test_value = absl::GetFlag(FLAGS_test_flag_with_cb); }

// Tests side-effects of callback invocation.
TEST(FlagTest, CallbackInvocation) {
TEST_F(FlagTest, CallbackInvocation) {
EXPECT_EQ(absl::GetFlag(FLAGS_test_flag_with_cb), 100);
EXPECT_EQ(absl::GetFlag(FLAGS_test_flag_with_lambda_cb), 200);
EXPECT_EQ(cb_test_value, 300);
Expand Down Expand Up @@ -343,7 +367,7 @@ ABSL_FLAG(CustomUDT, test_flag_15, CustomUDT(), "test flag 15");

namespace {

TEST(FlagTest, TestCustomUDT) {
TEST_F(FlagTest, TestCustomUDT) {
EXPECT_EQ(absl::GetFlag(FLAGS_test_flag_15), CustomUDT(1, 1));
absl::SetFlag(&FLAGS_test_flag_15, CustomUDT(2, 3));
EXPECT_EQ(absl::GetFlag(FLAGS_test_flag_15), CustomUDT(2, 3));
Expand Down Expand Up @@ -409,7 +433,7 @@ ABSL_FLAG(ConversionTestVal, test_flag_16,

namespace {

TEST(FlagTest, CanSetViaImplicitConversion) {
TEST_F(FlagTest, CanSetViaImplicitConversion) {
EXPECT_EQ(absl::GetFlag(FLAGS_test_flag_16).a, 10);
absl::SetFlag(&FLAGS_test_flag_16,
ConversionTestVal::ViaImplicitConv::kEleven);
Expand Down Expand Up @@ -447,7 +471,7 @@ ABSL_FLAG(NonDfltConstructible, ndc_flag2, 0,

namespace {

TEST(FlagTest, TestNonDefaultConstructibleType) {
TEST_F(FlagTest, TestNonDefaultConstructibleType) {
EXPECT_EQ(absl::GetFlag(FLAGS_ndc_flag1).value, '1' + 100);
EXPECT_EQ(absl::GetFlag(FLAGS_ndc_flag2).value, 0);

Expand All @@ -468,7 +492,7 @@ ABSL_RETIRED_FLAG(std::string, old_str_flag, "", absl::StrCat("old ", "descr"));

namespace {

TEST(FlagTest, TestRetiredFlagRegistration) {
TEST_F(FlagTest, TestRetiredFlagRegistration) {
bool is_bool = false;
EXPECT_TRUE(flags::IsRetiredFlag("old_bool_flag", &is_bool));
EXPECT_TRUE(is_bool);
Expand Down
34 changes: 28 additions & 6 deletions absl/flags/internal/commandlineflag_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@

#include "absl/flags/internal/commandlineflag.h"

#include <algorithm>
#include <string>

#include "gtest/gtest.h"
#include "absl/flags/flag.h"
#include "absl/flags/internal/registry.h"
#include "absl/flags/usage_config.h"
#include "absl/memory/memory.h"
#include "absl/strings/match.h"
#include "absl/strings/str_cat.h"
Expand All @@ -33,10 +37,26 @@ namespace flags = absl::flags_internal;

class CommandLineFlagTest : public testing::Test {
protected:
static void SetUpTestSuite() {
// Install a function to normalize filenames before this test is run.
absl::FlagsUsageConfig default_config;
default_config.normalize_filename = &CommandLineFlagTest::NormalizeFileName;
absl::SetFlagsUsageConfig(default_config);
}

void SetUp() override { flag_saver_ = absl::make_unique<flags::FlagSaver>(); }
void TearDown() override { flag_saver_.reset(); }

private:
static std::string NormalizeFileName(absl::string_view fname) {
#ifdef _WIN32
std::string normalized(fname);
std::replace(normalized.begin(), normalized.end(), '\\', '/');
fname = normalized;
#endif
return std::string(fname);
}

std::unique_ptr<flags::FlagSaver> flag_saver_;
};

Expand All @@ -49,9 +69,10 @@ TEST_F(CommandLineFlagTest, TestAttributesAccessMethods) {
EXPECT_EQ(flag_01->Typename(), "");
EXPECT_TRUE(!flag_01->IsRetired());
EXPECT_TRUE(flag_01->IsOfType<int>());
EXPECT_TRUE(absl::EndsWith(
flag_01->Filename(),
"absl/flags/internal/commandlineflag_test.cc"));
EXPECT_TRUE(
absl::EndsWith(flag_01->Filename(),
"absl/flags/internal/commandlineflag_test.cc"))
<< flag_01->Filename();

auto* flag_02 = flags::FindCommandLineFlag("string_flag");

Expand All @@ -61,9 +82,10 @@ TEST_F(CommandLineFlagTest, TestAttributesAccessMethods) {
EXPECT_EQ(flag_02->Typename(), "");
EXPECT_TRUE(!flag_02->IsRetired());
EXPECT_TRUE(flag_02->IsOfType<std::string>());
EXPECT_TRUE(absl::EndsWith(
flag_02->Filename(),
"absl/flags/internal/commandlineflag_test.cc"));
EXPECT_TRUE(
absl::EndsWith(flag_02->Filename(),
"absl/flags/internal/commandlineflag_test.cc"))
<< flag_02->Filename();

auto* flag_03 = flags::FindRetiredFlag("bool_retired_flag");

Expand Down
4 changes: 2 additions & 2 deletions absl/flags/internal/usage_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ static std::string NormalizeFileName(absl::string_view fname) {
fname = normalized;
#endif

auto absl_pos = fname.find("/absl/");
auto absl_pos = fname.rfind("absl/");
if (absl_pos != absl::string_view::npos) {
fname = fname.substr(absl_pos + 1);
fname = fname.substr(absl_pos);
}
return std::string(fname);
}
Expand Down
2 changes: 2 additions & 0 deletions absl/random/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,8 @@ absl_cc_test(
random_internal_iostream_state_saver_test
SRCS
"internal/iostream_state_saver_test.cc"
COPTS
${ABSL_TEST_COPTS}
LINKOPTS
${ABSL_DEFAULT_LINKOPTS}
DEPS
Expand Down
2 changes: 1 addition & 1 deletion absl/random/beta_distribution.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class beta_distribution {
private:
friend class beta_distribution;

#ifdef COMPILER_MSVC
#ifdef _MSC_VER
// MSVC does not have constexpr implementations for std::log and std::exp
// so they are computed at runtime.
#define ABSL_RANDOM_INTERNAL_LOG_EXP_CONSTEXPR
Expand Down
Loading

0 comments on commit 97c1664

Please sign in to comment.