aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lgc.c2
-rw-r--r--lstate.c2
-rw-r--r--lstate.h1
3 files changed, 5 insertions, 0 deletions
diff --git a/lgc.c b/lgc.c
index 2e749902..20e9b4aa 100644
--- a/lgc.c
+++ b/lgc.c
@@ -259,6 +259,7 @@ GCObject *luaC_newobjdt (lua_State *L, int tt, size_t sz, size_t offset) {
259 global_State *g = G(L); 259 global_State *g = G(L);
260 char *p = cast_charp(luaM_newobject(L, novariant(tt), sz)); 260 char *p = cast_charp(luaM_newobject(L, novariant(tt), sz));
261 GCObject *o = cast(GCObject *, p + offset); 261 GCObject *o = cast(GCObject *, p + offset);
262 g->totalobjs++;
262 o->marked = luaC_white(g); 263 o->marked = luaC_white(g);
263 o->tt = tt; 264 o->tt = tt;
264 o->next = g->allgc; 265 o->next = g->allgc;
@@ -768,6 +769,7 @@ static void freeupval (lua_State *L, UpVal *uv) {
768 769
769 770
770static void freeobj (lua_State *L, GCObject *o) { 771static void freeobj (lua_State *L, GCObject *o) {
772 G(L)->totalobjs--;
771 switch (o->tt) { 773 switch (o->tt) {
772 case LUA_VPROTO: 774 case LUA_VPROTO:
773 luaF_freeproto(L, gco2p(o)); 775 luaF_freeproto(L, gco2p(o));
diff --git a/lstate.c b/lstate.c
index 1fbefb4b..3091a00e 100644
--- a/lstate.c
+++ b/lstate.c
@@ -279,6 +279,7 @@ static void close_state (lua_State *L) {
279 luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size); 279 luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size);
280 freestack(L); 280 freestack(L);
281 lua_assert(gettotalbytes(g) == sizeof(LG)); 281 lua_assert(gettotalbytes(g) == sizeof(LG));
282 lua_assert(g->totalobjs == 1);
282 (*g->frealloc)(g->ud, fromstate(L), sizeof(LG), 0); /* free main block */ 283 (*g->frealloc)(g->ud, fromstate(L), sizeof(LG), 0); /* free main block */
283} 284}
284 285
@@ -387,6 +388,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
387 g->weak = g->ephemeron = g->allweak = NULL; 388 g->weak = g->ephemeron = g->allweak = NULL;
388 g->twups = NULL; 389 g->twups = NULL;
389 g->totalbytes = sizeof(LG); 390 g->totalbytes = sizeof(LG);
391 g->totalobjs = 1;
390 g->GCdebt = 0; 392 g->GCdebt = 0;
391 g->lastatomic = 0; 393 g->lastatomic = 0;
392 setivalue(&g->nilvalue, 0); /* to signal that state is not yet built */ 394 setivalue(&g->nilvalue, 0); /* to signal that state is not yet built */
diff --git a/lstate.h b/lstate.h
index 2e907818..62ad61c6 100644
--- a/lstate.h
+++ b/lstate.h
@@ -250,6 +250,7 @@ typedef struct global_State {
250 lua_Alloc frealloc; /* function to reallocate memory */ 250 lua_Alloc frealloc; /* function to reallocate memory */
251 void *ud; /* auxiliary data to 'frealloc' */ 251 void *ud; /* auxiliary data to 'frealloc' */
252 l_mem totalbytes; /* number of bytes currently allocated - GCdebt */ 252 l_mem totalbytes; /* number of bytes currently allocated - GCdebt */
253 l_mem totalobjs; /* total number of objects allocated */
253 l_mem GCdebt; /* bytes allocated not yet compensated by the collector */ 254 l_mem GCdebt; /* bytes allocated not yet compensated by the collector */
254 lu_mem GCestimate; /* an estimate of the non-garbage memory in use */ 255 lu_mem GCestimate; /* an estimate of the non-garbage memory in use */
255 lu_mem lastatomic; /* see function 'genstep' in file 'lgc.c' */ 256 lu_mem lastatomic; /* see function 'genstep' in file 'lgc.c' */