瀏覽代碼

better tests for correctness of `savedpc'

Roberto Ierusalimschy 20 年之前
父節點
當前提交
b320d37a80
共有 3 個文件被更改,包括 22 次插入4 次删除
  1. 2 1
      ldo.c
  2. 16 2
      ltests.c
  3. 4 1
      ltests.h

+ 2 - 1
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
 ** Stack and Call structure of Lua
 ** See Copyright Notice in lua.h
 ** 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->top = (ci->top - oldstack) + L->stack;
     ci->base = (ci->base - oldstack) + L->stack;
     ci->base = (ci->base - oldstack) + L->stack;
     ci->func = (ci->func - oldstack) + L->stack;
     ci->func = (ci->func - oldstack) + L->stack;
+    lua_assert(lua_checkpc(L, ci));
   }
   }
   L->base = L->ci->base;
   L->base = L->ci->base;
 }
 }

+ 16 - 2
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
 ** Internal Module for Debugging of the Lua Implementation
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -281,8 +281,10 @@ static void checkstack (global_State *g, lua_State *L1) {
   }
   }
   checkliveness(g, gt(L1));
   checkliveness(g, gt(L1));
   if (L1->base_ci) {
   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(ci->top <= L1->stack_last);
+      lua_assert(lua_checkpc(L1, ci));
+    }
   }
   }
   else lua_assert(L1->size_ci == 0);
   else lua_assert(L1->size_ci == 0);
   if (L1->stack) {
   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) {
 int lua_checkmemory (lua_State *L) {
   global_State *g = G(L);
   global_State *g = G(L);
   GCObject *o;
   GCObject *o;

+ 4 - 1
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
 ** Internal Header for Debugging of the Lua Implementation
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -47,7 +47,10 @@ void *debug_realloc (void *ud, void *block, size_t osize, size_t nsize);
 #endif
 #endif
 
 
 
 
+typedef struct CallInfo *pCallInfo;
+
 int lua_checkmemory (lua_State *L);
 int lua_checkmemory (lua_State *L);
+int lua_checkpc (lua_State *L, pCallInfo ci);
 
 
 
 
 /* test for lock/unlock */
 /* test for lock/unlock */