aboutsummaryrefslogtreecommitdiff
path: root/lstate.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2005-01-18 15:18:09 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2005-01-18 15:18:09 -0200
commit334ba8132bd0471ffe2a9964b577d3ae89ec490a (patch)
tree3e0dde3bca4f1f51dad42d8c85ad9cb624aab1fa /lstate.c
parentac71a0891d8571816ce32b5c2c1fd97942decf71 (diff)
downloadlua-334ba8132bd0471ffe2a9964b577d3ae89ec490a.tar.gz
lua-334ba8132bd0471ffe2a9964b577d3ae89ec490a.tar.bz2
lua-334ba8132bd0471ffe2a9964b577d3ae89ec490a.zip
cleaner way to remark open upvalues
Diffstat (limited to 'lstate.c')
-rw-r--r--lstate.c22
1 files changed, 7 insertions, 15 deletions
diff --git a/lstate.c b/lstate.c
index 33a5cd7d..7596a55d 100644
--- a/lstate.c
+++ b/lstate.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.c,v 2.21 2005/01/05 18:20:51 roberto Exp roberto $ 2** $Id: lstate.c,v 2.22 2005/01/14 14:19:42 roberto Exp $
3** Global State 3** Global State
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -76,16 +76,8 @@ static void freestack (lua_State *L, lua_State *L1) {
76** open parts that may cause memory-allocation errors 76** open parts that may cause memory-allocation errors
77*/ 77*/
78static void f_luaopen (lua_State *L, void *ud) { 78static void f_luaopen (lua_State *L, void *ud) {
79 Udata *u; /* head of udata list */
80 global_State *g = G(L); 79 global_State *g = G(L);
81 UNUSED(ud); 80 UNUSED(ud);
82 u = luaM_new(L, Udata);
83 u->uv.len = 0;
84 u->uv.metatable = NULL;
85 g->firstudata = obj2gco(u);
86 luaC_link(L, obj2gco(u), LUA_TUSERDATA);
87 setbit(u->uv.marked, FIXEDBIT);
88 setbit(L->marked, FIXEDBIT);
89 stack_init(L, L); /* init stack */ 81 stack_init(L, L); /* init stack */
90 sethvalue(L, gt(L), luaH_new(L, 0, 20)); /* table of globals */ 82 sethvalue(L, gt(L), luaH_new(L, 0, 20)); /* table of globals */
91 hvalue(gt(L))->metatable = luaH_new(L, 0, 0); /* globals metatable */ 83 hvalue(gt(L))->metatable = luaH_new(L, 0, 0); /* globals metatable */
@@ -100,8 +92,6 @@ static void f_luaopen (lua_State *L, void *ud) {
100 92
101static void preinit_state (lua_State *L, global_State *g) { 93static void preinit_state (lua_State *L, global_State *g) {
102 L->l_G = g; 94 L->l_G = g;
103 L->tt = LUA_TTHREAD;
104 L->marked = luaC_white(g);
105 L->stack = NULL; 95 L->stack = NULL;
106 L->stacksize = 0; 96 L->stacksize = 0;
107 L->errorJmp = NULL; 97 L->errorJmp = NULL;
@@ -136,8 +126,7 @@ static void close_state (lua_State *L) {
136 126
137lua_State *luaE_newthread (lua_State *L) { 127lua_State *luaE_newthread (lua_State *L) {
138 lua_State *L1 = tostate(luaM_malloc(L, state_size(lua_State))); 128 lua_State *L1 = tostate(luaM_malloc(L, state_size(lua_State)));
139 L1->next = L->next; /* link new thread after `L' */ 129 luaC_link(L, obj2gco(L1), LUA_TTHREAD);
140 L->next = obj2gco(L1);
141 preinit_state(L1, G(L)); 130 preinit_state(L1, G(L));
142 stack_init(L1, L); /* init stack */ 131 stack_init(L1, L); /* init stack */
143 setobj2n(L, gt(L1), gt(L)); /* share table of globals */ 132 setobj2n(L, gt(L1), gt(L)); /* share table of globals */
@@ -166,11 +155,15 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
166 L = tostate(l); 155 L = tostate(l);
167 g = &((LG *)L)->g; 156 g = &((LG *)L)->g;
168 L->next = NULL; 157 L->next = NULL;
169 g->currentwhite = bitmask(WHITE0BIT); 158 L->tt = LUA_TTHREAD;
159 L->marked = g->currentwhite = bitmask(WHITE0BIT);
160 setbit(L->marked, FIXEDBIT);
170 preinit_state(L, g); 161 preinit_state(L, g);
171 g->realloc = f; 162 g->realloc = f;
172 g->ud = ud; 163 g->ud = ud;
173 g->mainthread = L; 164 g->mainthread = L;
165 g->uvhead.u.l.prev = &g->uvhead;
166 g->uvhead.u.l.next = &g->uvhead;
174 g->GCthreshold = 0; /* mark it as unfinished state */ 167 g->GCthreshold = 0; /* mark it as unfinished state */
175 g->strt.size = 0; 168 g->strt.size = 0;
176 g->strt.nuse = 0; 169 g->strt.nuse = 0;
@@ -182,7 +175,6 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
182 g->rootgc = obj2gco(L); 175 g->rootgc = obj2gco(L);
183 g->sweepstrgc = 0; 176 g->sweepstrgc = 0;
184 g->sweepgc = &g->rootgc; 177 g->sweepgc = &g->rootgc;
185 g->firstudata = NULL;
186 g->gray = NULL; 178 g->gray = NULL;
187 g->grayagain = NULL; 179 g->grayagain = NULL;
188 g->weak = NULL; 180 g->weak = NULL;