]> granicus.if.org Git - icu/commitdiff
ICU-13177 Fixing dependency check errors in number formatting code.
authorShane Carr <shane@unicode.org>
Fri, 6 Oct 2017 02:03:16 +0000 (02:03 +0000)
committerShane Carr <shane@unicode.org>
Fri, 6 Oct 2017 02:03:16 +0000 (02:03 +0000)
X-SVN-Rev: 40586

icu4c/source/i18n/number_decimalquantity.cpp
icu4c/source/i18n/number_formatimpl.h
icu4c/source/i18n/number_longnames.h
icu4c/source/i18n/number_patternmodifier.h

index fc08eda6dc5ed9325e36617929e9cb0f67e51f9a..af6223ecb7e820038bd66bcaaa9b489e3dd76f99 100644 (file)
@@ -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<int64_t>(round(n));
+    auto result = static_cast<int64_t>(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<int8_t*>(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<int8_t*>(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;
index f92eb82c8348777e7ad2f544024c73bbdd77b173..cbc04ba30df4c4c2579bc48af4f195e163b3670e 100644 (file)
@@ -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.
index f30fb501b8de258f4c5ef73fee4f8244d33309d6..22ecbac30e1ebc0fba697a0c1cfae0c026f5818d 100644 (file)
@@ -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 &currency, const PluralRules *rules,
index 267c7f78981b45616e5470d116d19fcb7b008263..3679ad1f9ff479cf240530fe4b168a604ca79d98 100644 (file)
@@ -32,7 +32,7 @@ template class U_I18N_API LocalPointer<ParameterizedModifier>;
 #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;