summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--generic/tclBasic.c27
-rw-r--r--unix/configure.in31
-rw-r--r--unix/tclUnixInit.c15
4 files changed, 66 insertions, 12 deletions
diff --git a/ChangeLog b/ChangeLog
index 46cf11a..da46e58 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -6,6 +6,11 @@
2007-11-10 Miguel Sofer <msofer@users.sf.net>
* generic/tclBasic.c:
+ * unix/configure.in:
+ * unix/tclUnixInit.c: detect stack grwoth direction at compile
+ time, only fall to runtime detection when crosscompiling.
+
+ * generic/tclBasic.c:
* generic/tclInt.h:
* tests/interp.test:
* unix/tclUnixInit.c:
diff --git a/generic/tclBasic.c b/generic/tclBasic.c
index 893de64..e8faad0 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.275 2007/11/10 20:05:34 msofer Exp $
+ * RCS: @(#) $Id: tclBasic.c,v 1.276 2007/11/10 22:24:13 msofer Exp $
*/
#include "tclInt.h"
@@ -334,21 +334,32 @@ static const OpCmdInfo mathOpCmds[] = {
{0}, NULL }
};
-#ifndef TCL_NO_STACK_CHECK
+#ifdef TCL_NO_STACK_CHECK
+/* stack check disabled: make them noops */
+#define CheckCStack(interp, localIntPtr) 1
+#define GetCStackParams(iPtr)
+#else /* TCL_NO_STACK_CHECK */
+#ifdef TCL_CROSS_COMPILE
static int stackGrowsDown = 1;
-
#define GetCStackParams(iPtr) \
stackGrowsDown = TclpGetCStackParams(&((iPtr)->stackBound))
-
#define CheckCStack(iPtr, localIntPtr) \
(stackGrowsDown \
? ((localIntPtr) > (iPtr)->stackBound) \
: ((localIntPtr) < (iPtr)->stackBound) \
)
-#else /* stack check disabled: make them noops */
-#define CheckCStack(interp, localIntPtr) 1
-#define GetCStackParams(iPtr)
-#endif
+#else /* TCL_CROSS_COMPILE */
+#define GetCStackParams(iPtr) \
+ TclpGetCStackParams(&((iPtr)->stackBound))
+#ifdef TCL_STACK_GROWS_UP
+#define CheckCStack(iPtr, localIntPtr) \
+ ((localIntPtr) < (iPtr)->stackBound)
+#else /* TCL_STACK_GROWS_UP */
+#define CheckCStack(iPtr, localIntPtr) \
+ ((localIntPtr) > (iPtr)->stackBound)
+#endif /* TCL_STACK_GROWS_UP */
+#endif /* TCL_CROSS_COMPILE */
+#endif /* TCL_NO_STACK_CHECK */
/*
diff --git a/unix/configure.in b/unix/configure.in
index 3901138..ed1cb51 100644
--- a/unix/configure.in
+++ b/unix/configure.in
@@ -3,7 +3,7 @@ dnl This file is an input file used by the GNU "autoconf" program to
dnl generate the file "configure", which is run during Tcl installation
dnl to configure the system for the local environment.
#
-# RCS: @(#) $Id: configure.in,v 1.167 2007/10/30 19:03:57 dgp Exp $
+# RCS: @(#) $Id: configure.in,v 1.168 2007/11/10 22:24:14 msofer Exp $
AC_INIT([tcl],[8.5])
AC_PREREQ(2.59)
@@ -658,6 +658,35 @@ fi
AC_MSG_RESULT([$tcl_ok])
#--------------------------------------------------------------------
+# Does the C stack grow upwards or downwards? Or cross-compiling?
+#--------------------------------------------------------------------
+
+AC_CACHE_CHECK([does the C stack grow upwards in memory?], tcl_cv_stack_grows_up, [
+ AC_TRY_RUN([
+ int StackGrowsUp(int *parent)
+ {
+ int here;
+ return (&here < parent);
+ }
+
+ int main (int argc, char *argv[])
+ {
+ int foo;
+ return StackGrowsUp(&foo);
+ }
+ ],
+ tcl_cv_stack_grows_up=yes,
+ tcl_cv_stack_grows_up=no,
+ tcl_cv_stack_grows_up=unknown)])
+if test $tcl_cv_stack_grows_up = unknown; then
+ AC_DEFINE(TCL_CROSS_COMPILE, 1,
+ [Are we cross-compiling?])
+elif test $tcl_cv_stack_grows_up = yes; then
+ AC_DEFINE(TCL_STACK_GROWS_UP, 1,
+ [The C stack grows upwards in memory])
+fi
+
+#--------------------------------------------------------------------
# The statements below define a collection of symbols related to
# building libtcl as a shared library instead of a static library.
#--------------------------------------------------------------------
diff --git a/unix/tclUnixInit.c b/unix/tclUnixInit.c
index e4ba0f2..9202c26 100644
--- a/unix/tclUnixInit.c
+++ b/unix/tclUnixInit.c
@@ -7,7 +7,7 @@
* Copyright (c) 1999 by Scriptics Corporation.
* All rights reserved.
*
- * RCS: @(#) $Id: tclUnixInit.c,v 1.77 2007/11/10 20:49:21 das Exp $
+ * RCS: @(#) $Id: tclUnixInit.c,v 1.78 2007/11/10 22:24:14 msofer Exp $
*/
#include "tclInt.h"
@@ -81,8 +81,14 @@ typedef struct ThreadSpecificData {
int *stackBound; /* The current stack boundary */
} ThreadSpecificData;
static Tcl_ThreadDataKey dataKey;
+#ifdef TCL_CROSS_COMPILE
static int stackGrowsDown = -1;
static int StackGrowsDown(int *parent);
+#elif defined(TCL_STACK_GROWS_UP)
+static int stackGrowsDown = 0;
+#else
+static int stackGrowsDown = 1;
+#endif
#endif /* TCL_NO_STACK_CHECK */
#ifdef TCL_DEBUG_STACK_CHECK
@@ -1035,7 +1041,7 @@ TclpGetCStackParams(
/* Most variables are actually in a
* thread-specific data block to minimise the
* impact on the stack. */
-
+#ifdef TCL_CROSS_COMPILE
if (stackGrowsDown == -1) {
/*
* Not initialised!
@@ -1043,7 +1049,8 @@ TclpGetCStackParams(
stackGrowsDown = StackGrowsDown(&result);
}
-
+#endif
+
/*
* The first time through in a thread: record the "outermost" stack
* frame and inquire with the OS about the stack size.
@@ -1094,6 +1101,7 @@ TclpGetCStackParams(
return stackGrowsDown;
}
+#ifdef TCL_CROSS_COMPILE
int
StackGrowsDown(
int *parent)
@@ -1102,6 +1110,7 @@ StackGrowsDown(
return (&here < parent);
}
#endif
+#endif
/*