diff options
author | dgp <dgp@noemail.net> | 2007-03-21 16:25:25 (GMT) |
---|---|---|
committer | dgp <dgp@noemail.net> | 2007-03-21 16:25:25 (GMT) |
commit | 82fcd65f2be55ca85bdbcdbf39428d93ea7e8f42 (patch) | |
tree | 949e678a48439df209cef1c01cd090f1b36c3ee6 /generic/tclLiteral.c | |
parent | fbb587b02f4cf468025c823faa9b020e13ab7d16 (diff) | |
download | tcl-82fcd65f2be55ca85bdbcdbf39428d93ea7e8f42.zip tcl-82fcd65f2be55ca85bdbcdbf39428d93ea7e8f42.tar.gz tcl-82fcd65f2be55ca85bdbcdbf39428d93ea7e8f42.tar.bz2 |
* generic/tclExecute.c: More ckalloc -> ckrealloc conversions.
* generic/tclLiteral.c:
FossilOrigin-Name: 4a5a34e344bc64ecc72544352ee6f61831ef14e3
Diffstat (limited to 'generic/tclLiteral.c')
-rw-r--r-- | generic/tclLiteral.c | 55 |
1 files changed, 28 insertions, 27 deletions
diff --git a/generic/tclLiteral.c b/generic/tclLiteral.c index d683177..3f1d059 100644 --- a/generic/tclLiteral.c +++ b/generic/tclLiteral.c @@ -13,7 +13,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclLiteral.c,v 1.29 2007/02/20 23:24:03 nijtmans Exp $ + * RCS: @(#) $Id: tclLiteral.c,v 1.30 2007/03/21 16:25:28 dgp Exp $ */ #include "tclInt.h" @@ -683,43 +683,44 @@ ExpandLocalLiteralArray( LiteralTable *localTablePtr = &(envPtr->localLitTable); int currElems = envPtr->literalArrayNext; size_t currBytes = (currElems * sizeof(LiteralEntry)); - register LiteralEntry *currArrayPtr = envPtr->literalArrayPtr; - register LiteralEntry *newArrayPtr = - (LiteralEntry *) ckalloc((unsigned) (2 * currBytes)); + LiteralEntry *currArrayPtr = envPtr->literalArrayPtr; + LiteralEntry *newArrayPtr; int i; + if (envPtr->mallocedLiteralArray) { + newArrayPtr = (LiteralEntry *) ckrealloc( + (char *)currArrayPtr, 2 * currBytes); + } else { + /* + * envPtr->literalArrayPtr isn't a ckalloc'd pointer, so we must + * code a ckrealloc equivalent for ourselves + */ + newArrayPtr = (LiteralEntry *) ckalloc(2 * currBytes); + memcpy(newArrayPtr, currArrayPtr, currBytes); + envPtr->mallocedLiteralArray = 1; + } + /* - * Copy from the old literal array to the new, then update the local - * literal table's bucket array. + * Update the local literal table's bucket array. */ - memcpy((void *) newArrayPtr, (void *) currArrayPtr, currBytes); - for (i=0 ; i<currElems ; i++) { - if (currArrayPtr[i].nextPtr == NULL) { - newArrayPtr[i].nextPtr = NULL; - } else { - newArrayPtr[i].nextPtr = - newArrayPtr + (currArrayPtr[i].nextPtr - currArrayPtr); + if (currArrayPtr != newArrayPtr) { + for (i=0 ; i<currElems ; i++) { + if (newArrayPtr[i].nextPtr != NULL) { + newArrayPtr[i].nextPtr = newArrayPtr + + (newArrayPtr[i].nextPtr - currArrayPtr); + } } - } - for (i=0 ; i<localTablePtr->numBuckets ; i++) { - if (localTablePtr->buckets[i] != NULL) { - localTablePtr->buckets[i] = - newArrayPtr + (localTablePtr->buckets[i] - currArrayPtr); + for (i=0 ; i<localTablePtr->numBuckets ; i++) { + if (localTablePtr->buckets[i] != NULL) { + localTablePtr->buckets[i] = newArrayPtr + + (localTablePtr->buckets[i] - currArrayPtr); + } } } - /* - * Free the old literal array if needed, and mark the new literal array as - * malloced. - */ - - if (envPtr->mallocedLiteralArray) { - ckfree((char *) currArrayPtr); - } envPtr->literalArrayPtr = newArrayPtr; envPtr->literalArrayEnd = (2 * currElems); - envPtr->mallocedLiteralArray = 1; } /* |