Explorar o código

use appropriate macros to convert GCObject to specific types

Roberto Ierusalimschy %!s(int64=11) %!d(string=hai) anos
pai
achega
14929f5764
Modificáronse 3 ficheiros con 17 adicións e 9 borrados
  1. 7 4
      lfunc.c
  2. 7 3
      lstring.c
  3. 3 2
      ltable.c

+ 7 - 4
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;

+ 7 - 3
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);

+ 3 - 2
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;