diff options
-rw-r--r-- | lgc.c | 20 | ||||
-rw-r--r-- | lstate.c | 11 | ||||
-rw-r--r-- | lstate.h | 7 | ||||
-rw-r--r-- | lstring.c | 6 |
4 files changed, 24 insertions, 20 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lgc.c,v 1.181 2003/12/01 16:33:30 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 1.182 2003/12/01 18:22:56 roberto Exp roberto $ |
3 | ** Garbage Collector | 3 | ** Garbage Collector |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -158,7 +158,7 @@ static void marktmu (global_State *g) { | |||
158 | /* move `dead' udata that need finalization to list `tmudata' */ | 158 | /* move `dead' udata that need finalization to list `tmudata' */ |
159 | size_t luaC_separateudata (lua_State *L) { | 159 | size_t luaC_separateudata (lua_State *L) { |
160 | size_t deadmem = 0; | 160 | size_t deadmem = 0; |
161 | GCObject **p = &G(L)->rootudata; | 161 | GCObject **p = &G(L)->firstudata; |
162 | GCObject *curr; | 162 | GCObject *curr; |
163 | GCObject *collected = NULL; /* to collect udata with gc event */ | 163 | GCObject *collected = NULL; /* to collect udata with gc event */ |
164 | GCObject **lastcollected = &collected; | 164 | GCObject **lastcollected = &collected; |
@@ -495,8 +495,8 @@ static void GCTM (lua_State *L) { | |||
495 | Udata *udata = gcotou(o); | 495 | Udata *udata = gcotou(o); |
496 | const TObject *tm; | 496 | const TObject *tm; |
497 | g->tmudata = udata->uv.next; /* remove udata from `tmudata' */ | 497 | g->tmudata = udata->uv.next; /* remove udata from `tmudata' */ |
498 | udata->uv.next = g->rootudata; /* return it to `root' list */ | 498 | udata->uv.next = g->firstudata->uv.next; /* return it to `root' list */ |
499 | g->rootudata = o; | 499 | g->firstudata->uv.next = o; |
500 | makewhite(o); | 500 | makewhite(o); |
501 | tm = fasttm(L, udata->uv.metatable, TM_GC); | 501 | tm = fasttm(L, udata->uv.metatable, TM_GC); |
502 | if (tm != NULL) { | 502 | if (tm != NULL) { |
@@ -524,7 +524,6 @@ void luaC_callGCTM (lua_State *L) { | |||
524 | void luaC_sweepall (lua_State *L) { | 524 | void luaC_sweepall (lua_State *L) { |
525 | l_mem dummy = MAXLMEM; | 525 | l_mem dummy = MAXLMEM; |
526 | sweepstrings(L, 0); | 526 | sweepstrings(L, 0); |
527 | sweeplist(L, &G(L)->rootudata, 0, &dummy); | ||
528 | sweeplist(L, &G(L)->rootgc, 0, &dummy); | 527 | sweeplist(L, &G(L)->rootgc, 0, &dummy); |
529 | } | 528 | } |
530 | 529 | ||
@@ -537,8 +536,8 @@ static void markroot (lua_State *L) { | |||
537 | makewhite(valtogco(g->mainthread)); | 536 | makewhite(valtogco(g->mainthread)); |
538 | markobject(g, g->mainthread); | 537 | markobject(g, g->mainthread); |
539 | markvalue(g, registry(L)); | 538 | markvalue(g, registry(L)); |
540 | if (L != g->mainthread) /* another thread is running? */ | 539 | markobject(g, g->firstudata); |
541 | markobject(g, L); /* cannot collect it */ | 540 | markobject(g, L); /* mark running thread */ |
542 | g->gcstate = GCSpropagate; | 541 | g->gcstate = GCSpropagate; |
543 | } | 542 | } |
544 | 543 | ||
@@ -549,8 +548,10 @@ static void atomic (lua_State *L) { | |||
549 | marktmu(g); /* mark `preserved' userdata */ | 548 | marktmu(g); /* mark `preserved' userdata */ |
550 | propagatemarks(g, MAXLMEM); /* remark, to propagate `preserveness' */ | 549 | propagatemarks(g, MAXLMEM); /* remark, to propagate `preserveness' */ |
551 | cleartable(g->weak); /* remove collected objects from weak tables */ | 550 | cleartable(g->weak); /* remove collected objects from weak tables */ |
552 | g->sweepgc = &g->rootgc; | 551 | /* first element of root list will be used as temporary head for sweep |
553 | g->sweepudata = &g->rootudata; | 552 | phase, so it won't be seeped */ |
553 | makewhite(g->rootgc); | ||
554 | g->sweepgc = &g->rootgc->gch.next; | ||
554 | sweepstrings(L, maskbf); | 555 | sweepstrings(L, maskbf); |
555 | g->gcstate = GCSsweep; | 556 | g->gcstate = GCSsweep; |
556 | } | 557 | } |
@@ -559,7 +560,6 @@ static void atomic (lua_State *L) { | |||
559 | static void sweepstep (lua_State *L) { | 560 | static void sweepstep (lua_State *L) { |
560 | global_State *g = G(L); | 561 | global_State *g = G(L); |
561 | l_mem lim = GCSTEPSIZE; | 562 | l_mem lim = GCSTEPSIZE; |
562 | g->sweepudata = sweeplist(L, g->sweepudata, maskbf, &lim); | ||
563 | g->sweepgc = sweeplist(L, g->sweepgc, maskbf, &lim); | 563 | g->sweepgc = sweeplist(L, g->sweepgc, maskbf, &lim); |
564 | if (lim == GCSTEPSIZE) { /* nothing more to sweep? */ | 564 | if (lim == GCSTEPSIZE) { /* nothing more to sweep? */ |
565 | g->gcstate = GCSfinalize; /* end sweep phase */ | 565 | g->gcstate = GCSfinalize; /* end sweep phase */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstate.c,v 1.129 2003/12/01 16:33:30 roberto Exp roberto $ | 2 | ** $Id: lstate.c,v 1.130 2003/12/01 18:22:56 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 | */ |
@@ -74,7 +74,13 @@ static void freestack (lua_State *L, lua_State *L1) { | |||
74 | ** open parts that may cause memory-allocation errors | 74 | ** open parts that may cause memory-allocation errors |
75 | */ | 75 | */ |
76 | static void f_luaopen (lua_State *L, void *ud) { | 76 | static void f_luaopen (lua_State *L, void *ud) { |
77 | Udata *u; /* head of udata list */ | ||
77 | UNUSED(ud); | 78 | UNUSED(ud); |
79 | u = cast(Udata *, luaM_malloc(L, sizeudata(0))); | ||
80 | u->uv.len = 0; | ||
81 | u->uv.metatable = NULL; | ||
82 | G(L)->firstudata = valtogco(u); | ||
83 | luaC_link(L, valtogco(u), LUA_TUSERDATA); | ||
78 | stack_init(L, L); /* init stack */ | 84 | stack_init(L, L); /* init stack */ |
79 | sethvalue(gt(L), luaH_new(L, 0, 4)); /* table of globals */ | 85 | sethvalue(gt(L), luaH_new(L, 0, 4)); /* table of globals */ |
80 | sethvalue(registry(L), luaH_new(L, 4, 4)); /* registry */ | 86 | sethvalue(registry(L), luaH_new(L, 4, 4)); /* registry */ |
@@ -110,7 +116,6 @@ static void close_state (lua_State *L) { | |||
110 | luaF_close(L, L->stack); /* close all upvalues for this thread */ | 116 | luaF_close(L, L->stack); /* close all upvalues for this thread */ |
111 | luaC_sweepall(L); /* collect all elements */ | 117 | luaC_sweepall(L); /* collect all elements */ |
112 | lua_assert(g->rootgc == NULL); | 118 | lua_assert(g->rootgc == NULL); |
113 | lua_assert(g->rootudata == NULL); | ||
114 | luaS_freeall(L); | 119 | luaS_freeall(L); |
115 | luaZ_freebuffer(L, &g->buff); | 120 | luaZ_freebuffer(L, &g->buff); |
116 | freestack(L, L); | 121 | freestack(L, L); |
@@ -162,7 +167,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { | |||
162 | g->panic = NULL; | 167 | g->panic = NULL; |
163 | g->gcstate = 0; | 168 | g->gcstate = 0; |
164 | g->rootgc = NULL; | 169 | g->rootgc = NULL; |
165 | g->rootudata = NULL; | 170 | g->firstudata = NULL; |
166 | g->gray = NULL; | 171 | g->gray = NULL; |
167 | g->weak = NULL; | 172 | g->weak = NULL; |
168 | g->tmudata = NULL; | 173 | g->tmudata = NULL; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstate.h,v 1.114 2003/12/01 16:33:30 roberto Exp roberto $ | 2 | ** $Id: lstate.h,v 1.115 2003/12/01 18:22:56 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 | */ |
@@ -97,10 +97,9 @@ typedef struct global_State { | |||
97 | stringtable strt; /* hash table for strings */ | 97 | stringtable strt; /* hash table for strings */ |
98 | lua_Alloc realloc; /* function to reallocate memory */ | 98 | lua_Alloc realloc; /* function to reallocate memory */ |
99 | void *ud; /* auxiliary data to `realloc' */ | 99 | void *ud; /* auxiliary data to `realloc' */ |
100 | GCObject *rootgc; /* list of (almost) all collectable objects */ | 100 | GCObject *rootgc; /* list of all collectable objects */ |
101 | GCObject *rootudata; /* (separated) list of all userdata */ | 101 | GCObject *firstudata; /* udata go to the end of `rootgc' */ |
102 | GCObject **sweepgc; /* position of sweep in `rootgc' */ | 102 | GCObject **sweepgc; /* position of sweep in `rootgc' */ |
103 | GCObject **sweepudata; /* position of sweep in `rootudata' */ | ||
104 | GCObject *gray; /* list of gray objects */ | 103 | GCObject *gray; /* list of gray objects */ |
105 | GCObject *weak; /* list of weak tables (to be cleared) */ | 104 | GCObject *weak; /* list of weak tables (to be cleared) */ |
106 | GCObject *tmudata; /* list of userdata to be GC */ | 105 | GCObject *tmudata; /* list of userdata to be GC */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstring.c,v 1.80 2003/11/17 19:50:05 roberto Exp roberto $ | 2 | ** $Id: lstring.c,v 1.81 2003/12/01 18:22:56 roberto Exp roberto $ |
3 | ** String table (keeps all strings handled by Lua) | 3 | ** String table (keeps all strings handled by Lua) |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -96,8 +96,8 @@ Udata *luaS_newudata (lua_State *L, size_t s) { | |||
96 | u->uv.len = s; | 96 | u->uv.len = s; |
97 | u->uv.metatable = NULL; | 97 | u->uv.metatable = NULL; |
98 | /* chain it on udata list */ | 98 | /* chain it on udata list */ |
99 | u->uv.next = G(L)->rootudata; | 99 | u->uv.next = G(L)->firstudata->uv.next; |
100 | G(L)->rootudata = valtogco(u); | 100 | G(L)->firstudata->uv.next = valtogco(u); |
101 | return u; | 101 | return u; |
102 | } | 102 | } |
103 | 103 | ||