From 3e671c7821e6f4d80db8089e7e580e5f7448a495 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Tue, 22 May 2018 07:57:43 -0700 Subject: [PATCH] - f619bd3c1ab57586b7ed6010db09cdaf8a6882f9 Fix comment typos in strings/numbers.h . by Daniel Katz - 1f7096d96dcf2a75ba13c210b709432165a05963 Internal namespace change by Gennadiy Rozental - ac2911b3047a79a1fc8bbcdd3f3cb24b02ab0054 Fixing -Wunused-function warning in failure_signal_handler. by Abseil Team GitOrigin-RevId: f619bd3c1ab57586b7ed6010db09cdaf8a6882f9 Change-Id: Ib09117eacfcb40ad25b216dbe8dcc9b8f1a0df6c --- absl/debugging/failure_signal_handler.cc | 4 +-- absl/strings/numbers.h | 36 +++++++++++++++--------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/absl/debugging/failure_signal_handler.cc b/absl/debugging/failure_signal_handler.cc index 46ef7b8f..4c131fe0 100644 --- a/absl/debugging/failure_signal_handler.cc +++ b/absl/debugging/failure_signal_handler.cc @@ -158,6 +158,8 @@ static bool SetupAlternateStackOnce() { #endif +#ifdef ABSL_HAVE_SIGACTION + // Sets up an alternate stack for signal handlers once. // Returns the appropriate flag for sig_action.sa_flags // if the system supports using an alternate stack. @@ -170,8 +172,6 @@ static int MaybeSetupAlternateStack() { #endif } -#ifdef ABSL_HAVE_SIGACTION - static void InstallOneFailureHandler(FailureSignalData* data, void (*handler)(int, siginfo_t*, void*)) { struct sigaction act; diff --git a/absl/strings/numbers.h b/absl/strings/numbers.h index adf706a4..75925e61 100644 --- a/absl/strings/numbers.h +++ b/absl/strings/numbers.h @@ -124,17 +124,11 @@ char* FastIntToBuffer(int_type i, char* buffer) { } } -} // namespace numbers_internal - -// SimpleAtoi() -// -// Converts a std::string to an integer, using `safe_strto?()` functions for actual -// parsing, returning `true` if successful. The `safe_strto?()` functions apply -// strict checking; the std::string must be a base-10 integer, optionally followed or -// preceded by ASCII whitespace, with a value in the range of the corresponding -// integer type. +// Implementation of SimpleAtoi, generalized to support arbitrary base (used +// with base different from 10 elsewhere in Abseil implementation). template -ABSL_MUST_USE_RESULT bool SimpleAtoi(absl::string_view s, int_type* out) { +ABSL_MUST_USE_RESULT bool safe_strtoi_base(absl::string_view s, int_type* out, + int base) { static_assert(sizeof(*out) == 4 || sizeof(*out) == 8, "SimpleAtoi works only with 32-bit or 64-bit integers."); static_assert(!std::is_floating_point::value, @@ -146,27 +140,41 @@ ABSL_MUST_USE_RESULT bool SimpleAtoi(absl::string_view s, int_type* out) { if (static_cast(1) - 2 < 0) { // Signed if (sizeof(*out) == 64 / 8) { // 64-bit int64_t val; - parsed = numbers_internal::safe_strto64_base(s, &val, 10); + parsed = numbers_internal::safe_strto64_base(s, &val, base); *out = static_cast(val); } else { // 32-bit int32_t val; - parsed = numbers_internal::safe_strto32_base(s, &val, 10); + parsed = numbers_internal::safe_strto32_base(s, &val, base); *out = static_cast(val); } } else { // Unsigned if (sizeof(*out) == 64 / 8) { // 64-bit uint64_t val; - parsed = numbers_internal::safe_strtou64_base(s, &val, 10); + parsed = numbers_internal::safe_strtou64_base(s, &val, base); *out = static_cast(val); } else { // 32-bit uint32_t val; - parsed = numbers_internal::safe_strtou32_base(s, &val, 10); + parsed = numbers_internal::safe_strtou32_base(s, &val, base); *out = static_cast(val); } } return parsed; } +} // namespace numbers_internal + +// SimpleAtoi() +// +// Converts a std::string to an integer, using `safe_strto?()` functions for actual +// parsing, returning `true` if successful. The `safe_strto?()` functions apply +// strict checking; the std::string must be a base-10 integer, optionally followed or +// preceded by ASCII whitespace, with a value in the range of the corresponding +// integer type. +template +ABSL_MUST_USE_RESULT bool SimpleAtoi(absl::string_view s, int_type* out) { + return numbers_internal::safe_strtoi_base(s, out, 10); +} + } // namespace absl #endif // ABSL_STRINGS_NUMBERS_H_