mirror of https://github.com/lua/lua
'luaC_newobj' does not handle special cases; only special case
now is threads, which do not use 'luaC_newobj' anymore.
This commit is contained in:
parent
79ab21be90
commit
1150873447
8
lfunc.c
8
lfunc.c
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: lfunc.c,v 2.36 2013/08/27 18:53:35 roberto Exp roberto $
|
||||
** $Id: lfunc.c,v 2.37 2013/08/27 20:04:00 roberto Exp roberto $
|
||||
** Auxiliary functions to manipulate prototypes and closures
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
@ -21,14 +21,14 @@
|
|||
|
||||
|
||||
Closure *luaF_newCclosure (lua_State *L, int n) {
|
||||
Closure *c = &luaC_newobj(L, LUA_TCCL, sizeCclosure(n), NULL, 0)->cl;
|
||||
Closure *c = &luaC_newobj(L, LUA_TCCL, sizeCclosure(n))->cl;
|
||||
c->c.nupvalues = cast_byte(n);
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
Closure *luaF_newLclosure (lua_State *L, int n) {
|
||||
Closure *c = &luaC_newobj(L, LUA_TLCL, sizeLclosure(n), NULL, 0)->cl;
|
||||
Closure *c = &luaC_newobj(L, LUA_TLCL, sizeLclosure(n))->cl;
|
||||
c->l.p = NULL;
|
||||
c->l.nupvalues = cast_byte(n);
|
||||
while (n--) c->l.upvals[n] = NULL;
|
||||
|
@ -85,7 +85,7 @@ void luaF_close (lua_State *L, StkId level) {
|
|||
|
||||
|
||||
Proto *luaF_newproto (lua_State *L) {
|
||||
Proto *f = &luaC_newobj(L, LUA_TPROTO, sizeof(Proto), &G(L)->allgc, 0)->p;
|
||||
Proto *f = &luaC_newobj(L, LUA_TPROTO, sizeof(Proto))->p;
|
||||
nolocal(obj2gco(f)); /* prototypes are never local */
|
||||
f->k = NULL;
|
||||
f->sizek = 0;
|
||||
|
|
19
lgc.c
19
lgc.c
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: lgc.c,v 2.157 2013/08/30 19:14:26 roberto Exp roberto $
|
||||
** $Id: lgc.c,v 2.158 2013/09/03 15:37:10 roberto Exp roberto $
|
||||
** Garbage Collector
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
@ -200,22 +200,15 @@ void luaC_fix (lua_State *L, GCObject *o) {
|
|||
|
||||
/*
|
||||
** create a new collectable object (with given type and size) and link
|
||||
** it to '*list'. 'offset' tells how many bytes to allocate before the
|
||||
** object itself (used only by states).
|
||||
** it to 'localgc' list.
|
||||
*/
|
||||
GCObject *luaC_newobj (lua_State *L, int tt, size_t sz, GCObject **list,
|
||||
int offset) {
|
||||
GCObject *luaC_newobj (lua_State *L, int tt, size_t sz) {
|
||||
global_State *g = G(L);
|
||||
char *raw = cast(char *, luaM_newobject(L, novariant(tt), sz));
|
||||
GCObject *o = obj2gco(raw + offset);
|
||||
GCObject *o = cast(GCObject *, luaM_newobject(L, novariant(tt), sz));
|
||||
gch(o)->marked = luaC_white(g);
|
||||
if (list == NULL)
|
||||
list = &g->localgc; /* standard list for collectable objects */
|
||||
else
|
||||
l_setbit(gch(o)->marked, LOCALMARK); /* mark object as not in 'localgc' */
|
||||
gch(o)->tt = tt;
|
||||
gch(o)->next = *list;
|
||||
*list = o;
|
||||
gch(o)->next = g->localgc;
|
||||
g->localgc = o;
|
||||
return o;
|
||||
}
|
||||
|
||||
|
|
11
lgc.h
11
lgc.h
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: lgc.h,v 2.70 2013/08/30 19:14:26 roberto Exp roberto $
|
||||
** $Id: lgc.h,v 2.71 2013/09/03 15:37:10 roberto Exp roberto $
|
||||
** Garbage Collector
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
@ -79,7 +79,7 @@
|
|||
#define WHITE1BIT 1 /* object is white (type 1) */
|
||||
#define BLACKBIT 2 /* object is black */
|
||||
#define FINALIZEDBIT 3 /* object has been marked for finalization */
|
||||
#define LOCALBIT 4 /* object is not local */
|
||||
#define NOLOCALBIT 4 /* object is not local */
|
||||
#define LOCALMARK 5 /* object is 'locally marked' or out of local list */
|
||||
/* bit 7 is currently used by tests (luaL_checkmemory) */
|
||||
|
||||
|
@ -90,7 +90,7 @@
|
|||
#define isblack(x) testbit((x)->gch.marked, BLACKBIT)
|
||||
#define isgray(x) /* neither white nor black */ \
|
||||
(!testbits((x)->gch.marked, WHITEBITS | bitmask(BLACKBIT)))
|
||||
#define islocal(x) (!testbit((x)->gch.marked, LOCALBIT))
|
||||
#define islocal(x) (!testbit((x)->gch.marked, NOLOCALBIT))
|
||||
|
||||
#define tofinalize(x) testbit((x)->gch.marked, FINALIZEDBIT)
|
||||
|
||||
|
@ -101,7 +101,7 @@
|
|||
#define changewhite(x) ((x)->gch.marked ^= WHITEBITS)
|
||||
#define gray2black(x) l_setbit((x)->gch.marked, BLACKBIT)
|
||||
|
||||
#define nolocal(x) l_setbit((x)->gch.marked, LOCALBIT)
|
||||
#define nolocal(x) l_setbit((x)->gch.marked, NOLOCALBIT)
|
||||
#define valnolocal(v) { if (iscollectable(v)) nolocal(gcvalue(v)); }
|
||||
|
||||
#define luaC_white(g) cast(lu_byte, (g)->currentwhite & WHITEBITS)
|
||||
|
@ -140,8 +140,7 @@ LUAI_FUNC void luaC_step (lua_State *L);
|
|||
LUAI_FUNC void luaC_forcestep (lua_State *L);
|
||||
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,
|
||||
GCObject **list, int offset);
|
||||
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_barrierproto_ (lua_State *L, Proto *p, Closure *c);
|
||||
|
|
18
lstate.c
18
lstate.c
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: lstate.c,v 2.110 2013/09/03 15:37:10 roberto Exp roberto $
|
||||
** $Id: lstate.c,v 2.111 2013/09/05 19:31:49 roberto Exp roberto $
|
||||
** Global State
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
@ -237,16 +237,20 @@ static void close_state (lua_State *L) {
|
|||
|
||||
|
||||
LUA_API lua_State *lua_newthread (lua_State *L) {
|
||||
global_State *g = G(L);
|
||||
lua_State *L1;
|
||||
lua_lock(L);
|
||||
luaC_checkGC(L);
|
||||
/* create new thread, linked after 'l_registry' */
|
||||
L1 = &luaC_newobj(L, LUA_TTHREAD, sizeof(LX),
|
||||
&hvalue(&G(L)->l_registry)->next, offsetof(LX, l))->th;
|
||||
/* create new thread */
|
||||
L1 = &cast(LX *, luaM_newobject(L, LUA_TTHREAD, sizeof(LX)))->l;
|
||||
L1->marked = luaC_white(g) | bitmask(LOCALMARK) | bitmask(NOLOCALBIT);
|
||||
L1->tt = LUA_TTHREAD;
|
||||
/* link it after 'l_registry' */
|
||||
L1->next = hvalue(&g->l_registry)->next;
|
||||
hvalue(&g->l_registry)->next = obj2gco(L1);
|
||||
setthvalue(L, L->top, L1);
|
||||
api_incr_top(L);
|
||||
preinit_state(L1, G(L));
|
||||
nolocal(obj2gco(L1)); /* threads are never local */
|
||||
preinit_state(L1, g);
|
||||
L1->hookmask = L->hookmask;
|
||||
L1->basehookcount = L->basehookcount;
|
||||
L1->hook = L->hook;
|
||||
|
@ -279,7 +283,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
|
|||
L->next = NULL;
|
||||
L->tt = LUA_TTHREAD;
|
||||
g->currentwhite = bitmask(WHITE0BIT);
|
||||
L->marked = luaC_white(g) | bitmask(LOCALBIT);
|
||||
L->marked = luaC_white(g) | bitmask(NOLOCALBIT);
|
||||
g->gckind = KGC_NORMAL;
|
||||
preinit_state(L, g);
|
||||
g->frealloc = f;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: lstring.c,v 2.33 2013/08/28 18:30:26 roberto Exp roberto $
|
||||
** $Id: lstring.c,v 2.34 2013/09/05 19:31:49 roberto Exp roberto $
|
||||
** String table (keeps all strings handled by Lua)
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
@ -101,7 +101,7 @@ static TString *createstrobj (lua_State *L, const char *str, size_t l,
|
|||
TString *ts;
|
||||
size_t totalsize; /* total size of TString object */
|
||||
totalsize = sizeof(TString) + ((l + 1) * sizeof(char));
|
||||
ts = &luaC_newobj(L, tag, totalsize, NULL, 0)->ts;
|
||||
ts = &luaC_newobj(L, tag, totalsize)->ts;
|
||||
ts->tsv.len = l;
|
||||
ts->tsv.hash = h;
|
||||
ts->tsv.extra = 0;
|
||||
|
@ -178,7 +178,7 @@ Udata *luaS_newudata (lua_State *L, size_t s, Table *e) {
|
|||
Udata *u;
|
||||
if (s > MAX_SIZE - sizeof(Udata))
|
||||
luaM_toobig(L);
|
||||
u = &luaC_newobj(L, LUA_TUSERDATA, sizeof(Udata) + s, NULL, 0)->u;
|
||||
u = &luaC_newobj(L, LUA_TUSERDATA, sizeof(Udata) + s)->u;
|
||||
u->uv.len = s;
|
||||
u->uv.metatable = NULL;
|
||||
u->uv.env = e;
|
||||
|
|
4
ltable.c
4
ltable.c
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: ltable.c,v 2.81 2013/08/28 18:30:26 roberto Exp roberto $
|
||||
** $Id: ltable.c,v 2.82 2013/08/29 13:49:57 roberto Exp roberto $
|
||||
** Lua tables (hash)
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
@ -378,7 +378,7 @@ static void rehash (lua_State *L, Table *t, const TValue *ek) {
|
|||
|
||||
|
||||
Table *luaH_new (lua_State *L) {
|
||||
Table *t = &luaC_newobj(L, LUA_TTABLE, sizeof(Table), NULL, 0)->h;
|
||||
Table *t = &luaC_newobj(L, LUA_TTABLE, sizeof(Table))->h;
|
||||
t->metatable = NULL;
|
||||
t->flags = cast_byte(~0);
|
||||
t->array = NULL;
|
||||
|
|
Loading…
Reference in New Issue