diff options
Diffstat (limited to 'lgc.c')
-rw-r--r-- | lgc.c | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lgc.c,v 2.241 2017/12/01 17:38:49 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 2.242 2017/12/08 17:28:25 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 | */ |
@@ -569,13 +569,23 @@ static int traverseLclosure (global_State *g, LClosure *cl) { | |||
569 | } | 569 | } |
570 | 570 | ||
571 | 571 | ||
572 | /* | ||
573 | ** Traverse a thread, marking the elements in the stack up to its top | ||
574 | ** and cleaning the rest of the stack in the last traversal. | ||
575 | ** That ensures that the entire stack have valid (non-dead) objects. | ||
576 | ** In an emergency collection running Lua code, 'L->top' may not be | ||
577 | ** update. In that case, traverse at least up to 'ci->top'. | ||
578 | */ | ||
572 | static int traversethread (global_State *g, lua_State *th) { | 579 | static int traversethread (global_State *g, lua_State *th) { |
573 | StkId o = th->stack; | 580 | StkId o = th->stack; |
581 | StkId top = th->top; | ||
574 | if (o == NULL) | 582 | if (o == NULL) |
575 | return 1; /* stack not completely built yet */ | 583 | return 1; /* stack not completely built yet */ |
576 | lua_assert(g->gcstate == GCSatomic || | 584 | lua_assert(g->gcstate == GCSatomic || |
577 | th->openupval == NULL || isintwups(th)); | 585 | th->openupval == NULL || isintwups(th)); |
578 | for (; o < th->top; o++) /* mark live elements in the stack */ | 586 | if (g->gcemergency && isLuacode(th->ci) && top < th->ci->top) |
587 | top = th->ci->top; | ||
588 | for (; o < top; o++) /* mark live elements in the stack */ | ||
579 | markvalue(g, s2v(o)); | 589 | markvalue(g, s2v(o)); |
580 | if (g->gcstate == GCSatomic) { /* final traversal? */ | 590 | if (g->gcstate == GCSatomic) { /* final traversal? */ |
581 | StkId lim = th->stack + th->stacksize; /* real end of stack */ | 591 | StkId lim = th->stack + th->stacksize; /* real end of stack */ |