aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-07-19 12:09:37 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-07-19 12:09:37 -0300
commite43612aaf62bbb92fd7555b132d9ee1c0394dc58 (patch)
tree552eabfbbdce5a60754200d36f23e84ddf0e2adc
parent2898e2fd12db741c58813671e56e628039d9bdc7 (diff)
downloadlua-e43612aaf62bbb92fd7555b132d9ee1c0394dc58.tar.gz
lua-e43612aaf62bbb92fd7555b132d9ee1c0394dc58.tar.bz2
lua-e43612aaf62bbb92fd7555b132d9ee1c0394dc58.zip
put the restriction that 'luaC_barrierback' works only on tables
in its prototype
-rw-r--r--lapi.c40
-rw-r--r--lgc.c16
-rw-r--r--lgc.h6
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 @@
1/* 1/*
2** $Id: lapi.c,v 2.227 2014/07/18 12:17:54 roberto Exp roberto $ 2** $Id: lapi.c,v 2.228 2014/07/18 14:46:47 roberto Exp roberto $
3** Lua API 3** Lua API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -755,42 +755,48 @@ LUA_API void lua_setfield (lua_State *L, int idx, const char *k) {
755 755
756 756
757LUA_API void lua_rawset (lua_State *L, int idx) { 757LUA_API void lua_rawset (lua_State *L, int idx) {
758 StkId t; 758 StkId o;
759 Table *t;
759 lua_lock(L); 760 lua_lock(L);
760 api_checknelems(L, 2); 761 api_checknelems(L, 2);
761 t = index2addr(L, idx); 762 o = index2addr(L, idx);
762 api_check(ttistable(t), "table expected"); 763 api_check(ttistable(o), "table expected");
763 setobj2t(L, luaH_set(L, hvalue(t), L->top-2), L->top-1); 764 t = hvalue(o);
764 invalidateTMcache(hvalue(t)); 765 setobj2t(L, luaH_set(L, t, L->top-2), L->top-1);
765 luaC_barrierback(L, gcvalue(t), L->top-1); 766 invalidateTMcache(t);
767 luaC_barrierback(L, t, L->top-1);
766 L->top -= 2; 768 L->top -= 2;
767 lua_unlock(L); 769 lua_unlock(L);
768} 770}
769 771
770 772
771LUA_API void lua_rawseti (lua_State *L, int idx, lua_Integer n) { 773LUA_API void lua_rawseti (lua_State *L, int idx, lua_Integer n) {
772 StkId t; 774 StkId o;
775 Table *t;
773 lua_lock(L); 776 lua_lock(L);
774 api_checknelems(L, 1); 777 api_checknelems(L, 1);
775 t = index2addr(L, idx); 778 o = index2addr(L, idx);
776 api_check(ttistable(t), "table expected"); 779 api_check(ttistable(o), "table expected");
777 luaH_setint(L, hvalue(t), n, L->top - 1); 780 t = hvalue(o);
778 luaC_barrierback(L, gcvalue(t), L->top-1); 781 luaH_setint(L, t, n, L->top - 1);
782 luaC_barrierback(L, t, L->top-1);
779 L->top--; 783 L->top--;
780 lua_unlock(L); 784 lua_unlock(L);
781} 785}
782 786
783 787
784LUA_API void lua_rawsetp (lua_State *L, int idx, const void *p) { 788LUA_API void lua_rawsetp (lua_State *L, int idx, const void *p) {
785 StkId t; 789 StkId o;
790 Table *t;
786 TValue k; 791 TValue k;
787 lua_lock(L); 792 lua_lock(L);
788 api_checknelems(L, 1); 793 api_checknelems(L, 1);
789 t = index2addr(L, idx); 794 o = index2addr(L, idx);
790 api_check(ttistable(t), "table expected"); 795 api_check(ttistable(o), "table expected");
796 t = hvalue(o);
791 setpvalue(&k, cast(void *, p)); 797 setpvalue(&k, cast(void *, p));
792 setobj2t(L, luaH_set(L, hvalue(t), &k), L->top - 1); 798 setobj2t(L, luaH_set(L, t, &k), L->top - 1);
793 luaC_barrierback(L, gcvalue(t), L->top - 1); 799 luaC_barrierback(L, t, L->top - 1);
794 L->top--; 800 L->top--;
795 lua_unlock(L); 801 lua_unlock(L);
796} 802}
diff --git a/lgc.c b/lgc.c
index 958322a0..896aeef0 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.c,v 2.188 2014/07/18 14:46:47 roberto Exp roberto $ 2** $Id: lgc.c,v 2.189 2014/07/19 14:44:19 roberto Exp roberto $
3** Garbage Collector 3** Garbage Collector
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -153,16 +153,14 @@ void luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v) {
153 153
154/* 154/*
155** barrier that moves collector backward, that is, mark the black object 155** barrier that moves collector backward, that is, mark the black object
156** pointing to a white object as gray again. (Current implementation 156** pointing to a white object as gray again.
157** only works for tables; access to 'gclist' is not uniform across
158** different types.)
159*/ 157*/
160void luaC_barrierback_ (lua_State *L, GCObject *o) { 158void luaC_barrierback_ (lua_State *L, Table *t) {
161 global_State *g = G(L); 159 global_State *g = G(L);
162 lua_assert(isblack(o) && !isdead(g, o) && o->tt == LUA_TTABLE); 160 lua_assert(isblack(t) && !isdead(g, t));
163 black2gray(o); /* make object gray (again) */ 161 black2gray(t); /* make table gray (again) */
164 gco2t(o)->gclist = g->grayagain; 162 t->gclist = g->grayagain;
165 g->grayagain = o; 163 g->grayagain = obj2gco(t);
166} 164}
167 165
168 166
diff --git a/lgc.h b/lgc.h
index 1d0403f3..bc8032aa 100644
--- a/lgc.h
+++ b/lgc.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.h,v 2.82 2014/03/19 18:51:16 roberto Exp roberto $ 2** $Id: lgc.h,v 2.83 2014/07/17 17:27:49 roberto Exp roberto $
3** Garbage Collector 3** Garbage Collector
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -112,7 +112,7 @@
112 112
113#define luaC_barrierback(L,p,v) { \ 113#define luaC_barrierback(L,p,v) { \
114 if (iscollectable(v) && isblack(obj2gco(p)) && iswhite(gcvalue(v))) \ 114 if (iscollectable(v) && isblack(obj2gco(p)) && iswhite(gcvalue(v))) \
115 luaC_barrierback_(L,obj2gco(p)); } 115 luaC_barrierback_(L,p); }
116 116
117#define luaC_objbarrier(L,p,o) { \ 117#define luaC_objbarrier(L,p,o) { \
118 if (isblack(obj2gco(p)) && iswhite(obj2gco(o))) \ 118 if (isblack(obj2gco(p)) && iswhite(obj2gco(o))) \
@@ -129,7 +129,7 @@ LUAI_FUNC void luaC_runtilstate (lua_State *L, int statesmask);
129LUAI_FUNC void luaC_fullgc (lua_State *L, int isemergency); 129LUAI_FUNC void luaC_fullgc (lua_State *L, int isemergency);
130LUAI_FUNC GCObject *luaC_newobj (lua_State *L, int tt, size_t sz); 130LUAI_FUNC GCObject *luaC_newobj (lua_State *L, int tt, size_t sz);
131LUAI_FUNC void luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v); 131LUAI_FUNC void luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v);
132LUAI_FUNC void luaC_barrierback_ (lua_State *L, GCObject *o); 132LUAI_FUNC void luaC_barrierback_ (lua_State *L, Table *o);
133LUAI_FUNC void luaC_upvalbarrier_ (lua_State *L, UpVal *uv); 133LUAI_FUNC void luaC_upvalbarrier_ (lua_State *L, UpVal *uv);
134LUAI_FUNC void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt); 134LUAI_FUNC void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt);
135LUAI_FUNC void luaC_upvdeccount (lua_State *L, UpVal *uv); 135LUAI_FUNC void luaC_upvdeccount (lua_State *L, UpVal *uv);