Commit 8a9ef3c5 by Abseil Team Committed by Derek Mauro

Export of internal Abseil changes

--
b95862447354428f62ae1627cf526e42ca0b7a9d by Christian Blichmann <cblichmann@google.com>:

Minor cleanups:
* Sorting using declarations
* Changing the format of a NOLINT statement

PiperOrigin-RevId: 348448885

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

Enable some more Emscripten tests.
Requires setting -s PRINTF_LONG_DOUBLE=1 in a recent build.

PiperOrigin-RevId: 348043610
GitOrigin-RevId: b95862447354428f62ae1627cf526e42ca0b7a9d
Change-Id: I517c94a5fd0feb9b99823dc8552d28fa598723fe
parent 9f8b87b7
...@@ -80,7 +80,7 @@ Abseil contains the following C++ library components: ...@@ -80,7 +80,7 @@ Abseil contains the following C++ library components:
* [`numeric`](absl/numeric/) * [`numeric`](absl/numeric/)
<br /> The `numeric` library contains C++11-compatible 128-bit integers. <br /> The `numeric` library contains C++11-compatible 128-bit integers.
* [`status`](absl/status/) * [`status`](absl/status/)
<br /> The `status` library contains abstractions for error handling, specifically <br /> The `status` contains abstractions for error handling, specifically
`absl::Status` and `absl::StatusOr<T>`. `absl::Status` and `absl::StatusOr<T>`.
* [`strings`](absl/strings/) * [`strings`](absl/strings/)
<br /> The `strings` library contains a variety of strings routines and <br /> The `strings` library contains a variety of strings routines and
......
...@@ -551,7 +551,9 @@ cc_test( ...@@ -551,7 +551,9 @@ cc_test(
srcs = ["internal/low_level_alloc_test.cc"], srcs = ["internal/low_level_alloc_test.cc"],
copts = ABSL_TEST_COPTS, copts = ABSL_TEST_COPTS,
linkopts = ABSL_DEFAULT_LINKOPTS, linkopts = ABSL_DEFAULT_LINKOPTS,
tags = ["no_test_ios_x86_64"], tags = [
"no_test_ios_x86_64",
],
deps = [ deps = [
":malloc_internal", ":malloc_internal",
"//absl/container:node_hash_map", "//absl/container:node_hash_map",
......
...@@ -21,6 +21,10 @@ ...@@ -21,6 +21,10 @@
#include <unordered_map> #include <unordered_map>
#include <utility> #include <utility>
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#endif
#include "absl/container/node_hash_map.h" #include "absl/container/node_hash_map.h"
namespace absl { namespace absl {
...@@ -158,5 +162,20 @@ ABSL_NAMESPACE_END ...@@ -158,5 +162,20 @@ ABSL_NAMESPACE_END
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
// The actual test runs in the global constructor of `before_main`. // The actual test runs in the global constructor of `before_main`.
printf("PASS\n"); printf("PASS\n");
#ifdef __EMSCRIPTEN__
// clang-format off
// This is JS here. Don't try to format it.
MAIN_THREAD_EM_ASM({
if (ENVIRONMENT_IS_WEB) {
if (typeof TEST_FINISH === 'function') {
TEST_FINISH($0);
} else {
console.error('Attempted to exit with status ' + $0);
console.error('But TEST_FINSIHED is not a function.');
}
}
}, 0);
// clang-format on
#endif
return 0; return 0;
} }
...@@ -47,11 +47,7 @@ using absl::random_internal::kChiSquared; ...@@ -47,11 +47,7 @@ using absl::random_internal::kChiSquared;
template <typename RealType> template <typename RealType>
class ExponentialDistributionTypedTest : public ::testing::Test {}; class ExponentialDistributionTypedTest : public ::testing::Test {};
#if defined(__EMSCRIPTEN__)
using RealTypes = ::testing::Types<float, double>;
#else
using RealTypes = ::testing::Types<float, double, long double>; using RealTypes = ::testing::Types<float, double, long double>;
#endif // defined(__EMSCRIPTEN__)
TYPED_TEST_CASE(ExponentialDistributionTypedTest, RealTypes); TYPED_TEST_CASE(ExponentialDistributionTypedTest, RealTypes);
TYPED_TEST(ExponentialDistributionTypedTest, SerializeTest) { TYPED_TEST(ExponentialDistributionTypedTest, SerializeTest) {
......
...@@ -130,15 +130,12 @@ TYPED_TEST(GaussianDistributionInterfaceTest, SerializeTest) { ...@@ -130,15 +130,12 @@ TYPED_TEST(GaussianDistributionInterfaceTest, SerializeTest) {
ss >> after; ss >> after;
#if defined(__powerpc64__) || defined(__PPC64__) || defined(__powerpc__) || \ #if defined(__powerpc64__) || defined(__PPC64__) || defined(__powerpc__) || \
defined(__ppc__) || defined(__PPC__) || defined(__EMSCRIPTEN__) defined(__ppc__) || defined(__PPC__)
if (std::is_same<TypeParam, long double>::value) { if (std::is_same<TypeParam, long double>::value) {
// Roundtripping floating point values requires sufficient precision // Roundtripping floating point values requires sufficient precision
// to reconstruct the exact value. It turns out that long double // to reconstruct the exact value. It turns out that long double
// has some errors doing this on ppc, particularly for values // has some errors doing this on ppc, particularly for values
// near {1.0 +/- epsilon}. // near {1.0 +/- epsilon}.
//
// Emscripten is even worse, implementing long double as a 128-bit
// type, but shipping with a strtold() that doesn't support that.
if (mean <= std::numeric_limits<double>::max() && if (mean <= std::numeric_limits<double>::max() &&
mean >= std::numeric_limits<double>::lowest()) { mean >= std::numeric_limits<double>::lowest()) {
EXPECT_EQ(static_cast<double>(before.mean()), EXPECT_EQ(static_cast<double>(before.mean()),
......
...@@ -14,6 +14,9 @@ ...@@ -14,6 +14,9 @@
#include "absl/random/internal/iostream_state_saver.h" #include "absl/random/internal/iostream_state_saver.h"
#include <errno.h>
#include <stdio.h>
#include <sstream> #include <sstream>
#include <string> #include <string>
...@@ -272,7 +275,6 @@ TEST(IOStreamStateSaver, RoundTripDoubles) { ...@@ -272,7 +275,6 @@ TEST(IOStreamStateSaver, RoundTripDoubles) {
} }
} }
#if !defined(__EMSCRIPTEN__)
TEST(IOStreamStateSaver, RoundTripLongDoubles) { TEST(IOStreamStateSaver, RoundTripLongDoubles) {
// Technically, C++ only guarantees that long double is at least as large as a // Technically, C++ only guarantees that long double is at least as large as a
// double. Practically it varies from 64-bits to 128-bits. // double. Practically it varies from 64-bits to 128-bits.
...@@ -350,7 +352,6 @@ TEST(IOStreamStateSaver, RoundTripLongDoubles) { ...@@ -350,7 +352,6 @@ TEST(IOStreamStateSaver, RoundTripLongDoubles) {
} }
} }
} }
#endif // !defined(__EMSCRIPTEN__)
TEST(StrToDTest, DoubleMin) { TEST(StrToDTest, DoubleMin) {
const char kV[] = "2.22507385850720138e-308"; const char kV[] = "2.22507385850720138e-308";
......
...@@ -55,11 +55,7 @@ namespace { ...@@ -55,11 +55,7 @@ namespace {
template <typename RealType> template <typename RealType>
class UniformRealDistributionTest : public ::testing::Test {}; class UniformRealDistributionTest : public ::testing::Test {};
#if defined(__EMSCRIPTEN__)
using RealTypes = ::testing::Types<float, double>;
#else
using RealTypes = ::testing::Types<float, double, long double>; using RealTypes = ::testing::Types<float, double, long double>;
#endif // defined(__EMSCRIPTEN__)
TYPED_TEST_SUITE(UniformRealDistributionTest, RealTypes); TYPED_TEST_SUITE(UniformRealDistributionTest, RealTypes);
......
//
// Copyright 2017 The Abseil Authors. // Copyright 2017 The Abseil Authors.
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
...@@ -245,13 +244,6 @@ inline size_t FastHexToBufferZeroPad16(uint64_t val, char* out) { ...@@ -245,13 +244,6 @@ inline size_t FastHexToBufferZeroPad16(uint64_t val, char* out) {
} // namespace numbers_internal } // namespace numbers_internal
// SimpleAtoi()
//
// Converts a string to an integer, using `safe_strto?()` functions for actual
// parsing, returning `true` if successful. The `safe_strto?()` functions apply
// strict checking; the 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> template <typename int_type>
ABSL_MUST_USE_RESULT bool SimpleAtoi(absl::string_view str, int_type* out) { ABSL_MUST_USE_RESULT bool SimpleAtoi(absl::string_view str, int_type* out) {
return numbers_internal::safe_strtoi_base(str, out, 10); return numbers_internal::safe_strtoi_base(str, out, 10);
......
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
namespace { namespace {
using absl::SimpleAtoi;
using absl::numbers_internal::kSixDigitsToBufferSize; using absl::numbers_internal::kSixDigitsToBufferSize;
using absl::numbers_internal::safe_strto32_base; using absl::numbers_internal::safe_strto32_base;
using absl::numbers_internal::safe_strto64_base; using absl::numbers_internal::safe_strto64_base;
...@@ -55,7 +56,6 @@ using absl::numbers_internal::SixDigitsToBuffer; ...@@ -55,7 +56,6 @@ using absl::numbers_internal::SixDigitsToBuffer;
using absl::strings_internal::Itoa; using absl::strings_internal::Itoa;
using absl::strings_internal::strtouint32_test_cases; using absl::strings_internal::strtouint32_test_cases;
using absl::strings_internal::strtouint64_test_cases; using absl::strings_internal::strtouint64_test_cases;
using absl::SimpleAtoi;
using testing::Eq; using testing::Eq;
using testing::MatchesRegex; using testing::MatchesRegex;
...@@ -380,7 +380,7 @@ TEST(NumbersTest, Atoi) { ...@@ -380,7 +380,7 @@ TEST(NumbersTest, Atoi) {
VerifySimpleAtoiGood<uint32_t>(42, 42); VerifySimpleAtoiGood<uint32_t>(42, 42);
VerifySimpleAtoiGood<unsigned int>(42, 42); VerifySimpleAtoiGood<unsigned int>(42, 42);
VerifySimpleAtoiGood<int64_t>(-42, -42); VerifySimpleAtoiGood<int64_t>(-42, -42);
VerifySimpleAtoiGood<long>(-42, -42); // NOLINT(runtime/int) VerifySimpleAtoiGood<long>(-42, -42); // NOLINT: runtime-int
VerifySimpleAtoiGood<uint64_t>(42, 42); VerifySimpleAtoiGood<uint64_t>(42, 42);
VerifySimpleAtoiGood<size_t>(42, 42); VerifySimpleAtoiGood<size_t>(42, 42);
VerifySimpleAtoiGood<std::string::size_type>(42, 42); VerifySimpleAtoiGood<std::string::size_type>(42, 42);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment