commit d394d5536aeccb937fb6fd8e7476b08d672bc892
parent a2f98314a30859b217d6f7f7741c785a8e029e3c
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Mon, 5 Apr 2010 13:26:13 -0300
new macro 'eqstr'
Diffstat:
6 files changed, 25 insertions(+), 14 deletions(-)
diff --git a/ldebug.c b/ldebug.c
@@ -1,5 +1,5 @@
/*
-** $Id: ldebug.c,v 2.66 2010/03/12 19:14:06 roberto Exp roberto $
+** $Id: ldebug.c,v 2.67 2010/03/13 15:55:42 roberto Exp roberto $
** Debug Interface
** See Copyright Notice in lua.h
*/
@@ -300,11 +300,11 @@ static const char *getobjname (lua_State *L, CallInfo *ci, int reg,
if (reg == a) {
int k = GETARG_C(i); /* key index */
int t = GETARG_B(i);
- const char *tabname = (op == OP_GETTABLE)
- ? luaF_getlocalname(p, t + 1, pc)
- : getstr(p->upvalues[t].name);
+ const char *vn = (op == OP_GETTABLE) /* name of indexed variable */
+ ? luaF_getlocalname(p, t + 1, pc)
+ : getstr(p->upvalues[t].name);
kname(p, k, a, what, name);
- what = (tabname == getstr(G(L)->envn)) ? "global" : "field";
+ what = (vn && strcmp(vn, "_ENV") == 0) ? "global" : "field";
}
break;
}
@@ -427,7 +427,7 @@ static const char *getupvalname (CallInfo *ci, const TValue *o,
LClosure *c = &ci_func(ci)->l;
int i;
for (i = 0; i < c->nupvalues; i++) {
- if (c->upvals[i]->v == o) {
+ if (eqstr(c->upvals[i]->v, o)) {
*name = getstr(c->p->upvalues[i].name);
return "upvalue";
}
diff --git a/lobject.c b/lobject.c
@@ -1,5 +1,5 @@
/*
-** $Id: lobject.c,v 2.35 2010/02/05 19:09:09 roberto Exp roberto $
+** $Id: lobject.c,v 2.36 2010/04/02 15:30:27 roberto Exp roberto $
** Some generic functions over Lua objects
** See Copyright Notice in lua.h
*/
@@ -81,6 +81,8 @@ int luaO_rawequalObj (const TValue *t1, const TValue *t2) {
return bvalue(t1) == bvalue(t2); /* boolean true must be 1 !! */
case LUA_TLIGHTUSERDATA:
return pvalue(t1) == pvalue(t2);
+ case LUA_TSTRING:
+ return rawtsvalue(t1) == rawtsvalue(t2);
default:
lua_assert(iscollectable(t1));
return gcvalue(t1) == gcvalue(t2);
diff --git a/lparser.c b/lparser.c
@@ -1,5 +1,5 @@
/*
-** $Id: lparser.c,v 2.79 2010/03/12 19:14:06 roberto Exp roberto $
+** $Id: lparser.c,v 2.80 2010/03/13 15:55:42 roberto Exp roberto $
** Lua Parser
** See Copyright Notice in lua.h
*/
@@ -211,7 +211,7 @@ static int searchupvalue (FuncState *fs, TString *name) {
int i;
Upvaldesc *up = fs->f->upvalues;
for (i = 0; i < fs->nups; i++) {
- if (up[i].name == name) return i;
+ if (eqstr(up[i].name, name)) return i;
}
return -1; /* not found */
}
@@ -235,7 +235,7 @@ static int newupvalue (FuncState *fs, TString *name, expdesc *v) {
static int searchvar (FuncState *fs, TString *n) {
int i;
for (i=fs->nactvar-1; i >= 0; i--) {
- if (n == getlocvar(fs, i)->varname)
+ if (eqstr(n, getlocvar(fs, i)->varname))
return i;
}
return -1; /* not found */
diff --git a/lstring.h b/lstring.h
@@ -1,5 +1,5 @@
/*
-** $Id: lstring.h,v 1.44 2010/03/13 15:55:01 roberto Exp roberto $
+** $Id: lstring.h,v 1.45 2010/04/03 20:24:18 roberto Exp roberto $
** String table (keep all strings handled by Lua)
** See Copyright Notice in lua.h
*/
@@ -21,6 +21,13 @@
#define luaS_fix(s) l_setbit((s)->tsv.marked, FIXEDBIT)
+
+/*
+** as all string are internalized, string equality becomes
+** pointer equality
+*/
+#define eqstr(a,b) ((a) == (b))
+
LUAI_FUNC void luaS_resize (lua_State *L, int newsize);
LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, Table *e);
LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l);
diff --git a/ltable.c b/ltable.c
@@ -1,5 +1,5 @@
/*
-** $Id: ltable.c,v 2.46 2009/11/26 11:39:20 roberto Exp roberto $
+** $Id: ltable.c,v 2.47 2009/12/17 15:46:44 roberto Exp roberto $
** Lua tables (hash)
** See Copyright Notice in lua.h
*/
@@ -31,6 +31,7 @@
#include "lmem.h"
#include "lobject.h"
#include "lstate.h"
+#include "lstring.h"
#include "ltable.h"
@@ -452,7 +453,7 @@ const TValue *luaH_getint (Table *t, int key) {
const TValue *luaH_getstr (Table *t, TString *key) {
Node *n = hashstr(t, key);
do { /* check whether `key' is somewhere in the chain */
- if (ttisstring(gkey(n)) && rawtsvalue(gkey(n)) == key)
+ if (ttisstring(gkey(n)) && eqstr(rawtsvalue(gkey(n)), key))
return gval(n); /* that's it */
else n = gnext(n);
} while (n);
diff --git a/lvm.c b/lvm.c
@@ -1,5 +1,5 @@
/*
-** $Id: lvm.c,v 2.108 2010/03/29 20:45:49 roberto Exp roberto $
+** $Id: lvm.c,v 2.109 2010/04/02 15:39:07 roberto Exp roberto $
** Lua virtual machine
** See Copyright Notice in lua.h
*/
@@ -254,6 +254,7 @@ int luaV_equalval_ (lua_State *L, const TValue *t1, const TValue *t2) {
case LUA_TNUMBER: return luai_numeq(nvalue(t1), nvalue(t2));
case LUA_TBOOLEAN: return bvalue(t1) == bvalue(t2); /* true must be 1 !! */
case LUA_TLIGHTUSERDATA: return pvalue(t1) == pvalue(t2);
+ case LUA_TSTRING: return eqstr(rawtsvalue(t1), rawtsvalue(t2));
case LUA_TUSERDATA: {
if (uvalue(t1) == uvalue(t2)) return 1;
tm = get_compTM(L, uvalue(t1)->metatable, uvalue(t2)->metatable, TM_EQ);