mirror of
https://github.com/lua/lua.git
synced 2024-11-23 02:03:55 +08:00
'objsize' returns 'l_mem'
Sums of size_t may not fit in a size_t.
This commit is contained in:
parent
d4247befa1
commit
a4762b6ffe
10
lfunc.c
10
lfunc.c
@ -264,16 +264,16 @@ Proto *luaF_newproto (lua_State *L) {
|
||||
}
|
||||
|
||||
|
||||
size_t luaF_protosize (Proto *p) {
|
||||
size_t sz = sizeof(Proto)
|
||||
lu_mem luaF_protosize (Proto *p) {
|
||||
lu_mem sz = cast(lu_mem, sizeof(Proto))
|
||||
+ cast_uint(p->sizep) * sizeof(Proto*)
|
||||
+ cast_uint(p->sizek) * sizeof(TValue)
|
||||
+ cast_uint(p->sizelocvars) * sizeof(LocVar)
|
||||
+ cast_uint(p->sizeupvalues) * sizeof(Upvaldesc);
|
||||
if (!(p->flag & PF_FIXED)) {
|
||||
sz += cast_uint(p->sizecode) * sizeof(Instruction)
|
||||
+ cast_uint(p->sizelineinfo) * sizeof(lu_byte)
|
||||
+ cast_uint(p->sizeabslineinfo) * sizeof(AbsLineInfo);
|
||||
sz += cast_uint(p->sizecode) * sizeof(Instruction);
|
||||
sz += cast_uint(p->sizelineinfo) * sizeof(lu_byte);
|
||||
sz += cast_uint(p->sizeabslineinfo) * sizeof(AbsLineInfo);
|
||||
}
|
||||
return sz;
|
||||
}
|
||||
|
2
lfunc.h
2
lfunc.h
@ -56,7 +56,7 @@ LUAI_FUNC void luaF_newtbcupval (lua_State *L, StkId level);
|
||||
LUAI_FUNC void luaF_closeupval (lua_State *L, StkId level);
|
||||
LUAI_FUNC StkId luaF_close (lua_State *L, StkId level, int status, int yy);
|
||||
LUAI_FUNC void luaF_unlinkupval (UpVal *uv);
|
||||
LUAI_FUNC size_t luaF_protosize (Proto *p);
|
||||
LUAI_FUNC lu_mem luaF_protosize (Proto *p);
|
||||
LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f);
|
||||
LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number,
|
||||
int pc);
|
||||
|
39
lgc.c
39
lgc.c
@ -110,43 +110,54 @@ static void entersweep (lua_State *L);
|
||||
#define gnodelast(h) gnode(h, cast_sizet(sizenode(h)))
|
||||
|
||||
|
||||
static size_t objsize (GCObject *o) {
|
||||
static l_mem objsize (GCObject *o) {
|
||||
lu_mem res;
|
||||
switch (o->tt) {
|
||||
case LUA_VTABLE: {
|
||||
return luaH_size(gco2t(o));
|
||||
res = luaH_size(gco2t(o));
|
||||
break;
|
||||
}
|
||||
case LUA_VLCL: {
|
||||
LClosure *cl = gco2lcl(o);
|
||||
return sizeLclosure(cl->nupvalues);
|
||||
res = sizeLclosure(cl->nupvalues);
|
||||
break;
|
||||
}
|
||||
case LUA_VCCL: {
|
||||
CClosure *cl = gco2ccl(o);
|
||||
return sizeCclosure(cl->nupvalues);
|
||||
res = sizeCclosure(cl->nupvalues);
|
||||
break;
|
||||
break;
|
||||
}
|
||||
case LUA_VUSERDATA: {
|
||||
Udata *u = gco2u(o);
|
||||
return sizeudata(u->nuvalue, u->len);
|
||||
res = sizeudata(u->nuvalue, u->len);
|
||||
break;
|
||||
}
|
||||
case LUA_VPROTO: {
|
||||
return luaF_protosize(gco2p(o));
|
||||
res = luaF_protosize(gco2p(o));
|
||||
break;
|
||||
}
|
||||
case LUA_VTHREAD: {
|
||||
return luaE_threadsize(gco2th(o));
|
||||
res = luaE_threadsize(gco2th(o));
|
||||
break;
|
||||
}
|
||||
case LUA_VSHRSTR: {
|
||||
TString *ts = gco2ts(o);
|
||||
return sizestrshr(cast_uint(ts->shrlen));
|
||||
res = sizestrshr(cast_uint(ts->shrlen));
|
||||
break;
|
||||
}
|
||||
case LUA_VLNGSTR: {
|
||||
TString *ts = gco2ts(o);
|
||||
return luaS_sizelngstr(ts->u.lnglen, ts->shrlen);
|
||||
res = luaS_sizelngstr(ts->u.lnglen, ts->shrlen);
|
||||
break;
|
||||
}
|
||||
case LUA_VUPVAL: {
|
||||
return sizeof(UpVal);
|
||||
res = sizeof(UpVal);
|
||||
break;
|
||||
}
|
||||
default: lua_assert(0); return 0;
|
||||
default: res = 0; lua_assert(0);
|
||||
}
|
||||
return cast(l_mem, res);
|
||||
}
|
||||
|
||||
|
||||
@ -327,7 +338,7 @@ GCObject *luaC_newobj (lua_State *L, lu_byte tt, size_t sz) {
|
||||
** (only closures can), and a userdata's metatable must be a table.
|
||||
*/
|
||||
static void reallymarkobject (global_State *g, GCObject *o) {
|
||||
g->GCmarked += cast(l_mem, objsize(o));
|
||||
g->GCmarked += objsize(o);
|
||||
switch (o->tt) {
|
||||
case LUA_VSHRSTR:
|
||||
case LUA_VLNGSTR: {
|
||||
@ -803,6 +814,7 @@ static void freeupval (lua_State *L, UpVal *uv) {
|
||||
|
||||
|
||||
static void freeobj (lua_State *L, GCObject *o) {
|
||||
assert_code(l_mem newmem = gettotalbytes(G(L)) - objsize(o));
|
||||
switch (o->tt) {
|
||||
case LUA_VPROTO:
|
||||
luaF_freeproto(L, gco2p(o));
|
||||
@ -846,6 +858,7 @@ static void freeobj (lua_State *L, GCObject *o) {
|
||||
}
|
||||
default: lua_assert(0);
|
||||
}
|
||||
lua_assert(gettotalbytes(G(L)) == newmem);
|
||||
}
|
||||
|
||||
|
||||
@ -1167,7 +1180,7 @@ static GCObject **sweepgen (lua_State *L, global_State *g, GCObject **p,
|
||||
lua_assert(age != G_OLD1); /* advanced in 'markold' */
|
||||
setage(curr, nextage[age]);
|
||||
if (getage(curr) == G_OLD1) {
|
||||
addedold += cast(l_mem, objsize(curr)); /* bytes becoming old */
|
||||
addedold += objsize(curr); /* bytes becoming old */
|
||||
if (*pfirstold1 == NULL)
|
||||
*pfirstold1 = curr; /* first OLD1 object in the list */
|
||||
}
|
||||
|
5
lstate.c
5
lstate.c
@ -257,8 +257,9 @@ static void preinit_thread (lua_State *L, global_State *g) {
|
||||
}
|
||||
|
||||
|
||||
size_t luaE_threadsize (lua_State *L) {
|
||||
size_t sz = sizeof(LX) + cast_uint(L->nci) * sizeof(CallInfo);
|
||||
lu_mem luaE_threadsize (lua_State *L) {
|
||||
lu_mem sz = cast(lu_mem, sizeof(LX))
|
||||
+ cast_uint(L->nci) * sizeof(CallInfo);
|
||||
if (L->stack.p != NULL)
|
||||
sz += cast_uint(stacksize(L) + EXTRA_STACK) * sizeof(StackValue);
|
||||
return sz;
|
||||
|
2
lstate.h
2
lstate.h
@ -416,7 +416,7 @@ union GCUnion {
|
||||
|
||||
LUAI_FUNC void luaE_setdebt (global_State *g, l_mem debt);
|
||||
LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1);
|
||||
LUAI_FUNC size_t luaE_threadsize (lua_State *L);
|
||||
LUAI_FUNC lu_mem luaE_threadsize (lua_State *L);
|
||||
LUAI_FUNC CallInfo *luaE_extendCI (lua_State *L);
|
||||
LUAI_FUNC void luaE_shrinkCI (lua_State *L);
|
||||
LUAI_FUNC void luaE_checkcstack (lua_State *L);
|
||||
|
5
ltable.c
5
ltable.c
@ -863,8 +863,9 @@ Table *luaH_new (lua_State *L) {
|
||||
}
|
||||
|
||||
|
||||
size_t luaH_size (Table *t) {
|
||||
size_t sz = sizeof(Table) + luaH_realasize(t) * (sizeof(Value) + 1);
|
||||
lu_mem luaH_size (Table *t) {
|
||||
lu_mem sz = cast(lu_mem, sizeof(Table))
|
||||
+ luaH_realasize(t) * (sizeof(Value) + 1);
|
||||
if (!isdummy(t))
|
||||
sz += sizehash(t);
|
||||
return sz;
|
||||
|
2
ltable.h
2
ltable.h
@ -163,7 +163,7 @@ LUAI_FUNC Table *luaH_new (lua_State *L);
|
||||
LUAI_FUNC void luaH_resize (lua_State *L, Table *t, unsigned nasize,
|
||||
unsigned nhsize);
|
||||
LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, unsigned nasize);
|
||||
LUAI_FUNC size_t luaH_size (Table *t);
|
||||
LUAI_FUNC lu_mem luaH_size (Table *t);
|
||||
LUAI_FUNC void luaH_free (lua_State *L, Table *t);
|
||||
LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key);
|
||||
LUAI_FUNC lua_Unsigned luaH_getn (Table *t);
|
||||
|
Loading…
Reference in New Issue
Block a user