From e623ff4e6ad3a35bd8b2acbb416e56981286400a Mon Sep 17 00:00:00 2001 From: Miguel Sofer Date: Sat, 10 Nov 2007 20:05:34 +0000 Subject: Improved failure comments for stack checks (mistachkin). --- ChangeLog | 3 ++- generic/tclBasic.c | 25 +++++++++++++++---------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 065efec..a3f6358 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,11 +2,12 @@ * generic/tclBasic.c: * generic/tclInt.h: + * tests/interp.test ( * unix/tclUnixInit.c: * win/tclWin32Dll.c: restore simpler behaviour for stack checking, not adaptive to stack size changes after a thread is launched. Consensus is that "nobody does that", and so it is not - worth the cost. + worth the cost. Improved failure comments (mistachkin). 2007-11-10 Kevin Kenny diff --git a/generic/tclBasic.c b/generic/tclBasic.c index 53cd4fd..893de64 100644 --- a/generic/tclBasic.c +++ b/generic/tclBasic.c @@ -14,7 +14,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclBasic.c,v 1.274 2007/11/10 19:01:34 msofer Exp $ + * RCS: @(#) $Id: tclBasic.c,v 1.275 2007/11/10 20:05:34 msofer Exp $ */ #include "tclInt.h" @@ -340,13 +340,13 @@ static int stackGrowsDown = 1; #define GetCStackParams(iPtr) \ stackGrowsDown = TclpGetCStackParams(&((iPtr)->stackBound)) -#define StackOverflow(iPtr, localIntPtr) \ +#define CheckCStack(iPtr, localIntPtr) \ (stackGrowsDown \ - ? ((localIntPtr) < (iPtr)->stackBound) \ - : ((localIntPtr) > (iPtr)->stackBound) \ + ? ((localIntPtr) > (iPtr)->stackBound) \ + : ((localIntPtr) < (iPtr)->stackBound) \ ) #else /* stack check disabled: make them noops */ -#define StackOverflow(interp, localIntPtr) 0 +#define CheckCStack(interp, localIntPtr) 1 #define GetCStackParams(iPtr) #endif @@ -3435,14 +3435,19 @@ TclInterpReady( * probably because of an infinite loop somewhere. */ - if (((iPtr->numLevels) > iPtr->maxNestingDepth) - || StackOverflow(iPtr, &localInt)) { + if (((iPtr->numLevels) <= iPtr->maxNestingDepth) + && CheckCStack(iPtr, &localInt)) { + return TCL_OK; + } + + if (!CheckCStack(iPtr, &localInt)) { + Tcl_AppendResult(interp, + "out of stack space (infinite loop?)", NULL); + } else { Tcl_AppendResult(interp, "too many nested evaluations (infinite loop?)", NULL); - return TCL_ERROR; } - - return TCL_OK; + return TCL_ERROR; } /* -- cgit v0.12