diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2005-02-14 11:19:50 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2005-02-14 11:19:50 -0200 |
commit | 73d764024451c24bc43b8e5102fe90974a86b7f4 (patch) | |
tree | 0a0d15e303701ed849fd82dfce9afd82e3c5c649 /lgc.c | |
parent | a9af455b329fa49e7481068094a6a6b4551ccbef (diff) | |
download | lua-73d764024451c24bc43b8e5102fe90974a86b7f4.tar.gz lua-73d764024451c24bc43b8e5102fe90974a86b7f4.tar.bz2 lua-73d764024451c24bc43b8e5102fe90974a86b7f4.zip |
more secure way to stop GC cycles during finalizers
Diffstat (limited to 'lgc.c')
-rw-r--r-- | lgc.c | 7 |
1 files changed, 4 insertions, 3 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lgc.c,v 2.23 2005/02/10 13:25:02 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 2.24 2005/02/11 20:03:35 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 | */ |
@@ -461,12 +461,15 @@ static void GCTM (lua_State *L) { | |||
461 | tm = fasttm(L, udata->uv.metatable, TM_GC); | 461 | tm = fasttm(L, udata->uv.metatable, TM_GC); |
462 | if (tm != NULL) { | 462 | if (tm != NULL) { |
463 | lu_byte oldah = L->allowhook; | 463 | lu_byte oldah = L->allowhook; |
464 | lu_mem oldt = g->GCthreshold; | ||
464 | L->allowhook = 0; /* stop debug hooks during GC tag method */ | 465 | L->allowhook = 0; /* stop debug hooks during GC tag method */ |
466 | g->GCthreshold = 2*g->totalbytes; /* avoid GC steps */ | ||
465 | setobj2s(L, L->top, tm); | 467 | setobj2s(L, L->top, tm); |
466 | setuvalue(L, L->top+1, udata); | 468 | setuvalue(L, L->top+1, udata); |
467 | L->top += 2; | 469 | L->top += 2; |
468 | luaD_call(L, L->top - 2, 0); | 470 | luaD_call(L, L->top - 2, 0); |
469 | L->allowhook = oldah; /* restore hooks */ | 471 | L->allowhook = oldah; /* restore hooks */ |
472 | g->GCthreshold = oldt; /* restore threshold */ | ||
470 | } | 473 | } |
471 | } | 474 | } |
472 | 475 | ||
@@ -582,9 +585,7 @@ static l_mem singlestep (lua_State *L) { | |||
582 | } | 585 | } |
583 | case GCSfinalize: { | 586 | case GCSfinalize: { |
584 | if (g->tmudata) { | 587 | if (g->tmudata) { |
585 | g->GCthreshold += GCFINALIZECOST; /* avoid GC steps inside method */ | ||
586 | GCTM(L); | 588 | GCTM(L); |
587 | g->GCthreshold -= GCFINALIZECOST; /* correct threshold */ | ||
588 | return GCFINALIZECOST; | 589 | return GCFINALIZECOST; |
589 | } | 590 | } |
590 | else { | 591 | else { |