diff options
| -rw-r--r-- | lfunc.c | 8 | ||||
| -rw-r--r-- | lgc.c | 19 | ||||
| -rw-r--r-- | lgc.h | 11 | ||||
| -rw-r--r-- | lstate.c | 18 | ||||
| -rw-r--r-- | lstring.c | 6 | ||||
| -rw-r--r-- | ltable.c | 4 |
6 files changed, 31 insertions, 35 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lfunc.c,v 2.36 2013/08/27 18:53:35 roberto Exp roberto $ | 2 | ** $Id: lfunc.c,v 2.37 2013/08/27 20:04:00 roberto Exp roberto $ |
| 3 | ** Auxiliary functions to manipulate prototypes and closures | 3 | ** Auxiliary functions to manipulate prototypes and closures |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -21,14 +21,14 @@ | |||
| 21 | 21 | ||
| 22 | 22 | ||
| 23 | Closure *luaF_newCclosure (lua_State *L, int n) { | 23 | Closure *luaF_newCclosure (lua_State *L, int n) { |
| 24 | Closure *c = &luaC_newobj(L, LUA_TCCL, sizeCclosure(n), NULL, 0)->cl; | 24 | Closure *c = &luaC_newobj(L, LUA_TCCL, sizeCclosure(n))->cl; |
| 25 | c->c.nupvalues = cast_byte(n); | 25 | c->c.nupvalues = cast_byte(n); |
| 26 | return c; | 26 | return c; |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | 29 | ||
| 30 | Closure *luaF_newLclosure (lua_State *L, int n) { | 30 | Closure *luaF_newLclosure (lua_State *L, int n) { |
| 31 | Closure *c = &luaC_newobj(L, LUA_TLCL, sizeLclosure(n), NULL, 0)->cl; | 31 | Closure *c = &luaC_newobj(L, LUA_TLCL, sizeLclosure(n))->cl; |
| 32 | c->l.p = NULL; | 32 | c->l.p = NULL; |
| 33 | c->l.nupvalues = cast_byte(n); | 33 | c->l.nupvalues = cast_byte(n); |
| 34 | while (n--) c->l.upvals[n] = NULL; | 34 | while (n--) c->l.upvals[n] = NULL; |
| @@ -85,7 +85,7 @@ void luaF_close (lua_State *L, StkId level) { | |||
| 85 | 85 | ||
| 86 | 86 | ||
| 87 | Proto *luaF_newproto (lua_State *L) { | 87 | Proto *luaF_newproto (lua_State *L) { |
| 88 | Proto *f = &luaC_newobj(L, LUA_TPROTO, sizeof(Proto), &G(L)->allgc, 0)->p; | 88 | Proto *f = &luaC_newobj(L, LUA_TPROTO, sizeof(Proto))->p; |
| 89 | nolocal(obj2gco(f)); /* prototypes are never local */ | 89 | nolocal(obj2gco(f)); /* prototypes are never local */ |
| 90 | f->k = NULL; | 90 | f->k = NULL; |
| 91 | f->sizek = 0; | 91 | f->sizek = 0; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lgc.c,v 2.157 2013/08/30 19:14:26 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 2.158 2013/09/03 15:37:10 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 | */ |
| @@ -200,22 +200,15 @@ void luaC_fix (lua_State *L, GCObject *o) { | |||
| 200 | 200 | ||
| 201 | /* | 201 | /* |
| 202 | ** create a new collectable object (with given type and size) and link | 202 | ** create a new collectable object (with given type and size) and link |
| 203 | ** it to '*list'. 'offset' tells how many bytes to allocate before the | 203 | ** it to 'localgc' list. |
| 204 | ** object itself (used only by states). | ||
| 205 | */ | 204 | */ |
| 206 | GCObject *luaC_newobj (lua_State *L, int tt, size_t sz, GCObject **list, | 205 | GCObject *luaC_newobj (lua_State *L, int tt, size_t sz) { |
| 207 | int offset) { | ||
| 208 | global_State *g = G(L); | 206 | global_State *g = G(L); |
| 209 | char *raw = cast(char *, luaM_newobject(L, novariant(tt), sz)); | 207 | GCObject *o = cast(GCObject *, luaM_newobject(L, novariant(tt), sz)); |
| 210 | GCObject *o = obj2gco(raw + offset); | ||
| 211 | gch(o)->marked = luaC_white(g); | 208 | gch(o)->marked = luaC_white(g); |
| 212 | if (list == NULL) | ||
| 213 | list = &g->localgc; /* standard list for collectable objects */ | ||
| 214 | else | ||
| 215 | l_setbit(gch(o)->marked, LOCALMARK); /* mark object as not in 'localgc' */ | ||
| 216 | gch(o)->tt = tt; | 209 | gch(o)->tt = tt; |
| 217 | gch(o)->next = *list; | 210 | gch(o)->next = g->localgc; |
| 218 | *list = o; | 211 | g->localgc = o; |
| 219 | return o; | 212 | return o; |
| 220 | } | 213 | } |
| 221 | 214 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lgc.h,v 2.70 2013/08/30 19:14:26 roberto Exp roberto $ | 2 | ** $Id: lgc.h,v 2.71 2013/09/03 15:37:10 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 | */ |
| @@ -79,7 +79,7 @@ | |||
| 79 | #define WHITE1BIT 1 /* object is white (type 1) */ | 79 | #define WHITE1BIT 1 /* object is white (type 1) */ |
| 80 | #define BLACKBIT 2 /* object is black */ | 80 | #define BLACKBIT 2 /* object is black */ |
| 81 | #define FINALIZEDBIT 3 /* object has been marked for finalization */ | 81 | #define FINALIZEDBIT 3 /* object has been marked for finalization */ |
| 82 | #define LOCALBIT 4 /* object is not local */ | 82 | #define NOLOCALBIT 4 /* object is not local */ |
| 83 | #define LOCALMARK 5 /* object is 'locally marked' or out of local list */ | 83 | #define LOCALMARK 5 /* object is 'locally marked' or out of local list */ |
| 84 | /* bit 7 is currently used by tests (luaL_checkmemory) */ | 84 | /* bit 7 is currently used by tests (luaL_checkmemory) */ |
| 85 | 85 | ||
| @@ -90,7 +90,7 @@ | |||
| 90 | #define isblack(x) testbit((x)->gch.marked, BLACKBIT) | 90 | #define isblack(x) testbit((x)->gch.marked, BLACKBIT) |
| 91 | #define isgray(x) /* neither white nor black */ \ | 91 | #define isgray(x) /* neither white nor black */ \ |
| 92 | (!testbits((x)->gch.marked, WHITEBITS | bitmask(BLACKBIT))) | 92 | (!testbits((x)->gch.marked, WHITEBITS | bitmask(BLACKBIT))) |
| 93 | #define islocal(x) (!testbit((x)->gch.marked, LOCALBIT)) | 93 | #define islocal(x) (!testbit((x)->gch.marked, NOLOCALBIT)) |
| 94 | 94 | ||
| 95 | #define tofinalize(x) testbit((x)->gch.marked, FINALIZEDBIT) | 95 | #define tofinalize(x) testbit((x)->gch.marked, FINALIZEDBIT) |
| 96 | 96 | ||
| @@ -101,7 +101,7 @@ | |||
| 101 | #define changewhite(x) ((x)->gch.marked ^= WHITEBITS) | 101 | #define changewhite(x) ((x)->gch.marked ^= WHITEBITS) |
| 102 | #define gray2black(x) l_setbit((x)->gch.marked, BLACKBIT) | 102 | #define gray2black(x) l_setbit((x)->gch.marked, BLACKBIT) |
| 103 | 103 | ||
| 104 | #define nolocal(x) l_setbit((x)->gch.marked, LOCALBIT) | 104 | #define nolocal(x) l_setbit((x)->gch.marked, NOLOCALBIT) |
| 105 | #define valnolocal(v) { if (iscollectable(v)) nolocal(gcvalue(v)); } | 105 | #define valnolocal(v) { if (iscollectable(v)) nolocal(gcvalue(v)); } |
| 106 | 106 | ||
| 107 | #define luaC_white(g) cast(lu_byte, (g)->currentwhite & WHITEBITS) | 107 | #define luaC_white(g) cast(lu_byte, (g)->currentwhite & WHITEBITS) |
| @@ -140,8 +140,7 @@ LUAI_FUNC void luaC_step (lua_State *L); | |||
| 140 | LUAI_FUNC void luaC_forcestep (lua_State *L); | 140 | LUAI_FUNC void luaC_forcestep (lua_State *L); |
| 141 | LUAI_FUNC void luaC_runtilstate (lua_State *L, int statesmask); | 141 | LUAI_FUNC void luaC_runtilstate (lua_State *L, int statesmask); |
| 142 | LUAI_FUNC void luaC_fullgc (lua_State *L, int isemergency); | 142 | LUAI_FUNC void luaC_fullgc (lua_State *L, int isemergency); |
| 143 | LUAI_FUNC GCObject *luaC_newobj (lua_State *L, int tt, size_t sz, | 143 | LUAI_FUNC GCObject *luaC_newobj (lua_State *L, int tt, size_t sz); |
| 144 | GCObject **list, int offset); | ||
| 145 | LUAI_FUNC void luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v); | 144 | LUAI_FUNC void luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v); |
| 146 | LUAI_FUNC void luaC_barrierback_ (lua_State *L, GCObject *o); | 145 | LUAI_FUNC void luaC_barrierback_ (lua_State *L, GCObject *o); |
| 147 | LUAI_FUNC void luaC_barrierproto_ (lua_State *L, Proto *p, Closure *c); | 146 | LUAI_FUNC void luaC_barrierproto_ (lua_State *L, Proto *p, Closure *c); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstate.c,v 2.110 2013/09/03 15:37:10 roberto Exp roberto $ | 2 | ** $Id: lstate.c,v 2.111 2013/09/05 19:31: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 | */ |
| @@ -237,16 +237,20 @@ static void close_state (lua_State *L) { | |||
| 237 | 237 | ||
| 238 | 238 | ||
| 239 | LUA_API lua_State *lua_newthread (lua_State *L) { | 239 | LUA_API lua_State *lua_newthread (lua_State *L) { |
| 240 | global_State *g = G(L); | ||
| 240 | lua_State *L1; | 241 | lua_State *L1; |
| 241 | lua_lock(L); | 242 | lua_lock(L); |
| 242 | luaC_checkGC(L); | 243 | luaC_checkGC(L); |
| 243 | /* create new thread, linked after 'l_registry' */ | 244 | /* create new thread */ |
| 244 | L1 = &luaC_newobj(L, LUA_TTHREAD, sizeof(LX), | 245 | L1 = &cast(LX *, luaM_newobject(L, LUA_TTHREAD, sizeof(LX)))->l; |
| 245 | &hvalue(&G(L)->l_registry)->next, offsetof(LX, l))->th; | 246 | L1->marked = luaC_white(g) | bitmask(LOCALMARK) | bitmask(NOLOCALBIT); |
| 247 | L1->tt = LUA_TTHREAD; | ||
| 248 | /* link it after 'l_registry' */ | ||
| 249 | L1->next = hvalue(&g->l_registry)->next; | ||
| 250 | hvalue(&g->l_registry)->next = obj2gco(L1); | ||
| 246 | setthvalue(L, L->top, L1); | 251 | setthvalue(L, L->top, L1); |
| 247 | api_incr_top(L); | 252 | api_incr_top(L); |
| 248 | preinit_state(L1, G(L)); | 253 | preinit_state(L1, g); |
| 249 | nolocal(obj2gco(L1)); /* threads are never local */ | ||
| 250 | L1->hookmask = L->hookmask; | 254 | L1->hookmask = L->hookmask; |
| 251 | L1->basehookcount = L->basehookcount; | 255 | L1->basehookcount = L->basehookcount; |
| 252 | L1->hook = L->hook; | 256 | L1->hook = L->hook; |
| @@ -279,7 +283,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { | |||
| 279 | L->next = NULL; | 283 | L->next = NULL; |
| 280 | L->tt = LUA_TTHREAD; | 284 | L->tt = LUA_TTHREAD; |
| 281 | g->currentwhite = bitmask(WHITE0BIT); | 285 | g->currentwhite = bitmask(WHITE0BIT); |
| 282 | L->marked = luaC_white(g) | bitmask(LOCALBIT); | 286 | L->marked = luaC_white(g) | bitmask(NOLOCALBIT); |
| 283 | g->gckind = KGC_NORMAL; | 287 | g->gckind = KGC_NORMAL; |
| 284 | preinit_state(L, g); | 288 | preinit_state(L, g); |
| 285 | g->frealloc = f; | 289 | g->frealloc = f; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstring.c,v 2.33 2013/08/28 18:30:26 roberto Exp roberto $ | 2 | ** $Id: lstring.c,v 2.34 2013/09/05 19:31:49 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 | */ |
| @@ -101,7 +101,7 @@ static TString *createstrobj (lua_State *L, const char *str, size_t l, | |||
| 101 | TString *ts; | 101 | TString *ts; |
| 102 | size_t totalsize; /* total size of TString object */ | 102 | size_t totalsize; /* total size of TString object */ |
| 103 | totalsize = sizeof(TString) + ((l + 1) * sizeof(char)); | 103 | totalsize = sizeof(TString) + ((l + 1) * sizeof(char)); |
| 104 | ts = &luaC_newobj(L, tag, totalsize, NULL, 0)->ts; | 104 | ts = &luaC_newobj(L, tag, totalsize)->ts; |
| 105 | ts->tsv.len = l; | 105 | ts->tsv.len = l; |
| 106 | ts->tsv.hash = h; | 106 | ts->tsv.hash = h; |
| 107 | ts->tsv.extra = 0; | 107 | ts->tsv.extra = 0; |
| @@ -178,7 +178,7 @@ Udata *luaS_newudata (lua_State *L, size_t s, Table *e) { | |||
| 178 | Udata *u; | 178 | Udata *u; |
| 179 | if (s > MAX_SIZE - sizeof(Udata)) | 179 | if (s > MAX_SIZE - sizeof(Udata)) |
| 180 | luaM_toobig(L); | 180 | luaM_toobig(L); |
| 181 | u = &luaC_newobj(L, LUA_TUSERDATA, sizeof(Udata) + s, NULL, 0)->u; | 181 | u = &luaC_newobj(L, LUA_TUSERDATA, sizeof(Udata) + s)->u; |
| 182 | u->uv.len = s; | 182 | u->uv.len = s; |
| 183 | u->uv.metatable = NULL; | 183 | u->uv.metatable = NULL; |
| 184 | u->uv.env = e; | 184 | u->uv.env = e; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltable.c,v 2.81 2013/08/28 18:30:26 roberto Exp roberto $ | 2 | ** $Id: ltable.c,v 2.82 2013/08/29 13:49:57 roberto Exp roberto $ |
| 3 | ** Lua tables (hash) | 3 | ** Lua tables (hash) |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -378,7 +378,7 @@ static void rehash (lua_State *L, Table *t, const TValue *ek) { | |||
| 378 | 378 | ||
| 379 | 379 | ||
| 380 | Table *luaH_new (lua_State *L) { | 380 | Table *luaH_new (lua_State *L) { |
| 381 | Table *t = &luaC_newobj(L, LUA_TTABLE, sizeof(Table), NULL, 0)->h; | 381 | Table *t = &luaC_newobj(L, LUA_TTABLE, sizeof(Table))->h; |
| 382 | t->metatable = NULL; | 382 | t->metatable = NULL; |
| 383 | t->flags = cast_byte(~0); | 383 | t->flags = cast_byte(~0); |
| 384 | t->array = NULL; | 384 | t->array = NULL; |
