diff options
Diffstat (limited to '')
| -rw-r--r-- | ldo.c | 8 | ||||
| -rw-r--r-- | lgc.c | 3 | ||||
| -rw-r--r-- | lstate.c | 21 | ||||
| -rw-r--r-- | lstate.h | 3 |
4 files changed, 29 insertions, 6 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldo.c,v 2.109 2013/04/19 21:05:04 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 2.110 2013/08/27 18:53:35 roberto Exp roberto $ |
| 3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -206,7 +206,11 @@ void luaD_shrinkstack (lua_State *L) { | |||
| 206 | int inuse = stackinuse(L); | 206 | int inuse = stackinuse(L); |
| 207 | int goodsize = inuse + (inuse / 8) + 2*EXTRA_STACK; | 207 | int goodsize = inuse + (inuse / 8) + 2*EXTRA_STACK; |
| 208 | if (goodsize > LUAI_MAXSTACK) goodsize = LUAI_MAXSTACK; | 208 | if (goodsize > LUAI_MAXSTACK) goodsize = LUAI_MAXSTACK; |
| 209 | if (inuse > LUAI_MAXSTACK || /* handling stack overflow? */ | 209 | if (L->stacksize > LUAI_MAXSTACK) /* was handling stack overflow? */ |
| 210 | luaE_freeCI(L); /* free all CIs (list grew because of an error) */ | ||
| 211 | else | ||
| 212 | luaE_shrinkCI(L); /* shrink list */ | ||
| 213 | if (inuse > LUAI_MAXSTACK || /* still handling stack overflow? */ | ||
| 210 | goodsize >= L->stacksize) /* would grow instead of shrink? */ | 214 | goodsize >= L->stacksize) /* would grow instead of shrink? */ |
| 211 | condmovestack(L); /* don't change stack (change only for debugging) */ | 215 | condmovestack(L); /* don't change stack (change only for debugging) */ |
| 212 | else | 216 | else |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lgc.c,v 2.164 2013/09/11 14:56:15 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 2.165 2013/09/13 16:21:52 roberto Exp roberto $ |
| 3 | ** Garbage Collector | 3 | ** Garbage Collector |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -496,7 +496,6 @@ static lu_mem traversestack (global_State *g, lua_State *th) { | |||
| 496 | } | 496 | } |
| 497 | else { | 497 | else { |
| 498 | CallInfo *ci; | 498 | CallInfo *ci; |
| 499 | luaE_freeCI(th); /* free extra CallInfo slots */ | ||
| 500 | for (ci = &th->base_ci; ci != th->ci; ci = ci->next) | 499 | for (ci = &th->base_ci; ci != th->ci; ci = ci->next) |
| 501 | n++; /* count call infos to compute size */ | 500 | n++; /* count call infos to compute size */ |
| 502 | /* should not change the stack during an emergency gc cycle */ | 501 | /* should not change the stack during an emergency gc cycle */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstate.c,v 2.113 2013/09/11 14:09:55 roberto Exp roberto $ | 2 | ** $Id: lstate.c,v 2.114 2013/09/13 16:21:52 roberto Exp roberto $ |
| 3 | ** Global State | 3 | ** Global State |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -119,6 +119,9 @@ CallInfo *luaE_extendCI (lua_State *L) { | |||
| 119 | } | 119 | } |
| 120 | 120 | ||
| 121 | 121 | ||
| 122 | /* | ||
| 123 | ** free all CallInfo structures not in use by a thread | ||
| 124 | */ | ||
| 122 | void luaE_freeCI (lua_State *L) { | 125 | void luaE_freeCI (lua_State *L) { |
| 123 | CallInfo *ci = L->ci; | 126 | CallInfo *ci = L->ci; |
| 124 | CallInfo *next = ci->next; | 127 | CallInfo *next = ci->next; |
| @@ -130,6 +133,22 @@ void luaE_freeCI (lua_State *L) { | |||
| 130 | } | 133 | } |
| 131 | 134 | ||
| 132 | 135 | ||
| 136 | /* | ||
| 137 | ** free half of the CallInfo structures not in use by a thread | ||
| 138 | */ | ||
| 139 | void luaE_shrinkCI (lua_State *L) { | ||
| 140 | CallInfo *ci = L->ci; | ||
| 141 | while (ci->next != NULL) { /* while there is 'next' */ | ||
| 142 | CallInfo *next2 = ci->next->next; /* next's next */ | ||
| 143 | if (next2 == NULL) break; | ||
| 144 | luaM_free(L, ci->next); /* remove next */ | ||
| 145 | ci->next = next2; /* remove 'next' from the list */ | ||
| 146 | next2->previous = ci; | ||
| 147 | ci = next2; | ||
| 148 | } | ||
| 149 | } | ||
| 150 | |||
| 151 | |||
| 133 | static void stack_init (lua_State *L1, lua_State *L) { | 152 | static void stack_init (lua_State *L1, lua_State *L) { |
| 134 | int i; CallInfo *ci; | 153 | int i; CallInfo *ci; |
| 135 | /* initialize stack array */ | 154 | /* initialize stack array */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstate.h,v 2.95 2013/09/11 14:09:55 roberto Exp roberto $ | 2 | ** $Id: lstate.h,v 2.96 2013/09/13 16:21:52 roberto Exp roberto $ |
| 3 | ** Global State | 3 | ** Global State |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -214,6 +214,7 @@ LUAI_FUNC void luaE_setdebt (global_State *g, l_mem debt); | |||
| 214 | LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1); | 214 | LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1); |
| 215 | LUAI_FUNC CallInfo *luaE_extendCI (lua_State *L); | 215 | LUAI_FUNC CallInfo *luaE_extendCI (lua_State *L); |
| 216 | LUAI_FUNC void luaE_freeCI (lua_State *L); | 216 | LUAI_FUNC void luaE_freeCI (lua_State *L); |
| 217 | LUAI_FUNC void luaE_shrinkCI (lua_State *L); | ||
| 217 | 218 | ||
| 218 | 219 | ||
| 219 | #endif | 220 | #endif |
