diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-11-15 12:04:53 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-11-15 12:04:53 -0300 |
commit | a4762b6ffe74f5878882ef238d37bfa92d90e418 (patch) | |
tree | 4f52a82641838a318e6270522d9e7f83ccab388d | |
parent | d4247befa18a7911c56e7110154ad73574cd6648 (diff) | |
download | lua-a4762b6ffe74f5878882ef238d37bfa92d90e418.tar.gz lua-a4762b6ffe74f5878882ef238d37bfa92d90e418.tar.bz2 lua-a4762b6ffe74f5878882ef238d37bfa92d90e418.zip |
'objsize' returns 'l_mem'
Sums of size_t may not fit in a size_t.
-rw-r--r-- | lfunc.c | 10 | ||||
-rw-r--r-- | lfunc.h | 2 | ||||
-rw-r--r-- | lgc.c | 39 | ||||
-rw-r--r-- | lstate.c | 5 | ||||
-rw-r--r-- | lstate.h | 2 | ||||
-rw-r--r-- | ltable.c | 5 | ||||
-rw-r--r-- | ltable.h | 2 |
7 files changed, 40 insertions, 25 deletions
@@ -264,16 +264,16 @@ Proto *luaF_newproto (lua_State *L) { | |||
264 | } | 264 | } |
265 | 265 | ||
266 | 266 | ||
267 | size_t luaF_protosize (Proto *p) { | 267 | lu_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 | } |
@@ -56,7 +56,7 @@ LUAI_FUNC void luaF_newtbcupval (lua_State *L, StkId level); | |||
56 | LUAI_FUNC void luaF_closeupval (lua_State *L, StkId level); | 56 | LUAI_FUNC void luaF_closeupval (lua_State *L, StkId level); |
57 | LUAI_FUNC StkId luaF_close (lua_State *L, StkId level, int status, int yy); | 57 | LUAI_FUNC StkId luaF_close (lua_State *L, StkId level, int status, int yy); |
58 | LUAI_FUNC void luaF_unlinkupval (UpVal *uv); | 58 | LUAI_FUNC void luaF_unlinkupval (UpVal *uv); |
59 | LUAI_FUNC size_t luaF_protosize (Proto *p); | 59 | LUAI_FUNC lu_mem luaF_protosize (Proto *p); |
60 | LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); | 60 | LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); |
61 | LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, | 61 | LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, |
62 | int pc); | 62 | int pc); |
@@ -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 | ||
113 | static size_t objsize (GCObject *o) { | 113 | static 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 | */ |
329 | static void reallymarkobject (global_State *g, GCObject *o) { | 340 | static 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 | ||
805 | static void freeobj (lua_State *L, GCObject *o) { | 816 | static 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 | } |
@@ -257,8 +257,9 @@ static void preinit_thread (lua_State *L, global_State *g) { | |||
257 | } | 257 | } |
258 | 258 | ||
259 | 259 | ||
260 | size_t luaE_threadsize (lua_State *L) { | 260 | lu_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; |
@@ -416,7 +416,7 @@ union GCUnion { | |||
416 | 416 | ||
417 | LUAI_FUNC void luaE_setdebt (global_State *g, l_mem debt); | 417 | LUAI_FUNC void luaE_setdebt (global_State *g, l_mem debt); |
418 | LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1); | 418 | LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1); |
419 | LUAI_FUNC size_t luaE_threadsize (lua_State *L); | 419 | LUAI_FUNC lu_mem luaE_threadsize (lua_State *L); |
420 | LUAI_FUNC CallInfo *luaE_extendCI (lua_State *L); | 420 | LUAI_FUNC CallInfo *luaE_extendCI (lua_State *L); |
421 | LUAI_FUNC void luaE_shrinkCI (lua_State *L); | 421 | LUAI_FUNC void luaE_shrinkCI (lua_State *L); |
422 | LUAI_FUNC void luaE_checkcstack (lua_State *L); | 422 | LUAI_FUNC void luaE_checkcstack (lua_State *L); |
@@ -863,8 +863,9 @@ Table *luaH_new (lua_State *L) { | |||
863 | } | 863 | } |
864 | 864 | ||
865 | 865 | ||
866 | size_t luaH_size (Table *t) { | 866 | lu_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; |
@@ -163,7 +163,7 @@ LUAI_FUNC Table *luaH_new (lua_State *L); | |||
163 | LUAI_FUNC void luaH_resize (lua_State *L, Table *t, unsigned nasize, | 163 | LUAI_FUNC void luaH_resize (lua_State *L, Table *t, unsigned nasize, |
164 | unsigned nhsize); | 164 | unsigned nhsize); |
165 | LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, unsigned nasize); | 165 | LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, unsigned nasize); |
166 | LUAI_FUNC size_t luaH_size (Table *t); | 166 | LUAI_FUNC lu_mem luaH_size (Table *t); |
167 | LUAI_FUNC void luaH_free (lua_State *L, Table *t); | 167 | LUAI_FUNC void luaH_free (lua_State *L, Table *t); |
168 | LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key); | 168 | LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key); |
169 | LUAI_FUNC lua_Unsigned luaH_getn (Table *t); | 169 | LUAI_FUNC lua_Unsigned luaH_getn (Table *t); |