Skip to content
Permalink
Browse files
check table in luaV_fastset
  • Loading branch information
cloudwu committed Apr 12, 2016
1 parent d2340c5 commit 6f7816d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
@@ -361,7 +361,7 @@ void luaK_tableK (FuncState *fs, Table *t, int pc) {
}
break;
case OP_SETTABLE:
setobj2t(L, luaH_set(L, t, &f->k[INDEXK(GETARG_B(f->code[i]))]), &f->k[INDEXK(GETARG_B(f->code[i]))]);
setobj2t(L, luaH_set(L, t, &f->k[INDEXK(GETARG_B(f->code[i]))]), &f->k[INDEXK(GETARG_C(f->code[i]))]);
break;
default:
lua_assert(o == OP_SETLIST);
@@ -335,7 +335,7 @@ static void setnodevector (lua_State *L, Table *t, unsigned int size) {
t->lastfree = gnode(t, size); /* all positions are free */
}

static void makemutable (lua_State *L, Table *t) {
Table * luaH_makemutable_ (lua_State *L, Table *t) {
Table *from = t->constant;
int sizearray = from->sizearray;
int sizenode = twoto(from->lsizenode);
@@ -345,6 +345,7 @@ static void makemutable (lua_State *L, Table *t) {
memcpy(t->node, from->node, sizenode * sizeof(Node));
t->lastfree = t->node + (from->lastfree - from->node);
t->constant = NULL;
return t;
}

void luaH_resize (lua_State *L, Table *t, unsigned int nasize,
@@ -355,8 +356,7 @@ void luaH_resize (lua_State *L, Table *t, unsigned int nasize,
int oldhsize;
Node *nold;

if (t->constant)
makemutable(L, t);
luaH_makemutable(L, t);
oldasize = t->sizearray;
oldhsize = t->lsizenode;

@@ -391,8 +391,7 @@ void luaH_resize (lua_State *L, Table *t, unsigned int nasize,

void luaH_resizearray (lua_State *L, Table *t, unsigned int nasize) {
int nsize;
if (t->constant)
makemutable(L, t);
luaH_makemutable(L, t);
nsize = isdummy(t->node) ? 0 : sizenode(t);
luaH_resize(L, t, nasize, nsize);
}
@@ -468,8 +467,7 @@ static Node *getfreepos (Table *t) {
TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key) {
Node *mp;
TValue aux;
if (t->constant)
makemutable(L, t);
luaH_makemutable(L, t);
if (ttisnil(key)) luaG_runerror(L, "table index is nil");
else if (ttisfloat(key)) {
lua_Integer k;
@@ -626,8 +624,7 @@ const TValue *luaH_get (Table *t, const TValue *key) {
** barrier and invalidate the TM cache.
*/
TValue *luaH_set (lua_State *L, Table *t, const TValue *key) {
if (t->constant)
makemutable(L, t);
luaH_makemutable(L, t);
const TValue *p = luaH_get(t, key);
if (p != luaO_nilobject)
return cast(TValue *, p);
@@ -638,8 +635,7 @@ TValue *luaH_set (lua_State *L, Table *t, const TValue *key) {
void luaH_setint (lua_State *L, Table *t, lua_Integer key, TValue *value) {
const TValue *p;
TValue *cell;
if (t->constant)
makemutable(L, t);
luaH_makemutable(L, t);
p = luaH_getint(t, key);
if (p != luaO_nilobject)
cell = cast(TValue *, p);
@@ -39,6 +39,7 @@ LUAI_FUNC const TValue *luaH_getshortstr (Table *t, TString *key);
LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key);
LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key);
LUAI_FUNC TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key);
LUAI_FUNC Table * luaH_makemutable_ (lua_State *L, Table *t);
LUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key);
LUAI_FUNC Table *luaH_new (lua_State *L);
LUAI_FUNC void luaH_resize (lua_State *L, Table *t, unsigned int nasize,
@@ -48,6 +49,7 @@ LUAI_FUNC void luaH_free (lua_State *L, Table *t);
LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key);
LUAI_FUNC int luaH_getn (Table *t);

#define luaH_makemutable(L, t) (((t)->constant) ? luaH_makemutable_(L, t) : (t))

#if defined(LUA_DEBUG)
LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key);
@@ -11,6 +11,7 @@
#include "ldo.h"
#include "lobject.h"
#include "ltm.h"
#include "ltable.h"


#if !defined(LUA_NOCVTN2S)
@@ -81,7 +82,7 @@
#define luaV_fastset(L,t,k,slot,f,v) \
(!ttistable(t) \
? (slot = NULL, 0) \
: (slot = f(hvalue(t), k), \
: (luaH_makemutable(L, hvalue(t)), slot = f(hvalue(t), k), \
ttisnil(slot) ? 0 \
: (luaC_barrierback(L, hvalue(t), v), \
setobj2t(L, cast(TValue *,slot), v), \

0 comments on commit 6f7816d

Please sign in to comment.