Snap for 6877830 from a11e28c0c2b8dfe4ef1373f8f4f78373e8a4ccd5 to sdk-release
Change-Id: I7eee3fa9430790301a64d8685bcf42c0d04ca029
diff --git a/.clang-format b/.clang-format
index fd0645f..7ab20d4 120000
--- a/.clang-format
+++ b/.clang-format
@@ -1 +1 @@
-../.clang-format-2
\ No newline at end of file
+../../build/soong/scripts/system-clang-format-2
\ No newline at end of file
diff --git a/cmsg.cpp b/cmsg.cpp
index 1fa873c..95db303 100644
--- a/cmsg.cpp
+++ b/cmsg.cpp
@@ -31,9 +31,10 @@
ssize_t SendFileDescriptorVector(borrowed_fd sockfd, const void* data, size_t len,
const std::vector<int>& fds) {
+ static const size_t page_size = sysconf(_SC_PAGE_SIZE);
size_t cmsg_space = CMSG_SPACE(sizeof(int) * fds.size());
size_t cmsg_len = CMSG_LEN(sizeof(int) * fds.size());
- if (cmsg_space >= PAGE_SIZE) {
+ if (cmsg_space >= page_size) {
errno = ENOMEM;
return -1;
}
@@ -74,8 +75,9 @@
std::vector<unique_fd>* fds) {
fds->clear();
+ static const size_t page_size = sysconf(_SC_PAGE_SIZE);
size_t cmsg_space = CMSG_SPACE(sizeof(int) * max_fds);
- if (cmsg_space >= PAGE_SIZE) {
+ if (cmsg_space >= page_size) {
errno = ENOMEM;
return -1;
}
diff --git a/include/android-base/errno_restorer.h b/include/android-base/errno_restorer.h
index 1c8597c..2689505 100644
--- a/include/android-base/errno_restorer.h
+++ b/include/android-base/errno_restorer.h
@@ -30,7 +30,7 @@
~ErrnoRestorer() { errno = saved_errno_; }
// Allow this object to be used as part of && operation.
- operator bool() const { return true; }
+ explicit operator bool() const { return true; }
private:
const int saved_errno_;
diff --git a/include/android-base/logging.h b/include/android-base/logging.h
index ce0374b..9064075 100644
--- a/include/android-base/logging.h
+++ b/include/android-base/logging.h
@@ -98,21 +98,25 @@
CRASH,
};
-using LogFunction = std::function<void(LogId, LogSeverity, const char*, const char*,
- unsigned int, const char*)>;
-using AbortFunction = std::function<void(const char*)>;
+using LogFunction = std::function<void(LogId /*log_buffer_id*/,
+ LogSeverity /*severity*/,
+ const char* /*tag*/,
+ const char* /*file*/,
+ unsigned int /*line*/,
+ const char* /*message*/)>;
+using AbortFunction = std::function<void(const char* /*abort_message*/)>;
// Loggers for use with InitLogging/SetLogger.
// Log to the kernel log (dmesg).
-void KernelLogger(LogId, LogSeverity, const char*, const char*, unsigned int, const char*);
+void KernelLogger(LogId log_buffer_id, LogSeverity severity, const char* tag, const char* file, unsigned int line, const char* message);
// Log to stderr in the full logcat format (with pid/tid/time/tag details).
-void StderrLogger(LogId, LogSeverity, const char*, const char*, unsigned int, const char*);
+void StderrLogger(LogId log_buffer_id, LogSeverity severity, const char* tag, const char* file, unsigned int line, const char* message);
// Log just the message to stdout/stderr (without pid/tid/time/tag details).
// The choice of stdout versus stderr is based on the severity.
// Errors are also prefixed by the program name (as with err(3)/error(3)).
// Useful for replacing printf(3)/perror(3)/err(3)/error(3) in command-line tools.
-void StdioLogger(LogId, LogSeverity, const char*, const char*, unsigned int, const char*);
+void StdioLogger(LogId log_buffer_id, LogSeverity severity, const char* tag, const char* file, unsigned int line, const char* message);
void DefaultAborter(const char* abort_message);
@@ -151,11 +155,11 @@
AbortFunction&& aborter = DefaultAborter);
#undef INIT_LOGGING_DEFAULT_LOGGER
-// Replace the current logger.
-void SetLogger(LogFunction&& logger);
+// Replace the current logger and return the old one.
+LogFunction SetLogger(LogFunction&& logger);
-// Replace the current aborter.
-void SetAborter(AbortFunction&& aborter);
+// Replace the current aborter and return the old one.
+AbortFunction SetAborter(AbortFunction&& aborter);
// A helper macro that produces an expression that accepts both a qualified name and an
// unqualified name for a LogSeverity, and returns a LogSeverity value.
@@ -303,20 +307,6 @@
} \
} while (false)
-// CHECK that can be used in a constexpr function. For example:
-//
-// constexpr int half(int n) {
-// return
-// DCHECK_CONSTEXPR(n >= 0, , 0)
-// CHECK_CONSTEXPR((n & 1) == 0),
-// << "Extra debugging output: n = " << n, 0)
-// n / 2;
-// }
-#define CHECK_CONSTEXPR(x, out, dummy) \
- (UNLIKELY(!(x))) \
- ? (LOG(FATAL) << "Check failed: " << #x out, dummy) \
- :
-
// DCHECKs are debug variants of CHECKs only enabled in debug builds. Generally
// CHECK should be used unless profiling identifies a CHECK as being in
// performance critical code.
@@ -344,11 +334,6 @@
if (::android::base::kEnableDChecks) CHECK_STREQ(s1, s2)
#define DCHECK_STRNE(s1, s2) \
if (::android::base::kEnableDChecks) CHECK_STRNE(s1, s2)
-#if defined(NDEBUG) && !defined(__clang_analyzer__)
-#define DCHECK_CONSTEXPR(x, out, dummy)
-#else
-#define DCHECK_CONSTEXPR(x, out, dummy) CHECK_CONSTEXPR(x, out, dummy)
-#endif
namespace log_detail {
diff --git a/logging.cpp b/logging.cpp
index 5bd21da..d6ecc78 100644
--- a/logging.cpp
+++ b/logging.cpp
@@ -385,8 +385,8 @@
case 'f':
SetMinimumLogSeverity(FATAL_WITHOUT_ABORT);
continue;
- // liblog will even suppress FATAL if you say 's' for silent, but that's
- // crazy!
+ // liblog will even suppress FATAL if you say 's' for silent, but fatal should
+ // never be suppressed.
case 's':
SetMinimumLogSeverity(FATAL_WITHOUT_ABORT);
continue;
@@ -397,7 +397,8 @@
}
}
-void SetLogger(LogFunction&& logger) {
+LogFunction SetLogger(LogFunction&& logger) {
+ LogFunction old_logger = std::move(Logger());
Logger() = std::move(logger);
static auto& liblog_functions = GetLibLogFunctions();
@@ -410,9 +411,11 @@
log_message->message);
});
}
+ return old_logger;
}
-void SetAborter(AbortFunction&& aborter) {
+AbortFunction SetAborter(AbortFunction&& aborter) {
+ AbortFunction old_aborter = std::move(Aborter());
Aborter() = std::move(aborter);
static auto& liblog_functions = GetLibLogFunctions();
@@ -420,6 +423,7 @@
liblog_functions->__android_log_set_aborter(
[](const char* abort_message) { Aborter()(abort_message); });
}
+ return old_aborter;
}
// This indirection greatly reduces the stack impact of having lots of
diff --git a/logging_test.cpp b/logging_test.cpp
index d8d0855..be2e042 100644
--- a/logging_test.cpp
+++ b/logging_test.cpp
@@ -619,6 +619,14 @@
EXPECT_EQ(CountLineAborter::newline_count, 1U);
}
+TEST(logging, SetAborterReturnsOldFunction) {
+ // std::function is not comparable, it only supports a null check.
+ android::base::AbortFunction old_aborter;
+ EXPECT_FALSE(old_aborter);
+ old_aborter = android::base::SetAborter(android::base::DefaultAborter);
+ EXPECT_TRUE(old_aborter);
+}
+
__attribute__((constructor)) void TestLoggingInConstructor() {
LOG(ERROR) << "foobar";
}
@@ -638,6 +646,14 @@
ASSERT_EQ(android::base::Basename(android::base::GetExecutablePath()) + ": err\n", cap_err.str());
}
+TEST(logging, SetLoggerReturnsOldFunction) {
+ // std::function is not comparable, it only supports a null check.
+ android::base::LogFunction old_function;
+ EXPECT_FALSE(old_function);
+ old_function = android::base::SetLogger(android::base::StdioLogger);
+ EXPECT_TRUE(old_function);
+}
+
TEST(logging, ForkSafe) {
#if !defined(_WIN32)
using namespace android::base;
diff --git a/test_utils_test.cpp b/test_utils_test.cpp
index 15a79dd..d08d5d6 100644
--- a/test_utils_test.cpp
+++ b/test_utils_test.cpp
@@ -47,19 +47,24 @@
TEST(TestUtilsTest, CaptureStdout_smoke) {
CapturedStdout cap;
printf("This should be captured.\n");
+ fflush(stdout);
cap.Stop();
printf("This will not be captured.\n");
+ fflush(stdout);
ASSERT_EQ("This should be captured.\n", cap.str());
cap.Start();
printf("And this text should be captured too.\n");
+ fflush(stdout);
cap.Stop();
ASSERT_EQ("This should be captured.\nAnd this text should be captured too.\n", cap.str());
printf("Still not going to be captured.\n");
+ fflush(stdout);
cap.Reset();
cap.Start();
printf("Only this will be captured.\n");
+ fflush(stdout);
ASSERT_EQ("Only this will be captured.\n", cap.str());
}