浏览代码

'lua_Debug' not using 'CallInfo'

Roberto Ierusalimschy 7 年之前
父节点
当前提交
6bb3e40a8d
共有 3 个文件被更改,包括 20 次插入15 次删除
  1. 14 10
      ldebug.c
  2. 3 3
      ldo.c
  3. 3 2
      lua.h

+ 14 - 10
ldebug.c

@@ -1,5 +1,5 @@
 /*
-** $Id: ldebug.c,v 2.137 2017/11/03 17:22:54 roberto Exp roberto $
+** $Id: ldebug.c,v 2.138 2017/11/03 19:33:22 roberto Exp roberto $
 ** Debug Interface
 ** See Copyright Notice in lua.h
 */
@@ -146,14 +146,17 @@ LUA_API int lua_gethookcount (lua_State *L) {
 
 LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) {
   int status;
-  CallInfo *ci;
+  StkId func;
   if (level < 0) return 0;  /* invalid (negative) level */
   lua_lock(L);
-  for (ci = L->ci; level > 0 && ci != &L->base_ci; ci = ci->previous)
+  for (func = L->func;
+       level > 0 && func->stkci.previous != 0;
+       func -= func->stkci.previous)
     level--;
-  if (level == 0 && ci != &L->base_ci) {  /* level found? */
+  if (level == 0 && func->stkci.previous != 0) {  /* level found? */
     status = 1;
-    ar->i_ci = ci;
+    ar->i_actf = func - L->stack;
+    ar->i_actL = L;
   }
   else status = 0;  /* no such level */
   lua_unlock(L);
@@ -181,9 +184,10 @@ static StkId findcalled (lua_State *L, StkId caller) {
 }
 
 
-static const char *findlocal (lua_State *L, StkId stkf, int n,
-                              StkId *pos) {
+static const char *findlocal (lua_State *L, const lua_Debug *ar,
+                                            int n, StkId *pos) {
   const char *name = NULL;
+  StkId stkf = ar->i_actL->stack + ar->i_actf;
   if (isLua(stkf)) {
     name = luaF_getlocalname(ci_func(stkf)->p, n, currentpc(stkf));
   }
@@ -210,7 +214,7 @@ LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {
   }
   else {  /* active function; get information through 'ar' */
     StkId pos = NULL;  /* to avoid warnings */
-    name = findlocal(L, ar->i_ci->func, n, &pos);
+    name = findlocal(L, ar, n, &pos);
     if (name) {
       setobjs2s(L, L->top, pos);
       api_incr_top(L);
@@ -225,7 +229,7 @@ LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) {
   StkId pos = NULL;  /* to avoid warnings */
   const char *name;
   lua_lock(L);
-  name = findlocal(L, ar->i_ci->func, n, &pos);
+  name = findlocal(L, ar, n, &pos);
   if (name) {
     setobjs2s(L, pos, L->top - 1);
     L->top--;  /* pop value */
@@ -361,7 +365,7 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {
     L->top--;  /* pop function */
   }
   else {
-    stkf = ar->i_ci->func;
+    stkf = ar->i_actL->stack + ar->i_actf;
     func = s2v(stkf);
     lua_assert(ttisfunction(func));
   }

+ 3 - 3
ldo.c

@@ -1,5 +1,5 @@
 /*
-** $Id: ldo.c,v 2.166 2017/11/03 12:12:30 roberto Exp roberto $
+** $Id: ldo.c,v 2.167 2017/11/03 17:22:54 roberto Exp roberto $
 ** Stack and Call structure of Lua
 ** See Copyright Notice in lua.h
 */
@@ -253,14 +253,14 @@ void luaD_inctop (lua_State *L) {
 void luaD_hook (lua_State *L, int event, int line) {
   lua_Hook hook = L->hook;
   if (hook && L->allowhook) {  /* make sure there is a hook */
-    CallInfo *ci = L->ci;
     ptrdiff_t top = savestack(L, L->top);
     int origframesize = L->func->stkci.framesize;
     int tmpframesize;  /* frame size to run hook */
     lua_Debug ar;
     ar.event = event;
     ar.currentline = line;
-    ar.i_ci = ci;
+    ar.i_actf = L->func - L->stack;
+    ar.i_actL = L;
     luaD_checkstack(L, LUA_MINSTACK);  /* ensure minimum stack size */
     tmpframesize = L->top - L->func + LUA_MINSTACK;
     if (tmpframesize > origframesize)  /* need to grow frame? */

+ 3 - 2
lua.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lua.h,v 1.336 2017/07/27 13:36:54 roberto Exp roberto $
+** $Id: lua.h,v 1.337 2017/11/02 11:28:56 roberto Exp roberto $
 ** Lua - A Scripting Language
 ** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
 ** See Copyright Notice at the end of this file
@@ -456,7 +456,8 @@ struct lua_Debug {
   char istailcall;	/* (t) */
   char short_src[LUA_IDSIZE]; /* (S) */
   /* private part */
-  struct CallInfo *i_ci;  /* active function */
+  int i_actf;  /* active function */
+  lua_State *i_actL;  /* where active function is active */
 };
 
 /* }====================================================================== */