diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2015-11-02 14:01:41 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2015-11-02 14:01:41 -0200 |
commit | 33b366ec321646890780b96df96eacb558b82f6d (patch) | |
tree | 59e30d04f641a45e48f2ac7649d912bf877628fd | |
parent | c5363a1b58573162ef13ba4a345bd48ad3c355d9 (diff) | |
download | lua-33b366ec321646890780b96df96eacb558b82f6d.tar.gz lua-33b366ec321646890780b96df96eacb558b82f6d.tar.bz2 lua-33b366ec321646890780b96df96eacb558b82f6d.zip |
added counters for total and individual CallInfo entries (to allow
better syncronization between CallInfo size and stack size)
-rw-r--r-- | lstate.c | 24 | ||||
-rw-r--r-- | lstate.h | 4 |
2 files changed, 19 insertions, 9 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstate.c,v 2.130 2015/09/08 15:41:05 roberto Exp roberto $ | 2 | ** $Id: lstate.c,v 2.131 2015/10/20 13:11:05 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 | */ |
@@ -111,6 +111,7 @@ CallInfo *luaE_extendCI (lua_State *L) { | |||
111 | L->ci->next = ci; | 111 | L->ci->next = ci; |
112 | ci->previous = L->ci; | 112 | ci->previous = L->ci; |
113 | ci->next = NULL; | 113 | ci->next = NULL; |
114 | ci->n = ++L->nci; | ||
114 | return ci; | 115 | return ci; |
115 | } | 116 | } |
116 | 117 | ||
@@ -126,6 +127,7 @@ void luaE_freeCI (lua_State *L) { | |||
126 | next = ci->next; | 127 | next = ci->next; |
127 | luaM_free(L, ci); | 128 | luaM_free(L, ci); |
128 | } | 129 | } |
130 | L->nci = L->ci->n; | ||
129 | } | 131 | } |
130 | 132 | ||
131 | 133 | ||
@@ -134,14 +136,17 @@ void luaE_freeCI (lua_State *L) { | |||
134 | */ | 136 | */ |
135 | void luaE_shrinkCI (lua_State *L) { | 137 | void luaE_shrinkCI (lua_State *L) { |
136 | CallInfo *ci = L->ci; | 138 | CallInfo *ci = L->ci; |
137 | while (ci->next != NULL) { /* while there is 'next' */ | 139 | CallInfo *next; |
138 | CallInfo *next2 = ci->next->next; /* next's next */ | 140 | int n = (L->nci - ci->n + 1)/2; /* number of entries to be preserved */ |
139 | if (next2 == NULL) break; | 141 | for (; n > 0; n--) |
140 | luaM_free(L, ci->next); /* remove next */ | 142 | ci = ci->next; /* skip items to be preserved */ |
141 | ci->next = next2; /* remove 'next' from the list */ | 143 | lua_assert(n == 0); |
142 | next2->previous = ci; | 144 | while ((next = ci->next) != NULL) { /* remove all other items */ |
143 | ci = next2; | 145 | ci->next = next->next; |
146 | luaM_free(L, next); /* remove item */ | ||
147 | n++; /* count number of removed items */ | ||
144 | } | 148 | } |
149 | L->nci -= n; | ||
145 | } | 150 | } |
146 | 151 | ||
147 | 152 | ||
@@ -156,6 +161,7 @@ static void stack_init (lua_State *L1, lua_State *L) { | |||
156 | L1->stack_last = L1->stack + L1->stacksize - EXTRA_STACK; | 161 | L1->stack_last = L1->stack + L1->stacksize - EXTRA_STACK; |
157 | /* initialize first ci */ | 162 | /* initialize first ci */ |
158 | ci = &L1->base_ci; | 163 | ci = &L1->base_ci; |
164 | ci->n = 0; | ||
159 | ci->next = ci->previous = NULL; | 165 | ci->next = ci->previous = NULL; |
160 | ci->callstatus = 0; | 166 | ci->callstatus = 0; |
161 | ci->func = L1->top; | 167 | ci->func = L1->top; |
@@ -170,6 +176,7 @@ static void freestack (lua_State *L) { | |||
170 | return; /* stack not completely built yet */ | 176 | return; /* stack not completely built yet */ |
171 | L->ci = &L->base_ci; /* free the entire 'ci' list */ | 177 | L->ci = &L->base_ci; /* free the entire 'ci' list */ |
172 | luaE_freeCI(L); | 178 | luaE_freeCI(L); |
179 | lua_assert(L->nci == 0); | ||
173 | luaM_freearray(L, L->stack, L->stacksize); /* free stack array */ | 180 | luaM_freearray(L, L->stack, L->stacksize); /* free stack array */ |
174 | } | 181 | } |
175 | 182 | ||
@@ -218,6 +225,7 @@ static void preinit_thread (lua_State *L, global_State *g) { | |||
218 | G(L) = g; | 225 | G(L) = g; |
219 | L->stack = NULL; | 226 | L->stack = NULL; |
220 | L->ci = NULL; | 227 | L->ci = NULL; |
228 | L->nci = 0; | ||
221 | L->stacksize = 0; | 229 | L->stacksize = 0; |
222 | L->twups = L; /* thread has no upvalues */ | 230 | L->twups = L; /* thread has no upvalues */ |
223 | L->errorJmp = NULL; | 231 | L->errorJmp = NULL; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstate.h,v 2.125 2015/09/22 14:18:24 roberto Exp roberto $ | 2 | ** $Id: lstate.h,v 2.126 2015/11/02 11:43:17 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 | */ |
@@ -78,6 +78,7 @@ typedef struct CallInfo { | |||
78 | } c; | 78 | } c; |
79 | } u; | 79 | } u; |
80 | ptrdiff_t extra; | 80 | ptrdiff_t extra; |
81 | unsigned short n; /* ordinal number in call list */ | ||
81 | short nresults; /* expected number of results from this function */ | 82 | short nresults; /* expected number of results from this function */ |
82 | lu_byte callstatus; | 83 | lu_byte callstatus; |
83 | } CallInfo; | 84 | } CallInfo; |
@@ -149,6 +150,7 @@ typedef struct global_State { | |||
149 | */ | 150 | */ |
150 | struct lua_State { | 151 | struct lua_State { |
151 | CommonHeader; | 152 | CommonHeader; |
153 | unsigned short nci; /* number of items in 'ci' list */ | ||
152 | lu_byte status; | 154 | lu_byte status; |
153 | StkId top; /* first free slot in the stack */ | 155 | StkId top; /* first free slot in the stack */ |
154 | global_State *l_G; | 156 | global_State *l_G; |