Improve assertions.

This commit is contained in:
Mike Pall
2020-06-13 00:52:54 +02:00
parent 8b55054473
commit 8ae5170cdc
71 changed files with 1363 additions and 927 deletions

View File

@@ -60,7 +60,8 @@ static void resizestack(lua_State *L, MSize n)
MSize oldsize = L->stacksize;
MSize realsize = n + 1 + LJ_STACK_EXTRA;
GCobj *up;
lua_assert((MSize)(tvref(L->maxstack)-oldst)==L->stacksize-LJ_STACK_EXTRA-1);
lj_assertL((MSize)(tvref(L->maxstack)-oldst) == L->stacksize-LJ_STACK_EXTRA-1,
"inconsistent stack size");
st = (TValue *)lj_mem_realloc(L, tvref(L->stack),
(MSize)(oldsize*sizeof(TValue)),
(MSize)(realsize*sizeof(TValue)));
@@ -162,8 +163,9 @@ static void close_state(lua_State *L)
global_State *g = G(L);
lj_func_closeuv(L, tvref(L->stack));
lj_gc_freeall(g);
lua_assert(gcref(g->gc.root) == obj2gco(L));
lua_assert(g->strnum == 0);
lj_assertG(gcref(g->gc.root) == obj2gco(L),
"main thread is not first GC object");
lj_assertG(g->strnum == 0, "leaked %d strings", g->strnum);
lj_trace_freestate(g);
#if LJ_HASFFI
lj_ctype_freestate(g);
@@ -171,7 +173,9 @@ static void close_state(lua_State *L)
lj_mem_freevec(g, g->strhash, g->strmask+1, GCRef);
lj_buf_free(g, &g->tmpbuf);
lj_mem_freevec(g, tvref(L->stack), L->stacksize, TValue);
lua_assert(g->gc.total == sizeof(GG_State));
lj_assertG(g->gc.total == sizeof(GG_State),
"memory leak of %lld bytes",
(long long)(g->gc.total - sizeof(GG_State)));
#ifndef LUAJIT_USE_SYSMALLOC
if (g->allocf == lj_alloc_f)
lj_alloc_destroy(g->allocd);
@@ -283,17 +287,17 @@ lua_State *lj_state_new(lua_State *L)
setmrefr(L1->glref, L->glref);
setgcrefr(L1->env, L->env);
stack_init(L1, L); /* init stack */
lua_assert(iswhite(obj2gco(L1)));
lj_assertL(iswhite(obj2gco(L1)), "new thread object is not white");
return L1;
}
void LJ_FASTCALL lj_state_free(global_State *g, lua_State *L)
{
lua_assert(L != mainthread(g));
lj_assertG(L != mainthread(g), "free of main thread");
if (obj2gco(L) == gcref(g->cur_L))
setgcrefnull(g->cur_L);
lj_func_closeuv(L, tvref(L->stack));
lua_assert(gcref(L->openupval) == NULL);
lj_assertG(gcref(L->openupval) == NULL, "stale open upvalues");
lj_mem_freevec(g, tvref(L->stack), L->stacksize, TValue);
lj_mem_freet(g, L);
}