aboutsummaryrefslogtreecommitdiff
path: root/ltests.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--ltests.c65
1 files changed, 31 insertions, 34 deletions
diff --git a/ltests.c b/ltests.c
index e2bf76bd..6f556dc9 100644
--- a/ltests.c
+++ b/ltests.c
@@ -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))
@@ -534,7 +534,7 @@ static void checkobject (global_State *g, GCObject *o, int maybedead,
534} 534}
535 535
536 536
537static lu_mem checkgraylist (global_State *g, GCObject *o) { 537static l_obj checkgraylist (global_State *g, GCObject *o) {
538 int total = 0; /* count number of elements in the list */ 538 int total = 0; /* count number of elements in the list */
539 cast_void(g); /* better to keep it if we need to print an object */ 539 cast_void(g); /* better to keep it if we need to print an object */
540 while (o) { 540 while (o) {
@@ -563,7 +563,7 @@ static lu_mem checkgraylist (global_State *g, GCObject *o) {
563/* 563/*
564** Check objects in gray lists. 564** Check objects in gray lists.
565*/ 565*/
566static lu_mem checkgrays (global_State *g) { 566static l_obj checkgrays (global_State *g) {
567 int total = 0; /* count number of elements in all lists */ 567 int total = 0; /* count number of elements in all lists */
568 if (!keepinvariant(g)) return total; 568 if (!keepinvariant(g)) return total;
569 total += checkgraylist(g, g->gray); 569 total += checkgraylist(g, g->gray);
@@ -580,7 +580,7 @@ static lu_mem checkgrays (global_State *g) {
580** 'count' and check its TESTBIT. (It must have been previously set by 580** 'count' and check its TESTBIT. (It must have been previously set by
581** 'checkgraylist'.) 581** 'checkgraylist'.)
582*/ 582*/
583static void incifingray (global_State *g, GCObject *o, lu_mem *count) { 583static void incifingray (global_State *g, GCObject *o, l_obj *count) {
584 if (!keepinvariant(g)) 584 if (!keepinvariant(g))
585 return; /* gray lists not being kept in these phases */ 585 return; /* gray lists not being kept in these phases */
586 if (o->tt == LUA_VUPVAL) { 586 if (o->tt == LUA_VUPVAL) {
@@ -597,10 +597,10 @@ static void incifingray (global_State *g, GCObject *o, lu_mem *count) {
597} 597}
598 598
599 599
600static lu_mem checklist (global_State *g, int maybedead, int tof, 600static l_obj checklist (global_State *g, int maybedead, int tof,
601 GCObject *newl, GCObject *survival, GCObject *old, GCObject *reallyold) { 601 GCObject *newl, GCObject *survival, GCObject *old, GCObject *reallyold) {
602 GCObject *o; 602 GCObject *o;
603 lu_mem total = 0; /* number of object that should be in gray lists */ 603 l_obj total = 0; /* number of object that should be in gray lists */
604 for (o = newl; o != survival; o = o->next) { 604 for (o = newl; o != survival; o = o->next) {
605 checkobject(g, o, maybedead, G_NEW); 605 checkobject(g, o, maybedead, G_NEW);
606 incifingray(g, o, &total); 606 incifingray(g, o, &total);
@@ -629,8 +629,8 @@ int lua_checkmemory (lua_State *L) {
629 global_State *g = G(L); 629 global_State *g = G(L);
630 GCObject *o; 630 GCObject *o;
631 int maybedead; 631 int maybedead;
632 lu_mem totalin; /* total of objects that are in gray lists */ 632 l_obj totalin; /* total of objects that are in gray lists */
633 lu_mem totalshould; /* total of objects that should be in gray lists */ 633 l_obj totalshould; /* total of objects that should be in gray lists */
634 if (keepinvariant(g)) { 634 if (keepinvariant(g)) {
635 assert(!iswhite(g->mainthread)); 635 assert(!iswhite(g->mainthread));
636 assert(!iswhite(gcvalue(&g->l_registry))); 636 assert(!iswhite(gcvalue(&g->l_registry)));
@@ -1002,9 +1002,8 @@ static int table_query (lua_State *L) {
1002 if (i == -1) { 1002 if (i == -1) {
1003 lua_pushinteger(L, asize); 1003 lua_pushinteger(L, asize);
1004 lua_pushinteger(L, allocsizenode(t)); 1004 lua_pushinteger(L, allocsizenode(t));
1005 lua_pushinteger(L, isdummy(t) ? 0 : t->lastfree - t->node);
1006 lua_pushinteger(L, t->alimit); 1005 lua_pushinteger(L, t->alimit);
1007 return 4; 1006 return 3;
1008 } 1007 }
1009 else if ((unsigned int)i < asize) { 1008 else if ((unsigned int)i < asize) {
1010 lua_pushinteger(L, i); 1009 lua_pushinteger(L, i);
@@ -1032,6 +1031,16 @@ static int table_query (lua_State *L) {
1032} 1031}
1033 1032
1034 1033
1034static int query_inc (lua_State *L) {
1035 global_State *g = G(L);
1036 lua_pushinteger(L, gettotalobjs(g));
1037 lua_pushinteger(L, g->GCdebt);
1038 lua_pushinteger(L, applygcparam(g, gcpause, 100));
1039 lua_pushinteger(L, applygcparam(g, gcstepmul, 100));
1040 lua_pushinteger(L, cast(l_obj, 1) << g->gcstepsize);
1041 return 5;
1042}
1043
1035static int string_query (lua_State *L) { 1044static int string_query (lua_State *L) {
1036 stringtable *tb = &G(L)->strt; 1045 stringtable *tb = &G(L)->strt;
1037 int s = cast_int(luaL_optinteger(L, 1, 0)) - 1; 1046 int s = cast_int(luaL_optinteger(L, 1, 0)) - 1;
@@ -1154,7 +1163,7 @@ static int num2int (lua_State *L) {
1154static int newstate (lua_State *L) { 1163static int newstate (lua_State *L) {
1155 void *ud; 1164 void *ud;
1156 lua_Alloc f = lua_getallocf(L, &ud); 1165 lua_Alloc f = lua_getallocf(L, &ud);
1157 lua_State *L1 = lua_newstate(f, ud); 1166 lua_State *L1 = lua_newstate(f, ud, 0);
1158 if (L1) { 1167 if (L1) {
1159 lua_atpanic(L1, tpanic); 1168 lua_atpanic(L1, tpanic);
1160 lua_pushlightuserdata(L, L1); 1169 lua_pushlightuserdata(L, L1);
@@ -1173,31 +1182,15 @@ static lua_State *getstate (lua_State *L) {
1173 1182
1174 1183
1175static int loadlib (lua_State *L) { 1184static int loadlib (lua_State *L) {
1176 static const luaL_Reg libs[] = {
1177 {LUA_GNAME, luaopen_base},
1178 {"coroutine", luaopen_coroutine},
1179 {"debug", luaopen_debug},
1180 {"io", luaopen_io},
1181 {"os", luaopen_os},
1182 {"math", luaopen_math},
1183 {"string", luaopen_string},
1184 {"table", luaopen_table},
1185 {"T", luaB_opentests},
1186 {NULL, NULL}
1187 };
1188 lua_State *L1 = getstate(L); 1185 lua_State *L1 = getstate(L);
1189 int i; 1186 int what = luaL_checkinteger(L, 2);
1190 luaL_requiref(L1, "package", luaopen_package, 0); 1187 luaL_openselectedlibs(L1, what);
1188 luaL_requiref(L1, "T", luaB_opentests, 0);
1191 lua_assert(lua_type(L1, -1) == LUA_TTABLE); 1189 lua_assert(lua_type(L1, -1) == LUA_TTABLE);
1192 /* 'requiref' should not reload module already loaded... */ 1190 /* 'requiref' should not reload module already loaded... */
1193 luaL_requiref(L1, "package", NULL, 1); /* seg. fault if it reloads */ 1191 luaL_requiref(L1, "T", NULL, 1); /* seg. fault if it reloads */
1194 /* ...but should return the same module */ 1192 /* ...but should return the same module */
1195 lua_assert(lua_compare(L1, -1, -2, LUA_OPEQ)); 1193 lua_assert(lua_compare(L1, -1, -2, LUA_OPEQ));
1196 luaL_getsubtable(L1, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE);
1197 for (i = 0; libs[i].name; i++) {
1198 lua_pushcfunction(L1, libs[i].func);
1199 lua_setfield(L1, -2, libs[i].name);
1200 }
1201 return 0; 1194 return 0;
1202} 1195}
1203 1196
@@ -1263,7 +1256,7 @@ static int checkpanic (lua_State *L) {
1263 lua_Alloc f = lua_getallocf(L, &ud); 1256 lua_Alloc f = lua_getallocf(L, &ud);
1264 b.paniccode = luaL_optstring(L, 2, ""); 1257 b.paniccode = luaL_optstring(L, 2, "");
1265 b.L = L; 1258 b.L = L;
1266 L1 = lua_newstate(f, ud); /* create new state */ 1259 L1 = lua_newstate(f, ud, 0); /* create new state */
1267 if (L1 == NULL) { /* error? */ 1260 if (L1 == NULL) { /* error? */
1268 lua_pushnil(L); 1261 lua_pushnil(L);
1269 return 1; 1262 return 1;
@@ -1524,8 +1517,11 @@ static int runC (lua_State *L, lua_State *L1, const char *pc) {
1524 luaL_loadfile(L1, luaL_checkstring(L1, getnum)); 1517 luaL_loadfile(L1, luaL_checkstring(L1, getnum));
1525 } 1518 }
1526 else if EQ("loadstring") { 1519 else if EQ("loadstring") {
1527 const char *s = luaL_checkstring(L1, getnum); 1520 size_t slen;
1528 luaL_loadstring(L1, s); 1521 const char *s = luaL_checklstring(L1, getnum, &slen);
1522 const char *name = getstring;
1523 const char *mode = getstring;
1524 luaL_loadbufferx(L1, s, slen, name, mode);
1529 } 1525 }
1530 else if EQ("newmetatable") { 1526 else if EQ("newmetatable") {
1531 lua_pushboolean(L1, luaL_newmetatable(L1, getstring)); 1527 lua_pushboolean(L1, luaL_newmetatable(L1, getstring));
@@ -1938,6 +1934,7 @@ static const struct luaL_Reg tests_funcs[] = {
1938 {"pushuserdata", pushuserdata}, 1934 {"pushuserdata", pushuserdata},
1939 {"querystr", string_query}, 1935 {"querystr", string_query},
1940 {"querytab", table_query}, 1936 {"querytab", table_query},
1937 {"queryinc", query_inc},
1941 {"ref", tref}, 1938 {"ref", tref},
1942 {"resume", coresume}, 1939 {"resume", coresume},
1943 {"s2d", s2d}, 1940 {"s2d", s2d},