@@ -944,34 +944,63 @@ static int gc_printobj (lua_State *L) {
944944}
945945
946946
947+ static const char * statenames [] = {
948+ "propagate" , "enteratomic" , "atomic" , "sweepallgc" , "sweepfinobj" ,
949+ "sweeptobefnz" , "sweepend" , "callfin" , "pause" , "" };
950+
947951static int gc_state (lua_State * L ) {
948- static const char * statenames [] = {
949- "propagate" , "atomic" , "sweepallgc" , "sweepfinobj" ,
950- "sweeptobefnz" , "sweepend" , "callfin" , "pause" , "" };
951952 static const int states [] = {
952- GCSpropagate , GCSenteratomic , GCSswpallgc , GCSswpfinobj ,
953+ GCSpropagate , GCSenteratomic , GCSatomic , GCSswpallgc , GCSswpfinobj ,
953954 GCSswptobefnz , GCSswpend , GCScallfin , GCSpause , -1 };
954955 int option = states [luaL_checkoption (L , 1 , "" , statenames )];
956+ global_State * g = G (L );
955957 if (option == -1 ) {
956- lua_pushstring (L , statenames [G ( L ) -> gcstate ]);
958+ lua_pushstring (L , statenames [g -> gcstate ]);
957959 return 1 ;
958960 }
959961 else {
960- global_State * g = G (L );
961- if (G (L )-> gckind != KGC_INC )
962+ if (g -> gckind != KGC_INC )
962963 luaL_error (L , "cannot change states in generational mode" );
963964 lua_lock (L );
964965 if (option < g -> gcstate ) { /* must cross 'pause'? */
965966 luaC_runtilstate (L , GCSpause , 1 ); /* run until pause */
966967 }
967968 luaC_runtilstate (L , option , 0 ); /* do not skip propagation state */
968- lua_assert (G ( L ) -> gcstate == option );
969+ lua_assert (g -> gcstate == option );
969970 lua_unlock (L );
970971 return 0 ;
971972 }
972973}
973974
974975
976+ static int tracinggc = 0 ;
977+ void luai_tracegctest (lua_State * L , int first ) {
978+ if (!tracinggc ) return ;
979+ else {
980+ global_State * g = G (L );
981+ lua_unlock (L );
982+ g -> gcstp = GCSTPGC ;
983+ lua_checkstack (L , 10 );
984+ lua_getfield (L , LUA_REGISTRYINDEX , "tracegc" );
985+ lua_pushboolean (L , first );
986+ lua_call (L , 1 , 0 );
987+ g -> gcstp = 0 ;
988+ lua_lock (L );
989+ }
990+ }
991+
992+
993+ static int tracegc (lua_State * L ) {
994+ if (lua_isnil (L , 1 ))
995+ tracinggc = 0 ;
996+ else {
997+ tracinggc = 1 ;
998+ lua_setfield (L , LUA_REGISTRYINDEX , "tracegc" );
999+ }
1000+ return 0 ;
1001+ }
1002+
1003+
9751004static int hash_query (lua_State * L ) {
9761005 if (lua_isnone (L , 2 )) {
9771006 luaL_argcheck (L , lua_type (L , 1 ) == LUA_TSTRING , 1 , "string expected" );
@@ -1038,17 +1067,17 @@ static int table_query (lua_State *L) {
10381067}
10391068
10401069
1041- static int query_GCparams (lua_State * L ) {
1070+ static int gc_query (lua_State * L ) {
10421071 global_State * g = G (L );
1043- lua_pushinteger (L , cast ( lua_Integer , gettotalbytes ( g )));
1044- lua_pushinteger ( L , cast ( lua_Integer , g -> GCdebt ));
1045- lua_pushinteger ( L , cast ( lua_Integer , applygcparam ( g , MINORMUL , 100 )) );
1046- lua_pushinteger (L , cast ( lua_Integer , applygcparam ( g , MAJORMINOR , 100 )) );
1047- lua_pushinteger (L , cast ( lua_Integer , applygcparam ( g , MINORMAJOR , 100 )));
1048- lua_pushinteger (L , cast ( lua_Integer , applygcparam ( g , PAUSE , 100 ) ));
1049- lua_pushinteger (L , cast ( lua_Integer , applygcparam ( g , STEPMUL , 100 ) ));
1050- lua_pushinteger (L , cast ( lua_Integer , applygcparam ( g , STEPSIZE , 100 ) ));
1051- return 8 ;
1072+ lua_pushstring (L , g -> gckind == KGC_INC ? "inc"
1073+ : g -> gckind == KGC_GENMAJOR ? "genmajor"
1074+ : "genminor" );
1075+ lua_pushstring (L , statenames [ g -> gcstate ] );
1076+ lua_pushinteger (L , cast_st2S ( gettotalbytes ( g )));
1077+ lua_pushinteger (L , cast_st2S ( g -> GCdebt ));
1078+ lua_pushinteger (L , cast_st2S ( g -> GCmarked ));
1079+ lua_pushinteger (L , cast_st2S ( g -> GCmajorminor ));
1080+ return 6 ;
10521081}
10531082
10541083
@@ -2009,6 +2038,7 @@ static const struct luaL_Reg tests_funcs[] = {
20092038 {"gccolor" , gc_color },
20102039 {"gcage" , gc_age },
20112040 {"gcstate" , gc_state },
2041+ {"tracegc" , tracegc },
20122042 {"pobj" , gc_printobj },
20132043 {"getref" , getref },
20142044 {"hash" , hash_query },
@@ -2026,9 +2056,9 @@ static const struct luaL_Reg tests_funcs[] = {
20262056 {"num2int" , num2int },
20272057 {"makeseed" , makeseed },
20282058 {"pushuserdata" , pushuserdata },
2059+ {"gcquery" , gc_query },
20292060 {"querystr" , string_query },
20302061 {"querytab" , table_query },
2031- {"queryGCparams" , query_GCparams },
20322062 {"codeparam" , test_codeparam },
20332063 {"applyparam" , test_applyparam },
20342064 {"ref" , tref },
0 commit comments