- f619bd3c1ab57586b7ed6010db09cdaf8a6882f9 Fix comment typos in strings/numbers.h . by Daniel Katz <katzdm@google.com>

- 1f7096d96dcf2a75ba13c210b709432165a05963 Internal namespace change by Gennadiy Rozental <rogeeff@google.com>
  - ac2911b3047a79a1fc8bbcdd3f3cb24b02ab0054 Fixing -Wunused-function warning in failure_signal_handler. by Abseil Team <absl-team@google.com>

GitOrigin-RevId: f619bd3c1ab57586b7ed6010db09cdaf8a6882f9
Change-Id: Ib09117eacfcb40ad25b216dbe8dcc9b8f1a0df6c
pull/130/head
Abseil Team 7 years ago committed by katzdm
parent 59ae4d5a0e
commit 3e671c7821
  1. 4
      absl/debugging/failure_signal_handler.cc
  2. 36
      absl/strings/numbers.h

@ -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;

@ -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 <typename int_type>
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<int_type>::value,
@ -146,27 +140,41 @@ ABSL_MUST_USE_RESULT bool SimpleAtoi(absl::string_view s, int_type* out) {
if (static_cast<int_type>(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<int_type>(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<int_type>(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<int_type>(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<int_type>(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 <typename int_type>
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_

Loading…
Cancel
Save