Skip to content

Commit

Permalink
Export of internal Abseil changes
Browse files Browse the repository at this point in the history
--
20405fc394419d434d3ea09b2e62e4edcb282421 by Christian Blichmann <cblichmann@google.com>:

Include `status` subdirectory in main `CMakeLists.txt`

PiperOrigin-RevId: 297125966

--
101087af9689612bdda679ee0869e5cde4472244 by Matt Kulukundis <kfm@google.com>:

Fix typo

PiperOrigin-RevId: 296991360

--
55ff5bc6970d46214c0459d3a7a23973c7dc69b9 by Andy Getzendanner <durandal@google.com>:

Extract logging's ErrnoSaver to absl::base_internal and use it in a couple other places.

PiperOrigin-RevId: 296969168

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

Internal change

PiperOrigin-RevId: 296951474

--
8c04c73fc53f9a09c3e2400812b931157f35fe07 by Andy Soffer <asoffer@google.com>:

Auto-generate list of files in the DLL, and add new build targets to the DLL.

PiperOrigin-RevId: 296932061

--
2f77829e196094f1addefd8ac2ac9e398c5b6100 by Andy Soffer <asoffer@google.com>:

Fix bug introduced by DLL where we couldn't build shared libraries on
non-windows platforms.

Fixes #623

PiperOrigin-RevId: 296919347

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

typo: microprosessor

PiperOrigin-RevId: 296904933

--
b185da0dac44c91855373f0723df9242cbfb3db3 by Matthew Brown <matthewbr@google.com>:

Internal cleanup

PiperOrigin-RevId: 296509711
GitOrigin-RevId: 20405fc394419d434d3ea09b2e62e4edcb282421
Change-Id: I55c8eba6f353ceb337455ae144ab743ea21edbef
  • Loading branch information
Abseil Team authored and CJ-Johnson committed Feb 25, 2020
1 parent b69c7d8 commit 0d5ce27
Show file tree
Hide file tree
Showing 20 changed files with 248 additions and 128 deletions.
16 changes: 14 additions & 2 deletions CMake/AbseilDll.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ set(ABSL_INTERNAL_DLL_FILES
"base/internal/cycleclock.h"
"base/internal/direct_mmap.h"
"base/internal/endian.h"
"base/internal/errno_saver.h"
"base/internal/exponential_biased.cc"
"base/internal/exponential_biased.h"
"base/internal/hide_ptr.h"
Expand Down Expand Up @@ -108,6 +109,8 @@ set(ABSL_INTERNAL_DLL_FILES
"debugging/internal/symbolize.h"
"debugging/internal/vdso_support.cc"
"debugging/internal/vdso_support.h"
"functional/internal/front_binder.h"
"functional/bind_front.h"
"functional/function_ref.h"
"functional/internal/function_ref.h"
"hash/hash.h"
Expand Down Expand Up @@ -169,18 +172,23 @@ set(ABSL_INTERNAL_DLL_FILES
"random/uniform_int_distribution.h"
"random/uniform_real_distribution.h"
"random/zipf_distribution.h"
"status/status.h"
"status/status.cc"
"status/status_payload_printer.h"
"status/status_payload_printer.cc"
"strings/ascii.cc"
"strings/ascii.h"
"strings/charconv.cc"
"strings/charconv.h"
"strings/cord.cc"
"strings/cord.h"
"strings/escaping.cc"
"strings/escaping.h"
"strings/internal/cord_internal.h"
"strings/internal/charconv_bigint.cc"
"strings/internal/charconv_bigint.h"
"strings/internal/charconv_parse.cc"
"strings/internal/charconv_parse.h"
"strings/internal/escaping.cc"
"strings/internal/escaping.h"
"strings/internal/stl_type_traits.h"
"strings/match.cc"
"strings/match.h"
Expand All @@ -200,6 +208,8 @@ set(ABSL_INTERNAL_DLL_FILES
"strings/substitute.cc"
"strings/substitute.h"
"strings/internal/char_map.h"
"strings/internal/escaping.h"
"strings/internal/escaping.cc"
"strings/internal/memutil.cc"
"strings/internal/memutil.h"
"strings/internal/ostringstream.cc"
Expand Down Expand Up @@ -308,6 +318,7 @@ set(ABSL_INTERNAL_DLL_TARGETS
"memory"
"strings"
"strings_internal"
"cord"
"str_format"
"str_format_internal"
"pow10_helper"
Expand Down Expand Up @@ -377,6 +388,7 @@ set(ABSL_INTERNAL_DLL_TARGETS
"random_internal_randen_hwaes"
"random_internal_randen_hwaes_impl"
"random_internal_uniform_helper"
"status"
"time"
"civil_time"
"time_zone"
Expand Down
12 changes: 8 additions & 4 deletions CMake/AbseilHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,16 @@ function(absl_cc_library)
set(ABSL_CC_LIB_IS_INTERFACE 0)
endif()

# Determine this build target's relationship to the DLL. It's one of three things:
# Determine this build target's relationship to the DLL. It's one of four things:
# 1. "dll" -- This target is part of the DLL
# 2. "dll_dep" -- This target is not part of the DLL, but depends on the DLL.
# Note that we assume any target not in the DLL depends on the
# DLL. This is not a technical necessity but a convenience
# which happens to be true, because nearly every target is
# part of the DLL.
# 3. "static" -- This target does not depend on the DLL and should be built
# 3. "shared" -- This is a shared library, perhaps on a non-windows platform
# where DLL doesn't make sense.
# 4. "static" -- This target does not depend on the DLL and should be built
# statically.
if (${ABSL_BUILD_DLL})
absl_internal_dll_contains(TARGET ${_NAME} OUTPUT _in_dll)
Expand All @@ -127,6 +129,8 @@ function(absl_cc_library)
# Building a DLL, but this target is not part of the DLL
set(_build_type "dll_dep")
endif()
elseif(BUILD_SHARED_LIBS)
set(_build_type "shared")
else()
set(_build_type "static")
endif()
Expand Down Expand Up @@ -161,8 +165,8 @@ function(absl_cc_library)
"${_gtest_link_define}"
)

elseif(${_build_type} STREQUAL "static")
add_library(${_NAME} STATIC "")
elseif(${_build_type} STREQUAL "static" OR ${_build_type} STREQUAL "shared")
add_library(${_NAME} "")
target_sources(${_NAME} PRIVATE ${ABSL_CC_LIB_SRCS} ${ABSL_CC_LIB_HDRS})
target_link_libraries(${_NAME}
PUBLIC ${ABSL_CC_LIB_DEPS}
Expand Down
1 change: 1 addition & 0 deletions absl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ add_subdirectory(memory)
add_subdirectory(meta)
add_subdirectory(numeric)
add_subdirectory(random)
add_subdirectory(status)
add_subdirectory(strings)
add_subdirectory(synchronization)
add_subdirectory(time)
Expand Down
24 changes: 24 additions & 0 deletions absl/base/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ cc_library(
],
)

cc_library(
name = "errno_saver",
hdrs = ["internal/errno_saver.h"],
copts = ABSL_DEFAULT_COPTS,
linkopts = ABSL_DEFAULT_LINKOPTS,
visibility = [
"//absl:__subpackages__",
],
deps = [":config"],
)

cc_library(
name = "log_severity",
srcs = ["log_severity.cc"],
Expand Down Expand Up @@ -87,6 +98,7 @@ cc_library(
deps = [
":base_internal",
":core_headers",
":errno_saver",
],
)

Expand Down Expand Up @@ -287,6 +299,18 @@ cc_test(
],
)

cc_test(
name = "errno_saver_test",
size = "small",
srcs = ["internal/errno_saver_test.cc"],
copts = ABSL_TEST_COPTS,
linkopts = ABSL_DEFAULT_LINKOPTS,
deps = [
":errno_saver",
"@com_google_googletest//:gtest_main",
],
)

cc_library(
name = "exception_testing",
testonly = 1,
Expand Down
25 changes: 25 additions & 0 deletions absl/base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ absl_cc_library(
${ABSL_DEFAULT_COPTS}
)

absl_cc_library(
NAME
errno_saver
HDRS
"internal/errno_saver.h"
DEPS
absl::config
COPTS
${ABSL_DEFAULT_COPTS}
)

absl_cc_library(
NAME
log_severity
Expand Down Expand Up @@ -73,6 +84,7 @@ absl_cc_library(
DEPS
absl::base_internal
absl::core_headers
absl::errno_saver
)

absl_cc_library(
Expand Down Expand Up @@ -305,6 +317,19 @@ absl_cc_test(
gtest_main
)

absl_cc_test(
NAME
errno_saver_test
SRCS
"internal/errno_saver_test.cc"
COPTS
${ABSL_TEST_COPTS}
DEPS
absl::errno_saver
gmock
gtest_main
)

absl_cc_test(
NAME
throw_delegate_test
Expand Down
2 changes: 1 addition & 1 deletion absl/base/attributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@
// When applying ABSL_ATTRIBUTE_PACKED only to specific structure members the
// natural alignment of structure members not annotated is preserved. Aligned
// member accesses are faster than non-aligned member accesses even if the
// targeted microprosessor supports non-aligned accesses.
// targeted microprocessor supports non-aligned accesses.
#if ABSL_HAVE_ATTRIBUTE(packed) || (defined(__GNUC__) && !defined(__clang__))
#define ABSL_ATTRIBUTE_PACKED __attribute__((__packed__))
#else
Expand Down
43 changes: 43 additions & 0 deletions absl/base/internal/errno_saver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2017 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.

#ifndef ABSL_BASE_INTERNAL_ERRNO_SAVER_H_
#define ABSL_BASE_INTERNAL_ERRNO_SAVER_H_

#include <cerrno>

#include "absl/base/config.h"

namespace absl {
ABSL_NAMESPACE_BEGIN
namespace base_internal {

// `ErrnoSaver` captures the value of `errno` upon construction and restores it
// upon deletion. It is used in low-level code and must be super fast. Do not
// add instrumentation, even in debug modes.
class ErrnoSaver {
public:
ErrnoSaver() : saved_errno_(errno) {}
~ErrnoSaver() { errno = saved_errno_; }
int operator()() const { return saved_errno_; }

private:
const int saved_errno_;
};

} // namespace base_internal
ABSL_NAMESPACE_END
} // namespace absl

#endif // ABSL_BASE_INTERNAL_ERRNO_SAVER_H_
44 changes: 44 additions & 0 deletions absl/base/internal/errno_saver_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// 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
//
// 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/base/internal/errno_saver.h"

#include <cerrno>

#include "gmock/gmock.h"
#include "gtest/gtest.h"

namespace {
using ::testing::Eq;

struct ErrnoPrinter {
int no;
};
std::ostream &operator<<(std::ostream &os, ErrnoPrinter ep) {
return os << strerror(ep.no) << " [" << ep.no << "]";
}
bool operator==(ErrnoPrinter one, ErrnoPrinter two) { return one.no == two.no; }

TEST(ErrnoSaverTest, Works) {
errno = EDOM;
{
absl::base_internal::ErrnoSaver errno_saver;
EXPECT_THAT(ErrnoPrinter{errno}, Eq(ErrnoPrinter{EDOM}));
errno = ERANGE;
EXPECT_THAT(ErrnoPrinter{errno}, Eq(ErrnoPrinter{ERANGE}));
EXPECT_THAT(ErrnoPrinter{errno_saver()}, Eq(ErrnoPrinter{EDOM}));
}
EXPECT_THAT(ErrnoPrinter{errno}, Eq(ErrnoPrinter{EDOM}));
}
} // namespace
5 changes: 2 additions & 3 deletions absl/base/internal/spinlock_linux.inc
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
#include <unistd.h>

#include <atomic>
#include <cerrno>
#include <climits>
#include <cstdint>
#include <ctime>

#include "absl/base/attributes.h"
#include "absl/base/internal/errno_saver.h"

// The SpinLock lockword is `std::atomic<uint32_t>`. Here we assert that
// `std::atomic<uint32_t>` is bitwise equivalent of the `int` expected
Expand All @@ -51,12 +51,11 @@ extern "C" {
ABSL_ATTRIBUTE_WEAK void AbslInternalSpinLockDelay(
std::atomic<uint32_t> *w, uint32_t value, int loop,
absl::base_internal::SchedulingMode) {
int save_errno = errno;
absl::base_internal::ErrnoSaver errno_saver;
struct timespec tm;
tm.tv_sec = 0;
tm.tv_nsec = absl::base_internal::SpinLockSuggestedDelayNS(loop);
syscall(SYS_futex, w, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, value, &tm);
errno = save_errno;
}

ABSL_ATTRIBUTE_WEAK void AbslInternalSpinLockWake(std::atomic<uint32_t> *w,
Expand Down
6 changes: 3 additions & 3 deletions absl/base/internal/spinlock_posix.inc
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
// This file is a Posix-specific part of spinlock_wait.cc

#include <sched.h>

#include <atomic>
#include <ctime>
#include <cerrno>

#include "absl/base/internal/errno_saver.h"
#include "absl/base/internal/scheduling_mode.h"
#include "absl/base/port.h"

Expand All @@ -27,7 +28,7 @@ extern "C" {
ABSL_ATTRIBUTE_WEAK void AbslInternalSpinLockDelay(
std::atomic<uint32_t>* /* lock_word */, uint32_t /* value */, int loop,
absl::base_internal::SchedulingMode /* mode */) {
int save_errno = errno;
absl::base_internal::ErrnoSaver errno_saver;
if (loop == 0) {
} else if (loop == 1) {
sched_yield();
Expand All @@ -37,7 +38,6 @@ ABSL_ATTRIBUTE_WEAK void AbslInternalSpinLockDelay(
tm.tv_nsec = absl::base_internal::SpinLockSuggestedDelayNS(loop);
nanosleep(&tm, nullptr);
}
errno = save_errno;
}

ABSL_ATTRIBUTE_WEAK void AbslInternalSpinLockWake(
Expand Down
2 changes: 2 additions & 0 deletions absl/debugging/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ cc_library(
"//absl/base",
"//absl/base:config",
"//absl/base:core_headers",
"//absl/base:errno_saver",
"//absl/base:raw_logging_internal",
],
)
Expand Down Expand Up @@ -174,6 +175,7 @@ cc_library(
"//absl/base:config",
"//absl/base:core_headers",
"//absl/base:dynamic_annotations",
"//absl/base:errno_saver",
"//absl/base:raw_logging_internal",
],
)
Expand Down
2 changes: 2 additions & 0 deletions absl/debugging/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ absl_cc_library(
absl::base
absl::config
absl::core_headers
absl::errno_saver
absl::raw_logging_internal
PUBLIC
)
Expand Down Expand Up @@ -156,6 +157,7 @@ absl_cc_library(
absl::core_headers
absl::config
absl::dynamic_annotations
absl::errno_saver
absl::raw_logging_internal
)

Expand Down
Loading

0 comments on commit 0d5ce27

Please sign in to comment.