use appropriate macros to convert GCObject to specific types

This commit is contained in:
Roberto Ierusalimschy 2014-06-18 19:59:29 -03:00
parent 7021cc9bc8
commit 14929f5764
3 changed files with 17 additions and 9 deletions

11
lfunc.c
View File

@ -1,5 +1,5 @@
/*
** $Id: lfunc.c,v 2.40 2014/02/15 13:12:01 roberto Exp roberto $
** $Id: lfunc.c,v 2.41 2014/02/18 13:39:37 roberto Exp roberto $
** Auxiliary functions to manipulate prototypes and closures
** See Copyright Notice in lua.h
*/
@ -21,14 +21,16 @@
Closure *luaF_newCclosure (lua_State *L, int n) {
Closure *c = &luaC_newobj(L, LUA_TCCL, sizeCclosure(n))->cl;
GCObject *o = luaC_newobj(L, LUA_TCCL, sizeCclosure(n));
Closure *c = gco2cl(o);
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))->cl;
GCObject *o = luaC_newobj(L, LUA_TLCL, sizeLclosure(n));
Closure *c = gco2cl(o);
c->l.p = NULL;
c->l.nupvalues = cast_byte(n);
while (n--) c->l.upvals[n] = NULL;
@ -93,7 +95,8 @@ void luaF_close (lua_State *L, StkId level) {
Proto *luaF_newproto (lua_State *L) {
Proto *f = &luaC_newobj(L, LUA_TPROTO, sizeof(Proto))->p;
GCObject *o = luaC_newobj(L, LUA_TPROTO, sizeof(Proto));
Proto *f = gco2p(o);
f->k = NULL;
f->sizek = 0;
f->p = NULL;

View File

@ -1,5 +1,5 @@
/*
** $Id: lstring.c,v 2.38 2014/03/19 18:51:42 roberto Exp roberto $
** $Id: lstring.c,v 2.39 2014/04/02 16:44:42 roberto Exp roberto $
** String table (keeps all strings handled by Lua)
** See Copyright Notice in lua.h
*/
@ -90,9 +90,11 @@ void luaS_resize (lua_State *L, int newsize) {
static TString *createstrobj (lua_State *L, const char *str, size_t l,
int tag, unsigned int h) {
TString *ts;
GCObject *o;
size_t totalsize; /* total size of TString object */
totalsize = sizeof(TString) + ((l + 1) * sizeof(char));
ts = &luaC_newobj(L, tag, totalsize)->ts;
o = luaC_newobj(L, tag, totalsize);
ts = rawgco2ts(o);
ts->tsv.len = l;
ts->tsv.hash = h;
ts->tsv.extra = 0;
@ -165,9 +167,11 @@ TString *luaS_new (lua_State *L, const char *str) {
Udata *luaS_newudata (lua_State *L, size_t s) {
Udata *u;
GCObject *o;
if (s > MAX_SIZE - sizeof(Udata))
luaM_toobig(L);
u = &luaC_newobj(L, LUA_TUSERDATA, sizeof(Udata) + s)->u;
o = luaC_newobj(L, LUA_TUSERDATA, sizeof(Udata) + s);
u = rawgco2u(o);
u->uv.len = s;
u->uv.metatable = NULL;
setuservalue(L, u, luaO_nilobject);

View File

@ -1,5 +1,5 @@
/*
** $Id: ltable.c,v 2.88 2014/04/15 16:32:49 roberto Exp roberto $
** $Id: ltable.c,v 2.89 2014/05/26 17:10:22 roberto Exp roberto $
** Lua tables (hash)
** See Copyright Notice in lua.h
*/
@ -383,7 +383,8 @@ 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))->h;
GCObject *o = luaC_newobj(L, LUA_TTABLE, sizeof(Table));
Table *t = gco2t(o);
t->metatable = NULL;
t->flags = cast_byte(~0);
t->array = NULL;