| 897 | |
| 898 | |
| 899 | static void GCTM (lua_State *L) { |
| 900 | global_State *g = G(L); |
| 901 | const TValue *tm; |
| 902 | TValue v; |
| 903 | lua_assert(!g->gcemergency); |
| 904 | setgcovalue(L, &v, udata2finalize(g)); |
| 905 | tm = luaT_gettmbyobj(L, &v, TM_GC); |
| 906 | if (!notm(tm)) { /* is there a finalizer? */ |
| 907 | int status; |
| 908 | lu_byte oldah = L->allowhook; |
| 909 | int running = g->gcrunning; |
| 910 | L->allowhook = 0; /* stop debug hooks during GC metamethod */ |
| 911 | g->gcrunning = 0; /* avoid GC steps */ |
| 912 | setobj2s(L, L->top++, tm); /* push finalizer... */ |
| 913 | setobj2s(L, L->top++, &v); /* ... and its argument */ |
| 914 | L->ci->callstatus |= CIST_FIN; /* will run a finalizer */ |
| 915 | status = luaD_pcall(L, dothecall, NULL, savestack(L, L->top - 2), 0); |
| 916 | L->ci->callstatus &= ~CIST_FIN; /* not running a finalizer anymore */ |
| 917 | L->allowhook = oldah; /* restore hooks */ |
| 918 | g->gcrunning = running; /* restore state */ |
| 919 | if (l_unlikely(status != LUA_OK)) { /* error while running __gc? */ |
| 920 | luaE_warnerror(L, "__gc metamethod"); |
| 921 | L->top--; /* pops error object */ |
| 922 | } |
| 923 | } |
| 924 | } |
| 925 | |
| 926 | |
| 927 | /* |
no test coverage detected