From b320d37a80c6068cf6b7a91cdd8c8bc8bf71e06c Mon Sep 17 00:00:00 2001
From: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Tue, 3 May 2005 16:01:17 -0300
Subject: better tests for correctness of `savedpc'

---
 ltests.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

(limited to 'ltests.c')

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;
-- 
cgit v1.2.3-55-g6feb