From b320d37a80c6068cf6b7a91cdd8c8bc8bf71e06c Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 3 May 2005 16:01:17 -0300 Subject: [PATCH] better tests for correctness of `savedpc' --- ldo.c | 3 ++- ltests.c | 18 ++++++++++++++++-- ltests.h | 5 ++++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/ldo.c b/ldo.c index 1769b784..dc6da54f 100644 --- a/ldo.c +++ b/ldo.c @@ -1,5 +1,5 @@ /* -** $Id: ldo.c,v 2.21 2005/03/29 16:20:48 roberto Exp roberto $ +** $Id: ldo.c,v 2.22 2005/04/05 13:41:29 roberto Exp roberto $ ** Stack and Call structure of Lua ** See Copyright Notice in lua.h */ @@ -116,6 +116,7 @@ static void correctstack (lua_State *L, TValue *oldstack) { ci->top = (ci->top - oldstack) + L->stack; ci->base = (ci->base - oldstack) + L->stack; ci->func = (ci->func - oldstack) + L->stack; + lua_assert(lua_checkpc(L, ci)); } L->base = L->ci->base; } diff --git a/ltests.c b/ltests.c index 6ccc5042..9e7feda2 100644 --- a/ltests.c +++ b/ltests.c @@ -1,5 +1,5 @@ /* -** $Id: ltests.c,v 2.22 2005/03/23 17:51:11 roberto Exp roberto $ +** $Id: ltests.c,v 2.23 2005/03/28 17:17:53 roberto Exp roberto $ ** Internal Module for Debugging of the Lua Implementation ** See Copyright Notice in lua.h */ @@ -281,8 +281,10 @@ static void checkstack (global_State *g, lua_State *L1) { } checkliveness(g, gt(L1)); if (L1->base_ci) { - for (ci = L1->base_ci; ci <= L1->ci; ci++) + for (ci = L1->base_ci; ci <= L1->ci; ci++) { lua_assert(ci->top <= L1->stack_last); + lua_assert(lua_checkpc(L1, ci)); + } } else lua_assert(L1->size_ci == 0); if (L1->stack) { @@ -337,6 +339,18 @@ printf(">>> %d %s %02x\n", g->gcstate, luaT_typenames[o->gch.tt], o->gch.marke } +int lua_checkpc (lua_State *L, pCallInfo ci) { + if (ci == L->base_ci || !f_isLua(ci)) return 1; + else { + Proto *p = ci_func(ci)->l.p; + if (ci < L->ci) + return p->code <= ci->savedpc && ci->savedpc <= p->code + p->sizecode; + else + return p->code <= L->savedpc && L->savedpc <= p->code + p->sizecode; + } +} + + int lua_checkmemory (lua_State *L) { global_State *g = G(L); GCObject *o; diff --git a/ltests.h b/ltests.h index 7c145680..ff843092 100644 --- a/ltests.h +++ b/ltests.h @@ -1,5 +1,5 @@ /* -** $Id: ltests.h,v 2.12 2005/03/18 18:55:45 roberto Exp roberto $ +** $Id: ltests.h,v 2.13 2005/04/13 17:24:20 roberto Exp roberto $ ** Internal Header for Debugging of the Lua Implementation ** See Copyright Notice in lua.h */ @@ -47,7 +47,10 @@ void *debug_realloc (void *ud, void *block, size_t osize, size_t nsize); #endif +typedef struct CallInfo *pCallInfo; + int lua_checkmemory (lua_State *L); +int lua_checkpc (lua_State *L, pCallInfo ci); /* test for lock/unlock */