From 30c37a9114f2bff6231f07dc4a6398aa3e0d08bd Mon Sep 17 00:00:00 2001 From: Markus Scherer Date: Tue, 16 Jul 2002 01:55:55 +0000 Subject: [PATCH] ICU-1962 use uprv_malloc/free instead of new/delete for non-class types X-SVN-Rev: 9194 --- icu4c/source/common/brkdict.cpp | 20 ++++++++++---------- icu4c/source/common/charstr.h | 5 +++-- icu4c/source/common/normlzr.cpp | 21 +++++++++++++-------- icu4c/source/common/rbbiscan.cpp | 4 ++-- icu4c/source/common/rbbisetb.cpp | 5 ++++- icu4c/source/common/rbbisetb.h | 23 ++++++++++++++++++++++- icu4c/source/common/unistr.cpp | 2 +- 7 files changed, 55 insertions(+), 25 deletions(-) diff --git a/icu4c/source/common/brkdict.cpp b/icu4c/source/common/brkdict.cpp index 6f3977cb967..396c8e0b12d 100644 --- a/icu4c/source/common/brkdict.cpp +++ b/icu4c/source/common/brkdict.cpp @@ -48,11 +48,11 @@ BreakDictionary::BreakDictionary(const char* dictionaryFilename, UErrorCode& sta BreakDictionary::~BreakDictionary() { ucmp8_close(columnMap); - delete [] table; - delete [] rowIndex; - delete [] rowIndexFlags; - delete [] rowIndexFlagsIndex; - delete [] rowIndexShifts; + uprv_free(table); + uprv_free(rowIndex); + uprv_free(rowIndexFlags); + uprv_free(rowIndexFlagsIndex); + uprv_free(rowIndexShifts); } // macros to support readDictionaryFile. The data files originated from a Java @@ -102,7 +102,7 @@ BreakDictionary::readDictionaryFile(UMemoryStream* in) // read in the row-number index uprv_mstrm_read(in, &l, 4); SWAP32(l); - rowIndex = new int16_t[l]; + rowIndex = (int16_t *)uprv_malloc(l*2); uprv_mstrm_read(in, rowIndex, l * sizeof (int16_t) ); for (i = 0; i < l; i++) { SWAP16(rowIndex[i]); @@ -111,14 +111,14 @@ BreakDictionary::readDictionaryFile(UMemoryStream* in) // load in the populated-cells bitmap: index first, then bitmap list uprv_mstrm_read(in, &l, 4); SWAP32(l); - rowIndexFlagsIndex = new int16_t[l]; + rowIndexFlagsIndex = (int16_t *)uprv_malloc(l*2); uprv_mstrm_read(in, rowIndexFlagsIndex, l * sizeof(int16_t) ); for (i = 0; i < l; i++) { SWAP16(rowIndexFlagsIndex[i]); } uprv_mstrm_read(in, &l, 4); SWAP32(l); - rowIndexFlags = new int32_t[l]; + rowIndexFlags = (int32_t *)uprv_malloc(l*4); uprv_mstrm_read(in, rowIndexFlags, l * sizeof(int32_t)); for (i = 0; i < l; i++) { SWAP32(rowIndexFlags[i]); @@ -127,13 +127,13 @@ BreakDictionary::readDictionaryFile(UMemoryStream* in) // load in the row-shift index uprv_mstrm_read(in, &l, 4); SWAP32(l); - rowIndexShifts = new int8_t[l]; + rowIndexShifts = (int8_t *)uprv_malloc(l); uprv_mstrm_read(in, rowIndexShifts, l); // finally, load in the actual state table uprv_mstrm_read(in, &l, 4); SWAP32(l); - table = new int16_t[l]; + table = (int16_t *)uprv_malloc(l*2); uprv_mstrm_read(in, table, l * sizeof(int16_t) ); for (i = 0; i < l; i++) { SWAP16(table[i]); diff --git a/icu4c/source/common/charstr.h b/icu4c/source/common/charstr.h index 6994aa18ca4..05500e31e49 100644 --- a/icu4c/source/common/charstr.h +++ b/icu4c/source/common/charstr.h @@ -11,6 +11,7 @@ #include "unicode/utypes.h" #include "unicode/uobject.h" #include "unicode/unistr.h" +#include "cmemory.h" //-------------------------------------------------------------------- // class CharString @@ -57,7 +58,7 @@ inline CharString::CharString(const UnicodeString& str) { // TODO This isn't quite right -- we should probably do // preflighting here to determine the real length. if (str.length() >= (int32_t)sizeof(buf)) { - ptr = new char[str.length() + 8]; + ptr = (char *)uprv_malloc(str.length() + 8); } else { ptr = buf; } @@ -66,7 +67,7 @@ inline CharString::CharString(const UnicodeString& str) { inline CharString::~CharString() { if (ptr != buf) { - delete[] ptr; + uprv_free(ptr); } } diff --git a/icu4c/source/common/normlzr.cpp b/icu4c/source/common/normlzr.cpp index aa3ad1003c4..e3769c8bd3d 100644 --- a/icu4c/source/common/normlzr.cpp +++ b/icu4c/source/common/normlzr.cpp @@ -110,20 +110,25 @@ void Normalizer::init(CharacterIterator *iter) { UErrorCode errorCode=U_ZERO_ERROR; - text=new UCharIterator; - - if(unorm_haveData(&errorCode)) { - uiter_setCharacterIterator(text, iter); + text=(UCharIterator *)uprv_malloc(sizeof(UCharIterator)); + if(text!=NULL) { + if(unorm_haveData(&errorCode)) { + uiter_setCharacterIterator(text, iter); + } else { + delete iter; + uiter_setCharacterIterator(text, new UCharCharacterIterator(&_NUL, 0)); + } } else { delete iter; - uiter_setCharacterIterator(text, new UCharCharacterIterator(&_NUL, 0)); } } Normalizer::~Normalizer() { - delete (CharacterIterator *)text->context; - delete text; + if(text!=NULL) { + delete (CharacterIterator *)text->context; + uprv_free(text); + } } Normalizer* @@ -300,7 +305,7 @@ Normalizer::concatenate(UnicodeString &left, UnicodeString &right, //------------------------------------------------------------------------- /** - * Return the current character in the normalized text-> + * Return the current character in the normalized text. */ UChar32 Normalizer::current() { if(bufferPoskey; // Note: px->val is owned by the linked list "fSetsListHead" in scanner. // Don't delete the value nodes here. - delete px; + uprv_free(px); }; U_CDECL_END @@ -685,7 +685,7 @@ void RBBIRuleScanner::findSetFor(const UnicodeString &s, RBBINode *node, Unicode // // Add the new set to the set hash table. // - el = new RBBISetTableEl; + el = (RBBISetTableEl *)uprv_malloc(sizeof(RBBISetTableEl)); UnicodeString *tkey = new UnicodeString(s); if (tkey == NULL || el == NULL || setToAdopt == NULL) { error(U_MEMORY_ALLOCATION_ERROR); diff --git a/icu4c/source/common/rbbisetb.cpp b/icu4c/source/common/rbbisetb.cpp index 7819fb75c9f..1902ec1d090 100644 --- a/icu4c/source/common/rbbisetb.cpp +++ b/icu4c/source/common/rbbisetb.cpp @@ -459,9 +459,12 @@ void RBBISetBuilder::printSets() { //------------------------------------------------------------------------------------- // -// RangeDesriptor copy constructor +// RangeDescriptor copy constructor // //------------------------------------------------------------------------------------- + +const char RangeDescriptor::fgClassID=0; + RangeDescriptor::RangeDescriptor(const RangeDescriptor &other, UErrorCode &status) { int i; diff --git a/icu4c/source/common/rbbisetb.h b/icu4c/source/common/rbbisetb.h index d6f41761c72..a15e2307c35 100644 --- a/icu4c/source/common/rbbisetb.h +++ b/icu4c/source/common/rbbisetb.h @@ -33,7 +33,7 @@ U_NAMESPACE_BEGIN // All of them are strung together in a linked list, which is kept in order // (by character) // -struct RangeDescriptor { +struct RangeDescriptor : public UObject { UChar32 fStartChar; // Start of range, unicode 32 bit value. UChar32 fEndChar; // End of range, unicode 32 bit value. int32_t fNum; // runtime-mapped input value for this range. @@ -49,6 +49,27 @@ struct RangeDescriptor { // where appearing in the second (higher) part. void setDictionaryFlag(); // Check whether this range appears as part of // the Unicode set named "dictionary" + + /** + * ICU "poor man's RTTI", returns a UClassID for the actual class. + * + * @draft ICU 2.2 + */ + virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); } + + /** + * ICU "poor man's RTTI", returns a UClassID for this class. + * + * @draft ICU 2.2 + */ + static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; } + +private: + /** + * The address of this static class variable serves as this class's ID + * for ICU "poor man's RTTI". + */ + static const char fgClassID; }; diff --git a/icu4c/source/common/unistr.cpp b/icu4c/source/common/unistr.cpp index f807343cf56..50e5adb6870 100644 --- a/icu4c/source/common/unistr.cpp +++ b/icu4c/source/common/unistr.cpp @@ -1195,7 +1195,7 @@ UnicodeString::caseMap(BreakIterator *titleIter, oldArray, oldLength, &errorCode); if(U_FAILURE(errorCode)) { - delete [] bufferToDelete; + uprv_free(bufferToDelete); setToBogus(); return *this; }