From 0316f56e5191553ae897286bb9bc4a7259ffd8f0 Mon Sep 17 00:00:00 2001 From: James Clark Date: Wed, 4 Feb 1998 03:49:24 +0000 Subject: [PATCH] Get rid of magic numbers from the source --- expat/xmlparse/xmlparse.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/expat/xmlparse/xmlparse.c b/expat/xmlparse/xmlparse.c index c5e4ae0d..f401609a 100755 --- a/expat/xmlparse/xmlparse.c +++ b/expat/xmlparse/xmlparse.c @@ -6,6 +6,12 @@ #include #include +#define INIT_TAG_STACK_SIZE 128 +#define INIT_DATA_BUF_SIZE 1024 +#define INIT_ATTS_SIZE 16 +#define INIT_BLOCK_SIZE 1024 +#define INIT_BUFFER_SIZE 1024 + typedef struct { const char *name; const char *textPtr; @@ -17,8 +23,6 @@ typedef struct { char magic; } ENTITY; -#define INIT_BLOCK_SIZE 1024 - typedef struct block { struct block *next; int size; @@ -230,11 +234,11 @@ XML_Parser XML_ParserCreate(const char *encodingName) errorByteIndex = 0; errorPtr = 0; tagLevel = 0; - tagStack = malloc(1024); + tagStack = malloc(INIT_TAG_STACK_SIZE); tagStackPtr = tagStack; - attsSize = 1024; + attsSize = INIT_ATTS_SIZE; atts = malloc(attsSize * sizeof(ATTRIBUTE)); - dataBuf = malloc(1024); + dataBuf = malloc(INIT_DATA_BUF_SIZE); groupSize = 0; groupConnector = 0; poolInit(&tempPool); @@ -243,8 +247,8 @@ XML_Parser XML_ParserCreate(const char *encodingName) XML_ParserFree(parser); return 0; } - tagStackEnd = tagStack + 1024; - dataBufEnd = dataBuf + 1024; + tagStackEnd = tagStack + INIT_TAG_STACK_SIZE; + dataBufEnd = dataBuf + INIT_DATA_BUF_SIZE; *tagStackPtr++ = '\0'; return parser; } @@ -375,7 +379,7 @@ void *XML_GetBuffer(XML_Parser parser, size_t len) char *newBuf; size_t bufferSize = bufferLim - bufferPtr; if (bufferSize == 0) - bufferSize = 1024; + bufferSize = INIT_BUFFER_SIZE; do { bufferSize *= 2; } while (bufferSize < neededSize);