浏览代码

ensure that 'luai_userstatethread' is always called (even if
'stack_init' throws a memory error)

Roberto Ierusalimschy 15 年之前
父节点
当前提交
4db6f20770
共有 3 个文件被更改,包括 12 次插入11 次删除
  1. 5 5
      llimits.h
  2. 4 5
      lstate.c
  3. 3 1
      ltests.h

+ 5 - 5
llimits.h

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: llimits.h,v 1.76 2009/12/17 12:26:09 roberto Exp roberto $
+** $Id: llimits.h,v 1.77 2009/12/17 12:50:20 roberto Exp roberto $
 ** Limits, basic types, and some other `installation-dependent' definitions
 ** Limits, basic types, and some other `installation-dependent' definitions
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -139,19 +139,19 @@ typedef lu_int32 Instruction;
 ** created/deleted/resumed/yielded.
 ** created/deleted/resumed/yielded.
 */
 */
 #if !defined(luai_userstateopen)
 #if !defined(luai_userstateopen)
-#define luai_userstateopen(L)           ((void)L)
+#define luai_userstateopen(L)		((void)L)
 #endif
 #endif
 
 
 #if !defined(luai_userstateclose)
 #if !defined(luai_userstateclose)
-#define luai_userstateclose(L)          ((void)L)
+#define luai_userstateclose(L)		((void)L)
 #endif
 #endif
 
 
 #if !defined(luai_userstatethread)
 #if !defined(luai_userstatethread)
-#define luai_userstatethread(L,L1)      ((void)L)
+#define luai_userstatethread(L,L1)	((void)L)
 #endif
 #endif
 
 
 #if !defined(luai_userstatefree)
 #if !defined(luai_userstatefree)
-#define luai_userstatefree(L)           ((void)L)
+#define luai_userstatefree(L,L1)	((void)L)
 #endif
 #endif
 
 
 #if !defined(luai_userstateresume)
 #if !defined(luai_userstateresume)

+ 4 - 5
lstate.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: lstate.c,v 2.80 2010/04/14 15:14:21 roberto Exp roberto $
+** $Id: lstate.c,v 2.81 2010/04/19 16:34:46 roberto Exp roberto $
 ** Global State
 ** Global State
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -192,14 +192,13 @@ LUA_API lua_State *lua_newthread (lua_State *L) {
   setthvalue(L, L->top, L1);
   setthvalue(L, L->top, L1);
   api_incr_top(L);
   api_incr_top(L);
   preinit_state(L1, G(L));
   preinit_state(L1, G(L));
-  stack_init(L1, L);  /* init stack */
   L1->hookmask = L->hookmask;
   L1->hookmask = L->hookmask;
   L1->basehookcount = L->basehookcount;
   L1->basehookcount = L->basehookcount;
   L1->hook = L->hook;
   L1->hook = L->hook;
   resethookcount(L1);
   resethookcount(L1);
-  lua_assert(iswhite(obj2gco(L1)));
-  lua_unlock(L);
   luai_userstatethread(L, L1);
   luai_userstatethread(L, L1);
+  stack_init(L1, L);  /* init stack */
+  lua_unlock(L);
   return L1;
   return L1;
 }
 }
 
 
@@ -208,7 +207,7 @@ void luaE_freethread (lua_State *L, lua_State *L1) {
   LX *l = fromstate(L1);
   LX *l = fromstate(L1);
   luaF_close(L1, L1->stack);  /* close all upvalues for this thread */
   luaF_close(L1, L1->stack);  /* close all upvalues for this thread */
   lua_assert(L1->openupval == NULL);
   lua_assert(L1->openupval == NULL);
-  luai_userstatefree(L1);
+  luai_userstatefree(L, L1);
   freestack(L1);
   freestack(L1);
   luaM_free(L, l);
   luaM_free(L, l);
 }
 }

+ 3 - 1
ltests.h

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: ltests.h,v 2.30 2010/01/11 17:33:09 roberto Exp roberto $
+** $Id: ltests.h,v 2.31 2010/04/12 16:07:29 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
 */
 */
@@ -62,6 +62,8 @@ struct L_EXTRA { int lock; int *plock; };
 #define luai_userstateopen(l)  \
 #define luai_userstateopen(l)  \
 	(getlock(l)->lock = 0, getlock(l)->plock = &(getlock(l)->lock))
 	(getlock(l)->lock = 0, getlock(l)->plock = &(getlock(l)->lock))
 #define luai_userstatethread(l,l1)  (getlock(l1)->plock = getlock(l)->plock)
 #define luai_userstatethread(l,l1)  (getlock(l1)->plock = getlock(l)->plock)
+#define luai_userstatefree(l,l1) \
+  lua_assert(getlock(l)->plock == getlock(l1)->plock)
 #define lua_lock(l)     lua_assert((*getlock(l)->plock)++ == 0)
 #define lua_lock(l)     lua_assert((*getlock(l)->plock)++ == 0)
 #define lua_unlock(l)   lua_assert(--(*getlock(l)->plock) == 0)
 #define lua_unlock(l)   lua_assert(--(*getlock(l)->plock) == 0)