Improve assertions.
This commit is contained in:
@@ -55,7 +55,8 @@ static BCPos debug_framepc(lua_State *L, GCfunc *fn, cTValue *nextframe)
|
||||
const BCIns *ins;
|
||||
GCproto *pt;
|
||||
BCPos pos;
|
||||
lua_assert(fn->c.gct == ~LJ_TFUNC || fn->c.gct == ~LJ_TTHREAD);
|
||||
lj_assertL(fn->c.gct == ~LJ_TFUNC || fn->c.gct == ~LJ_TTHREAD,
|
||||
"function or frame expected");
|
||||
if (!isluafunc(fn)) { /* Cannot derive a PC for non-Lua functions. */
|
||||
return NO_BCPOS;
|
||||
} else if (nextframe == NULL) { /* Lua function on top. */
|
||||
@@ -100,7 +101,7 @@ static BCPos debug_framepc(lua_State *L, GCfunc *fn, cTValue *nextframe)
|
||||
#if LJ_HASJIT
|
||||
if (pos > pt->sizebc) { /* Undo the effects of lj_trace_exit for JLOOP. */
|
||||
GCtrace *T = (GCtrace *)((char *)(ins-1) - offsetof(GCtrace, startins));
|
||||
lua_assert(bc_isret(bc_op(ins[-1])));
|
||||
lj_assertL(bc_isret(bc_op(ins[-1])), "return bytecode expected");
|
||||
pos = proto_bcpos(pt, mref(T->startpc, const BCIns));
|
||||
}
|
||||
#endif
|
||||
@@ -133,7 +134,7 @@ static BCLine debug_frameline(lua_State *L, GCfunc *fn, cTValue *nextframe)
|
||||
BCPos pc = debug_framepc(L, fn, nextframe);
|
||||
if (pc != NO_BCPOS) {
|
||||
GCproto *pt = funcproto(fn);
|
||||
lua_assert(pc <= pt->sizebc);
|
||||
lj_assertL(pc <= pt->sizebc, "PC out of range");
|
||||
return lj_debug_line(pt, pc);
|
||||
}
|
||||
return -1;
|
||||
@@ -214,7 +215,7 @@ static TValue *debug_localname(lua_State *L, const lua_Debug *ar,
|
||||
const char *lj_debug_uvname(GCproto *pt, uint32_t idx)
|
||||
{
|
||||
const uint8_t *p = proto_uvinfo(pt);
|
||||
lua_assert(idx < pt->sizeuv);
|
||||
lj_assertX(idx < pt->sizeuv, "bad upvalue index");
|
||||
if (!p) return "";
|
||||
if (idx) while (*p++ || --idx) ;
|
||||
return (const char *)p;
|
||||
@@ -439,13 +440,14 @@ int lj_debug_getinfo(lua_State *L, const char *what, lj_Debug *ar, int ext)
|
||||
} else {
|
||||
uint32_t offset = (uint32_t)ar->i_ci & 0xffff;
|
||||
uint32_t size = (uint32_t)ar->i_ci >> 16;
|
||||
lua_assert(offset != 0);
|
||||
lj_assertL(offset != 0, "bad frame offset");
|
||||
frame = tvref(L->stack) + offset;
|
||||
if (size) nextframe = frame + size;
|
||||
lua_assert(frame <= tvref(L->maxstack) &&
|
||||
(!nextframe || nextframe <= tvref(L->maxstack)));
|
||||
lj_assertL(frame <= tvref(L->maxstack) &&
|
||||
(!nextframe || nextframe <= tvref(L->maxstack)),
|
||||
"broken frame chain");
|
||||
fn = frame_func(frame);
|
||||
lua_assert(fn->c.gct == ~LJ_TFUNC);
|
||||
lj_assertL(fn->c.gct == ~LJ_TFUNC, "bad frame function");
|
||||
}
|
||||
for (; *what; what++) {
|
||||
if (*what == 'S') {
|
||||
|
||||
Reference in New Issue
Block a user