فهرست منبع

put the restriction that 'luaC_barrierback' works only on tables
in its prototype

Roberto Ierusalimschy 11 سال پیش
والد
کامیت
e43612aaf6
3فایلهای تغییر یافته به همراه33 افزوده شده و 29 حذف شده
  1. 23 17
      lapi.c
  2. 7 9
      lgc.c
  3. 3 3
      lgc.h

+ 23 - 17
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
 ** Lua API
 ** See Copyright Notice in lua.h
 ** 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) {
 LUA_API void lua_rawset (lua_State *L, int idx) {
-  StkId t;
+  StkId o;
+  Table *t;
   lua_lock(L);
   lua_lock(L);
   api_checknelems(L, 2);
   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;
   L->top -= 2;
   lua_unlock(L);
   lua_unlock(L);
 }
 }
 
 
 
 
 LUA_API void lua_rawseti (lua_State *L, int idx, lua_Integer n) {
 LUA_API void lua_rawseti (lua_State *L, int idx, lua_Integer n) {
-  StkId t;
+  StkId o;
+  Table *t;
   lua_lock(L);
   lua_lock(L);
   api_checknelems(L, 1);
   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--;
   L->top--;
   lua_unlock(L);
   lua_unlock(L);
 }
 }
 
 
 
 
 LUA_API void lua_rawsetp (lua_State *L, int idx, const void *p) {
 LUA_API void lua_rawsetp (lua_State *L, int idx, const void *p) {
-  StkId t;
+  StkId o;
+  Table *t;
   TValue k;
   TValue k;
   lua_lock(L);
   lua_lock(L);
   api_checknelems(L, 1);
   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));
   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--;
   L->top--;
   lua_unlock(L);
   lua_unlock(L);
 }
 }

+ 7 - 9
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
 ** Garbage Collector
 ** See Copyright Notice in lua.h
 ** 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
 ** 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);
   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);
 }
 }
 
 
 
 

+ 3 - 3
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
 ** Garbage Collector
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -112,7 +112,7 @@
 
 
 #define luaC_barrierback(L,p,v) {  \
 #define luaC_barrierback(L,p,v) {  \
 	if (iscollectable(v) && isblack(obj2gco(p)) && iswhite(gcvalue(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) {  \
 #define luaC_objbarrier(L,p,o) {  \
 	if (isblack(obj2gco(p)) && iswhite(obj2gco(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 void luaC_fullgc (lua_State *L, int isemergency);
 LUAI_FUNC GCObject *luaC_newobj (lua_State *L, int tt, size_t sz);
 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_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_upvalbarrier_ (lua_State *L, UpVal *uv);
 LUAI_FUNC void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt);
 LUAI_FUNC void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt);
 LUAI_FUNC void luaC_upvdeccount (lua_State *L, UpVal *uv);
 LUAI_FUNC void luaC_upvdeccount (lua_State *L, UpVal *uv);