ICU-7887 remove fixed limit on icupkg/gencmn
X-SVN-Rev: 28470
This commit is contained in:
parent
c86940b784
commit
4a0b0ef791
@ -1,7 +1,7 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
*
|
||||
* Copyright (C) 1999-2009, International Business Machines
|
||||
* Copyright (C) 1999-2010, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*
|
||||
*******************************************************************************
|
||||
@ -31,11 +31,15 @@
|
||||
#include "swapimpl.h"
|
||||
#include "toolutil.h"
|
||||
#include "package.h"
|
||||
#include "cmemory.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
static const int32_t kItemsChunk = 256; /* How much to increase the filesarray by each time */
|
||||
|
||||
// general definitions ----------------------------------------------------- ***
|
||||
|
||||
#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
|
||||
@ -387,6 +391,9 @@ Package::Package() {
|
||||
inIsBigEndian=U_IS_BIG_ENDIAN;
|
||||
|
||||
itemCount=0;
|
||||
itemMax=0;
|
||||
items=NULL;
|
||||
|
||||
inStringTop=outStringTop=0;
|
||||
|
||||
matchMode=0;
|
||||
@ -420,6 +427,8 @@ Package::~Package() {
|
||||
free(items[idx].data);
|
||||
}
|
||||
}
|
||||
|
||||
uprv_free((void*)items);
|
||||
}
|
||||
|
||||
void
|
||||
@ -495,6 +504,7 @@ Package::readPackage(const char *filename) {
|
||||
offset=0x7fffffff;
|
||||
} else {
|
||||
itemCount=udata_readInt32(ds, *(const int32_t *)inBytes);
|
||||
setItemCapacity(itemCount); /* resize so there's space */
|
||||
if(itemCount==0) {
|
||||
offset=4;
|
||||
} else if(length<(4+8*itemCount)) {
|
||||
@ -517,8 +527,8 @@ Package::readPackage(const char *filename) {
|
||||
char *s, *inItemStrings;
|
||||
int32_t inPkgNameLength, prefixLength, stringsOffset;
|
||||
|
||||
if(itemCount>MAX_FILE_COUNT) {
|
||||
fprintf(stderr, "icupkg: too many items, maximum is %d\n", MAX_FILE_COUNT);
|
||||
if(itemCount>itemMax) {
|
||||
fprintf(stderr, "icupkg: too many items, maximum is %d\n", itemMax);
|
||||
exit(U_BUFFER_OVERFLOW_ERROR);
|
||||
}
|
||||
|
||||
@ -967,10 +977,7 @@ Package::addItem(const char *name, uint8_t *data, int32_t length, UBool isDataOw
|
||||
idx=findItem(name);
|
||||
if(idx<0) {
|
||||
// new item, make space at the insertion point
|
||||
if(itemCount>=MAX_FILE_COUNT) {
|
||||
fprintf(stderr, "icupkg: too many items, maximum is %d\n", MAX_FILE_COUNT);
|
||||
exit(U_BUFFER_OVERFLOW_ERROR);
|
||||
}
|
||||
ensureItemCapacity();
|
||||
// move the following items down
|
||||
idx=~idx;
|
||||
if(idx<itemCount) {
|
||||
@ -1220,4 +1227,30 @@ Package::sortItems() {
|
||||
}
|
||||
}
|
||||
|
||||
void Package::setItemCapacity(int32_t max)
|
||||
{
|
||||
if(max<=itemMax) {
|
||||
return;
|
||||
}
|
||||
Item *newItems = (Item*)uprv_malloc(max * sizeof(items[0]));
|
||||
Item *oldItems = items;
|
||||
if(newItems == NULL) {
|
||||
fprintf(stderr, "icupkg: Out of memory trying to allocate %ld bytes for %d items\n", max*sizeof(items[0]), max);
|
||||
exit(U_MEMORY_ALLOCATION_ERROR);
|
||||
}
|
||||
if(items && itemCount>0) {
|
||||
uprv_memcpy((void*)newItems, (const void*)items, itemCount*sizeof(items[0]));
|
||||
}
|
||||
itemMax = max;
|
||||
items = newItems;
|
||||
uprv_free(oldItems);
|
||||
}
|
||||
|
||||
void Package::ensureItemCapacity()
|
||||
{
|
||||
if((itemCount+1)>itemMax) {
|
||||
setItemCapacity(itemCount+kItemsChunk);
|
||||
}
|
||||
}
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
*
|
||||
* Copyright (C) 2005-2009, International Business Machines
|
||||
* Copyright (C) 2005-2010, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*
|
||||
*******************************************************************************
|
||||
@ -26,7 +26,6 @@
|
||||
// .dat package file representation ---------------------------------------- ***
|
||||
|
||||
#define STRING_STORE_SIZE 100000
|
||||
#define MAX_FILE_COUNT 2000
|
||||
#define MAX_PKG_NAME_LENGTH 32
|
||||
|
||||
typedef void CheckDependency(void *context, const char *itemName, const char *targetName);
|
||||
@ -145,7 +144,8 @@ private:
|
||||
UBool inIsBigEndian;
|
||||
|
||||
int32_t itemCount;
|
||||
Item items[MAX_FILE_COUNT];
|
||||
int32_t itemMax;
|
||||
Item *items;
|
||||
|
||||
int32_t inStringTop, outStringTop;
|
||||
char inStrings[STRING_STORE_SIZE], outStrings[STRING_STORE_SIZE];
|
||||
@ -160,8 +160,20 @@ private:
|
||||
|
||||
// state for checkDependencies()
|
||||
UBool isMissingItems;
|
||||
|
||||
/**
|
||||
* Grow itemMax to new value
|
||||
*/
|
||||
void setItemCapacity(int32_t max);
|
||||
|
||||
/**
|
||||
* Grow itemMax to at least itemCount+1
|
||||
*/
|
||||
void ensureItemCapacity();
|
||||
};
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/******************************************************************************
|
||||
* Copyright (C) 2008, International Business Machines
|
||||
* Copyright (C) 2008-2010, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*******************************************************************************
|
||||
*/
|
||||
@ -19,7 +19,6 @@
|
||||
#include "pkg_gencmn.h"
|
||||
|
||||
#define STRING_STORE_SIZE 100000
|
||||
#define MAX_FILE_COUNT 2000
|
||||
|
||||
#define COMMON_DATA_NAME U_ICUDATA_NAME
|
||||
#define DATA_TYPE "dat"
|
||||
@ -85,8 +84,11 @@ typedef struct {
|
||||
uint32_t basenameLength, basenameOffset, fileSize, fileOffset;
|
||||
} File;
|
||||
|
||||
static File files[MAX_FILE_COUNT];
|
||||
#define CHUNK_FILE_COUNT 256
|
||||
static File *files = NULL;
|
||||
static uint32_t fileCount=0;
|
||||
static uint32_t fileMax = 0;
|
||||
|
||||
|
||||
static char *symPrefix = NULL;
|
||||
|
||||
@ -383,9 +385,13 @@ addFile(const char *filename, const char *name, const char *source, UBool source
|
||||
uint32_t length;
|
||||
char *fullPath = NULL;
|
||||
|
||||
if(fileCount==MAX_FILE_COUNT) {
|
||||
fprintf(stderr, "gencmn: too many files, maximum is %d\n", MAX_FILE_COUNT);
|
||||
exit(U_BUFFER_OVERFLOW_ERROR);
|
||||
if(fileCount==fileMax) {
|
||||
fileMax += CHUNK_FILE_COUNT;
|
||||
files = uprv_realloc(files, fileMax*sizeof(files[0])); /* note: never freed. */
|
||||
if(files==NULL) {
|
||||
fprintf(stderr, "pkgdata/gencmn: Could not allocate %ld bytes for %d files\n", (fileMax*sizeof(files[0])), fileCount);
|
||||
exit(U_MEMORY_ALLOCATION_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
if(!sourceTOC) {
|
||||
|
Loading…
Reference in New Issue
Block a user