Skip to content

Commit

Permalink
Export of internal Abseil changes.
Browse files Browse the repository at this point in the history
--
898e99cae89ca4cc27f86f719148f020d521dd58 by Abseil Team <absl-team@google.com>:

Update comment.

PiperOrigin-RevId: 204323401

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

Internal change

PiperOrigin-RevId: 204178059

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

Fix a potential reinterpret_cast compile error in absl::InlinedVector

The current code will trigger a reinterpret_cast error enhanced by llvm r336738.

PiperOrigin-RevId: 204131536

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

Internal change.

PiperOrigin-RevId: 203979040

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

Internal: add internal logging hooks

PiperOrigin-RevId: 203850605

--
503655c248f557f677c920078613522b010e73c8 by Derek Mauro <dmauro@google.com>:

Cleanup stacktrace_config.h

Instead of listing the platforms that aren't supported, list the ones
we do support, and fallback to stacktrace_unimplemented-inl.inc at the
end. Previously any platform that wasn't listed gets "#error Not supported yet".

GitHub issue #135

PiperOrigin-RevId: 203823079

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

Fix a minor typo in absl::variant documentation.

PiperOrigin-RevId: 203679877

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

Format .bzl files with buildifier

PiperOrigin-RevId: 203461813

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

Make the absl::SleepFor() tests treat any successful retry within
a 48x deadline as a total success, thereby reducing flakiness.

PiperOrigin-RevId: 203401603

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

Replace config_setting.values{"compiler"} with config_setting.flag_values{"@bazel_tools//tools/cpp:compiler"}

Due to changes in Bazel we need to change the way "compiler" is specified in config_setting. This will not change the behavior of the config_setting itself.

PiperOrigin-RevId: 203345693

--
170f1692537460a4ba1756d34852275899c2339b by Matt Armstrong <marmstrong@google.com>:

Address test flakiness in the TimeoutTest.

The basic idea is to loop forever until the expected
scheduling delays are observed (within reasonable bounds),
and only then assert the other invariants.

PiperOrigin-RevId: 203188162
GitOrigin-RevId: 898e99cae89ca4cc27f86f719148f020d521dd58
Change-Id: Ie853ec050afa3a04c519393afe666bc03e11dc87
  • Loading branch information
Abseil Team authored and zhangxy988 committed Jul 12, 2018
1 parent 8f612eb commit 0268795
Show file tree
Hide file tree
Showing 15 changed files with 577 additions and 284 deletions.
7 changes: 3 additions & 4 deletions absl/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ package(default_visibility = ["//visibility:public"])

licenses(["notice"]) # Apache 2.0

config_setting(
load(":compiler_config_setting.bzl", "create_llvm_config")

create_llvm_config(
name = "llvm_compiler",
values = {
"compiler": "llvm",
},
visibility = [":__subpackages__"],
)

Expand Down
1 change: 1 addition & 0 deletions absl/base/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ cc_test(
copts = ABSL_TEST_COPTS,
deps = [
":base",
"//absl/strings",
"@com_google_googletest//:gtest_main",
],
)
Expand Down
2 changes: 1 addition & 1 deletion absl/base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ absl_test(

# test raw_logging_test
set(RAW_LOGGING_TEST_SRC "raw_logging_test.cc")
set(RAW_LOGGING_TEST_PUBLIC_LIBRARIES absl::base)
set(RAW_LOGGING_TEST_PUBLIC_LIBRARIES absl::base absl::strings)

absl_test(
TARGET
Expand Down
16 changes: 16 additions & 0 deletions absl/base/internal/raw_logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,15 @@ void RawLog(absl::LogSeverity severity, const char* file, int line,
va_end(ap);
}

// Non-formatting version of RawLog().
//
// TODO(gfalcon): When string_view no longer depends on base, change this
// interface to take its message as a string_view instead.
static void DefaultInternalLog(absl::LogSeverity severity, const char* file,
int line, const std::string& message) {
RawLog(severity, file, line, "%s", message.c_str());
}

bool RawLoggingFullySupported() {
#ifdef ABSL_LOW_LEVEL_WRITE_SUPPORTED
return true;
Expand All @@ -214,5 +223,12 @@ bool RawLoggingFullySupported() {
#endif // !ABSL_LOW_LEVEL_WRITE_SUPPORTED
}

ABSL_CONST_INIT absl::base_internal::AtomicHook<InternalLogFunction>
internal_log_function(DefaultInternalLog);

void RegisterInternalLogFunction(InternalLogFunction func) {
internal_log_function.Store(func);
}

} // namespace raw_logging_internal
} // namespace absl
43 changes: 43 additions & 0 deletions absl/base/internal/raw_logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
#ifndef ABSL_BASE_INTERNAL_RAW_LOGGING_H_
#define ABSL_BASE_INTERNAL_RAW_LOGGING_H_

#include <string>

#include "absl/base/attributes.h"
#include "absl/base/internal/atomic_hook.h"
#include "absl/base/log_severity.h"
#include "absl/base/macros.h"
#include "absl/base/port.h"
Expand Down Expand Up @@ -57,6 +60,34 @@
} \
} while (0)

// ABSL_INTERNAL_LOG and ABSL_INTERNAL_CHECK work like the RAW variants above,
// except that if the richer log library is linked into the binary, we dispatch
// to that instead. This is potentially useful for internal logging and
// assertions, where we are using RAW_LOG neither for its async-signal-safety
// nor for its non-allocating nature, but rather because raw logging has very
// few other dependencies.
//
// The API is a subset of the above: each macro only takes two arguments. Use
// StrCat if you need to build a richer message.
#define ABSL_INTERNAL_LOG(severity, message) \
do { \
constexpr const char* absl_raw_logging_internal_basename = \
::absl::raw_logging_internal::Basename(__FILE__, \
sizeof(__FILE__) - 1); \
::absl::raw_logging_internal::internal_log_function( \
ABSL_RAW_LOGGING_INTERNAL_##severity, \
absl_raw_logging_internal_basename, __LINE__, message); \
} while (0)

#define ABSL_INTERNAL_CHECK(condition, message) \
do { \
if (ABSL_PREDICT_FALSE(!(condition))) { \
std::string death_message = "Check " #condition " failed: "; \
death_message += std::string(message); \
ABSL_INTERNAL_LOG(FATAL, death_message); \
} \
} while (0)

#define ABSL_RAW_LOGGING_INTERNAL_INFO ::absl::LogSeverity::kInfo
#define ABSL_RAW_LOGGING_INTERNAL_WARNING ::absl::LogSeverity::kWarning
#define ABSL_RAW_LOGGING_INTERNAL_ERROR ::absl::LogSeverity::kError
Expand Down Expand Up @@ -131,6 +162,18 @@ using LogPrefixHook = bool (*)(absl::LogSeverity severity, const char* file,
using AbortHook = void (*)(const char* file, int line, const char* buf_start,
const char* prefix_end, const char* buf_end);

// Internal logging function for ABSL_INTERNAL_LOG to dispatch to.
//
// TODO(gfalcon): When string_view no longer depends on base, change this
// interface to take its message as a string_view instead.
using InternalLogFunction = void (*)(absl::LogSeverity severity,
const char* file, int line,
const std::string& message);

extern base_internal::AtomicHook<InternalLogFunction> internal_log_function;

void RegisterInternalLogFunction(InternalLogFunction func);

} // namespace raw_logging_internal
} // namespace absl

Expand Down
29 changes: 29 additions & 0 deletions absl/base/raw_logging_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,20 @@

#include "absl/base/internal/raw_logging.h"

#include <tuple>

#include "gtest/gtest.h"
#include "absl/strings/str_cat.h"

namespace {

TEST(RawLoggingCompilationTest, Log) {
ABSL_RAW_LOG(INFO, "RAW INFO: %d", 1);
ABSL_RAW_LOG(INFO, "RAW INFO: %d %d", 1, 2);
ABSL_RAW_LOG(INFO, "RAW INFO: %d %d %d", 1, 2, 3);
ABSL_RAW_LOG(INFO, "RAW INFO: %d %d %d %d", 1, 2, 3, 4);
ABSL_RAW_LOG(INFO, "RAW INFO: %d %d %d %d %d", 1, 2, 3, 4, 5);
ABSL_RAW_LOG(WARNING, "RAW WARNING: %d", 1);
ABSL_RAW_LOG(ERROR, "RAW ERROR: %d", 1);
}

Expand All @@ -47,4 +55,25 @@ TEST(RawLoggingDeathTest, LogFatal) {
kExpectedDeathOutput);
}

TEST(InternalLog, CompilationTest) {
ABSL_INTERNAL_LOG(INFO, "Internal Log");
std::string log_msg = "Internal Log";
ABSL_INTERNAL_LOG(INFO, log_msg);

ABSL_INTERNAL_LOG(INFO, log_msg + " 2");

float d = 1.1f;
ABSL_INTERNAL_LOG(INFO, absl::StrCat("Internal log ", 3, " + ", d));
}

TEST(InternalLogDeathTest, FailingCheck) {
EXPECT_DEATH_IF_SUPPORTED(ABSL_INTERNAL_CHECK(1 == 0, "explanation"),
kExpectedDeathOutput);
}

TEST(InternalLogDeathTest, LogFatal) {
EXPECT_DEATH_IF_SUPPORTED(ABSL_INTERNAL_LOG(FATAL, "my dog has fleas"),
kExpectedDeathOutput);
}

} // namespace
39 changes: 39 additions & 0 deletions absl/compiler_config_setting.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#
# Copyright 2018 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
#
# http://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.
#

"""Creates config_setting that allows selecting based on 'compiler' value."""

def create_llvm_config(name, visibility):
# The "do_not_use_tools_cpp_compiler_present" attribute exists to
# distinguish between older versions of Bazel that do not support
# "@bazel_tools//tools/cpp:compiler" flag_value, and newer ones that do.
# In the future, the only way to select on the compiler will be through
# flag_values{"@bazel_tools//tools/cpp:compiler"} and the else branch can
# be removed.
if hasattr(cc_common, "do_not_use_tools_cpp_compiler_present"):
native.config_setting(
name = name,
flag_values = {
"@bazel_tools//tools/cpp:compiler": "llvm",
},
visibility = visibility,
)
else:
native.config_setting(
name = name,
values = {"compiler": "llvm"},
visibility = visibility,
)
7 changes: 5 additions & 2 deletions absl/container/inlined_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -689,11 +689,14 @@ class InlinedVector {
new (&rep_.allocation_storage.allocation) Allocation(allocation);
}

// TODO(absl-team): investigate whether the reinterpret_cast is appropriate.
value_type* inlined_space() {
return reinterpret_cast<value_type*>(&rep_.inlined_storage.inlined);
return reinterpret_cast<value_type*>(
std::addressof(rep_.inlined_storage.inlined[0]));
}
const value_type* inlined_space() const {
return reinterpret_cast<const value_type*>(&rep_.inlined_storage.inlined);
return reinterpret_cast<const value_type*>(
std::addressof(rep_.inlined_storage.inlined[0]));
}

value_type* allocated_space() { return allocation().buffer(); }
Expand Down
1 change: 0 additions & 1 deletion absl/copts.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ GCC_TEST_FLAGS = [
"-Wno-unused-private-field",
]


# Docs on single flags is preceded by a comment.
# Docs on groups of flags is preceded by ###.

Expand Down
37 changes: 16 additions & 21 deletions absl/debugging/internal/stacktrace_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,16 @@
#ifndef ABSL_DEBUGGING_INTERNAL_STACKTRACE_CONFIG_H_
#define ABSL_DEBUGGING_INTERNAL_STACKTRACE_CONFIG_H_

// First, test platforms which only support a stub.
#if ABSL_STACKTRACE_INL_HEADER
#if defined(ABSL_STACKTRACE_INL_HEADER)
#error ABSL_STACKTRACE_INL_HEADER cannot be directly set
#elif defined(__native_client__) || defined(__APPLE__) || \
defined(__FreeBSD__) || defined(__ANDROID__) || defined(__myriad2__) || \
defined(__asmjs__) || defined(__wasm__) || defined(__Fuchsia__)
#define ABSL_STACKTRACE_INL_HEADER \
"absl/debugging/internal/stacktrace_unimplemented-inl.inc"

// Next, test for Mips and Windows.
// TODO(marmstrong): Mips case, remove the check for ABSL_STACKTRACE_INL_HEADER
#elif defined(__mips__) && !defined(ABSL_STACKTRACE_INL_HEADER)
#define ABSL_STACKTRACE_INL_HEADER \
"absl/debugging/internal/stacktrace_unimplemented-inl.inc"
#elif defined(_WIN32) // windows
#elif defined(_WIN32)
#define ABSL_STACKTRACE_INL_HEADER \
"absl/debugging/internal/stacktrace_win32-inl.inc"

// Finally, test NO_FRAME_POINTER.
#elif !defined(NO_FRAME_POINTER)
#elif defined(__linux__) && !defined(__ANDROID__)

#if !defined(NO_FRAME_POINTER)
# if defined(__i386__) || defined(__x86_64__)
#define ABSL_STACKTRACE_INL_HEADER \
"absl/debugging/internal/stacktrace_x86-inl.inc"
Expand All @@ -53,22 +43,27 @@
# elif defined(__arm__)
#define ABSL_STACKTRACE_INL_HEADER \
"absl/debugging/internal/stacktrace_arm-inl.inc"
# else
#define ABSL_STACKTRACE_INL_HEADER \
"absl/debugging/internal/stacktrace_unimplemented-inl.inc"
# endif
#else // defined(NO_FRAME_POINTER)
# if defined(__i386__) || defined(__x86_64__) || defined(__aarch64__)
#define ABSL_STACKTRACE_INL_HEADER \
"absl/debugging/internal/stacktrace_unimplemented-inl.inc"
"absl/debugging/internal/stacktrace_generic-inl.inc"
# elif defined(__ppc__) || defined(__PPC__)
// Use glibc's backtrace.
#define ABSL_STACKTRACE_INL_HEADER \
"absl/debugging/internal/stacktrace_generic-inl.inc"
# elif defined(__arm__)
# error stacktrace without frame pointer is not supported on ARM
# else
#define ABSL_STACKTRACE_INL_HEADER \
"absl/debugging/internal/stacktrace_unimplemented-inl.inc"
# endif
#endif // NO_FRAME_POINTER

#if !defined(ABSL_STACKTRACE_INL_HEADER)
#error Not supported yet
#else
#define ABSL_STACKTRACE_INL_HEADER \
"absl/debugging/internal/stacktrace_unimplemented-inl.inc"

#endif

#endif // ABSL_DEBUGGING_INTERNAL_STACKTRACE_CONFIG_H_
4 changes: 2 additions & 2 deletions absl/strings/str_format_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,8 @@ TEST(StrFormat, BehavesAsDocumented) {
EXPECT_EQ(StrFormat("%G", 1e10), "1E+10");
// a/A - lower,upper case hex Eg: -3.0 -> "-0x1.8p+1"/"-0X1.8P+1"

// On NDK r16, there is a regression in hexfloat formatting.
#if !defined(__NDK_MAJOR__) || __NDK_MAJOR__ != 16
// On Android platform <=21, there is a regression in hexfloat formatting.
#if !defined(__ANDROID_API__) || __ANDROID_API__ > 21
EXPECT_EQ(StrFormat("%.1a", -3.0), "-0x1.8p+1"); // .1 to fix MSVC output
EXPECT_EQ(StrFormat("%.1A", -3.0), "-0X1.8P+1"); // .1 to fix MSVC output
#endif
Expand Down
4 changes: 2 additions & 2 deletions absl/synchronization/mutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
// Unlike a `std::mutex`, the Abseil `Mutex` provides the following additional
// features:
// * Conditional predicates intrinsic to the `Mutex` object
// * Reader/writer locks, in addition to standard exclusive/writer locks
// * Shared/reader locks, in addition to standard exclusive/writer locks
// * Deadlock detection and debug support.
//
// The following helper classes are also defined within this file:
Expand Down Expand Up @@ -290,7 +290,7 @@ class LOCKABLE Mutex {
// Mutex::ReaderLockWhen()
// Mutex::WriterLockWhen()
//
// Blocks until simultaneously both `cond` is `true` and this` Mutex` can
// Blocks until simultaneously both `cond` is `true` and this `Mutex` can
// be acquired, then atomically acquires this `Mutex`. `LockWhen()` is
// logically equivalent to `*Lock(); Await();` though they may have different
// performance characteristics.
Expand Down
Loading

0 comments on commit 0268795

Please sign in to comment.