From 8f454748c96a81bfa1d37e8d7623fa5aeee9e22a Mon Sep 17 00:00:00 2001 From: stanton Date: Thu, 4 Mar 1999 00:59:04 +0000 Subject: * win/tclWinInt.h: * win/tclWin32Dll.c: * unix/tclUnixInit.c: Added TclpCheckStackSpace. --- unix/tclUnixInit.c | 29 ++++++++++++++++++++++++++++- win/tclWin32Dll.c | 37 ++++++++++++++++++++++++++++++++++++- win/tclWinInt.h | 10 +++++++++- 3 files changed, 73 insertions(+), 3 deletions(-) diff --git a/unix/tclUnixInit.c b/unix/tclUnixInit.c index ded700b..32a4101 100644 --- a/unix/tclUnixInit.c +++ b/unix/tclUnixInit.c @@ -8,7 +8,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclUnixInit.c,v 1.11 1998/09/14 18:40:17 stanton Exp $ + * RCS: @(#) $Id: tclUnixInit.c,v 1.11.4.1 1999/03/04 00:59:04 stanton Exp $ */ #include "tclInt.h" @@ -280,3 +280,30 @@ Tcl_SourceRCFile(interp) Tcl_DStringFree(&temp); } } + +/* + *---------------------------------------------------------------------- + * + * TclpCheckStackSpace -- + * + * Detect if we are about to blow the stack. Called before an + * evaluation can happen when nesting depth is checked. + * + * Results: + * 1 if there is enough stack space to continue; 0 if not. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +int +TclpCheckStackSpace() +{ + /* + * This function is unimplemented on Unix platforms. + */ + + return 1; +} diff --git a/win/tclWin32Dll.c b/win/tclWin32Dll.c index 9de0589..c3de691 100644 --- a/win/tclWin32Dll.c +++ b/win/tclWin32Dll.c @@ -9,7 +9,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclWin32Dll.c,v 1.4 1998/09/14 18:40:19 stanton Exp $ + * RCS: @(#) $Id: tclWin32Dll.c,v 1.4.4.1 1999/03/04 00:59:04 stanton Exp $ */ #include "tclWinInt.h" @@ -378,6 +378,41 @@ TclWinGetTclInstance() /* *---------------------------------------------------------------------- * + * TclpCheckStackSpace -- + * + * Detect if we are about to blow the stack. Called before an + * evaluation can happen when nesting depth is checked. + * + * Results: + * 1 if there is enough stack space to continue; 0 if not. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +int +TclpCheckStackSpace() +{ + /* + * We can recurse only if there is at least TCL_WIN_STACK_THRESHOLD + * bytes of stack space left. alloca() is cheap on windows; basically + * it just subtracts from the stack pointer causing the OS to throw an + * exception if the stack pointer is set below the bottom of the stack. + */ + + try { + alloca(TCL_WIN_STACK_THRESHOLD); + return 1; + } except (1) {} + + return 0; +} + +/* + *---------------------------------------------------------------------- + * * TclWinGetPlatformId -- * * Determines whether running under NT, 95, or Win32s, to allow diff --git a/win/tclWinInt.h b/win/tclWinInt.h index 4169472..64c43f7 100644 --- a/win/tclWinInt.h +++ b/win/tclWinInt.h @@ -8,7 +8,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclWinInt.h,v 1.5 1998/09/14 18:40:20 stanton Exp $ + * RCS: @(#) $Id: tclWinInt.h,v 1.5.4.1 1999/03/04 00:59:04 stanton Exp $ */ #ifndef _TCLWININT @@ -27,6 +27,14 @@ #endif /* + * The following specifies how much stack space TclpCheckStackSpace() + * ensures is available. TclpCheckStackSpace() is called by Tcl_EvalObj() + * to help avoid overflowing the stack in the case of infinite recursion. + */ + +#define TCL_WIN_STACK_THRESHOLD 0x2000 + +/* * Some versions of Borland C have a define for the OSVERSIONINFO for * Win32s and for NT, but not for Windows 95. */ -- cgit v0.12