ICU-2625 Add LE_NEW_ARRAY and LE_DELETE_ARRAY to replace calls to uprv_malloc and uprv_free.

X-SVN-Rev: 10814
This commit is contained in:
Eric Mader 2003-01-07 22:47:19 +00:00
parent c26438715e
commit 21e1caf69a
12 changed files with 49 additions and 48 deletions

View file

@ -83,7 +83,7 @@ le_int32 ArabicOpenTypeLayoutEngine::characterProcessing(const LEUnicode chars[]
return 0;
}
featureTags = (const LETag **)uprv_malloc(count * sizeof(const LETag *));
featureTags = LE_NEW_ARRAY(const LETag *, count);
if (featureTags == NULL) {
success = LE_MEMORY_ALLOCATION_ERROR;
@ -202,17 +202,17 @@ void UnicodeArabicOpenTypeLayoutEngine::mapCharsToGlyphs(const LEUnicode chars[]
dir = -1;
}
glyphs = (LEGlyphID *)uprv_malloc(count * sizeof(LEGlyphID));
glyphs = LE_NEW_ARRAY(LEGlyphID, count);
if (glyphs == NULL) {
success = LE_MEMORY_ALLOCATION_ERROR;
return;
}
charIndices = (le_int32 *)uprv_malloc(count * sizeof(le_int32));
charIndices = LE_NEW_ARRAY(le_int32, count);
if (charIndices == NULL) {
uprv_free(glyphs);
LE_DELETE_ARRAY(glyphs);
success = LE_MEMORY_ALLOCATION_ERROR;
return;
}

View file

@ -12,7 +12,6 @@
#include "OpenTypeTables.h"
#include "GlyphDefinitionTables.h"
#include "GlyphPositionAdjustments.h"
#include "cmemory.h"
U_NAMESPACE_BEGIN

View file

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

View file

@ -2,7 +2,7 @@
/*
* @(#)LETypes.h 1.2 00/03/15
*
* (C) Copyright IBM Corp. 1998-2002 - All Rights Reserved
* (C) Copyright IBM Corp. 1998-2003 - All Rights Reserved
*
*/
@ -11,6 +11,7 @@
#include "unicode/utypes.h"
#include "unicode/uobject.h"
#include "cmemory.h"
U_NAMESPACE_BEGIN
@ -166,6 +167,22 @@ typedef struct LEPoint LEPoint;
*/
#define LE_ARRAY_COPY(dst, src, count) memcpy(dst, src, (count) * sizeof (src)[0])
/**
* Allocate an array of basic types. This is used to isolate the rest of
* the LayoutEngine code from cmemory.h.
*
* @draft ICU 2.6
*/
#define LE_NEW_ARRAY(type, count) (type *) uprv_malloc((count) * sizeof(type))
/**
* Free an array of basic types. This is used to isolate the rest of
* the LayoutEngine code from cmemory.h.
*
* @draft ICU 2.6
*/
#define LE_DELETE_ARRAY(array) uprv_free(array)
/**
* Error codes returned by the LayoutEngine.
*

View file

@ -166,7 +166,7 @@ void LayoutEngine::positionGlyphs(const LEGlyphID glyphs[], le_int32 glyphCount,
}
if (positions == NULL) {
positions = (float *)uprv_malloc((2 * (glyphCount + 1)) * sizeof(float));
positions = LE_NEW_ARRAY(float, 2 * (glyphCount + 1));
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 = (LEGlyphID *)uprv_malloc(count * sizeof(LEGlyphID));
glyphs = LE_NEW_ARRAY(LEGlyphID, count);
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 = (le_int32 *)uprv_malloc(count * sizeof(le_int32));
charIndices = LE_NEW_ARRAY(le_int32, count);
if (charIndices == NULL) {
success = LE_MEMORY_ALLOCATION_ERROR;
@ -303,17 +303,17 @@ void LayoutEngine::reset()
fGlyphCount = 0;
if (fGlyphs != NULL) {
uprv_free(fGlyphs);
LE_DELETE_ARRAY(fGlyphs);
fGlyphs = NULL;
}
if (fCharIndices != NULL) {
uprv_free(fCharIndices);
LE_DELETE_ARRAY(fCharIndices);
fCharIndices = NULL;
}
if (fPositions != NULL) {
uprv_free(fPositions);
LE_DELETE_ARRAY(fPositions);
fPositions = NULL;
}
}

View file

@ -9,7 +9,6 @@
#define __LAYOUTTABLES_H
#include "LETypes.h"
#include "cmemory.h"
U_NAMESPACE_BEGIN

View file

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

View file

@ -2,16 +2,14 @@
* (C) Copyright IBM Corp. 2002, 2003 - All Rights Reserved
*
* $Source: /xsrl/Nsvn/icu/icu/source/layout/MPreFixups.cpp,v $
* $Date: 2003/01/04 02:52:23 $
* $Revision: 1.1 $
* $Date: 2003/01/07 22:47:18 $
* $Revision: 1.2 $
*
*/
#include "LETypes.h"
#include "MPreFixups.h"
#include "cmemory.h"
U_NAMESPACE_BEGIN
struct FixupData
@ -20,14 +18,6 @@ struct FixupData
le_int32 fMPreIndex;
};
#define LE_NEW_ARRAY(type, count) (type *) uprv_malloc(count * sizeof(type))
#define LE_DELETE_ARRAY(array) uprv_free(array)
#if 0
#define LE_NEW_ARRAY(type, count) new type[count]
#define LE_DELETE_ARRAY(array) delete[] array
#endif
MPreFixups::MPreFixups(le_int32 charCount)
: fFixupData(NULL), fFixupCount(0)
{

View file

@ -48,7 +48,7 @@ void OpenTypeLayoutEngine::reset()
// method that's called from here and
// from our destructor
if (fFeatureTags != NULL) {
uprv_free(fFeatureTags);
LE_DELETE_ARRAY(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) {
uprv_free(outChars);
LE_DELETE_ARRAY(outChars);
}
if (fakeGlyphs != glyphs) {
uprv_free(fakeGlyphs);
LE_DELETE_ARRAY(fakeGlyphs);
}
if (tempCharIndices != charIndices) {
uprv_free(tempCharIndices);
LE_DELETE_ARRAY(tempCharIndices);
}
return outGlyphCount;
@ -211,7 +211,7 @@ void OpenTypeLayoutEngine::adjustGlyphPositions(const LEUnicode chars[], le_int3
delete[] adjustments;
}
uprv_free(fFeatureTags);
LE_DELETE_ARRAY(fFeatureTags);
fFeatureTags = NULL;
}

View file

@ -18,8 +18,6 @@
#include "GlyphDefinitionTables.h"
#include "GlyphPositioningTables.h"
#include "cmemory.h"
U_NAMESPACE_BEGIN
/**

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 = (LEUnicode *)uprv_malloc((count * 2) * sizeof(LEUnicode));
outChars = LE_NEW_ARRAY(LEUnicode, count * 2);
if (outChars == NULL) {
success = LE_MEMORY_ALLOCATION_ERROR;
return 0;
}
charIndices = (le_int32 *)uprv_malloc((count * 2) * sizeof(le_int32));
charIndices = LE_NEW_ARRAY(le_int32, count * 2);
if (charIndices == NULL) {
uprv_free(outChars);
LE_DELETE_ARRAY(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);
uprv_free(outChars);
LE_DELETE_ARRAY(outChars);
return glyphCount;
}

View file

@ -15,8 +15,6 @@
#include "ThaiShaping.h"
#include "cmemory.h"
U_NAMESPACE_BEGIN
/**