From e43612aaf62bbb92fd7555b132d9ee1c0394dc58 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Sat, 19 Jul 2014 12:09:37 -0300 Subject: put the restriction that 'luaC_barrierback' works only on tables in its prototype --- lapi.c | 40 +++++++++++++++++++++++----------------- lgc.c | 16 +++++++--------- lgc.h | 6 +++--- 3 files changed, 33 insertions(+), 29 deletions(-) diff --git a/lapi.c b/lapi.c index 2f0a35cc..de1d9c64 100644 --- a/lapi.c +++ b/lapi.c @@ -1,5 +1,5 @@ /* -** $Id: lapi.c,v 2.227 2014/07/18 12:17:54 roberto Exp roberto $ +** $Id: lapi.c,v 2.228 2014/07/18 14:46:47 roberto Exp roberto $ ** Lua API ** See Copyright Notice in lua.h */ @@ -755,42 +755,48 @@ LUA_API void lua_setfield (lua_State *L, int idx, const char *k) { LUA_API void lua_rawset (lua_State *L, int idx) { - StkId t; + StkId o; + Table *t; lua_lock(L); api_checknelems(L, 2); - t = index2addr(L, idx); - api_check(ttistable(t), "table expected"); - setobj2t(L, luaH_set(L, hvalue(t), L->top-2), L->top-1); - invalidateTMcache(hvalue(t)); - luaC_barrierback(L, gcvalue(t), L->top-1); + o = index2addr(L, idx); + api_check(ttistable(o), "table expected"); + t = hvalue(o); + setobj2t(L, luaH_set(L, t, L->top-2), L->top-1); + invalidateTMcache(t); + luaC_barrierback(L, t, L->top-1); L->top -= 2; lua_unlock(L); } LUA_API void lua_rawseti (lua_State *L, int idx, lua_Integer n) { - StkId t; + StkId o; + Table *t; lua_lock(L); api_checknelems(L, 1); - t = index2addr(L, idx); - api_check(ttistable(t), "table expected"); - luaH_setint(L, hvalue(t), n, L->top - 1); - luaC_barrierback(L, gcvalue(t), L->top-1); + o = index2addr(L, idx); + api_check(ttistable(o), "table expected"); + t = hvalue(o); + luaH_setint(L, t, n, L->top - 1); + luaC_barrierback(L, t, L->top-1); L->top--; lua_unlock(L); } LUA_API void lua_rawsetp (lua_State *L, int idx, const void *p) { - StkId t; + StkId o; + Table *t; TValue k; lua_lock(L); api_checknelems(L, 1); - t = index2addr(L, idx); - api_check(ttistable(t), "table expected"); + o = index2addr(L, idx); + api_check(ttistable(o), "table expected"); + t = hvalue(o); setpvalue(&k, cast(void *, p)); - setobj2t(L, luaH_set(L, hvalue(t), &k), L->top - 1); - luaC_barrierback(L, gcvalue(t), L->top - 1); + setobj2t(L, luaH_set(L, t, &k), L->top - 1); + luaC_barrierback(L, t, L->top - 1); L->top--; lua_unlock(L); } diff --git a/lgc.c b/lgc.c index 958322a0..896aeef0 100644 --- a/lgc.c +++ b/lgc.c @@ -1,5 +1,5 @@ /* -** $Id: lgc.c,v 2.188 2014/07/18 14:46:47 roberto Exp roberto $ +** $Id: lgc.c,v 2.189 2014/07/19 14:44:19 roberto Exp roberto $ ** Garbage Collector ** See Copyright Notice in lua.h */ @@ -153,16 +153,14 @@ void luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v) { /* ** barrier that moves collector backward, that is, mark the black object -** pointing to a white object as gray again. (Current implementation -** only works for tables; access to 'gclist' is not uniform across -** different types.) +** pointing to a white object as gray again. */ -void luaC_barrierback_ (lua_State *L, GCObject *o) { +void luaC_barrierback_ (lua_State *L, Table *t) { global_State *g = G(L); - lua_assert(isblack(o) && !isdead(g, o) && o->tt == LUA_TTABLE); - black2gray(o); /* make object gray (again) */ - gco2t(o)->gclist = g->grayagain; - g->grayagain = o; + lua_assert(isblack(t) && !isdead(g, t)); + black2gray(t); /* make table gray (again) */ + t->gclist = g->grayagain; + g->grayagain = obj2gco(t); } diff --git a/lgc.h b/lgc.h index 1d0403f3..bc8032aa 100644 --- a/lgc.h +++ b/lgc.h @@ -1,5 +1,5 @@ /* -** $Id: lgc.h,v 2.82 2014/03/19 18:51:16 roberto Exp roberto $ +** $Id: lgc.h,v 2.83 2014/07/17 17:27:49 roberto Exp roberto $ ** Garbage Collector ** See Copyright Notice in lua.h */ @@ -112,7 +112,7 @@ #define luaC_barrierback(L,p,v) { \ if (iscollectable(v) && isblack(obj2gco(p)) && iswhite(gcvalue(v))) \ - luaC_barrierback_(L,obj2gco(p)); } + luaC_barrierback_(L,p); } #define luaC_objbarrier(L,p,o) { \ if (isblack(obj2gco(p)) && iswhite(obj2gco(o))) \ @@ -129,7 +129,7 @@ LUAI_FUNC void luaC_runtilstate (lua_State *L, int statesmask); LUAI_FUNC void luaC_fullgc (lua_State *L, int isemergency); LUAI_FUNC GCObject *luaC_newobj (lua_State *L, int tt, size_t sz); LUAI_FUNC void luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v); -LUAI_FUNC void luaC_barrierback_ (lua_State *L, GCObject *o); +LUAI_FUNC void luaC_barrierback_ (lua_State *L, Table *o); LUAI_FUNC void luaC_upvalbarrier_ (lua_State *L, UpVal *uv); LUAI_FUNC void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt); LUAI_FUNC void luaC_upvdeccount (lua_State *L, UpVal *uv); -- cgit v1.2.3-55-g6feb