summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2007-06-22 17:09:15 (GMT)
committerdgp <dgp@users.sourceforge.net>2007-06-22 17:09:15 (GMT)
commit6d2ef9cec6186ac320b6baea1c8c35d20b953061 (patch)
tree9c19ed0c63b59641ab72595ab8bc69512cc25b1c
parentabe71b0d5a315b3f7fa348e2318547e5180ef089 (diff)
downloadtcl-6d2ef9cec6186ac320b6baea1c8c35d20b953061.zip
tcl-6d2ef9cec6186ac320b6baea1c8c35d20b953061.tar.gz
tcl-6d2ef9cec6186ac320b6baea1c8c35d20b953061.tar.bz2
* generic/tclExecute.c: Revised TclStackRealloc() signature to better
* generic/tclInt.h: parallel (and fall back on) Tcl_Realloc. * generic/tclNamesp.c (TclResetShadowesCmdRefs): Replaced ckrealloc based allocations with TclStackRealloc allocations.
-rw-r--r--ChangeLog8
-rw-r--r--generic/tclExecute.c29
-rw-r--r--generic/tclInt.h4
-rw-r--r--generic/tclNamesp.c35
4 files changed, 40 insertions, 36 deletions
diff --git a/ChangeLog b/ChangeLog
index 7051815..206bdee 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2007-06-22 Don Porter <dgp@users.sourceforge.net>
+
+ * generic/tclExecute.c: Revised TclStackRealloc() signature to better
+ * generic/tclInt.h: parallel (and fall back on) Tcl_Realloc.
+
+ * generic/tclNamesp.c (TclResetShadowesCmdRefs): Replaced
+ ckrealloc based allocations with TclStackRealloc allocations.
+
2007-06-21 Don Porter <dgp@users.sourceforge.net>
* generic/tclBasic.c: Move most instances of the Tcl_Parse struct
diff --git a/generic/tclExecute.c b/generic/tclExecute.c
index 21109cb..d51c8fd 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.302 2007/06/21 17:45:40 msofer Exp $
+ * RCS: @(#) $Id: tclExecute.c,v 1.303 2007/06/22 17:09:17 dgp Exp $
*/
#include "tclInt.h"
@@ -444,8 +444,6 @@ static void DeleteExecStack(ExecStack *esPtr);
static Tcl_Obj ** StackAllocWords(Tcl_Interp *interp, int numWords);
static Tcl_Obj ** StackReallocWords(Tcl_Interp *interp, int numWords);
-/* Move to internal stubs? For now, unused */
-extern char * TclStackRealloc(Tcl_Interp *interp, int numBytes);
/*
*----------------------------------------------------------------------
@@ -878,14 +876,33 @@ TclStackAlloc(
return (void *) StackAllocWords(interp, numWords);
}
-char *
+void *
TclStackRealloc(
Tcl_Interp *interp,
+ void *ptr,
int numBytes)
{
- int numWords = (numBytes + sizeof(void *) - 1)/sizeof(void *);
+ Interp *iPtr;
+ ExecEnv *eePtr;
+ ExecStack *esPtr;
+ Tcl_Obj **markerPtr;
+ int numWords;
+
+ if (interp == NULL) {
+ return (void *) Tcl_Realloc((char *) ptr, numBytes);
+ }
+
+ iPtr = (Interp *) interp;
+ eePtr = iPtr->execEnvPtr;
+ esPtr = eePtr->execStackPtr;
+ markerPtr = esPtr->markerPtr;
+
+ if ((markerPtr+1) != (Tcl_Obj **)ptr) {
+ Tcl_Panic("TclStackRealloc: incorrect ptr. Call out of sequence?");
+ }
- return (char *) StackReallocWords(interp, numWords);
+ numWords = (numBytes + (sizeof(Tcl_Obj *) - 1))/sizeof(Tcl_Obj *);
+ return (void *) StackReallocWords(interp, numWords);
}
/*
diff --git a/generic/tclInt.h b/generic/tclInt.h
index 8ad0c0b..58d371f 100644
--- a/generic/tclInt.h
+++ b/generic/tclInt.h
@@ -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: tclInt.h,v 1.319 2007/06/14 21:02:19 msofer Exp $
+ * RCS: @(#) $Id: tclInt.h,v 1.320 2007/06/22 17:09:17 dgp Exp $
*/
#ifndef _TCLINT
@@ -2461,6 +2461,8 @@ MODULE_SCOPE void TclSetBignumIntRep (Tcl_Obj *objPtr,
MODULE_SCOPE void TclSetProcessGlobalValue(ProcessGlobalValue *pgvPtr,
Tcl_Obj *newValue, Tcl_Encoding encoding);
MODULE_SCOPE void TclSignalExitThread(Tcl_ThreadId id, int result);
+MODULE_SCOPE void * TclStackRealloc(Tcl_Interp *interp, void *ptr,
+ int numBytes);
MODULE_SCOPE Tcl_Obj * TclStringObjReverse(Tcl_Obj *objPtr);
MODULE_SCOPE int TclSubstTokens(Tcl_Interp *interp, Tcl_Token *tokenPtr,
int count, int *tokensLeftPtr, int line);
diff --git a/generic/tclNamesp.c b/generic/tclNamesp.c
index 779ed22..70beba7 100644
--- a/generic/tclNamesp.c
+++ b/generic/tclNamesp.c
@@ -22,7 +22,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclNamesp.c,v 1.141 2007/06/20 19:27:40 dgp Exp $
+ * RCS: @(#) $Id: tclNamesp.c,v 1.142 2007/06/22 17:09:18 dgp Exp $
*/
#include "tclInt.h"
@@ -2660,17 +2660,10 @@ TclResetShadowedCmdRefs(
Namespace *trailNsPtr, *shadowNsPtr;
Namespace *globalNsPtr = (Namespace *) TclGetGlobalNamespace(interp);
int found, i;
-
- /*
- * This function generates an array used to hold the trail list. This
- * starts out with stack-allocated space but uses dynamically-allocated
- * storage if needed.
- */
-
- Namespace *(trailStorage[NUM_TRAIL_ELEMS]);
- Namespace **trailPtr = trailStorage;
int trailFront = -1;
int trailSize = NUM_TRAIL_ELEMS;
+ Namespace **trailPtr = (Namespace **)
+ TclStackAlloc(interp, trailSize * sizeof(Namespace *));
/*
* Start at the namespace containing the new command, and work up through
@@ -2748,30 +2741,14 @@ TclResetShadowedCmdRefs(
trailFront++;
if (trailFront == trailSize) {
- size_t currBytes = trailSize * sizeof(Namespace *);
int newSize = 2 * trailSize;
- size_t newBytes = newSize * sizeof(Namespace *);
-
- if (trailPtr != trailStorage) {
- trailPtr = (Namespace **) ckrealloc((char *) trailPtr,
- newBytes);
- } else {
- Namespace **newPtr = (Namespace **) ckalloc(newBytes);
- memcpy(newPtr, trailPtr, currBytes);
- trailPtr = newPtr;
- }
+ trailPtr = (Namespace **) TclStackRealloc(interp,
+ trailPtr, newSize * sizeof(Namespace *));
trailSize = newSize;
}
trailPtr[trailFront] = nsPtr;
}
-
- /*
- * Free any allocated storage.
- */
-
- if (trailPtr != trailStorage) {
- ckfree((char *) trailPtr);
- }
+ TclStackFree(interp, trailPtr);
}
/*