aboutsummaryrefslogtreecommitdiff
path: root/ldebug.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2018-11-29 16:02:44 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2018-11-29 16:02:44 -0200
commit6d04537ea660fd12fc16c328366b701fabaf4919 (patch)
tree41eab6e4d87552e29731db552f7d58d679c56973 /ldebug.c
parent7696c6474fe51ed59fee324e78c1233af74febdd (diff)
downloadlua-6d04537ea660fd12fc16c328366b701fabaf4919.tar.gz
lua-6d04537ea660fd12fc16c328366b701fabaf4919.tar.bz2
lua-6d04537ea660fd12fc16c328366b701fabaf4919.zip
A to-be-closed variable must have a closable value (or be nil)
It is an error for a to-be-closed variable to have a non-closable non-nil value when it is being closed. This situation does not seem to be useful and often hints to an error. (Particularly in the C API, it is easy to change a to-be-closed index by mistake.)
Diffstat (limited to 'ldebug.c')
-rw-r--r--ldebug.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/ldebug.c b/ldebug.c
index 766a5231..bd471e0c 100644
--- a/ldebug.c
+++ b/ldebug.c
@@ -192,15 +192,14 @@ static const char *findvararg (CallInfo *ci, int n, StkId *pos) {
192 int nextra = ci->u.l.nextraargs; 192 int nextra = ci->u.l.nextraargs;
193 if (n <= nextra) { 193 if (n <= nextra) {
194 *pos = ci->func - nextra + (n - 1); 194 *pos = ci->func - nextra + (n - 1);
195 return "(*vararg)"; /* generic name for any vararg */ 195 return "(vararg)"; /* generic name for any vararg */
196 } 196 }
197 } 197 }
198 return NULL; /* no such vararg */ 198 return NULL; /* no such vararg */
199} 199}
200 200
201 201
202static const char *findlocal (lua_State *L, CallInfo *ci, int n, 202const char *luaG_findlocal (lua_State *L, CallInfo *ci, int n, StkId *pos) {
203 StkId *pos) {
204 StkId base = ci->func + 1; 203 StkId base = ci->func + 1;
205 const char *name = NULL; 204 const char *name = NULL;
206 if (isLua(ci)) { 205 if (isLua(ci)) {
@@ -211,12 +210,15 @@ static const char *findlocal (lua_State *L, CallInfo *ci, int n,
211 } 210 }
212 if (name == NULL) { /* no 'standard' name? */ 211 if (name == NULL) { /* no 'standard' name? */
213 StkId limit = (ci == L->ci) ? L->top : ci->next->func; 212 StkId limit = (ci == L->ci) ? L->top : ci->next->func;
214 if (limit - base >= n && n > 0) /* is 'n' inside 'ci' stack? */ 213 if (limit - base >= n && n > 0) { /* is 'n' inside 'ci' stack? */
215 name = "(*temporary)"; /* generic name for any valid slot */ 214 /* generic name for any valid slot */
215 name = isLua(ci) ? "(temporary)" : "(C temporary)";
216 }
216 else 217 else
217 return NULL; /* no name */ 218 return NULL; /* no name */
218 } 219 }
219 *pos = base + (n - 1); 220 if (pos)
221 *pos = base + (n - 1);
220 return name; 222 return name;
221} 223}
222 224
@@ -232,7 +234,7 @@ LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {
232 } 234 }
233 else { /* active function; get information through 'ar' */ 235 else { /* active function; get information through 'ar' */
234 StkId pos = NULL; /* to avoid warnings */ 236 StkId pos = NULL; /* to avoid warnings */
235 name = findlocal(L, ar->i_ci, n, &pos); 237 name = luaG_findlocal(L, ar->i_ci, n, &pos);
236 if (name) { 238 if (name) {
237 setobjs2s(L, L->top, pos); 239 setobjs2s(L, L->top, pos);
238 api_incr_top(L); 240 api_incr_top(L);
@@ -247,7 +249,7 @@ LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) {
247 StkId pos = NULL; /* to avoid warnings */ 249 StkId pos = NULL; /* to avoid warnings */
248 const char *name; 250 const char *name;
249 lua_lock(L); 251 lua_lock(L);
250 name = findlocal(L, ar->i_ci, n, &pos); 252 name = luaG_findlocal(L, ar->i_ci, n, &pos);
251 if (name) { 253 if (name) {
252 setobjs2s(L, pos, L->top - 1); 254 setobjs2s(L, pos, L->top - 1);
253 L->top--; /* pop value */ 255 L->top--; /* pop value */