From 14929f5764a7990dfb62c8792cfdfe03c061da21 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 18 Jun 2014 19:59:29 -0300 Subject: [PATCH] use appropriate macros to convert GCObject to specific types --- lfunc.c | 11 +++++++---- lstring.c | 10 +++++++--- ltable.c | 5 +++-- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/lfunc.c b/lfunc.c index 9d0703e1..999c35a5 100644 --- a/lfunc.c +++ b/lfunc.c @@ -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; diff --git a/lstring.c b/lstring.c index f666ebf9..55d55013 100644 --- a/lstring.c +++ b/lstring.c @@ -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); diff --git a/ltable.c b/ltable.c index 18802c9f..3a80d9d0 100644 --- a/ltable.c +++ b/ltable.c @@ -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;