Skip to content

Commit

Permalink
ICU-21957 Update double-conversion to 256ac809561b756645e73ab7127c2aa…
Browse files Browse the repository at this point in the history
…aeabaa427

See #2179
  • Loading branch information
sffc committed Sep 9, 2022
1 parent b9fdd2a commit e4df304
Show file tree
Hide file tree
Showing 20 changed files with 146 additions and 121 deletions.
15 changes: 8 additions & 7 deletions icu4c/source/i18n/double-conversion-bignum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ void Bignum::AssignHexString(Vector<const char> value) {
DOUBLE_CONVERSION_ASSERT(sizeof(uint64_t) * 8 >= kBigitSize + 4); // TODO: static_assert
// Accumulates converted hex digits until at least kBigitSize bits.
// Works with non-factor-of-four kBigitSizes.
uint64_t tmp = 0; // Accumulates converted hex digits until at least
uint64_t tmp = 0;
for (int cnt = 0; !value.is_empty(); value.pop_back()) {
tmp |= (HexCharValue(value.last()) << cnt);
if ((cnt += 4) >= kBigitSize) {
Expand All @@ -160,7 +160,8 @@ void Bignum::AssignHexString(Vector<const char> value) {
}
}
if (tmp > 0) {
RawBigit(used_bigits_++) = tmp;
DOUBLE_CONVERSION_ASSERT(tmp <= kBigitMask);
RawBigit(used_bigits_++) = static_cast<Bignum::Chunk>(tmp & kBigitMask);
}
Clamp();
}
Expand Down Expand Up @@ -217,7 +218,7 @@ void Bignum::AddBignum(const Bignum& other) {
carry = sum >> kBigitSize;
++bigit_pos;
}
used_bigits_ = (std::max)(bigit_pos, static_cast<int>(used_bigits_));
used_bigits_ = static_cast<int16_t>(std::max(bigit_pos, static_cast<int>(used_bigits_)));
DOUBLE_CONVERSION_ASSERT(IsClamped());
}

Expand Down Expand Up @@ -253,7 +254,7 @@ void Bignum::ShiftLeft(const int shift_amount) {
if (used_bigits_ == 0) {
return;
}
exponent_ += (shift_amount / kBigitSize);
exponent_ += static_cast<int16_t>(shift_amount / kBigitSize);
const int local_shift = shift_amount % kBigitSize;
EnsureCapacity(used_bigits_ + 1);
BigitsShiftLeft(local_shift);
Expand Down Expand Up @@ -431,7 +432,7 @@ void Bignum::Square() {
DOUBLE_CONVERSION_ASSERT(accumulator == 0);

// Don't forget to update the used_digits and the exponent.
used_bigits_ = product_length;
used_bigits_ = static_cast<int16_t>(product_length);
exponent_ *= 2;
Clamp();
}
Expand Down Expand Up @@ -752,8 +753,8 @@ void Bignum::Align(const Bignum& other) {
for (int i = 0; i < zero_bigits; ++i) {
RawBigit(i) = 0;
}
used_bigits_ += zero_bigits;
exponent_ -= zero_bigits;
used_bigits_ += static_cast<int16_t>(zero_bigits);
exponent_ -= static_cast<int16_t>(zero_bigits);

DOUBLE_CONVERSION_ASSERT(used_bigits_ >= 0);
DOUBLE_CONVERSION_ASSERT(exponent_ >= 0);
Expand Down
4 changes: 2 additions & 2 deletions icu4c/source/i18n/double-conversion-double-to-string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ bool DoubleToStringConverter::HandleSpecialValues(
StringBuilder* result_builder) const {
Double double_inspect(value);
if (double_inspect.IsInfinite()) {
if (infinity_symbol_ == NULL) return false;
if (infinity_symbol_ == DOUBLE_CONVERSION_NULLPTR) return false;
if (value < 0) {
result_builder->AddCharacter('-');
}
result_builder->AddString(infinity_symbol_);
return true;
}
if (double_inspect.IsNan()) {
if (nan_symbol_ == NULL) return false;
if (nan_symbol_ == DOUBLE_CONVERSION_NULLPTR) return false;
result_builder->AddString(nan_symbol_);
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions icu4c/source/i18n/double-conversion-string-to-double.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ double StringToDoubleConverter::StringToIeee(
current = next_non_space;
}

if (infinity_symbol_ != NULL) {
if (infinity_symbol_ != DOUBLE_CONVERSION_NULLPTR) {
if (ConsumeFirstCharacter(*current, infinity_symbol_, allow_case_insensitivity)) {
if (!ConsumeSubString(&current, end, infinity_symbol_, allow_case_insensitivity)) {
return junk_string_value_;
Expand All @@ -513,7 +513,7 @@ double StringToDoubleConverter::StringToIeee(
}
}

if (nan_symbol_ != NULL) {
if (nan_symbol_ != DOUBLE_CONVERSION_NULLPTR) {
if (ConsumeFirstCharacter(*current, nan_symbol_, allow_case_insensitivity)) {
if (!ConsumeSubString(&current, end, nan_symbol_, allow_case_insensitivity)) {
return junk_string_value_;
Expand Down
13 changes: 10 additions & 3 deletions icu4c/source/i18n/double-conversion-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@
#include <cstdlib>
#include <cstring>

// For pre-C++11 compatibility
#if __cplusplus >= 201103L
#define DOUBLE_CONVERSION_NULLPTR nullptr
#else
#define DOUBLE_CONVERSION_NULLPTR NULL
#endif

// ICU PATCH: Use U_ASSERT instead of <assert.h>
#include "uassert.h"
#ifndef DOUBLE_CONVERSION_ASSERT
Expand Down Expand Up @@ -254,9 +261,9 @@ inline int StrLength(const char* string) {
template <typename T>
class Vector {
public:
Vector() : start_(NULL), length_(0) {}
Vector() : start_(DOUBLE_CONVERSION_NULLPTR), length_(0) {}
Vector(T* data, int len) : start_(data), length_(len) {
DOUBLE_CONVERSION_ASSERT(len == 0 || (len > 0 && data != NULL));
DOUBLE_CONVERSION_ASSERT(len == 0 || (len > 0 && data != DOUBLE_CONVERSION_NULLPTR));
}

// Returns a vector using the same backing storage as this one,
Expand Down Expand Up @@ -339,7 +346,7 @@ class StringBuilder {
void AddSubstring(const char* s, int n) {
DOUBLE_CONVERSION_ASSERT(!is_finalized() && position_ + n < buffer_.length());
DOUBLE_CONVERSION_ASSERT(static_cast<size_t>(n) <= strlen(s));
memmove(&buffer_[position_], s, n);
memmove(&buffer_[position_], s, static_cast<size_t>(n));
position_ += n;
}

Expand Down
34 changes: 0 additions & 34 deletions vendor/double-conversion/upstream/.github/workflows/cmake.yml

This file was deleted.

12 changes: 12 additions & 0 deletions vendor/double-conversion/upstream/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
cmake_minimum_required(VERSION 3.0)
project(double-conversion VERSION 3.2.0)

option(BUILD_SHARED_LIBS "Build shared libraries (.dll/.so) instead of static ones (.lib/.a)" OFF)

if(BUILD_SHARED_LIBS AND MSVC)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
endif()
Expand Down Expand Up @@ -116,3 +118,13 @@ install(
NAMESPACE "${namespace}"
DESTINATION "${config_install_dir}"
)

if (MSVC AND BUILD_SHARED_LIBS)
# Install companion PDB for Visual Studio
install(
FILES $<TARGET_PDB_FILE:double-conversion>
TYPE BIN
OPTIONAL
)
endif()

3 changes: 3 additions & 0 deletions vendor/double-conversion/upstream/Changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
2022-01-16:
Install Visual Studio debugger (pdb) files.

2022-01-10:
Fix quiet NANs on MIPS* and PA-RISC architectures.
Update version number.
Expand Down
15 changes: 8 additions & 7 deletions vendor/double-conversion/upstream/double-conversion/bignum.cc
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void Bignum::AssignHexString(Vector<const char> value) {
DOUBLE_CONVERSION_ASSERT(sizeof(uint64_t) * 8 >= kBigitSize + 4); // TODO: static_assert
// Accumulates converted hex digits until at least kBigitSize bits.
// Works with non-factor-of-four kBigitSizes.
uint64_t tmp = 0; // Accumulates converted hex digits until at least
uint64_t tmp = 0;
for (int cnt = 0; !value.is_empty(); value.pop_back()) {
tmp |= (HexCharValue(value.last()) << cnt);
if ((cnt += 4) >= kBigitSize) {
Expand All @@ -146,7 +146,8 @@ void Bignum::AssignHexString(Vector<const char> value) {
}
}
if (tmp > 0) {
RawBigit(used_bigits_++) = tmp;
DOUBLE_CONVERSION_ASSERT(tmp <= kBigitMask);
RawBigit(used_bigits_++) = static_cast<Bignum::Chunk>(tmp & kBigitMask);
}
Clamp();
}
Expand Down Expand Up @@ -203,7 +204,7 @@ void Bignum::AddBignum(const Bignum& other) {
carry = sum >> kBigitSize;
++bigit_pos;
}
used_bigits_ = (std::max)(bigit_pos, static_cast<int>(used_bigits_));
used_bigits_ = static_cast<int16_t>(std::max(bigit_pos, static_cast<int>(used_bigits_)));
DOUBLE_CONVERSION_ASSERT(IsClamped());
}

Expand Down Expand Up @@ -239,7 +240,7 @@ void Bignum::ShiftLeft(const int shift_amount) {
if (used_bigits_ == 0) {
return;
}
exponent_ += (shift_amount / kBigitSize);
exponent_ += static_cast<int16_t>(shift_amount / kBigitSize);
const int local_shift = shift_amount % kBigitSize;
EnsureCapacity(used_bigits_ + 1);
BigitsShiftLeft(local_shift);
Expand Down Expand Up @@ -417,7 +418,7 @@ void Bignum::Square() {
DOUBLE_CONVERSION_ASSERT(accumulator == 0);

// Don't forget to update the used_digits and the exponent.
used_bigits_ = product_length;
used_bigits_ = static_cast<int16_t>(product_length);
exponent_ *= 2;
Clamp();
}
Expand Down Expand Up @@ -738,8 +739,8 @@ void Bignum::Align(const Bignum& other) {
for (int i = 0; i < zero_bigits; ++i) {
RawBigit(i) = 0;
}
used_bigits_ += zero_bigits;
exponent_ -= zero_bigits;
used_bigits_ += static_cast<int16_t>(zero_bigits);
exponent_ -= static_cast<int16_t>(zero_bigits);

DOUBLE_CONVERSION_ASSERT(used_bigits_ >= 0);
DOUBLE_CONVERSION_ASSERT(exponent_ >= 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ bool DoubleToStringConverter::HandleSpecialValues(
StringBuilder* result_builder) const {
Double double_inspect(value);
if (double_inspect.IsInfinite()) {
if (infinity_symbol_ == NULL) return false;
if (infinity_symbol_ == DOUBLE_CONVERSION_NULLPTR) return false;
if (value < 0) {
result_builder->AddCharacter('-');
}
result_builder->AddString(infinity_symbol_);
return true;
}
if (double_inspect.IsNan()) {
if (nan_symbol_ == NULL) return false;
if (nan_symbol_ == DOUBLE_CONVERSION_NULLPTR) return false;
result_builder->AddString(nan_symbol_);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ double StringToDoubleConverter::StringToIeee(
current = next_non_space;
}

if (infinity_symbol_ != NULL) {
if (infinity_symbol_ != DOUBLE_CONVERSION_NULLPTR) {
if (ConsumeFirstCharacter(*current, infinity_symbol_, allow_case_insensitivity)) {
if (!ConsumeSubString(&current, end, infinity_symbol_, allow_case_insensitivity)) {
return junk_string_value_;
Expand All @@ -492,7 +492,7 @@ double StringToDoubleConverter::StringToIeee(
}
}

if (nan_symbol_ != NULL) {
if (nan_symbol_ != DOUBLE_CONVERSION_NULLPTR) {
if (ConsumeFirstCharacter(*current, nan_symbol_, allow_case_insensitivity)) {
if (!ConsumeSubString(&current, end, nan_symbol_, allow_case_insensitivity)) {
return junk_string_value_;
Expand Down
13 changes: 10 additions & 3 deletions vendor/double-conversion/upstream/double-conversion/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@
#include <cstdlib>
#include <cstring>

// For pre-C++11 compatibility
#if __cplusplus >= 201103L
#define DOUBLE_CONVERSION_NULLPTR nullptr
#else
#define DOUBLE_CONVERSION_NULLPTR NULL
#endif

#include <cassert>
#ifndef DOUBLE_CONVERSION_ASSERT
#define DOUBLE_CONVERSION_ASSERT(condition) \
Expand Down Expand Up @@ -241,9 +248,9 @@ inline int StrLength(const char* string) {
template <typename T>
class Vector {
public:
Vector() : start_(NULL), length_(0) {}
Vector() : start_(DOUBLE_CONVERSION_NULLPTR), length_(0) {}
Vector(T* data, int len) : start_(data), length_(len) {
DOUBLE_CONVERSION_ASSERT(len == 0 || (len > 0 && data != NULL));
DOUBLE_CONVERSION_ASSERT(len == 0 || (len > 0 && data != DOUBLE_CONVERSION_NULLPTR));
}

// Returns a vector using the same backing storage as this one,
Expand Down Expand Up @@ -326,7 +333,7 @@ class StringBuilder {
void AddSubstring(const char* s, int n) {
DOUBLE_CONVERSION_ASSERT(!is_finalized() && position_ + n < buffer_.length());
DOUBLE_CONVERSION_ASSERT(static_cast<size_t>(n) <= strlen(s));
memmove(&buffer_[position_], s, n);
memmove(&buffer_[position_], s, static_cast<size_t>(n));
position_ += n;
}

Expand Down
15 changes: 12 additions & 3 deletions vendor/double-conversion/upstream/test/cctest/cctest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@

CcTest* CcTest::last_ = NULL;

// The windows compiler doesn't like to use `strdup`, and claims it's a
// deprecated name.
// For simplicity just implement it ourselves.
static char* Strdup(const char* str) {
size_t len = strlen(str);
char* result = reinterpret_cast<char*>(malloc(len + 1));
memcpy(result, str, len + 1);
return result;
}

CcTest::CcTest(TestFunction* callback, const char* test_file,
const char* test_name, const char* test_dependency,
Expand All @@ -45,9 +54,9 @@ CcTest::CcTest(TestFunction* callback, const char* test_file,
basename = strrchr(const_cast<char *>(test_file), '\\');
}
if (!basename) {
basename = strdup(test_file);
basename = Strdup(test_file);
} else {
basename = strdup(basename + 1);
basename = Strdup(basename + 1);
}
// Drop the extension, if there is one.
char *extension = strrchr(basename, '.');
Expand Down Expand Up @@ -93,7 +102,7 @@ int main(int argc, char* argv[]) {
print_run_count = false;

} else {
char* arg_copy = strdup(arg);
char* arg_copy = Strdup(arg);
char* testname = strchr(arg_copy, '/');
if (testname) {
// Split the string in two by nulling the slash and then run
Expand Down
Loading

0 comments on commit e4df304

Please sign in to comment.