Attachment "fixLevels0.patch" to
ticket [483611ffff]
added by
msofer
2001-11-22 07:22:51.
Index: generic/tclCompile.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclCompile.c,v
retrieving revision 1.28
diff -u -r1.28 tclCompile.c
--- generic/tclCompile.c 2001/11/21 02:36:20 1.28
+++ generic/tclCompile.c 2001/11/22 00:15:05
@@ -1584,8 +1584,23 @@
codePtr->numAuxDataItems = envPtr->auxDataArrayNext;
codePtr->numCmdLocBytes = cmdLocBytes;
codePtr->maxExceptDepth = envPtr->maxExceptDepth;
- codePtr->maxStackDepth = envPtr->maxStackDepth;
+ /* Temporary bug fix, quick and dirty. As the maxStackDepth is
+ * sometimes underestimated by the compiler, we replace by a
+ * safe overestimate which relies on the following facts:
+ * 1 - no instruction has a stack balance > 1
+ * 2 - there are always more bytes than instructions
+ *
+ * Less crude upper bounds will take this place in the future.
+ * Remark that the cost of overestimating is a possible increase
+ * in memory consumption; the cost of underestimating is a
+ * possible SEGFAULT.
+ *
+ * codePtr->maxStackDepth = envPtr->maxStackDepth;
+ */
+
+ codePtr->maxStackDepth = codePtr->numCodeBytes;
+
p += sizeof(ByteCode);
codePtr->codeStart = p;
memcpy((VOID *) p, (VOID *) envPtr->codeStart, (size_t) codeBytes);
Index: generic/tclExecute.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclExecute.c,v
retrieving revision 1.42
diff -u -r1.42 tclExecute.c
--- generic/tclExecute.c 2001/11/20 22:47:58 1.42
+++ generic/tclExecute.c 2001/11/22 00:15:08
@@ -268,8 +268,7 @@
static char * StringForResultCode _ANSI_ARGS_((int result));
static void ValidatePcAndStackTop _ANSI_ARGS_((
ByteCode *codePtr, unsigned char *pc,
- int stackTop, int stackLowerBound,
- int stackUpperBound));
+ int stackTop, int stackLowerBound));
#endif
static int VerifyExprObjType _ANSI_ARGS_((Tcl_Interp *interp,
Tcl_Obj *objPtr));
@@ -1049,8 +1048,7 @@
for (;;) {
#ifdef TCL_COMPILE_DEBUG
- ValidatePcAndStackTop(codePtr, pc, stackTop, initStackTop,
- eePtr->stackEnd);
+ ValidatePcAndStackTop(codePtr, pc, stackTop, initStackTop);
if (traceInstructions) {
fprintf(stdout, "%2d: %2d ", iPtr->numLevels, stackTop);
TclPrintInstruction(codePtr, pc);
@@ -4090,8 +4088,7 @@
#ifdef TCL_COMPILE_DEBUG
static void
-ValidatePcAndStackTop(codePtr, pc, stackTop, stackLowerBound,
- stackUpperBound)
+ValidatePcAndStackTop(codePtr, pc, stackTop, stackLowerBound)
register ByteCode *codePtr; /* The bytecode whose summary is printed
* to stdout. */
unsigned char *pc; /* Points to first byte of a bytecode
@@ -4100,8 +4097,9 @@
* stackLowerBound and stackUpperBound
* (inclusive). */
int stackLowerBound; /* Smallest legal value for stackTop. */
- int stackUpperBound; /* Greatest legal value for stackTop. */
{
+int stackUpperBound = stackLowerBound + codePtr->maxStackDepth;
+ /* Greatest legal value for stackTop. */
unsigned int relativePc = (unsigned int) (pc - codePtr->codeStart);
unsigned int codeStart = (unsigned int) codePtr->codeStart;
unsigned int codeEnd = (unsigned int)