@@ -906,16 +906,16 @@ static void GCTM (lua_State *L) {
906906 if (!notm (tm )) { /* is there a finalizer? */
907907 int status ;
908908 lu_byte oldah = L -> allowhook ;
909- int running = g -> gcrunning ;
909+ int oldgcstp = g -> gcstp ;
910+ g -> gcstp = GCSTPGC ; /* avoid GC steps */
910911 L -> allowhook = 0 ; /* stop debug hooks during GC metamethod */
911- g -> gcrunning = 0 ; /* avoid GC steps */
912912 setobj2s (L , L -> top ++ , tm ); /* push finalizer... */
913913 setobj2s (L , L -> top ++ , & v ); /* ... and its argument */
914914 L -> ci -> callstatus |= CIST_FIN ; /* will run a finalizer */
915915 status = luaD_pcall (L , dothecall , NULL , savestack (L , L -> top - 2 ), 0 );
916916 L -> ci -> callstatus &= ~CIST_FIN ; /* not running a finalizer anymore */
917917 L -> allowhook = oldah ; /* restore hooks */
918- g -> gcrunning = running ; /* restore state */
918+ g -> gcstp = oldgcstp ; /* restore state */
919919 if (l_unlikely (status != LUA_OK )) { /* error while running __gc? */
920920 luaE_warnerror (L , "__gc metamethod" );
921921 L -> top -- ; /* pops error object */
@@ -1502,9 +1502,11 @@ static void deletelist (lua_State *L, GCObject *p, GCObject *limit) {
15021502*/
15031503void luaC_freeallobjects (lua_State * L ) {
15041504 global_State * g = G (L );
1505+ g -> gcstp = GCSTPGC ;
15051506 luaC_changemode (L , KGC_INC );
15061507 separatetobefnz (g , 1 ); /* separate all objects with finalizers */
15071508 lua_assert (g -> finobj == NULL );
1509+ g -> gcstp = 0 ;
15081510 callallpendingfinalizers (L );
15091511 deletelist (L , g -> allgc , obj2gco (g -> mainthread ));
15101512 deletelist (L , g -> finobj , NULL );
@@ -1647,6 +1649,7 @@ void luaC_runtilstate (lua_State *L, int statesmask) {
16471649}
16481650
16491651
1652+
16501653/*
16511654** Performs a basic incremental step. The debt and step size are
16521655** converted from bytes to "units of work"; then the function loops
@@ -1678,7 +1681,7 @@ static void incstep (lua_State *L, global_State *g) {
16781681void luaC_step (lua_State * L ) {
16791682 global_State * g = G (L );
16801683 lua_assert (!g -> gcemergency );
1681- if (g -> gcrunning ) { /* running? */
1684+ if (gcrunning ( g ) ) { /* running? */
16821685 if (isdecGCmodegen (g ))
16831686 genstep (L , g );
16841687 else
0 commit comments