aboutsummaryrefslogtreecommitdiff
path: root/lstate.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2004-03-15 18:04:33 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2004-03-15 18:04:33 -0300
commita4e1230f95223f2106cf0e118426ba91f1017d89 (patch)
treebc6b67ae14a3381498a203e715d48e8d059b6fef /lstate.c
parent9804467eeb9836bc147adffee411b21e6257da6b (diff)
downloadlua-a4e1230f95223f2106cf0e118426ba91f1017d89.tar.gz
lua-a4e1230f95223f2106cf0e118426ba91f1017d89.tar.bz2
lua-a4e1230f95223f2106cf0e118426ba91f1017d89.zip
better way to control open upvalues
Diffstat (limited to 'lstate.c')
-rw-r--r--lstate.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/lstate.c b/lstate.c
index 36e7d9c3..0b38615a 100644
--- a/lstate.c
+++ b/lstate.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.c,v 2.2 2003/12/12 18:29:34 roberto Exp roberto $ 2** $Id: lstate.c,v 2.3 2004/02/16 19:09:52 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*/
@@ -93,7 +93,10 @@ static void f_luaopen (lua_State *L, void *ud) {
93} 93}
94 94
95 95
96static void preinit_state (lua_State *L) { 96static void preinit_state (lua_State *L, global_State *g) {
97 L->l_G = g;
98 L->tt = LUA_TTHREAD;
99 L->marked = luaC_white(g);
97 L->stack = NULL; 100 L->stack = NULL;
98 L->stacksize = 0; 101 L->stacksize = 0;
99 L->errorJmp = NULL; 102 L->errorJmp = NULL;
@@ -116,7 +119,7 @@ static void close_state (lua_State *L) {
116 global_State *g = G(L); 119 global_State *g = G(L);
117 luaF_close(L, L->stack); /* close all upvalues for this thread */ 120 luaF_close(L, L->stack); /* close all upvalues for this thread */
118 luaC_sweepall(L); /* collect all elements */ 121 luaC_sweepall(L); /* collect all elements */
119 lua_assert(g->rootgc == NULL); 122 lua_assert(g->rootgc == obj2gco(L));
120 luaS_freeall(L); 123 luaS_freeall(L);
121 luaZ_freebuffer(L, &g->buff); 124 luaZ_freebuffer(L, &g->buff);
122 freestack(L, L); 125 freestack(L, L);
@@ -127,9 +130,9 @@ static void close_state (lua_State *L) {
127 130
128lua_State *luaE_newthread (lua_State *L) { 131lua_State *luaE_newthread (lua_State *L) {
129 lua_State *L1 = tostate(luaM_malloc(L, state_size(lua_State))); 132 lua_State *L1 = tostate(luaM_malloc(L, state_size(lua_State)));
130 luaC_link(L, obj2gco(L1), LUA_TTHREAD); 133 L1->next = L->next; /* link new thread after `L' */
131 preinit_state(L1); 134 L->next = obj2gco(L1);
132 L1->l_G = L->l_G; 135 preinit_state(L1, G(L));
133 stack_init(L1, L); /* init stack */ 136 stack_init(L1, L); /* init stack */
134 setobj2n(L, gt(L1), gt(L)); /* share table of globals */ 137 setobj2n(L, gt(L1), gt(L)); /* share table of globals */
135 lua_assert(iswhite(obj2gco(L1))); 138 lua_assert(iswhite(obj2gco(L1)));
@@ -152,11 +155,9 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
152 if (l == NULL) return NULL; 155 if (l == NULL) return NULL;
153 L = tostate(l); 156 L = tostate(l);
154 g = &((LG *)L)->g; 157 g = &((LG *)L)->g;
155 L->tt = LUA_TTHREAD; 158 L->next = NULL;
156 L->marked = 0; 159 g->currentwhite = bitmask(WHITE0BIT);
157 L->next = L->gclist = NULL; 160 preinit_state(L, g);
158 preinit_state(L);
159 L->l_G = g;
160 g->realloc = f; 161 g->realloc = f;
161 g->ud = ud; 162 g->ud = ud;
162 g->mainthread = L; 163 g->mainthread = L;
@@ -168,9 +169,9 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
168 luaZ_initbuffer(L, &g->buff); 169 luaZ_initbuffer(L, &g->buff);
169 g->panic = NULL; 170 g->panic = NULL;
170 g->gcstate = GCSfinalize; 171 g->gcstate = GCSfinalize;
171 g->rootgc = NULL; 172 g->rootgc = obj2gco(L);
172 g->sweepstrgc = 0; 173 g->sweepstrgc = 0;
173 g->currentwhite = bitmask(WHITE0BIT); 174 g->sweepgc = &g->rootgc;
174 g->firstudata = NULL; 175 g->firstudata = NULL;
175 g->gray = NULL; 176 g->gray = NULL;
176 g->grayagain = NULL; 177 g->grayagain = NULL;