ICU-1962 use uprv_malloc/free instead of new/delete for non-class types

X-SVN-Rev: 9209
This commit is contained in:
Markus Scherer 2002-07-16 19:29:19 +00:00
parent 8ce39fe6ea
commit 7c5fa43519
12 changed files with 102 additions and 51 deletions

View File

@ -24,16 +24,38 @@
U_NAMESPACE_BEGIN
class CharSubstitutionFilter : public LEGlyphFilter
class CharSubstitutionFilter : public UObject, public LEGlyphFilter
{
private:
const LEFontInstance *fFontInstance;
/**
* The address of this static class variable serves as this class's ID
* for ICU "poor man's RTTI".
*/
static const char fgClassID;
public:
CharSubstitutionFilter(const LEFontInstance *fontInstance);
le_bool accept(LEGlyphID glyph) const;
/**
* 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; }
};
const char CharSubstitutionFilter::fgClassID=0;
CharSubstitutionFilter::CharSubstitutionFilter(const LEFontInstance *fontInstance)
: fFontInstance(fontInstance)
{
@ -80,7 +102,7 @@ le_int32 ArabicOpenTypeLayoutEngine::characterProcessing(const LEUnicode chars[]
return 0;
}
featureTags = new const LETag*[count];
featureTags = (const LETag **)uprv_malloc(count * sizeof(const LETag *));
if (featureTags == NULL) {
success = LE_MEMORY_ALLOCATION_ERROR;
@ -154,7 +176,7 @@ UnicodeArabicOpenTypeLayoutEngine::UnicodeArabicOpenTypeLayoutEngine(const LEFon
UnicodeArabicOpenTypeLayoutEngine::~UnicodeArabicOpenTypeLayoutEngine()
{
delete fSubstitutionFilter;
delete (CharSubstitutionFilter *)fSubstitutionFilter;
}
// "glyphs", "indices" -> glyphs, indices
@ -199,17 +221,17 @@ void UnicodeArabicOpenTypeLayoutEngine::mapCharsToGlyphs(const LEUnicode chars[]
dir = -1;
}
glyphs = new LEGlyphID[count];
glyphs = (LEGlyphID *)uprv_malloc(count * sizeof(LEGlyphID));
if (glyphs == NULL) {
success = LE_MEMORY_ALLOCATION_ERROR;
return;
}
charIndices = new le_int32[count];
charIndices = (le_int32 *)uprv_malloc(count * sizeof(le_int32));
if (charIndices == NULL) {
delete [] glyphs;
uprv_free(glyphs);
success = LE_MEMORY_ALLOCATION_ERROR;
return;
}

View File

@ -12,6 +12,8 @@
U_NAMESPACE_BEGIN
const char GDEFMarkFilter::fgClassID=0;
GDEFMarkFilter::GDEFMarkFilter(const GlyphDefinitionTableHeader *gdefTable)
{
classDefTable = gdefTable->getGlyphClassDefinitionTable();

View File

@ -14,16 +14,36 @@
U_NAMESPACE_BEGIN
class GDEFMarkFilter : public LEGlyphFilter
class GDEFMarkFilter : public UObject, public LEGlyphFilter
{
private:
const GlyphClassDefinitionTable *classDefTable;
/**
* The address of this static class variable serves as this class's ID
* for ICU "poor man's RTTI".
*/
static const char fgClassID;
public:
GDEFMarkFilter(const GlyphDefinitionTableHeader *gdefTable);
virtual ~GDEFMarkFilter();
virtual le_bool accept(LEGlyphID glyph) const;
/**
* 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; }
};
U_NAMESPACE_END

View File

@ -79,25 +79,25 @@ le_int32 IndicOpenTypeLayoutEngine::characterProcessing(const LEUnicode chars[],
le_int32 worstCase = count * IndicReordering::getWorstCaseExpansion(fScriptCode);
outChars = new LEUnicode[worstCase];
outChars = (LEUnicode *)uprv_malloc(worstCase * sizeof(LEUnicode));
if (outChars == NULL) {
success = LE_MEMORY_ALLOCATION_ERROR;
return 0;
}
charIndices = new le_int32[worstCase];
charIndices = (le_int32 *)uprv_malloc(worstCase * sizeof(le_int32));
if (charIndices == NULL) {
delete[] outChars;
uprv_free(outChars);
success = LE_MEMORY_ALLOCATION_ERROR;
return 0;
}
featureTags = new const LETag*[worstCase];
featureTags = (const LETag **)uprv_malloc(worstCase * sizeof(const LETag *));
if (featureTags == NULL) {
delete[] charIndices;
delete[] outChars;
uprv_free(charIndices);
uprv_free(outChars);
success = LE_MEMORY_ALLOCATION_ERROR;
return 0;
}

View File

@ -11,6 +11,7 @@
#include "unicode/utypes.h"
#include "unicode/uobject.h"
#include "cmemory.h"
U_NAMESPACE_BEGIN

View File

@ -166,7 +166,7 @@ void LayoutEngine::positionGlyphs(const LEGlyphID glyphs[], le_int32 glyphCount,
}
if (positions == NULL) {
positions = new float[2 * (glyphCount + 1)];
positions = (float *)uprv_malloc((2 * (glyphCount + 1)) * sizeof(float));
if (positions == NULL) {
success = LE_MEMORY_ALLOCATION_ERROR;
@ -243,7 +243,7 @@ void LayoutEngine::mapCharsToGlyphs(const LEUnicode chars[], le_int32 offset, le
}
if (glyphs == NULL) {
glyphs = new LEGlyphID[count];
glyphs = (LEGlyphID *)uprv_malloc(count * sizeof(LEGlyphID));
if (glyphs == NULL) {
success = LE_MEMORY_ALLOCATION_ERROR;
@ -259,7 +259,7 @@ void LayoutEngine::mapCharsToGlyphs(const LEUnicode chars[], le_int32 offset, le
dir = -1;
}
charIndices = new le_int32[count];
charIndices = (le_int32 *)uprv_malloc(count * sizeof(le_int32));
if (charIndices == NULL) {
success = LE_MEMORY_ALLOCATION_ERROR;
@ -303,17 +303,17 @@ void LayoutEngine::reset()
fGlyphCount = 0;
if (fGlyphs != NULL) {
delete[] fGlyphs;
uprv_free(fGlyphs);
fGlyphs = NULL;
}
if (fCharIndices != NULL) {
delete[] fCharIndices;
uprv_free(fCharIndices);
fCharIndices = NULL;
}
if (fPositions != NULL) {
delete[] fPositions;
uprv_free(fPositions);
fPositions = NULL;
}
}

View File

@ -142,7 +142,7 @@ LookupProcessor::LookupProcessor(const char *baseAddress,
requiredFeatureIndex = SWAPW(langSysTable->reqFeatureIndex);
lookupSelectArray = new LETag[lookupListCount];
lookupSelectArray = (LETag *)uprv_malloc(lookupListCount * sizeof(LETag));
for (int i = 0; i < lookupListCount; i += 1) {
lookupSelectArray[i] = notSelected;
@ -152,7 +152,7 @@ LookupProcessor::LookupProcessor(const char *baseAddress,
const FeatureTable *featureTable = 0;
LETag featureTag;
lookupOrderArray = new le_uint16[lookupListCount];
lookupOrderArray = (le_uint16 *)uprv_malloc(lookupListCount * sizeof(le_uint16));
if (requiredFeatureIndex != 0xFFFF) {
featureTable = featureListTable->getFeatureTable(requiredFeatureIndex, &featureTag);
@ -198,8 +198,8 @@ LookupProcessor::LookupProcessor()
LookupProcessor::~LookupProcessor()
{
delete[] lookupOrderArray;
delete[] lookupSelectArray;
uprv_free(lookupOrderArray);
uprv_free(lookupSelectArray);
};
U_NAMESPACE_END

View File

@ -48,7 +48,7 @@ void OpenTypeLayoutEngine::reset()
// method that's called from here and
// from our destructor
if (fFeatureTags != NULL) {
delete[] fFeatureTags;
uprv_free(fFeatureTags);
fFeatureTags = NULL;
}
}
@ -142,15 +142,15 @@ le_int32 OpenTypeLayoutEngine::computeGlyphs(const LEUnicode chars[], le_int32 o
outGlyphCount = glyphPostProcessing(fakeGlyphs, tempCharIndices, fakeGlyphCount, glyphs, charIndices, success);
if (outChars != chars) {
delete[] outChars;
uprv_free(outChars);
}
if (fakeGlyphs != glyphs) {
delete[] fakeGlyphs;
uprv_free(fakeGlyphs);
}
if (tempCharIndices != charIndices) {
delete[] tempCharIndices;
uprv_free(tempCharIndices);
}
return outGlyphCount;
@ -211,7 +211,7 @@ void OpenTypeLayoutEngine::adjustGlyphPositions(const LEUnicode chars[], le_int3
delete[] adjustments;
}
delete[] fFeatureTags;
uprv_free(fFeatureTags);
fFeatureTags = NULL;
}

View File

@ -67,17 +67,17 @@ le_int32 ThaiLayoutEngine::computeGlyphs(const LEUnicode chars[], le_int32 offse
// This is enough room for the worst-case expansion
// (it says here...)
outChars = new LEUnicode[count * 2];
outChars = (LEUnicode *)uprv_malloc((count * 2) * sizeof(LEUnicode));
if (outChars == NULL) {
success = LE_MEMORY_ALLOCATION_ERROR;
return 0;
}
charIndices = new le_int32[count * 2];
charIndices = (le_int32 *)uprv_malloc((count * 2) * sizeof(le_int32));
if (charIndices == NULL) {
delete[] outChars;
uprv_free(outChars);
success = LE_MEMORY_ALLOCATION_ERROR;
return 0;
}
@ -85,7 +85,7 @@ le_int32 ThaiLayoutEngine::computeGlyphs(const LEUnicode chars[], le_int32 offse
glyphCount = ThaiShaping::compose(chars, offset, count, fGlyphSet, fErrorChar, outChars, charIndices);
mapCharsToGlyphs(outChars, 0, glyphCount, false, false, glyphs, charIndices, success);
delete[] outChars;
uprv_free(outChars);
return glyphCount;
}

View File

@ -302,6 +302,8 @@ le_int32 ThaiShaping::compose(const LEUnicode *input, le_int32 offset, le_int32
return outputIndex;
}
const char ThaiMarkFilter::fgClassID=0;
ThaiMarkFilter::ThaiMarkFilter(le_uint8 glyphSet)
: rangeList(NULL)
{

View File

@ -14,7 +14,7 @@
U_NAMESPACE_BEGIN
class ThaiMarkFilter : public LEGlyphFilter
class ThaiMarkFilter : public UObject, public LEGlyphFilter
{
private:
struct MarkRange
@ -25,11 +25,31 @@ private:
MarkRange *rangeList;
/**
* The address of this static class variable serves as this class's ID
* for ICU "poor man's RTTI".
*/
static const char fgClassID;
public:
ThaiMarkFilter(le_uint8 glyphSet);
~ThaiMarkFilter();
virtual le_bool filter(LEGlyphID glyph);
/**
* 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; }
};
class ThaiShaping /* not : public UObject because all methods are static */ {

View File

@ -287,31 +287,15 @@ inline int32_t ICULayoutEngine::layoutString(const UnicodeString &str,
float x, float y,
UErrorCode &success)
{
int32_t glyphCount = 0;
int32_t max = str.length();
UChar *chars = new UChar[max];
/* test for NULL */
if(chars == 0) {
success = U_MEMORY_ALLOCATION_ERROR;
return 0;
}
str.extract(0, max, chars);
// NOTE: call reset() so that clients can safely reuse
fLayoutEngine->reset();
glyphCount = fLayoutEngine->layoutChars(chars,
return fLayoutEngine->layoutChars(str.getBuffer(),
startOffset,
endOffset - startOffset,
max,
str.length(),
rightToLeft,
x, y,
(LEErrorCode &) success);
delete[] chars;
return glyphCount;
}
inline int32_t ICULayoutEngine::countGlyphs() const