Browse Source

new macro `condhardstacktests' to control hard stack tests

Roberto Ierusalimschy 23 years ago
parent
commit
5142e630bf
3 changed files with 18 additions and 4 deletions
  1. 2 1
      ldo.c
  2. 13 2
      ldo.h
  3. 3 1
      lgc.c

+ 2 - 1
ldo.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: ldo.c,v 1.205 2002/11/21 15:16:04 roberto Exp roberto $
+** $Id: ldo.c,v 1.206 2002/11/21 15:46:44 roberto Exp roberto $
 ** Stack and Call structure of Lua
 ** Stack and Call structure of Lua
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -218,6 +218,7 @@ StkId luaD_precall (lua_State *L, StkId func) {
   if (!ttisfunction(func)) /* `func' is not a function? */
   if (!ttisfunction(func)) /* `func' is not a function? */
     func = tryfuncTM(L, func);  /* check the `function' tag method */
     func = tryfuncTM(L, func);  /* check the `function' tag method */
   if (L->ci + 1 == L->end_ci) luaD_growCI(L);
   if (L->ci + 1 == L->end_ci) luaD_growCI(L);
+  else condhardstacktests(luaD_reallocCI(L, L->size_ci));
   cl = &clvalue(func)->l;
   cl = &clvalue(func)->l;
   if (!cl->isC) {  /* Lua function? prepare its call */
   if (!cl->isC) {  /* Lua function? prepare its call */
     CallInfo *ci;
     CallInfo *ci;

+ 13 - 2
ldo.h

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: ldo.h,v 1.52 2002/09/02 20:00:41 roberto Exp roberto $
+** $Id: ldo.h,v 1.53 2002/11/21 16:46:16 roberto Exp roberto $
 ** Stack and Call structure of Lua
 ** Stack and Call structure of Lua
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -13,10 +13,21 @@
 #include "lzio.h"
 #include "lzio.h"
 
 
 
 
+/*
+** macro to control inclusion of some hard tests on stack reallocation
+*/ 
+#ifndef CONDHARDSTACKTESTS
+#define condhardstacktests(x)	{ /* empty */ }
+#else
+#define condhardstacktests(x)	x
+#endif
+
 
 
 #define luaD_checkstack(L,n)	\
 #define luaD_checkstack(L,n)	\
   if ((char *)L->stack_last - (char *)L->top <= (n)*(int)sizeof(TObject)) \
   if ((char *)L->stack_last - (char *)L->top <= (n)*(int)sizeof(TObject)) \
-    luaD_growstack(L, n)
+    luaD_growstack(L, n); \
+  else condhardstacktests(luaD_reallocstack(L, L->stacksize));
+
 
 
 #define incr_top(L) {luaD_checkstack(L,1); L->top++;}
 #define incr_top(L) {luaD_checkstack(L,1); L->top++;}
 
 

+ 3 - 1
lgc.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: lgc.c,v 1.160 2002/11/21 14:17:15 roberto Exp roberto $
+** $Id: lgc.c,v 1.161 2002/11/21 15:46:20 roberto Exp roberto $
 ** Garbage Collector
 ** Garbage Collector
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -224,9 +224,11 @@ static void checkstacksizes (lua_State *L, StkId max) {
   int used = L->ci - L->base_ci;  /* number of `ci' in use */
   int used = L->ci - L->base_ci;  /* number of `ci' in use */
   if (4*used < L->size_ci && 2*BASIC_CI_SIZE < L->size_ci)
   if (4*used < L->size_ci && 2*BASIC_CI_SIZE < L->size_ci)
     luaD_reallocCI(L, L->size_ci/2);  /* still big enough... */
     luaD_reallocCI(L, L->size_ci/2);  /* still big enough... */
+  else condhardstacktests(luaD_reallocCI(L, L->size_ci));
   used = max - L->stack;  /* part of stack in use */
   used = max - L->stack;  /* part of stack in use */
   if (4*used < L->stacksize && 2*(BASIC_STACK_SIZE+EXTRA_STACK) < L->stacksize)
   if (4*used < L->stacksize && 2*(BASIC_STACK_SIZE+EXTRA_STACK) < L->stacksize)
     luaD_reallocstack(L, L->stacksize/2);  /* still big enough... */
     luaD_reallocstack(L, L->stacksize/2);  /* still big enough... */
+  else condhardstacktests(luaD_reallocstack(L, L->stacksize));
 }
 }