aboutsummaryrefslogtreecommitdiff
path: root/lstate.c
diff options
context:
space:
mode:
Diffstat (limited to 'lstate.c')
-rw-r--r--lstate.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/lstate.c b/lstate.c
index 1fbefb4b..bee3bf66 100644
--- a/lstate.c
+++ b/lstate.c
@@ -83,15 +83,15 @@ static unsigned int luai_makeseed (lua_State *L) {
83 83
84 84
85/* 85/*
86** set GCdebt to a new value keeping the value (totalbytes + GCdebt) 86** set GCdebt to a new value keeping the value (totalobjs + GCdebt)
87** invariant (and avoiding underflows in 'totalbytes') 87** invariant (and avoiding underflows in 'totalobjs')
88*/ 88*/
89void luaE_setdebt (global_State *g, l_mem debt) { 89void luaE_setdebt (global_State *g, l_obj debt) {
90 l_mem tb = gettotalbytes(g); 90 l_obj tb = gettotalobjs(g);
91 lua_assert(tb > 0); 91 lua_assert(tb > 0);
92 if (debt < tb - MAX_LMEM) 92 if (debt > MAX_LOBJ - tb)
93 debt = tb - MAX_LMEM; /* will make 'totalbytes == MAX_LMEM' */ 93 debt = MAX_LOBJ - tb; /* will make 'totalobjs == MAX_LMEM' */
94 g->totalbytes = tb - debt; 94 g->totalobjs = tb + debt;
95 g->GCdebt = debt; 95 g->GCdebt = debt;
96} 96}
97 97
@@ -278,7 +278,8 @@ static void close_state (lua_State *L) {
278 } 278 }
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(g->totalbytes == sizeof(LG));
282 lua_assert(gettotalobjs(g) == 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,14 +388,15 @@ 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;
392 g->marked = 0;
390 g->GCdebt = 0; 393 g->GCdebt = 0;
391 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 */
393 setgcparam(g->gcpause, LUAI_GCPAUSE); 395 setgcparam(g, gcpause, LUAI_GCPAUSE);
394 setgcparam(g->gcstepmul, LUAI_GCMUL); 396 setgcparam(g, gcstepmul, LUAI_GCMUL);
395 g->gcstepsize = LUAI_GCSTEPSIZE; 397 g->gcstepsize = LUAI_GCSTEPSIZE;
396 setgcparam(g->genmajormul, LUAI_GENMAJORMUL); 398 setgcparam(g, genmajormul, LUAI_GENMAJORMUL);
397 g->genminormul = LUAI_GENMINORMUL; 399 setgcparam(g, genminormul, LUAI_GENMINORMUL);
398 for (i=0; i < LUA_NUMTAGS; i++) g->mt[i] = NULL; 400 for (i=0; i < LUA_NUMTAGS; i++) g->mt[i] = NULL;
399 if (luaD_rawrunprotected(L, f_luaopen, NULL) != LUA_OK) { 401 if (luaD_rawrunprotected(L, f_luaopen, NULL) != LUA_OK) {
400 /* memory allocation error: free partial state */ 402 /* memory allocation error: free partial state */