diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-07-18 09:17:54 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-07-18 09:17:54 -0300 |
commit | 56137d58ff7abe8cb22ee3469366e08888c84f28 (patch) | |
tree | 6769e3c2403a69cf3f0d6dbf6fb4acb7442367e0 | |
parent | 9aec500a2691d2b13c307d143868c8a4fab33220 (diff) | |
download | lua-56137d58ff7abe8cb22ee3469366e08888c84f28.tar.gz lua-56137d58ff7abe8cb22ee3469366e08888c84f28.tar.bz2 lua-56137d58ff7abe8cb22ee3469366e08888c84f28.zip |
added check for conversion 'obj2gco' (and corrections for small
problems detected by this check)
-rw-r--r-- | lapi.c | 6 | ||||
-rw-r--r-- | lgc.c | 13 | ||||
-rw-r--r-- | llex.c | 6 | ||||
-rw-r--r-- | lobject.h | 6 | ||||
-rw-r--r-- | lparser.c | 8 | ||||
-rw-r--r-- | lstate.c | 4 | ||||
-rw-r--r-- | lstate.h | 16 | ||||
-rw-r--r-- | lstring.c | 6 | ||||
-rw-r--r-- | ltests.c | 21 | ||||
-rw-r--r-- | ltm.c | 4 |
10 files changed, 51 insertions, 39 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 2.225 2014/07/15 21:26:50 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 2.226 2014/07/17 13:53:37 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 | */ |
@@ -820,7 +820,7 @@ LUA_API int lua_setmetatable (lua_State *L, int objindex) { | |||
820 | case LUA_TUSERDATA: { | 820 | case LUA_TUSERDATA: { |
821 | uvalue(obj)->metatable = mt; | 821 | uvalue(obj)->metatable = mt; |
822 | if (mt) { | 822 | if (mt) { |
823 | luaC_objbarrier(L, rawuvalue(obj), mt); | 823 | luaC_objbarrier(L, uvalue(obj), mt); |
824 | luaC_checkfinalizer(L, gcvalue(obj), mt); | 824 | luaC_checkfinalizer(L, gcvalue(obj), mt); |
825 | } | 825 | } |
826 | break; | 826 | break; |
@@ -958,7 +958,7 @@ LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data, | |||
958 | const TValue *gt = luaH_getint(reg, LUA_RIDX_GLOBALS); | 958 | const TValue *gt = luaH_getint(reg, LUA_RIDX_GLOBALS); |
959 | /* set global table as 1st upvalue of 'f' (may be LUA_ENV) */ | 959 | /* set global table as 1st upvalue of 'f' (may be LUA_ENV) */ |
960 | setobj(L, f->upvals[0]->v, gt); | 960 | setobj(L, f->upvals[0]->v, gt); |
961 | luaC_barrier(L, f->upvals[0], gt); | 961 | luaC_upvalbarrier(L, f->upvals[0]); |
962 | } | 962 | } |
963 | } | 963 | } |
964 | lua_unlock(L); | 964 | lua_unlock(L); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lgc.c,v 2.184 2014/06/30 19:48:08 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 2.185 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 | */ |
@@ -83,6 +83,9 @@ | |||
83 | #define markobject(g,t) \ | 83 | #define markobject(g,t) \ |
84 | { if ((t) && iswhite(obj2gco(t))) reallymarkobject(g, obj2gco(t)); } | 84 | { if ((t) && iswhite(obj2gco(t))) reallymarkobject(g, obj2gco(t)); } |
85 | 85 | ||
86 | #define markstring(g,t) \ | ||
87 | { if ((t) && iswhite(ts2gco(t))) reallymarkobject(g, ts2gco(t)); } | ||
88 | |||
86 | static void reallymarkobject (global_State *g, GCObject *o); | 89 | static void reallymarkobject (global_State *g, GCObject *o); |
87 | 90 | ||
88 | 91 | ||
@@ -126,7 +129,7 @@ static void removeentry (Node *n) { | |||
126 | static int iscleared (global_State *g, const TValue *o) { | 129 | static int iscleared (global_State *g, const TValue *o) { |
127 | if (!iscollectable(o)) return 0; | 130 | if (!iscollectable(o)) return 0; |
128 | else if (ttisstring(o)) { | 131 | else if (ttisstring(o)) { |
129 | markobject(g, rawtsvalue(o)); /* strings are `values', so are never weak */ | 132 | markobject(g, tsvalue(o)); /* strings are `values', so are never weak */ |
130 | return 0; | 133 | return 0; |
131 | } | 134 | } |
132 | else return iswhite(gcvalue(o)); | 135 | else return iswhite(gcvalue(o)); |
@@ -448,15 +451,15 @@ static int traverseproto (global_State *g, Proto *f) { | |||
448 | int i; | 451 | int i; |
449 | if (f->cache && iswhite(obj2gco(f->cache))) | 452 | if (f->cache && iswhite(obj2gco(f->cache))) |
450 | f->cache = NULL; /* allow cache to be collected */ | 453 | f->cache = NULL; /* allow cache to be collected */ |
451 | markobject(g, f->source); | 454 | markstring(g, f->source); |
452 | for (i = 0; i < f->sizek; i++) /* mark literals */ | 455 | for (i = 0; i < f->sizek; i++) /* mark literals */ |
453 | markvalue(g, &f->k[i]); | 456 | markvalue(g, &f->k[i]); |
454 | for (i = 0; i < f->sizeupvalues; i++) /* mark upvalue names */ | 457 | for (i = 0; i < f->sizeupvalues; i++) /* mark upvalue names */ |
455 | markobject(g, f->upvalues[i].name); | 458 | markstring(g, f->upvalues[i].name); |
456 | for (i = 0; i < f->sizep; i++) /* mark nested protos */ | 459 | for (i = 0; i < f->sizep; i++) /* mark nested protos */ |
457 | markobject(g, f->p[i]); | 460 | markobject(g, f->p[i]); |
458 | for (i = 0; i < f->sizelocvars; i++) /* mark local-variable names */ | 461 | for (i = 0; i < f->sizelocvars; i++) /* mark local-variable names */ |
459 | markobject(g, f->locvars[i].varname); | 462 | markstring(g, f->locvars[i].varname); |
460 | return sizeof(Proto) + sizeof(Instruction) * f->sizecode + | 463 | return sizeof(Proto) + sizeof(Instruction) * f->sizecode + |
461 | sizeof(Proto *) * f->sizep + | 464 | sizeof(Proto *) * f->sizep + |
462 | sizeof(TValue) * f->sizek + | 465 | sizeof(TValue) * f->sizek + |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: llex.c,v 2.77 2014/05/11 14:45:43 roberto Exp roberto $ | 2 | ** $Id: llex.c,v 2.78 2014/05/21 15:22:02 roberto Exp roberto $ |
3 | ** Lexical Analyzer | 3 | ** Lexical Analyzer |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -67,10 +67,10 @@ static void save (LexState *ls, int c) { | |||
67 | void luaX_init (lua_State *L) { | 67 | void luaX_init (lua_State *L) { |
68 | int i; | 68 | int i; |
69 | TString *e = luaS_new(L, LUA_ENV); /* create env name */ | 69 | TString *e = luaS_new(L, LUA_ENV); /* create env name */ |
70 | luaC_fix(L, obj2gco(e)); /* never collect this name */ | 70 | luaC_fix(L, ts2gco(e)); /* never collect this name */ |
71 | for (i=0; i<NUM_RESERVED; i++) { | 71 | for (i=0; i<NUM_RESERVED; i++) { |
72 | TString *ts = luaS_new(L, luaX_tokens[i]); | 72 | TString *ts = luaS_new(L, luaX_tokens[i]); |
73 | luaC_fix(L, obj2gco(ts)); /* reserved words are never collected */ | 73 | luaC_fix(L, ts2gco(ts)); /* reserved words are never collected */ |
74 | ts->tsv.extra = cast_byte(i+1); /* reserved word */ | 74 | ts->tsv.extra = cast_byte(i+1); /* reserved word */ |
75 | } | 75 | } |
76 | } | 76 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lobject.h,v 2.95 2014/07/17 17:09:50 roberto Exp roberto $ | 2 | ** $Id: lobject.h,v 2.96 2014/07/17 17:27:49 roberto Exp roberto $ |
3 | ** Type definitions for Lua objects | 3 | ** Type definitions for Lua objects |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -210,12 +210,12 @@ typedef struct lua_TValue TValue; | |||
210 | 210 | ||
211 | #define setsvalue(L,obj,x) \ | 211 | #define setsvalue(L,obj,x) \ |
212 | { TValue *io = (obj); TString *x_ = (x); \ | 212 | { TValue *io = (obj); TString *x_ = (x); \ |
213 | val_(io).gc = obj2gco(x_); settt_(io, ctb(x_->tsv.tt)); \ | 213 | val_(io).gc = obj2gco(&x_->tsv); settt_(io, ctb(x_->tsv.tt)); \ |
214 | checkliveness(G(L),io); } | 214 | checkliveness(G(L),io); } |
215 | 215 | ||
216 | #define setuvalue(L,obj,x) \ | 216 | #define setuvalue(L,obj,x) \ |
217 | { TValue *io = (obj); Udata *x_ = (x); \ | 217 | { TValue *io = (obj); Udata *x_ = (x); \ |
218 | val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TUSERDATA)); \ | 218 | val_(io).gc = obj2gco(&x_->uv); settt_(io, ctb(LUA_TUSERDATA)); \ |
219 | checkliveness(G(L),io); } | 219 | checkliveness(G(L),io); } |
220 | 220 | ||
221 | #define setthvalue(L,obj,x) \ | 221 | #define setthvalue(L,obj,x) \ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lparser.c,v 2.138 2013/12/30 20:47:58 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 2.139 2014/06/19 18:27:20 roberto Exp roberto $ |
3 | ** Lua Parser | 3 | ** Lua Parser |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -164,7 +164,7 @@ static int registerlocalvar (LexState *ls, TString *varname) { | |||
164 | LocVar, SHRT_MAX, "local variables"); | 164 | LocVar, SHRT_MAX, "local variables"); |
165 | while (oldsize < f->sizelocvars) f->locvars[oldsize++].varname = NULL; | 165 | while (oldsize < f->sizelocvars) f->locvars[oldsize++].varname = NULL; |
166 | f->locvars[fs->nlocvars].varname = varname; | 166 | f->locvars[fs->nlocvars].varname = varname; |
167 | luaC_objbarrier(ls->L, f, varname); | 167 | luaC_objbarrier(ls->L, f, ts2gco(varname)); |
168 | return fs->nlocvars++; | 168 | return fs->nlocvars++; |
169 | } | 169 | } |
170 | 170 | ||
@@ -232,7 +232,7 @@ static int newupvalue (FuncState *fs, TString *name, expdesc *v) { | |||
232 | f->upvalues[fs->nups].instack = (v->k == VLOCAL); | 232 | f->upvalues[fs->nups].instack = (v->k == VLOCAL); |
233 | f->upvalues[fs->nups].idx = cast_byte(v->u.info); | 233 | f->upvalues[fs->nups].idx = cast_byte(v->u.info); |
234 | f->upvalues[fs->nups].name = name; | 234 | f->upvalues[fs->nups].name = name; |
235 | luaC_objbarrier(fs->ls->L, f, name); | 235 | luaC_objbarrier(fs->ls->L, f, ts2gco(name)); |
236 | return fs->nups++; | 236 | return fs->nups++; |
237 | } | 237 | } |
238 | 238 | ||
@@ -1630,7 +1630,7 @@ LClosure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, | |||
1630 | incr_top(L); | 1630 | incr_top(L); |
1631 | funcstate.f = cl->p = luaF_newproto(L); | 1631 | funcstate.f = cl->p = luaF_newproto(L); |
1632 | funcstate.f->source = luaS_new(L, name); /* create and anchor TString */ | 1632 | funcstate.f->source = luaS_new(L, name); /* create and anchor TString */ |
1633 | luaC_objbarrier(L, funcstate.f, funcstate.f->source); | 1633 | luaC_objbarrier(L, funcstate.f, ts2gco(funcstate.f->source)); |
1634 | lexstate.buff = buff; | 1634 | lexstate.buff = buff; |
1635 | lexstate.dyd = dyd; | 1635 | lexstate.dyd = dyd; |
1636 | dyd->actvar.n = dyd->gt.n = dyd->label.n = 0; | 1636 | dyd->actvar.n = dyd->gt.n = dyd->label.n = 0; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstate.c,v 2.120 2014/02/18 13:39:37 roberto Exp roberto $ | 2 | ** $Id: lstate.c,v 2.121 2014/02/18 13:46:26 roberto Exp roberto $ |
3 | ** Global State | 3 | ** Global State |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -206,7 +206,7 @@ static void f_luaopen (lua_State *L, void *ud) { | |||
206 | luaX_init(L); | 206 | luaX_init(L); |
207 | /* pre-create memory-error message */ | 207 | /* pre-create memory-error message */ |
208 | g->memerrmsg = luaS_newliteral(L, MEMERRMSG); | 208 | g->memerrmsg = luaS_newliteral(L, MEMERRMSG); |
209 | luaC_fix(L, obj2gco(g->memerrmsg)); /* it should never be collected */ | 209 | luaC_fix(L, ts2gco(g->memerrmsg)); /* it should never be collected */ |
210 | g->gcrunning = 1; /* allow gc */ | 210 | g->gcrunning = 1; /* allow gc */ |
211 | g->version = lua_version(NULL); | 211 | g->version = lua_version(NULL); |
212 | luai_userstateopen(L); | 212 | luai_userstateopen(L); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstate.h,v 2.109 2014/07/17 17:09:50 roberto Exp roberto $ | 2 | ** $Id: lstate.h,v 2.110 2014/07/17 17:27:49 roberto Exp roberto $ |
3 | ** Global State | 3 | ** Global State |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -170,7 +170,7 @@ struct lua_State { | |||
170 | 170 | ||
171 | 171 | ||
172 | /* | 172 | /* |
173 | ** Union of all collectable objects | 173 | ** Union of all collectable objects (only for conversions) |
174 | */ | 174 | */ |
175 | union GCUnion { | 175 | union GCUnion { |
176 | GCObject gc; /* common header */ | 176 | GCObject gc; /* common header */ |
@@ -200,8 +200,16 @@ union GCUnion { | |||
200 | #define gco2th(o) check_exp((o)->tt == LUA_TTHREAD, &((cast_u(o))->th)) | 200 | #define gco2th(o) check_exp((o)->tt == LUA_TTHREAD, &((cast_u(o))->th)) |
201 | 201 | ||
202 | 202 | ||
203 | /* macro to convert any Lua object into a GCObject */ | 203 | /* macro to convert a Lua object into a GCObject */ |
204 | #define obj2gco(v) (&(cast_u(v)->gc)) | 204 | #define obj2gco(v) \ |
205 | check_exp(novariant((v)->tt) < LUA_TDEADKEY, (&(cast_u(v)->gc))) | ||
206 | |||
207 | /* | ||
208 | ** macro to convert a TString into a GCObject. | ||
209 | ** (TString is a union, and therefore needs an access slightly different | ||
210 | ** from the other objects.) | ||
211 | */ | ||
212 | #define ts2gco(v) (obj2gco(&(v)->tsv)) | ||
205 | 213 | ||
206 | 214 | ||
207 | /* actual number of total bytes allocated */ | 215 | /* actual number of total bytes allocated */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstring.c,v 2.39 2014/04/02 16:44:42 roberto Exp roberto $ | 2 | ** $Id: lstring.c,v 2.40 2014/06/18 22:59:29 roberto Exp roberto $ |
3 | ** String table (keeps all strings handled by Lua) | 3 | ** String table (keeps all strings handled by Lua) |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -126,8 +126,8 @@ static TString *internshrstr (lua_State *L, const char *str, size_t l) { | |||
126 | if (l == ts->tsv.len && | 126 | if (l == ts->tsv.len && |
127 | (memcmp(str, getstr(ts), l * sizeof(char)) == 0)) { | 127 | (memcmp(str, getstr(ts), l * sizeof(char)) == 0)) { |
128 | /* found! */ | 128 | /* found! */ |
129 | if (isdead(g, obj2gco(ts))) /* dead (but not collected yet)? */ | 129 | if (isdead(g, ts2gco(ts))) /* dead (but not collected yet)? */ |
130 | changewhite(obj2gco(ts)); /* resurrect it */ | 130 | changewhite(ts2gco(ts)); /* resurrect it */ |
131 | return ts; | 131 | return ts; |
132 | } | 132 | } |
133 | } | 133 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltests.c,v 2.176 2014/07/17 13:53:37 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 2.177 2014/07/17 17:27:49 roberto Exp roberto $ |
3 | ** Internal Module for Debugging of the Lua Implementation | 3 | ** Internal Module for Debugging of the Lua Implementation |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -207,10 +207,11 @@ static int testobjref (global_State *g, GCObject *f, GCObject *t) { | |||
207 | return r1; | 207 | return r1; |
208 | } | 208 | } |
209 | 209 | ||
210 | #define checkobjref(g,f,t) checkobjref_(g,f,obj2gco(t)) | 210 | #define checkobjref(g,f,t) \ |
211 | static void checkobjref_ (global_State *g, GCObject *f, GCObject *t) { | 211 | { if (t) lua_longassert(testobjref(g,f,obj2gco(t))); } |
212 | lua_assert((t) == NULL || testobjref(g,f,obj2gco(t))); | 212 | |
213 | } | 213 | #define checkstrref(g,f,t) \ |
214 | { if (t) lua_longassert(testobjref(g,f,ts2gco(t))); } | ||
214 | 215 | ||
215 | 216 | ||
216 | static void checkvalref (global_State *g, GCObject *f, const TValue *t) { | 217 | static void checkvalref (global_State *g, GCObject *f, const TValue *t) { |
@@ -244,17 +245,17 @@ static void checkproto (global_State *g, Proto *f) { | |||
244 | int i; | 245 | int i; |
245 | GCObject *fgc = obj2gco(f); | 246 | GCObject *fgc = obj2gco(f); |
246 | checkobjref(g, fgc, f->cache); | 247 | checkobjref(g, fgc, f->cache); |
247 | checkobjref(g, fgc, f->source); | 248 | checkstrref(g, fgc, f->source); |
248 | for (i=0; i<f->sizek; i++) { | 249 | for (i=0; i<f->sizek; i++) { |
249 | if (ttisstring(f->k+i)) | 250 | if (ttisstring(f->k + i)) |
250 | checkobjref(g, fgc, rawtsvalue(f->k+i)); | 251 | checkobjref(g, fgc, tsvalue(f->k + i)); |
251 | } | 252 | } |
252 | for (i=0; i<f->sizeupvalues; i++) | 253 | for (i=0; i<f->sizeupvalues; i++) |
253 | checkobjref(g, fgc, f->upvalues[i].name); | 254 | checkstrref(g, fgc, f->upvalues[i].name); |
254 | for (i=0; i<f->sizep; i++) | 255 | for (i=0; i<f->sizep; i++) |
255 | checkobjref(g, fgc, f->p[i]); | 256 | checkobjref(g, fgc, f->p[i]); |
256 | for (i=0; i<f->sizelocvars; i++) | 257 | for (i=0; i<f->sizelocvars; i++) |
257 | checkobjref(g, fgc, f->locvars[i].varname); | 258 | checkstrref(g, fgc, f->locvars[i].varname); |
258 | } | 259 | } |
259 | 260 | ||
260 | 261 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltm.c,v 2.26 2014/04/11 20:17:39 roberto Exp roberto $ | 2 | ** $Id: ltm.c,v 2.27 2014/06/10 18:53:18 roberto Exp roberto $ |
3 | ** Tag methods | 3 | ** Tag methods |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -45,7 +45,7 @@ void luaT_init (lua_State *L) { | |||
45 | int i; | 45 | int i; |
46 | for (i=0; i<TM_N; i++) { | 46 | for (i=0; i<TM_N; i++) { |
47 | G(L)->tmname[i] = luaS_new(L, luaT_eventname[i]); | 47 | G(L)->tmname[i] = luaS_new(L, luaT_eventname[i]); |
48 | luaC_fix(L, obj2gco(G(L)->tmname[i])); /* never collect these names */ | 48 | luaC_fix(L, ts2gco(G(L)->tmname[i])); /* never collect these names */ |
49 | } | 49 | } |
50 | } | 50 | } |
51 | 51 | ||