From bca22369f6b743ccaf5d397a8a8d7e35edc7541b Mon Sep 17 00:00:00 2001 From: Shane Carr Date: Fri, 6 Oct 2017 02:03:16 +0000 Subject: [PATCH] ICU-13177 Fixing dependency check errors in number formatting code. X-SVN-Rev: 40586 --- icu4c/source/i18n/number_decimalquantity.cpp | 16 +++++++++------- icu4c/source/i18n/number_formatimpl.h | 2 +- icu4c/source/i18n/number_longnames.h | 2 +- icu4c/source/i18n/number_patternmodifier.h | 8 ++++++-- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/icu4c/source/i18n/number_decimalquantity.cpp b/icu4c/source/i18n/number_decimalquantity.cpp index fc08eda6dc5..af6223ecb7e 100644 --- a/icu4c/source/i18n/number_decimalquantity.cpp +++ b/icu4c/source/i18n/number_decimalquantity.cpp @@ -87,7 +87,7 @@ DecimalQuantity::DecimalQuantity() { DecimalQuantity::~DecimalQuantity() { if (usingBytes) { - delete[] fBCD.bcdBytes.ptr; + uprv_free(fBCD.bcdBytes.ptr); fBCD.bcdBytes.ptr = nullptr; usingBytes = false; } @@ -383,7 +383,7 @@ void DecimalQuantity::_setToDoubleFast(double n) { for (; i <= -22; i += 22) n /= 1e22; n /= DOUBLE_MULTIPLIERS[-i]; } - auto result = static_cast(round(n)); + auto result = static_cast(std::round(n)); if (result != 0) { _setToLong(result); scale -= fracLength; @@ -764,7 +764,7 @@ void DecimalQuantity::shiftRight(int32_t numDigits) { void DecimalQuantity::setBcdToZero() { if (usingBytes) { - delete[] fBCD.bcdBytes.ptr; + uprv_free(fBCD.bcdBytes.ptr); fBCD.bcdBytes.ptr = nullptr; usingBytes = false; } @@ -885,16 +885,18 @@ void DecimalQuantity::ensureCapacity(int32_t capacity) { int32_t oldCapacity = usingBytes ? fBCD.bcdBytes.len : 0; if (!usingBytes) { // TODO: There is nothing being done to check for memory allocation failures. - fBCD.bcdBytes.ptr = new int8_t[capacity]; + // TODO: Consider indexing by nybbles instead of bytes in C++, so that we can + // make these arrays half the size. + fBCD.bcdBytes.ptr = static_cast(uprv_malloc(capacity * sizeof(int8_t))); fBCD.bcdBytes.len = capacity; // Initialize the byte array to zeros (this is done automatically in Java) uprv_memset(fBCD.bcdBytes.ptr, 0, capacity * sizeof(int8_t)); } else if (oldCapacity < capacity) { - auto bcd1 = new int8_t[capacity * 2]; + auto bcd1 = static_cast(uprv_malloc(capacity * 2 * sizeof(int8_t))); uprv_memcpy(bcd1, fBCD.bcdBytes.ptr, oldCapacity * sizeof(int8_t)); // Initialize the rest of the byte array to zeros (this is done automatically in Java) uprv_memset(fBCD.bcdBytes.ptr + oldCapacity, 0, (capacity - oldCapacity) * sizeof(int8_t)); - delete[] fBCD.bcdBytes.ptr; + uprv_free(fBCD.bcdBytes.ptr); fBCD.bcdBytes.ptr = bcd1; fBCD.bcdBytes.len = capacity * 2; } @@ -909,7 +911,7 @@ void DecimalQuantity::switchStorage() { bcdLong <<= 4; bcdLong |= fBCD.bcdBytes.ptr[i]; } - delete[] fBCD.bcdBytes.ptr; + uprv_free(fBCD.bcdBytes.ptr); fBCD.bcdBytes.ptr = nullptr; fBCD.bcdLong = bcdLong; usingBytes = false; diff --git a/icu4c/source/i18n/number_formatimpl.h b/icu4c/source/i18n/number_formatimpl.h index f92eb82c834..cbc04ba30df 100644 --- a/icu4c/source/i18n/number_formatimpl.h +++ b/icu4c/source/i18n/number_formatimpl.h @@ -22,7 +22,7 @@ namespace impl { * This is the "brain" of the number formatting pipeline. It ties all the pieces together, taking in a MacroProps and a * DecimalQuantity and outputting a properly formatted number string. */ -class NumberFormatterImpl { +class NumberFormatterImpl : public UMemory { public: /** * Builds a "safe" MicroPropsGenerator, which is thread-safe and can be used repeatedly. diff --git a/icu4c/source/i18n/number_longnames.h b/icu4c/source/i18n/number_longnames.h index f30fb501b8d..22ecbac30e1 100644 --- a/icu4c/source/i18n/number_longnames.h +++ b/icu4c/source/i18n/number_longnames.h @@ -14,7 +14,7 @@ U_NAMESPACE_BEGIN namespace number { namespace impl { -class LongNameHandler : public MicroPropsGenerator, public UObject { +class LongNameHandler : public MicroPropsGenerator, public UMemory { public: static LongNameHandler forCurrencyLongNames(const Locale &loc, const CurrencyUnit ¤cy, const PluralRules *rules, diff --git a/icu4c/source/i18n/number_patternmodifier.h b/icu4c/source/i18n/number_patternmodifier.h index 267c7f78981..3679ad1f9ff 100644 --- a/icu4c/source/i18n/number_patternmodifier.h +++ b/icu4c/source/i18n/number_patternmodifier.h @@ -32,7 +32,7 @@ template class U_I18N_API LocalPointer; #endif // Exported as U_I18N_API because it is needed for the unit test PatternModifierTest -class U_I18N_API ImmutablePatternModifier : public MicroPropsGenerator { +class U_I18N_API ImmutablePatternModifier : public MicroPropsGenerator, public UMemory { public: ~ImmutablePatternModifier() U_OVERRIDE = default; @@ -70,7 +70,11 @@ class U_I18N_API ImmutablePatternModifier : public MicroPropsGenerator { * variant. */ class U_I18N_API MutablePatternModifier - : public MicroPropsGenerator, public Modifier, public SymbolProvider, public CharSequence { + : public MicroPropsGenerator, + public Modifier, + public SymbolProvider, + public CharSequence, + public UMemory { public: ~MutablePatternModifier() U_OVERRIDE = default; -- 2.40.0