diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | generic/tclExecute.c | 31 | ||||
-rw-r--r-- | generic/tclLiteral.c | 55 |
3 files changed, 44 insertions, 47 deletions
@@ -1,3 +1,8 @@ +2007-03-21 Don Porter <dgp@users.sourceforge.net> + + * generic/tclExecute.c: More ckalloc -> ckrealloc conversions. + * generic/tclLiteral.c: + 2007-03-20 Don Porter <dgp@users.sourceforge.net> * generic/tclEnv.c: Some more ckalloc -> ckrealloc replacements. diff --git a/generic/tclExecute.c b/generic/tclExecute.c index e15053b..2833ee8 100644 --- a/generic/tclExecute.c +++ b/generic/tclExecute.c @@ -12,7 +12,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclExecute.c,v 1.262 2007/03/20 15:23:51 dkf Exp $ + * RCS: @(#) $Id: tclExecute.c,v 1.263 2007/03/21 16:25:27 dgp Exp $ */ #include "tclInt.h" @@ -564,8 +564,7 @@ GrowEvaluationStack( int newElems = 2*currElems; int currBytes = currElems * sizeof(Tcl_Obj *); int newBytes = 2*currBytes; - Tcl_Obj **newStackPtr = (Tcl_Obj **) ckalloc((unsigned) newBytes); - Tcl_Obj **oldStackPtr = eePtr->stackPtr; + Tcl_Obj **newStackPtr, **oldStackPtr = eePtr->stackPtr; /* * We keep the stack reference count as a (char *), as that works nicely @@ -574,30 +573,22 @@ GrowEvaluationStack( char *refCount = (char *) oldStackPtr[-1]; - /* - * Copy the existing stack items to the new stack space, free the old - * storage if appropriate, and record the refCount of the new stack held - * by the environment. - */ - - newStackPtr++; - memcpy((VOID *) newStackPtr, (VOID *) oldStackPtr, - (size_t) currBytes); - if (refCount == (char *) 1) { - ckfree((VOID *) (oldStackPtr-1)); + newStackPtr = (Tcl_Obj **) ckrealloc( + (char *) (oldStackPtr - 1), newBytes); + newStackPtr++; } else { - /* - * Remove the reference corresponding to the environment pointer. - */ - + /* Can't free oldStackPtr, so can't use ckrealloc */ + newStackPtr = (Tcl_Obj **) ckalloc(newBytes); + newStackPtr++; + memcpy(newStackPtr, oldStackPtr, currBytes); oldStackPtr[-1] = (Tcl_Obj *) (refCount-1); + newStackPtr[-1] = (Tcl_Obj *) ((char *) 1); } eePtr->stackPtr = newStackPtr; eePtr->endPtr = newStackPtr + (newElems - 2); /* index of last usable item */ - eePtr->tosPtr += (newStackPtr - oldStackPtr); - newStackPtr[-1] = (Tcl_Obj *) ((char *) 1); + eePtr->tosPtr = newStackPtr + (eePtr->tosPtr - oldStackPtr); } /* 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; } /* |