diff options
Diffstat (limited to 'ltests.c')
-rw-r--r-- | ltests.c | 54 |
1 files changed, 24 insertions, 30 deletions
@@ -297,7 +297,7 @@ static int testobjref1 (global_State *g, GCObject *f, GCObject *t) { | |||
297 | if (isdead(g,t)) return 0; | 297 | if (isdead(g,t)) return 0; |
298 | if (issweepphase(g)) | 298 | if (issweepphase(g)) |
299 | return 1; /* no invariants */ | 299 | return 1; /* no invariants */ |
300 | else if (g->gckind == KGC_INC) | 300 | else if (g->gckind != KGC_GEN) |
301 | return !(isblack(f) && iswhite(t)); /* basic incremental invariant */ | 301 | return !(isblack(f) && iswhite(t)); /* basic incremental invariant */ |
302 | else { /* generational mode */ | 302 | else { /* generational mode */ |
303 | if ((getage(f) == G_OLD && isblack(f)) && !isold(t)) | 303 | if ((getage(f) == G_OLD && isblack(f)) && !isold(t)) |
@@ -531,7 +531,7 @@ static void checkobject (global_State *g, GCObject *o, int maybedead, | |||
531 | } | 531 | } |
532 | 532 | ||
533 | 533 | ||
534 | static lu_mem checkgraylist (global_State *g, GCObject *o) { | 534 | static l_obj checkgraylist (global_State *g, GCObject *o) { |
535 | int total = 0; /* count number of elements in the list */ | 535 | int total = 0; /* count number of elements in the list */ |
536 | cast_void(g); /* better to keep it if we need to print an object */ | 536 | cast_void(g); /* better to keep it if we need to print an object */ |
537 | while (o) { | 537 | while (o) { |
@@ -560,7 +560,7 @@ static lu_mem checkgraylist (global_State *g, GCObject *o) { | |||
560 | /* | 560 | /* |
561 | ** Check objects in gray lists. | 561 | ** Check objects in gray lists. |
562 | */ | 562 | */ |
563 | static lu_mem checkgrays (global_State *g) { | 563 | static l_obj checkgrays (global_State *g) { |
564 | int total = 0; /* count number of elements in all lists */ | 564 | int total = 0; /* count number of elements in all lists */ |
565 | if (!keepinvariant(g)) return total; | 565 | if (!keepinvariant(g)) return total; |
566 | total += checkgraylist(g, g->gray); | 566 | total += checkgraylist(g, g->gray); |
@@ -577,7 +577,7 @@ static lu_mem checkgrays (global_State *g) { | |||
577 | ** 'count' and check its TESTBIT. (It must have been previously set by | 577 | ** 'count' and check its TESTBIT. (It must have been previously set by |
578 | ** 'checkgraylist'.) | 578 | ** 'checkgraylist'.) |
579 | */ | 579 | */ |
580 | static void incifingray (global_State *g, GCObject *o, lu_mem *count) { | 580 | static void incifingray (global_State *g, GCObject *o, l_obj *count) { |
581 | if (!keepinvariant(g)) | 581 | if (!keepinvariant(g)) |
582 | return; /* gray lists not being kept in these phases */ | 582 | return; /* gray lists not being kept in these phases */ |
583 | if (o->tt == LUA_VUPVAL) { | 583 | if (o->tt == LUA_VUPVAL) { |
@@ -594,10 +594,10 @@ static void incifingray (global_State *g, GCObject *o, lu_mem *count) { | |||
594 | } | 594 | } |
595 | 595 | ||
596 | 596 | ||
597 | static lu_mem checklist (global_State *g, int maybedead, int tof, | 597 | static l_obj checklist (global_State *g, int maybedead, int tof, |
598 | GCObject *newl, GCObject *survival, GCObject *old, GCObject *reallyold) { | 598 | GCObject *newl, GCObject *survival, GCObject *old, GCObject *reallyold) { |
599 | GCObject *o; | 599 | GCObject *o; |
600 | lu_mem total = 0; /* number of object that should be in gray lists */ | 600 | l_obj total = 0; /* number of object that should be in gray lists */ |
601 | for (o = newl; o != survival; o = o->next) { | 601 | for (o = newl; o != survival; o = o->next) { |
602 | checkobject(g, o, maybedead, G_NEW); | 602 | checkobject(g, o, maybedead, G_NEW); |
603 | incifingray(g, o, &total); | 603 | incifingray(g, o, &total); |
@@ -626,8 +626,8 @@ int lua_checkmemory (lua_State *L) { | |||
626 | global_State *g = G(L); | 626 | global_State *g = G(L); |
627 | GCObject *o; | 627 | GCObject *o; |
628 | int maybedead; | 628 | int maybedead; |
629 | lu_mem totalin; /* total of objects that are in gray lists */ | 629 | l_obj totalin; /* total of objects that are in gray lists */ |
630 | lu_mem totalshould; /* total of objects that should be in gray lists */ | 630 | l_obj totalshould; /* total of objects that should be in gray lists */ |
631 | if (keepinvariant(g)) { | 631 | if (keepinvariant(g)) { |
632 | assert(!iswhite(g->mainthread)); | 632 | assert(!iswhite(g->mainthread)); |
633 | assert(!iswhite(gcvalue(&g->l_registry))); | 633 | assert(!iswhite(gcvalue(&g->l_registry))); |
@@ -999,9 +999,8 @@ static int table_query (lua_State *L) { | |||
999 | if (i == -1) { | 999 | if (i == -1) { |
1000 | lua_pushinteger(L, asize); | 1000 | lua_pushinteger(L, asize); |
1001 | lua_pushinteger(L, allocsizenode(t)); | 1001 | lua_pushinteger(L, allocsizenode(t)); |
1002 | lua_pushinteger(L, isdummy(t) ? 0 : t->lastfree - t->node); | ||
1003 | lua_pushinteger(L, t->alimit); | 1002 | lua_pushinteger(L, t->alimit); |
1004 | return 4; | 1003 | return 3; |
1005 | } | 1004 | } |
1006 | else if ((unsigned int)i < asize) { | 1005 | else if ((unsigned int)i < asize) { |
1007 | lua_pushinteger(L, i); | 1006 | lua_pushinteger(L, i); |
@@ -1028,6 +1027,16 @@ static int table_query (lua_State *L) { | |||
1028 | } | 1027 | } |
1029 | 1028 | ||
1030 | 1029 | ||
1030 | static int query_inc (lua_State *L) { | ||
1031 | global_State *g = G(L); | ||
1032 | lua_pushinteger(L, gettotalobjs(g)); | ||
1033 | lua_pushinteger(L, g->GCdebt); | ||
1034 | lua_pushinteger(L, applygcparam(g, gcpause, 100)); | ||
1035 | lua_pushinteger(L, applygcparam(g, gcstepmul, 100)); | ||
1036 | lua_pushinteger(L, cast(l_obj, 1) << g->gcstepsize); | ||
1037 | return 5; | ||
1038 | } | ||
1039 | |||
1031 | static int string_query (lua_State *L) { | 1040 | static int string_query (lua_State *L) { |
1032 | stringtable *tb = &G(L)->strt; | 1041 | stringtable *tb = &G(L)->strt; |
1033 | int s = cast_int(luaL_optinteger(L, 1, 0)) - 1; | 1042 | int s = cast_int(luaL_optinteger(L, 1, 0)) - 1; |
@@ -1169,31 +1178,15 @@ static lua_State *getstate (lua_State *L) { | |||
1169 | 1178 | ||
1170 | 1179 | ||
1171 | static int loadlib (lua_State *L) { | 1180 | static int loadlib (lua_State *L) { |
1172 | static const luaL_Reg libs[] = { | ||
1173 | {LUA_GNAME, luaopen_base}, | ||
1174 | {"coroutine", luaopen_coroutine}, | ||
1175 | {"debug", luaopen_debug}, | ||
1176 | {"io", luaopen_io}, | ||
1177 | {"os", luaopen_os}, | ||
1178 | {"math", luaopen_math}, | ||
1179 | {"string", luaopen_string}, | ||
1180 | {"table", luaopen_table}, | ||
1181 | {"T", luaB_opentests}, | ||
1182 | {NULL, NULL} | ||
1183 | }; | ||
1184 | lua_State *L1 = getstate(L); | 1181 | lua_State *L1 = getstate(L); |
1185 | int i; | 1182 | int what = luaL_checkinteger(L, 2); |
1186 | luaL_requiref(L1, "package", luaopen_package, 0); | 1183 | luaL_openselectedlibs(L1, what); |
1184 | luaL_requiref(L1, "T", luaB_opentests, 0); | ||
1187 | lua_assert(lua_type(L1, -1) == LUA_TTABLE); | 1185 | lua_assert(lua_type(L1, -1) == LUA_TTABLE); |
1188 | /* 'requiref' should not reload module already loaded... */ | 1186 | /* 'requiref' should not reload module already loaded... */ |
1189 | luaL_requiref(L1, "package", NULL, 1); /* seg. fault if it reloads */ | 1187 | luaL_requiref(L1, "T", NULL, 1); /* seg. fault if it reloads */ |
1190 | /* ...but should return the same module */ | 1188 | /* ...but should return the same module */ |
1191 | lua_assert(lua_compare(L1, -1, -2, LUA_OPEQ)); | 1189 | lua_assert(lua_compare(L1, -1, -2, LUA_OPEQ)); |
1192 | luaL_getsubtable(L1, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE); | ||
1193 | for (i = 0; libs[i].name; i++) { | ||
1194 | lua_pushcfunction(L1, libs[i].func); | ||
1195 | lua_setfield(L1, -2, libs[i].name); | ||
1196 | } | ||
1197 | return 0; | 1190 | return 0; |
1198 | } | 1191 | } |
1199 | 1192 | ||
@@ -1934,6 +1927,7 @@ static const struct luaL_Reg tests_funcs[] = { | |||
1934 | {"pushuserdata", pushuserdata}, | 1927 | {"pushuserdata", pushuserdata}, |
1935 | {"querystr", string_query}, | 1928 | {"querystr", string_query}, |
1936 | {"querytab", table_query}, | 1929 | {"querytab", table_query}, |
1930 | {"queryinc", query_inc}, | ||
1937 | {"ref", tref}, | 1931 | {"ref", tref}, |
1938 | {"resume", coresume}, | 1932 | {"resume", coresume}, |
1939 | {"s2d", s2d}, | 1933 | {"s2d", s2d}, |