aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lfunc.c10
-rw-r--r--lfunc.h2
-rw-r--r--lgc.c39
-rw-r--r--lstate.c5
-rw-r--r--lstate.h2
-rw-r--r--ltable.c5
-rw-r--r--ltable.h2
7 files changed, 40 insertions, 25 deletions
diff --git a/lfunc.c b/lfunc.c
index 2b041281..0ea05e00 100644
--- a/lfunc.c
+++ b/lfunc.c
@@ -264,16 +264,16 @@ Proto *luaF_newproto (lua_State *L) {
264} 264}
265 265
266 266
267size_t luaF_protosize (Proto *p) { 267lu_mem luaF_protosize (Proto *p) {
268 size_t sz = sizeof(Proto) 268 lu_mem sz = cast(lu_mem, sizeof(Proto))
269 + cast_uint(p->sizep) * sizeof(Proto*) 269 + cast_uint(p->sizep) * sizeof(Proto*)
270 + cast_uint(p->sizek) * sizeof(TValue) 270 + cast_uint(p->sizek) * sizeof(TValue)
271 + cast_uint(p->sizelocvars) * sizeof(LocVar) 271 + cast_uint(p->sizelocvars) * sizeof(LocVar)
272 + cast_uint(p->sizeupvalues) * sizeof(Upvaldesc); 272 + cast_uint(p->sizeupvalues) * sizeof(Upvaldesc);
273 if (!(p->flag & PF_FIXED)) { 273 if (!(p->flag & PF_FIXED)) {
274 sz += cast_uint(p->sizecode) * sizeof(Instruction) 274 sz += cast_uint(p->sizecode) * sizeof(Instruction);
275 + cast_uint(p->sizelineinfo) * sizeof(lu_byte) 275 sz += cast_uint(p->sizelineinfo) * sizeof(lu_byte);
276 + cast_uint(p->sizeabslineinfo) * sizeof(AbsLineInfo); 276 sz += cast_uint(p->sizeabslineinfo) * sizeof(AbsLineInfo);
277 } 277 }
278 return sz; 278 return sz;
279} 279}
diff --git a/lfunc.h b/lfunc.h
index b9651074..b981edeb 100644
--- a/lfunc.h
+++ b/lfunc.h
@@ -56,7 +56,7 @@ LUAI_FUNC void luaF_newtbcupval (lua_State *L, StkId level);
56LUAI_FUNC void luaF_closeupval (lua_State *L, StkId level); 56LUAI_FUNC void luaF_closeupval (lua_State *L, StkId level);
57LUAI_FUNC StkId luaF_close (lua_State *L, StkId level, int status, int yy); 57LUAI_FUNC StkId luaF_close (lua_State *L, StkId level, int status, int yy);
58LUAI_FUNC void luaF_unlinkupval (UpVal *uv); 58LUAI_FUNC void luaF_unlinkupval (UpVal *uv);
59LUAI_FUNC size_t luaF_protosize (Proto *p); 59LUAI_FUNC lu_mem luaF_protosize (Proto *p);
60LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); 60LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f);
61LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, 61LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number,
62 int pc); 62 int pc);
diff --git a/lgc.c b/lgc.c
index e8b9ad5e..e4130bd5 100644
--- a/lgc.c
+++ b/lgc.c
@@ -110,43 +110,54 @@ static void entersweep (lua_State *L);
110#define gnodelast(h) gnode(h, cast_sizet(sizenode(h))) 110#define gnodelast(h) gnode(h, cast_sizet(sizenode(h)))
111 111
112 112
113static size_t objsize (GCObject *o) { 113static l_mem objsize (GCObject *o) {
114 lu_mem res;
114 switch (o->tt) { 115 switch (o->tt) {
115 case LUA_VTABLE: { 116 case LUA_VTABLE: {
116 return luaH_size(gco2t(o)); 117 res = luaH_size(gco2t(o));
118 break;
117 } 119 }
118 case LUA_VLCL: { 120 case LUA_VLCL: {
119 LClosure *cl = gco2lcl(o); 121 LClosure *cl = gco2lcl(o);
120 return sizeLclosure(cl->nupvalues); 122 res = sizeLclosure(cl->nupvalues);
123 break;
121 } 124 }
122 case LUA_VCCL: { 125 case LUA_VCCL: {
123 CClosure *cl = gco2ccl(o); 126 CClosure *cl = gco2ccl(o);
124 return sizeCclosure(cl->nupvalues); 127 res = sizeCclosure(cl->nupvalues);
128 break;
125 break; 129 break;
126 } 130 }
127 case LUA_VUSERDATA: { 131 case LUA_VUSERDATA: {
128 Udata *u = gco2u(o); 132 Udata *u = gco2u(o);
129 return sizeudata(u->nuvalue, u->len); 133 res = sizeudata(u->nuvalue, u->len);
134 break;
130 } 135 }
131 case LUA_VPROTO: { 136 case LUA_VPROTO: {
132 return luaF_protosize(gco2p(o)); 137 res = luaF_protosize(gco2p(o));
138 break;
133 } 139 }
134 case LUA_VTHREAD: { 140 case LUA_VTHREAD: {
135 return luaE_threadsize(gco2th(o)); 141 res = luaE_threadsize(gco2th(o));
142 break;
136 } 143 }
137 case LUA_VSHRSTR: { 144 case LUA_VSHRSTR: {
138 TString *ts = gco2ts(o); 145 TString *ts = gco2ts(o);
139 return sizestrshr(cast_uint(ts->shrlen)); 146 res = sizestrshr(cast_uint(ts->shrlen));
147 break;
140 } 148 }
141 case LUA_VLNGSTR: { 149 case LUA_VLNGSTR: {
142 TString *ts = gco2ts(o); 150 TString *ts = gco2ts(o);
143 return luaS_sizelngstr(ts->u.lnglen, ts->shrlen); 151 res = luaS_sizelngstr(ts->u.lnglen, ts->shrlen);
152 break;
144 } 153 }
145 case LUA_VUPVAL: { 154 case LUA_VUPVAL: {
146 return sizeof(UpVal); 155 res = sizeof(UpVal);
156 break;
147 } 157 }
148 default: lua_assert(0); return 0; 158 default: res = 0; lua_assert(0);
149 } 159 }
160 return cast(l_mem, res);
150} 161}
151 162
152 163
@@ -327,7 +338,7 @@ GCObject *luaC_newobj (lua_State *L, lu_byte tt, size_t sz) {
327** (only closures can), and a userdata's metatable must be a table. 338** (only closures can), and a userdata's metatable must be a table.
328*/ 339*/
329static void reallymarkobject (global_State *g, GCObject *o) { 340static void reallymarkobject (global_State *g, GCObject *o) {
330 g->GCmarked += cast(l_mem, objsize(o)); 341 g->GCmarked += objsize(o);
331 switch (o->tt) { 342 switch (o->tt) {
332 case LUA_VSHRSTR: 343 case LUA_VSHRSTR:
333 case LUA_VLNGSTR: { 344 case LUA_VLNGSTR: {
@@ -803,6 +814,7 @@ static void freeupval (lua_State *L, UpVal *uv) {
803 814
804 815
805static void freeobj (lua_State *L, GCObject *o) { 816static void freeobj (lua_State *L, GCObject *o) {
817 assert_code(l_mem newmem = gettotalbytes(G(L)) - objsize(o));
806 switch (o->tt) { 818 switch (o->tt) {
807 case LUA_VPROTO: 819 case LUA_VPROTO:
808 luaF_freeproto(L, gco2p(o)); 820 luaF_freeproto(L, gco2p(o));
@@ -846,6 +858,7 @@ static void freeobj (lua_State *L, GCObject *o) {
846 } 858 }
847 default: lua_assert(0); 859 default: lua_assert(0);
848 } 860 }
861 lua_assert(gettotalbytes(G(L)) == newmem);
849} 862}
850 863
851 864
@@ -1167,7 +1180,7 @@ static GCObject **sweepgen (lua_State *L, global_State *g, GCObject **p,
1167 lua_assert(age != G_OLD1); /* advanced in 'markold' */ 1180 lua_assert(age != G_OLD1); /* advanced in 'markold' */
1168 setage(curr, nextage[age]); 1181 setage(curr, nextage[age]);
1169 if (getage(curr) == G_OLD1) { 1182 if (getage(curr) == G_OLD1) {
1170 addedold += cast(l_mem, objsize(curr)); /* bytes becoming old */ 1183 addedold += objsize(curr); /* bytes becoming old */
1171 if (*pfirstold1 == NULL) 1184 if (*pfirstold1 == NULL)
1172 *pfirstold1 = curr; /* first OLD1 object in the list */ 1185 *pfirstold1 = curr; /* first OLD1 object in the list */
1173 } 1186 }
diff --git a/lstate.c b/lstate.c
index a8db9477..0e1cb01e 100644
--- a/lstate.c
+++ b/lstate.c
@@ -257,8 +257,9 @@ static void preinit_thread (lua_State *L, global_State *g) {
257} 257}
258 258
259 259
260size_t luaE_threadsize (lua_State *L) { 260lu_mem luaE_threadsize (lua_State *L) {
261 size_t sz = sizeof(LX) + cast_uint(L->nci) * sizeof(CallInfo); 261 lu_mem sz = cast(lu_mem, sizeof(LX))
262 + cast_uint(L->nci) * sizeof(CallInfo);
262 if (L->stack.p != NULL) 263 if (L->stack.p != NULL)
263 sz += cast_uint(stacksize(L) + EXTRA_STACK) * sizeof(StackValue); 264 sz += cast_uint(stacksize(L) + EXTRA_STACK) * sizeof(StackValue);
264 return sz; 265 return sz;
diff --git a/lstate.h b/lstate.h
index a1b463c6..d1bc0542 100644
--- a/lstate.h
+++ b/lstate.h
@@ -416,7 +416,7 @@ union GCUnion {
416 416
417LUAI_FUNC void luaE_setdebt (global_State *g, l_mem debt); 417LUAI_FUNC void luaE_setdebt (global_State *g, l_mem debt);
418LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1); 418LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1);
419LUAI_FUNC size_t luaE_threadsize (lua_State *L); 419LUAI_FUNC lu_mem luaE_threadsize (lua_State *L);
420LUAI_FUNC CallInfo *luaE_extendCI (lua_State *L); 420LUAI_FUNC CallInfo *luaE_extendCI (lua_State *L);
421LUAI_FUNC void luaE_shrinkCI (lua_State *L); 421LUAI_FUNC void luaE_shrinkCI (lua_State *L);
422LUAI_FUNC void luaE_checkcstack (lua_State *L); 422LUAI_FUNC void luaE_checkcstack (lua_State *L);
diff --git a/ltable.c b/ltable.c
index 981e9df4..21fafa5e 100644
--- a/ltable.c
+++ b/ltable.c
@@ -863,8 +863,9 @@ Table *luaH_new (lua_State *L) {
863} 863}
864 864
865 865
866size_t luaH_size (Table *t) { 866lu_mem luaH_size (Table *t) {
867 size_t sz = sizeof(Table) + luaH_realasize(t) * (sizeof(Value) + 1); 867 lu_mem sz = cast(lu_mem, sizeof(Table))
868 + luaH_realasize(t) * (sizeof(Value) + 1);
868 if (!isdummy(t)) 869 if (!isdummy(t))
869 sz += sizehash(t); 870 sz += sizehash(t);
870 return sz; 871 return sz;
diff --git a/ltable.h b/ltable.h
index c352da38..17e4fb4a 100644
--- a/ltable.h
+++ b/ltable.h
@@ -163,7 +163,7 @@ LUAI_FUNC Table *luaH_new (lua_State *L);
163LUAI_FUNC void luaH_resize (lua_State *L, Table *t, unsigned nasize, 163LUAI_FUNC void luaH_resize (lua_State *L, Table *t, unsigned nasize,
164 unsigned nhsize); 164 unsigned nhsize);
165LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, unsigned nasize); 165LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, unsigned nasize);
166LUAI_FUNC size_t luaH_size (Table *t); 166LUAI_FUNC lu_mem luaH_size (Table *t);
167LUAI_FUNC void luaH_free (lua_State *L, Table *t); 167LUAI_FUNC void luaH_free (lua_State *L, Table *t);
168LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key); 168LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key);
169LUAI_FUNC lua_Unsigned luaH_getn (Table *t); 169LUAI_FUNC lua_Unsigned luaH_getn (Table *t);