summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-06-18 19:59:29 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-06-18 19:59:29 -0300
commit14929f5764a7990dfb62c8792cfdfe03c061da21 (patch)
tree76ca48dced058135cc2ff0877e81dd96d43e0ea1
parent7021cc9bc8c216e941c5e5a49b34d58672b3f4c2 (diff)
downloadlua-14929f5764a7990dfb62c8792cfdfe03c061da21.tar.gz
lua-14929f5764a7990dfb62c8792cfdfe03c061da21.tar.bz2
lua-14929f5764a7990dfb62c8792cfdfe03c061da21.zip
use appropriate macros to convert GCObject to specific types
-rw-r--r--lfunc.c11
-rw-r--r--lstring.c10
-rw-r--r--ltable.c5
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 @@
1/* 1/*
2** $Id: lfunc.c,v 2.40 2014/02/15 13:12:01 roberto Exp roberto $ 2** $Id: lfunc.c,v 2.41 2014/02/18 13:39:37 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,16 @@
21 21
22 22
23Closure *luaF_newCclosure (lua_State *L, int n) { 23Closure *luaF_newCclosure (lua_State *L, int n) {
24 Closure *c = &luaC_newobj(L, LUA_TCCL, sizeCclosure(n))->cl; 24 GCObject *o = luaC_newobj(L, LUA_TCCL, sizeCclosure(n));
25 Closure *c = gco2cl(o);
25 c->c.nupvalues = cast_byte(n); 26 c->c.nupvalues = cast_byte(n);
26 return c; 27 return c;
27} 28}
28 29
29 30
30Closure *luaF_newLclosure (lua_State *L, int n) { 31Closure *luaF_newLclosure (lua_State *L, int n) {
31 Closure *c = &luaC_newobj(L, LUA_TLCL, sizeLclosure(n))->cl; 32 GCObject *o = luaC_newobj(L, LUA_TLCL, sizeLclosure(n));
33 Closure *c = gco2cl(o);
32 c->l.p = NULL; 34 c->l.p = NULL;
33 c->l.nupvalues = cast_byte(n); 35 c->l.nupvalues = cast_byte(n);
34 while (n--) c->l.upvals[n] = NULL; 36 while (n--) c->l.upvals[n] = NULL;
@@ -93,7 +95,8 @@ void luaF_close (lua_State *L, StkId level) {
93 95
94 96
95Proto *luaF_newproto (lua_State *L) { 97Proto *luaF_newproto (lua_State *L) {
96 Proto *f = &luaC_newobj(L, LUA_TPROTO, sizeof(Proto))->p; 98 GCObject *o = luaC_newobj(L, LUA_TPROTO, sizeof(Proto));
99 Proto *f = gco2p(o);
97 f->k = NULL; 100 f->k = NULL;
98 f->sizek = 0; 101 f->sizek = 0;
99 f->p = NULL; 102 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 @@
1/* 1/*
2** $Id: lstring.c,v 2.38 2014/03/19 18:51:42 roberto Exp roberto $ 2** $Id: lstring.c,v 2.39 2014/04/02 16:44:42 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*/
@@ -90,9 +90,11 @@ void luaS_resize (lua_State *L, int newsize) {
90static TString *createstrobj (lua_State *L, const char *str, size_t l, 90static TString *createstrobj (lua_State *L, const char *str, size_t l,
91 int tag, unsigned int h) { 91 int tag, unsigned int h) {
92 TString *ts; 92 TString *ts;
93 GCObject *o;
93 size_t totalsize; /* total size of TString object */ 94 size_t totalsize; /* total size of TString object */
94 totalsize = sizeof(TString) + ((l + 1) * sizeof(char)); 95 totalsize = sizeof(TString) + ((l + 1) * sizeof(char));
95 ts = &luaC_newobj(L, tag, totalsize)->ts; 96 o = luaC_newobj(L, tag, totalsize);
97 ts = rawgco2ts(o);
96 ts->tsv.len = l; 98 ts->tsv.len = l;
97 ts->tsv.hash = h; 99 ts->tsv.hash = h;
98 ts->tsv.extra = 0; 100 ts->tsv.extra = 0;
@@ -165,9 +167,11 @@ TString *luaS_new (lua_State *L, const char *str) {
165 167
166Udata *luaS_newudata (lua_State *L, size_t s) { 168Udata *luaS_newudata (lua_State *L, size_t s) {
167 Udata *u; 169 Udata *u;
170 GCObject *o;
168 if (s > MAX_SIZE - sizeof(Udata)) 171 if (s > MAX_SIZE - sizeof(Udata))
169 luaM_toobig(L); 172 luaM_toobig(L);
170 u = &luaC_newobj(L, LUA_TUSERDATA, sizeof(Udata) + s)->u; 173 o = luaC_newobj(L, LUA_TUSERDATA, sizeof(Udata) + s);
174 u = rawgco2u(o);
171 u->uv.len = s; 175 u->uv.len = s;
172 u->uv.metatable = NULL; 176 u->uv.metatable = NULL;
173 setuservalue(L, u, luaO_nilobject); 177 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 @@
1/* 1/*
2** $Id: ltable.c,v 2.88 2014/04/15 16:32:49 roberto Exp roberto $ 2** $Id: ltable.c,v 2.89 2014/05/26 17:10:22 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*/
@@ -383,7 +383,8 @@ static void rehash (lua_State *L, Table *t, const TValue *ek) {
383 383
384 384
385Table *luaH_new (lua_State *L) { 385Table *luaH_new (lua_State *L) {
386 Table *t = &luaC_newobj(L, LUA_TTABLE, sizeof(Table))->h; 386 GCObject *o = luaC_newobj(L, LUA_TTABLE, sizeof(Table));
387 Table *t = gco2t(o);
387 t->metatable = NULL; 388 t->metatable = NULL;
388 t->flags = cast_byte(~0); 389 t->flags = cast_byte(~0);
389 t->array = NULL; 390 t->array = NULL;