aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2011-04-28 11:00:11 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2011-04-28 11:00:11 -0300
commitd120ec29ca6bae7a8f0040c7a0cee27aca7dd81a (patch)
tree8fc27ceb18ff8a10eef242f5ea492a71f803ae36
parent2aff901c932862ccdb32c145d0034c20fe4fc41d (diff)
downloadlua-d120ec29ca6bae7a8f0040c7a0cee27aca7dd81a.tar.gz
lua-d120ec29ca6bae7a8f0040c7a0cee27aca7dd81a.tar.bz2
lua-d120ec29ca6bae7a8f0040c7a0cee27aca7dd81a.zip
bug in OP_SELF when method name goes to a register
-rw-r--r--lcode.c14
-rw-r--r--ldebug.c44
2 files changed, 39 insertions, 19 deletions
diff --git a/lcode.c b/lcode.c
index d2d4b819..a1650979 100644
--- a/lcode.c
+++ b/lcode.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lcode.c,v 2.52 2011/04/07 18:14:12 roberto Exp roberto $ 2** $Id: lcode.c,v 2.53 2011/04/19 16:22:13 roberto Exp roberto $
3** Code generator for Lua 3** Code generator for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -581,15 +581,15 @@ void luaK_storevar (FuncState *fs, expdesc *var, expdesc *ex) {
581 581
582 582
583void luaK_self (FuncState *fs, expdesc *e, expdesc *key) { 583void luaK_self (FuncState *fs, expdesc *e, expdesc *key) {
584 int func; 584 int ereg;
585 luaK_exp2anyreg(fs, e); 585 luaK_exp2anyreg(fs, e);
586 ereg = e->u.info; /* register where 'e' was placed */
586 freeexp(fs, e); 587 freeexp(fs, e);
587 func = fs->freereg; 588 e->u.info = fs->freereg; /* base register for op_self */
588 luaK_codeABC(fs, OP_SELF, func, e->u.info, luaK_exp2RK(fs, key));
589 freeexp(fs, key);
590 luaK_reserveregs(fs, 2);
591 e->u.info = func;
592 e->k = VNONRELOC; 589 e->k = VNONRELOC;
590 luaK_reserveregs(fs, 2); /* function and 'self' produced by op_self */
591 luaK_codeABC(fs, OP_SELF, e->u.info, ereg, luaK_exp2RK(fs, key));
592 freeexp(fs, key);
593} 593}
594 594
595 595
diff --git a/ldebug.c b/ldebug.c
index 1d0be89e..1576aebf 100644
--- a/ldebug.c
+++ b/ldebug.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldebug.c,v 2.79 2011/04/18 19:49:13 roberto Exp roberto $ 2** $Id: ldebug.c,v 2.80 2011/04/19 16:22:13 roberto Exp roberto $
3** Debug Interface 3** Debug Interface
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -284,15 +284,32 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {
284** ======================================================= 284** =======================================================
285*/ 285*/
286 286
287static const char *getobjname (lua_State *L, CallInfo *ci, int reg,
288 const char **name);
287 289
288static void kname (Proto *p, int c, int reg, const char *what, 290
289 const char **name) { 291/*
290 if (c == reg && what && *what == 'c') 292** find a "name" for the RK value 'c'
291 return; /* index is a constant; name already correct */ 293*/
292 else if (ISK(c) && ttisstring(&p->k[INDEXK(c)])) 294static void kname (lua_State *L, CallInfo *ci, int c, int oreg,
293 *name = svalue(&p->k[INDEXK(c)]); 295 const char *what, const char **name) {
294 else 296 if (ISK(c)) { /* is 'c' a constant? */
295 *name = "?"; 297 TValue *kvalue = &ci_func(ci)->l.p->k[INDEXK(c)];
298 if (ttisstring(kvalue)) { /* literal constant? */
299 *name = svalue(kvalue); /* it is its own name */
300 return;
301 }
302 /* else no reasonable name found */
303 }
304 else { /* 'c' is a register */
305 if (c != oreg) /* not the original register? */
306 what = getobjname(L, ci, c, name); /* search for 'c' */
307 if (what && *what == 'c') { /* found a constant name? */
308 return; /* 'name' already filled */
309 }
310 /* else no reasonable name found */
311 }
312 *name = "?"; /* no reasonable name found */
296} 313}
297 314
298 315
@@ -328,7 +345,7 @@ static const char *getobjname (lua_State *L, CallInfo *ci, int reg,
328 const char *vn = (op == OP_GETTABLE) /* name of indexed variable */ 345 const char *vn = (op == OP_GETTABLE) /* name of indexed variable */
329 ? luaF_getlocalname(p, t + 1, pc) 346 ? luaF_getlocalname(p, t + 1, pc)
330 : getstr(p->upvalues[t].name); 347 : getstr(p->upvalues[t].name);
331 kname(p, k, a, what, name); 348 kname(L, ci, k, a, what, name);
332 what = (vn && strcmp(vn, LUA_ENV) == 0) ? "global" : "field"; 349 what = (vn && strcmp(vn, LUA_ENV) == 0) ? "global" : "field";
333 } 350 }
334 break; 351 break;
@@ -363,7 +380,7 @@ static const char *getobjname (lua_State *L, CallInfo *ci, int reg,
363 case OP_SELF: { 380 case OP_SELF: {
364 if (reg == a) { 381 if (reg == a) {
365 int k = GETARG_C(i); /* key index */ 382 int k = GETARG_C(i); /* key index */
366 kname(p, k, a, what, name); 383 kname(L, ci, k, a, what, name);
367 what = "method"; 384 what = "method";
368 } 385 }
369 break; 386 break;
@@ -443,7 +460,10 @@ static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) {
443 460
444 461
445 462
446/* only ANSI way to check whether a pointer points to an array */ 463/*
464** only ANSI way to check whether a pointer points to an array
465** (used only for error messages, so efficiency is not a big concern)
466*/
447static int isinstack (CallInfo *ci, const TValue *o) { 467static int isinstack (CallInfo *ci, const TValue *o) {
448 StkId p; 468 StkId p;
449 for (p = ci->u.l.base; p < ci->top; p++) 469 for (p = ci->u.l.base; p < ci->top; p++)