aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2010-04-19 14:40:13 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2010-04-19 14:40:13 -0300
commit4db6f20770ff3953a4e7472116e9158d4d584d2c (patch)
treed29547858619d1c3973a5a4c3599b993793798b2
parentcca71912e6c884c7a2fcf45c19d15e5d69810c97 (diff)
downloadlua-4db6f20770ff3953a4e7472116e9158d4d584d2c.tar.gz
lua-4db6f20770ff3953a4e7472116e9158d4d584d2c.tar.bz2
lua-4db6f20770ff3953a4e7472116e9158d4d584d2c.zip
ensure that 'luai_userstatethread' is always called (even if
'stack_init' throws a memory error)
-rw-r--r--llimits.h10
-rw-r--r--lstate.c9
-rw-r--r--ltests.h4
3 files changed, 12 insertions, 11 deletions
diff --git a/llimits.h b/llimits.h
index c6b5b479..b7459533 100644
--- a/llimits.h
+++ b/llimits.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: llimits.h,v 1.76 2009/12/17 12:26:09 roberto Exp roberto $ 2** $Id: llimits.h,v 1.77 2009/12/17 12:50:20 roberto Exp roberto $
3** Limits, basic types, and some other `installation-dependent' definitions 3** Limits, basic types, and some other `installation-dependent' definitions
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -139,19 +139,19 @@ typedef lu_int32 Instruction;
139** created/deleted/resumed/yielded. 139** created/deleted/resumed/yielded.
140*/ 140*/
141#if !defined(luai_userstateopen) 141#if !defined(luai_userstateopen)
142#define luai_userstateopen(L) ((void)L) 142#define luai_userstateopen(L) ((void)L)
143#endif 143#endif
144 144
145#if !defined(luai_userstateclose) 145#if !defined(luai_userstateclose)
146#define luai_userstateclose(L) ((void)L) 146#define luai_userstateclose(L) ((void)L)
147#endif 147#endif
148 148
149#if !defined(luai_userstatethread) 149#if !defined(luai_userstatethread)
150#define luai_userstatethread(L,L1) ((void)L) 150#define luai_userstatethread(L,L1) ((void)L)
151#endif 151#endif
152 152
153#if !defined(luai_userstatefree) 153#if !defined(luai_userstatefree)
154#define luai_userstatefree(L) ((void)L) 154#define luai_userstatefree(L,L1) ((void)L)
155#endif 155#endif
156 156
157#if !defined(luai_userstateresume) 157#if !defined(luai_userstateresume)
diff --git a/lstate.c b/lstate.c
index 462b7db8..c3aaeaf5 100644
--- a/lstate.c
+++ b/lstate.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.c,v 2.80 2010/04/14 15:14:21 roberto Exp roberto $ 2** $Id: lstate.c,v 2.81 2010/04/19 16:34:46 roberto Exp roberto $
3** Global State 3** Global State
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -192,14 +192,13 @@ LUA_API lua_State *lua_newthread (lua_State *L) {
192 setthvalue(L, L->top, L1); 192 setthvalue(L, L->top, L1);
193 api_incr_top(L); 193 api_incr_top(L);
194 preinit_state(L1, G(L)); 194 preinit_state(L1, G(L));
195 stack_init(L1, L); /* init stack */
196 L1->hookmask = L->hookmask; 195 L1->hookmask = L->hookmask;
197 L1->basehookcount = L->basehookcount; 196 L1->basehookcount = L->basehookcount;
198 L1->hook = L->hook; 197 L1->hook = L->hook;
199 resethookcount(L1); 198 resethookcount(L1);
200 lua_assert(iswhite(obj2gco(L1)));
201 lua_unlock(L);
202 luai_userstatethread(L, L1); 199 luai_userstatethread(L, L1);
200 stack_init(L1, L); /* init stack */
201 lua_unlock(L);
203 return L1; 202 return L1;
204} 203}
205 204
@@ -208,7 +207,7 @@ void luaE_freethread (lua_State *L, lua_State *L1) {
208 LX *l = fromstate(L1); 207 LX *l = fromstate(L1);
209 luaF_close(L1, L1->stack); /* close all upvalues for this thread */ 208 luaF_close(L1, L1->stack); /* close all upvalues for this thread */
210 lua_assert(L1->openupval == NULL); 209 lua_assert(L1->openupval == NULL);
211 luai_userstatefree(L1); 210 luai_userstatefree(L, L1);
212 freestack(L1); 211 freestack(L1);
213 luaM_free(L, l); 212 luaM_free(L, l);
214} 213}
diff --git a/ltests.h b/ltests.h
index 27dd9836..73676f64 100644
--- a/ltests.h
+++ b/ltests.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltests.h,v 2.30 2010/01/11 17:33:09 roberto Exp roberto $ 2** $Id: ltests.h,v 2.31 2010/04/12 16:07:29 roberto Exp roberto $
3** Internal Header for Debugging of the Lua Implementation 3** Internal Header for Debugging of the Lua Implementation
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -62,6 +62,8 @@ struct L_EXTRA { int lock; int *plock; };
62#define luai_userstateopen(l) \ 62#define luai_userstateopen(l) \
63 (getlock(l)->lock = 0, getlock(l)->plock = &(getlock(l)->lock)) 63 (getlock(l)->lock = 0, getlock(l)->plock = &(getlock(l)->lock))
64#define luai_userstatethread(l,l1) (getlock(l1)->plock = getlock(l)->plock) 64#define luai_userstatethread(l,l1) (getlock(l1)->plock = getlock(l)->plock)
65#define luai_userstatefree(l,l1) \
66 lua_assert(getlock(l)->plock == getlock(l1)->plock)
65#define lua_lock(l) lua_assert((*getlock(l)->plock)++ == 0) 67#define lua_lock(l) lua_assert((*getlock(l)->plock)++ == 0)
66#define lua_unlock(l) lua_assert(--(*getlock(l)->plock) == 0) 68#define lua_unlock(l) lua_assert(--(*getlock(l)->plock) == 0)
67 69