diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-04-16 14:42:49 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-04-16 14:42:49 -0300 |
| commit | 1e6940f291258986f1720ac1a6e5293160367388 (patch) | |
| tree | f6559999b737d4a61e7f0bc81557620ebd8eea8f | |
| parent | d8d81ba891e32581cb92d4fc89e069dc2cad84f4 (diff) | |
| download | lua-1e6940f291258986f1720ac1a6e5293160367388.tar.gz lua-1e6940f291258986f1720ac1a6e5293160367388.tar.bz2 lua-1e6940f291258986f1720ac1a6e5293160367388.zip | |
'gcstate' now also runs collector until given state + small changes
in 'testC' to test 'lua_topointer' and 'lua_tocfunction'
| -rw-r--r-- | ltests.c | 43 |
1 files changed, 22 insertions, 21 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltests.c,v 2.93 2010/04/12 16:07:39 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 2.94 2010/04/13 20:48:12 roberto Exp roberto $ |
| 3 | ** Internal Module for Debugging of the Lua Implementation | 3 | ** Internal Module for Debugging of the Lua Implementation |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -535,12 +535,6 @@ static int settrick (lua_State *L) { | |||
| 535 | } | 535 | } |
| 536 | 536 | ||
| 537 | 537 | ||
| 538 | /*static int set_gcstate (lua_State *L) { | ||
| 539 | static const char *const state[] = {"propagate", "sweep", "finalize"}; | ||
| 540 | return 0; | ||
| 541 | }*/ | ||
| 542 | |||
| 543 | |||
| 544 | static int get_gccolor (lua_State *L) { | 538 | static int get_gccolor (lua_State *L) { |
| 545 | TValue *o; | 539 | TValue *o; |
| 546 | luaL_checkany(L, 1); | 540 | luaL_checkany(L, 1); |
| @@ -554,15 +548,23 @@ static int get_gccolor (lua_State *L) { | |||
| 554 | } | 548 | } |
| 555 | 549 | ||
| 556 | 550 | ||
| 557 | static int gcstate (lua_State *L) { | 551 | static int gc_state (lua_State *L) { |
| 558 | switch(G(L)->gcstate) { | 552 | static const char *statenames[] = {"", "pause", "propagate", "atomic", |
| 559 | case GCSpropagate: lua_pushstring(L, "propagate"); break; | 553 | "sweepstring", "sweepudata", "sweep", "finalize"}; |
| 560 | case GCSsweepstring: lua_pushstring(L, "sweep strings"); break; | 554 | static const int states[] = {0, GCSpause, GCSpropagate, GCSatomic, |
| 561 | case GCSsweep: lua_pushstring(L, "sweep"); break; | 555 | GCSsweepstring, GCSsweepudata, GCSsweep, GCSfinalize}; |
| 562 | case GCSfinalize: lua_pushstring(L, "finalize"); break; | 556 | int option = luaL_checkoption(L, 1, "", statenames); |
| 563 | default: lua_assert(0); | 557 | if (option == 0) { |
| 558 | lua_pushstring(L, statenames[G(L)->gcstate]); | ||
| 559 | return 1; | ||
| 560 | } | ||
| 561 | else { | ||
| 562 | lua_lock(L); | ||
| 563 | luaC_runtilstate(L, bitmask(states[option])); | ||
| 564 | lua_assert(G(L)->gcstate == states[option]); | ||
| 565 | lua_unlock(L); | ||
| 566 | return 0; | ||
| 564 | } | 567 | } |
| 565 | return 1; | ||
| 566 | } | 568 | } |
| 567 | 569 | ||
| 568 | 570 | ||
| @@ -945,7 +947,7 @@ static int runC (lua_State *L, lua_State *L1, const char *pc) { | |||
| 945 | lua_pushnumber(L1, lua_tonumber(L1, getindex)); | 947 | lua_pushnumber(L1, lua_tonumber(L1, getindex)); |
| 946 | } | 948 | } |
| 947 | else if EQ("topointer") { | 949 | else if EQ("topointer") { |
| 948 | lua_pushlightuserdata(L1, cast(void *, lua_topointer(L1, getindex))); | 950 | lua_pushnumber(L1, cast(size_t, lua_topointer(L1, getindex))); |
| 949 | } | 951 | } |
| 950 | else if EQ("tostring") { | 952 | else if EQ("tostring") { |
| 951 | const char *s = lua_tostring(L1, getindex); | 953 | const char *s = lua_tostring(L1, getindex); |
| @@ -964,9 +966,9 @@ static int runC (lua_State *L, lua_State *L1, const char *pc) { | |||
| 964 | else if EQ("tocfunction") { | 966 | else if EQ("tocfunction") { |
| 965 | lua_pushcfunction(L1, lua_tocfunction(L1, getindex)); | 967 | lua_pushcfunction(L1, lua_tocfunction(L1, getindex)); |
| 966 | } | 968 | } |
| 967 | else if EQ("func2udata") { | 969 | else if EQ("func2num") { |
| 968 | lua_CFunction func = lua_tocfunction(L1, getindex); | 970 | lua_CFunction func = lua_tocfunction(L1, getindex); |
| 969 | lua_pushlightuserdata(L1, &func); | 971 | lua_pushnumber(L1, cast(size_t, func)); |
| 970 | } | 972 | } |
| 971 | else if EQ("return") { | 973 | else if EQ("return") { |
| 972 | int n = getnum; | 974 | int n = getnum; |
| @@ -1166,8 +1168,7 @@ static int runC (lua_State *L, lua_State *L1, const char *pc) { | |||
| 1166 | lua_pushinteger(L1, i); | 1168 | lua_pushinteger(L1, i); |
| 1167 | } | 1169 | } |
| 1168 | else if EQ("checkstack") { | 1170 | else if EQ("checkstack") { |
| 1169 | if (!lua_checkstack(L1, getnum)) | 1171 | luaL_checkstack(L1, getnum, NULL); |
| 1170 | luaL_error(L, "C stack overflow"); | ||
| 1171 | } | 1172 | } |
| 1172 | else if EQ("newmetatable") { | 1173 | else if EQ("newmetatable") { |
| 1173 | lua_pushboolean(L1, luaL_newmetatable(L1, getstring)); | 1174 | lua_pushboolean(L1, luaL_newmetatable(L1, getstring)); |
| @@ -1333,7 +1334,7 @@ static const struct luaL_Reg tests_funcs[] = { | |||
| 1333 | {"doonnewstack", doonnewstack}, | 1334 | {"doonnewstack", doonnewstack}, |
| 1334 | {"doremote", doremote}, | 1335 | {"doremote", doremote}, |
| 1335 | {"gccolor", get_gccolor}, | 1336 | {"gccolor", get_gccolor}, |
| 1336 | {"gcstate", gcstate}, | 1337 | {"gcstate", gc_state}, |
| 1337 | {"getref", getref}, | 1338 | {"getref", getref}, |
| 1338 | {"hash", hash_query}, | 1339 | {"hash", hash_query}, |
| 1339 | {"int2fb", int2fb_aux}, | 1340 | {"int2fb", int2fb_aux}, |
