diff options
Diffstat (limited to 'ltests.c')
-rw-r--r-- | ltests.c | 190 |
1 files changed, 138 insertions, 52 deletions
@@ -217,7 +217,7 @@ void *debug_realloc (void *ud, void *b, size_t oldsize, size_t size) { | |||
217 | mc->memlimit = limit ? strtoul(limit, NULL, 10) : ULONG_MAX; | 217 | mc->memlimit = limit ? strtoul(limit, NULL, 10) : ULONG_MAX; |
218 | } | 218 | } |
219 | if (block == NULL) { | 219 | if (block == NULL) { |
220 | type = (oldsize < LUA_NUMTAGS) ? oldsize : 0; | 220 | type = (oldsize < LUA_NUMTYPES) ? oldsize : 0; |
221 | oldsize = 0; | 221 | oldsize = 0; |
222 | } | 222 | } |
223 | else { | 223 | else { |
@@ -298,13 +298,13 @@ static int testobjref1 (global_State *g, GCObject *f, GCObject *t) { | |||
298 | if (isdead(g,t)) return 0; | 298 | if (isdead(g,t)) return 0; |
299 | if (issweepphase(g)) | 299 | if (issweepphase(g)) |
300 | return 1; /* no invariants */ | 300 | return 1; /* no invariants */ |
301 | else if (g->gckind == KGC_INC) | 301 | else if (g->gckind != KGC_GENMINOR) |
302 | return !(isblack(f) && iswhite(t)); /* basic incremental invariant */ | 302 | return !(isblack(f) && iswhite(t)); /* basic incremental invariant */ |
303 | else { /* generational mode */ | 303 | else { /* generational mode */ |
304 | if ((getage(f) == G_OLD && isblack(f)) && !isold(t)) | 304 | if ((getage(f) == G_OLD && isblack(f)) && !isold(t)) |
305 | return 0; | 305 | return 0; |
306 | if (((getage(f) == G_OLD1 || getage(f) == G_TOUCHED2) && isblack(f)) && | 306 | if ((getage(f) == G_OLD1 || getage(f) == G_TOUCHED2) && |
307 | getage(t) == G_NEW) | 307 | getage(t) == G_NEW) |
308 | return 0; | 308 | return 0; |
309 | return 1; | 309 | return 1; |
310 | } | 310 | } |
@@ -363,8 +363,11 @@ static void checktable (global_State *g, Table *h) { | |||
363 | Node *n, *limit = gnode(h, sizenode(h)); | 363 | Node *n, *limit = gnode(h, sizenode(h)); |
364 | GCObject *hgc = obj2gco(h); | 364 | GCObject *hgc = obj2gco(h); |
365 | checkobjrefN(g, hgc, h->metatable); | 365 | checkobjrefN(g, hgc, h->metatable); |
366 | for (i = 0; i < asize; i++) | 366 | for (i = 0; i < asize; i++) { |
367 | checkvalref(g, hgc, &h->array[i]); | 367 | TValue aux; |
368 | arr2obj(h, i + 1, &aux); | ||
369 | checkvalref(g, hgc, &aux); | ||
370 | } | ||
368 | for (n = gnode(h, 0); n < limit; n++) { | 371 | for (n = gnode(h, 0); n < limit; n++) { |
369 | if (!isempty(gval(n))) { | 372 | if (!isempty(gval(n))) { |
370 | TValue k; | 373 | TValue k; |
@@ -508,7 +511,8 @@ static void checkrefs (global_State *g, GCObject *o) { | |||
508 | ** * objects must be old enough for their lists ('listage'). | 511 | ** * objects must be old enough for their lists ('listage'). |
509 | ** * old objects cannot be white. | 512 | ** * old objects cannot be white. |
510 | ** * old objects must be black, except for 'touched1', 'old0', | 513 | ** * old objects must be black, except for 'touched1', 'old0', |
511 | ** threads, and open upvalues. | 514 | ** threads, and open upvalues. |
515 | ** * 'touched1' objects must be gray. | ||
512 | */ | 516 | */ |
513 | static void checkobject (global_State *g, GCObject *o, int maybedead, | 517 | static void checkobject (global_State *g, GCObject *o, int maybedead, |
514 | int listage) { | 518 | int listage) { |
@@ -516,23 +520,24 @@ static void checkobject (global_State *g, GCObject *o, int maybedead, | |||
516 | assert(maybedead); | 520 | assert(maybedead); |
517 | else { | 521 | else { |
518 | assert(g->gcstate != GCSpause || iswhite(o)); | 522 | assert(g->gcstate != GCSpause || iswhite(o)); |
519 | if (g->gckind == KGC_GEN) { /* generational mode? */ | 523 | if (g->gckind == KGC_GENMINOR) { /* generational mode? */ |
520 | assert(getage(o) >= listage); | 524 | assert(getage(o) >= listage); |
521 | assert(!iswhite(o) || !isold(o)); | ||
522 | if (isold(o)) { | 525 | if (isold(o)) { |
526 | assert(!iswhite(o)); | ||
523 | assert(isblack(o) || | 527 | assert(isblack(o) || |
524 | getage(o) == G_TOUCHED1 || | 528 | getage(o) == G_TOUCHED1 || |
525 | getage(o) == G_OLD0 || | 529 | getage(o) == G_OLD0 || |
526 | o->tt == LUA_VTHREAD || | 530 | o->tt == LUA_VTHREAD || |
527 | (o->tt == LUA_VUPVAL && upisopen(gco2upv(o)))); | 531 | (o->tt == LUA_VUPVAL && upisopen(gco2upv(o)))); |
528 | } | 532 | } |
533 | assert(getage(o) != G_TOUCHED1 || isgray(o)); | ||
529 | } | 534 | } |
530 | checkrefs(g, o); | 535 | checkrefs(g, o); |
531 | } | 536 | } |
532 | } | 537 | } |
533 | 538 | ||
534 | 539 | ||
535 | static lu_mem checkgraylist (global_State *g, GCObject *o) { | 540 | static l_obj checkgraylist (global_State *g, GCObject *o) { |
536 | int total = 0; /* count number of elements in the list */ | 541 | int total = 0; /* count number of elements in the list */ |
537 | cast_void(g); /* better to keep it if we need to print an object */ | 542 | cast_void(g); /* better to keep it if we need to print an object */ |
538 | while (o) { | 543 | while (o) { |
@@ -561,7 +566,7 @@ static lu_mem checkgraylist (global_State *g, GCObject *o) { | |||
561 | /* | 566 | /* |
562 | ** Check objects in gray lists. | 567 | ** Check objects in gray lists. |
563 | */ | 568 | */ |
564 | static lu_mem checkgrays (global_State *g) { | 569 | static l_obj checkgrays (global_State *g) { |
565 | int total = 0; /* count number of elements in all lists */ | 570 | int total = 0; /* count number of elements in all lists */ |
566 | if (!keepinvariant(g)) return total; | 571 | if (!keepinvariant(g)) return total; |
567 | total += checkgraylist(g, g->gray); | 572 | total += checkgraylist(g, g->gray); |
@@ -578,7 +583,7 @@ static lu_mem checkgrays (global_State *g) { | |||
578 | ** 'count' and check its TESTBIT. (It must have been previously set by | 583 | ** 'count' and check its TESTBIT. (It must have been previously set by |
579 | ** 'checkgraylist'.) | 584 | ** 'checkgraylist'.) |
580 | */ | 585 | */ |
581 | static void incifingray (global_State *g, GCObject *o, lu_mem *count) { | 586 | static void incifingray (global_State *g, GCObject *o, l_obj *count) { |
582 | if (!keepinvariant(g)) | 587 | if (!keepinvariant(g)) |
583 | return; /* gray lists not being kept in these phases */ | 588 | return; /* gray lists not being kept in these phases */ |
584 | if (o->tt == LUA_VUPVAL) { | 589 | if (o->tt == LUA_VUPVAL) { |
@@ -595,10 +600,10 @@ static void incifingray (global_State *g, GCObject *o, lu_mem *count) { | |||
595 | } | 600 | } |
596 | 601 | ||
597 | 602 | ||
598 | static lu_mem checklist (global_State *g, int maybedead, int tof, | 603 | static l_obj checklist (global_State *g, int maybedead, int tof, |
599 | GCObject *newl, GCObject *survival, GCObject *old, GCObject *reallyold) { | 604 | GCObject *newl, GCObject *survival, GCObject *old, GCObject *reallyold) { |
600 | GCObject *o; | 605 | GCObject *o; |
601 | lu_mem total = 0; /* number of object that should be in gray lists */ | 606 | l_obj total = 0; /* number of object that should be in gray lists */ |
602 | for (o = newl; o != survival; o = o->next) { | 607 | for (o = newl; o != survival; o = o->next) { |
603 | checkobject(g, o, maybedead, G_NEW); | 608 | checkobject(g, o, maybedead, G_NEW); |
604 | incifingray(g, o, &total); | 609 | incifingray(g, o, &total); |
@@ -627,8 +632,8 @@ int lua_checkmemory (lua_State *L) { | |||
627 | global_State *g = G(L); | 632 | global_State *g = G(L); |
628 | GCObject *o; | 633 | GCObject *o; |
629 | int maybedead; | 634 | int maybedead; |
630 | lu_mem totalin; /* total of objects that are in gray lists */ | 635 | l_obj totalin; /* total of objects that are in gray lists */ |
631 | lu_mem totalshould; /* total of objects that should be in gray lists */ | 636 | l_obj totalshould; /* total of objects that should be in gray lists */ |
632 | if (keepinvariant(g)) { | 637 | if (keepinvariant(g)) { |
633 | assert(!iswhite(g->mainthread)); | 638 | assert(!iswhite(g->mainthread)); |
634 | assert(!iswhite(gcvalue(&g->l_registry))); | 639 | assert(!iswhite(gcvalue(&g->l_registry))); |
@@ -852,7 +857,7 @@ static int mem_query (lua_State *L) { | |||
852 | else { | 857 | else { |
853 | const char *t = luaL_checkstring(L, 1); | 858 | const char *t = luaL_checkstring(L, 1); |
854 | int i; | 859 | int i; |
855 | for (i = LUA_NUMTAGS - 1; i >= 0; i--) { | 860 | for (i = LUA_NUMTYPES - 1; i >= 0; i--) { |
856 | if (strcmp(t, ttypename(i)) == 0) { | 861 | if (strcmp(t, ttypename(i)) == 0) { |
857 | lua_pushinteger(L, l_memcontrol.objcount[i]); | 862 | lua_pushinteger(L, l_memcontrol.objcount[i]); |
858 | return 1; | 863 | return 1; |
@@ -937,10 +942,10 @@ static int gc_printobj (lua_State *L) { | |||
937 | 942 | ||
938 | static int gc_state (lua_State *L) { | 943 | static int gc_state (lua_State *L) { |
939 | static const char *statenames[] = { | 944 | static const char *statenames[] = { |
940 | "propagate", "atomic", "enteratomic", "sweepallgc", "sweepfinobj", | 945 | "propagate", "atomic", "sweepallgc", "sweepfinobj", |
941 | "sweeptobefnz", "sweepend", "callfin", "pause", ""}; | 946 | "sweeptobefnz", "sweepend", "callfin", "pause", ""}; |
942 | static const int states[] = { | 947 | static const int states[] = { |
943 | GCSpropagate, GCSenteratomic, GCSatomic, GCSswpallgc, GCSswpfinobj, | 948 | GCSpropagate, GCSenteratomic, GCSswpallgc, GCSswpfinobj, |
944 | GCSswptobefnz, GCSswpend, GCScallfin, GCSpause, -1}; | 949 | GCSswptobefnz, GCSswpend, GCScallfin, GCSpause, -1}; |
945 | int option = states[luaL_checkoption(L, 1, "", statenames)]; | 950 | int option = states[luaL_checkoption(L, 1, "", statenames)]; |
946 | if (option == -1) { | 951 | if (option == -1) { |
@@ -949,13 +954,13 @@ static int gc_state (lua_State *L) { | |||
949 | } | 954 | } |
950 | else { | 955 | else { |
951 | global_State *g = G(L); | 956 | global_State *g = G(L); |
952 | if (G(L)->gckind == KGC_GEN) | 957 | if (G(L)->gckind != KGC_INC) |
953 | luaL_error(L, "cannot change states in generational mode"); | 958 | luaL_error(L, "cannot change states in generational mode"); |
954 | lua_lock(L); | 959 | lua_lock(L); |
955 | if (option < g->gcstate) { /* must cross 'pause'? */ | 960 | if (option < g->gcstate) { /* must cross 'pause'? */ |
956 | luaC_runtilstate(L, bitmask(GCSpause)); /* run until pause */ | 961 | luaC_runtilstate(L, GCSpause, 1); /* run until pause */ |
957 | } | 962 | } |
958 | luaC_runtilstate(L, bitmask(option)); | 963 | luaC_runtilstate(L, option, 0); /* do not skip propagation state */ |
959 | lua_assert(G(L)->gcstate == option); | 964 | lua_assert(G(L)->gcstate == option); |
960 | lua_unlock(L); | 965 | lua_unlock(L); |
961 | return 0; | 966 | return 0; |
@@ -1000,13 +1005,13 @@ static int table_query (lua_State *L) { | |||
1000 | if (i == -1) { | 1005 | if (i == -1) { |
1001 | lua_pushinteger(L, asize); | 1006 | lua_pushinteger(L, asize); |
1002 | lua_pushinteger(L, allocsizenode(t)); | 1007 | lua_pushinteger(L, allocsizenode(t)); |
1003 | lua_pushinteger(L, isdummy(t) ? 0 : t->lastfree - t->node); | ||
1004 | lua_pushinteger(L, t->alimit); | 1008 | lua_pushinteger(L, t->alimit); |
1005 | return 4; | 1009 | return 3; |
1006 | } | 1010 | } |
1007 | else if ((unsigned int)i < asize) { | 1011 | else if ((unsigned int)i < asize) { |
1008 | lua_pushinteger(L, i); | 1012 | lua_pushinteger(L, i); |
1009 | pushobject(L, &t->array[i]); | 1013 | arr2obj(t, i + 1, s2v(L->top.p)); |
1014 | api_incr_top(L); | ||
1010 | lua_pushnil(L); | 1015 | lua_pushnil(L); |
1011 | } | 1016 | } |
1012 | else if ((i -= asize) < sizenode(t)) { | 1017 | else if ((i -= asize) < sizenode(t)) { |
@@ -1029,6 +1034,35 @@ static int table_query (lua_State *L) { | |||
1029 | } | 1034 | } |
1030 | 1035 | ||
1031 | 1036 | ||
1037 | static int query_GCparams (lua_State *L) { | ||
1038 | global_State *g = G(L); | ||
1039 | lua_pushinteger(L, gettotalobjs(g)); | ||
1040 | lua_pushinteger(L, g->GCdebt); | ||
1041 | lua_pushinteger(L, applygcparam(g, MINORMUL, 100)); | ||
1042 | lua_pushinteger(L, applygcparam(g, MAJORMINOR, 100)); | ||
1043 | lua_pushinteger(L, applygcparam(g, MINORMAJOR, 100)); | ||
1044 | lua_pushinteger(L, applygcparam(g, PAUSE, 100)); | ||
1045 | lua_pushinteger(L, applygcparam(g, STEPMUL, 100)); | ||
1046 | lua_pushinteger(L, applygcparam(g, STEPSIZE, 100)); | ||
1047 | return 8; | ||
1048 | } | ||
1049 | |||
1050 | |||
1051 | static int test_codeparam (lua_State *L) { | ||
1052 | lua_Integer p = luaL_checkinteger(L, 1); | ||
1053 | lua_pushinteger(L, luaO_codeparam(p)); | ||
1054 | return 1; | ||
1055 | } | ||
1056 | |||
1057 | |||
1058 | static int test_applyparam (lua_State *L) { | ||
1059 | lua_Integer p = luaL_checkinteger(L, 1); | ||
1060 | lua_Integer x = luaL_checkinteger(L, 2); | ||
1061 | lua_pushinteger(L, luaO_applyparam(p, x)); | ||
1062 | return 1; | ||
1063 | } | ||
1064 | |||
1065 | |||
1032 | static int string_query (lua_State *L) { | 1066 | static int string_query (lua_State *L) { |
1033 | stringtable *tb = &G(L)->strt; | 1067 | stringtable *tb = &G(L)->strt; |
1034 | int s = cast_int(luaL_optinteger(L, 1, 0)) - 1; | 1068 | int s = cast_int(luaL_optinteger(L, 1, 0)) - 1; |
@@ -1051,27 +1085,39 @@ static int string_query (lua_State *L) { | |||
1051 | } | 1085 | } |
1052 | 1086 | ||
1053 | 1087 | ||
1088 | static int getreftable (lua_State *L) { | ||
1089 | if (lua_istable(L, 2)) /* is there a table as second argument? */ | ||
1090 | return 2; /* use it as the table */ | ||
1091 | else | ||
1092 | return LUA_REGISTRYINDEX; /* default is to use the register */ | ||
1093 | } | ||
1094 | |||
1095 | |||
1054 | static int tref (lua_State *L) { | 1096 | static int tref (lua_State *L) { |
1097 | int t = getreftable(L); | ||
1055 | int level = lua_gettop(L); | 1098 | int level = lua_gettop(L); |
1056 | luaL_checkany(L, 1); | 1099 | luaL_checkany(L, 1); |
1057 | lua_pushvalue(L, 1); | 1100 | lua_pushvalue(L, 1); |
1058 | lua_pushinteger(L, luaL_ref(L, LUA_REGISTRYINDEX)); | 1101 | lua_pushinteger(L, luaL_ref(L, t)); |
1059 | cast_void(level); /* to avoid warnings */ | 1102 | cast_void(level); /* to avoid warnings */ |
1060 | lua_assert(lua_gettop(L) == level+1); /* +1 for result */ | 1103 | lua_assert(lua_gettop(L) == level+1); /* +1 for result */ |
1061 | return 1; | 1104 | return 1; |
1062 | } | 1105 | } |
1063 | 1106 | ||
1107 | |||
1064 | static int getref (lua_State *L) { | 1108 | static int getref (lua_State *L) { |
1109 | int t = getreftable(L); | ||
1065 | int level = lua_gettop(L); | 1110 | int level = lua_gettop(L); |
1066 | lua_rawgeti(L, LUA_REGISTRYINDEX, luaL_checkinteger(L, 1)); | 1111 | lua_rawgeti(L, t, luaL_checkinteger(L, 1)); |
1067 | cast_void(level); /* to avoid warnings */ | 1112 | cast_void(level); /* to avoid warnings */ |
1068 | lua_assert(lua_gettop(L) == level+1); | 1113 | lua_assert(lua_gettop(L) == level+1); |
1069 | return 1; | 1114 | return 1; |
1070 | } | 1115 | } |
1071 | 1116 | ||
1072 | static int unref (lua_State *L) { | 1117 | static int unref (lua_State *L) { |
1118 | int t = getreftable(L); | ||
1073 | int level = lua_gettop(L); | 1119 | int level = lua_gettop(L); |
1074 | luaL_unref(L, LUA_REGISTRYINDEX, cast_int(luaL_checkinteger(L, 1))); | 1120 | luaL_unref(L, t, cast_int(luaL_checkinteger(L, 1))); |
1075 | cast_void(level); /* to avoid warnings */ | 1121 | cast_void(level); /* to avoid warnings */ |
1076 | lua_assert(lua_gettop(L) == level); | 1122 | lua_assert(lua_gettop(L) == level); |
1077 | return 0; | 1123 | return 0; |
@@ -1148,10 +1194,16 @@ static int num2int (lua_State *L) { | |||
1148 | } | 1194 | } |
1149 | 1195 | ||
1150 | 1196 | ||
1197 | static int makeseed (lua_State *L) { | ||
1198 | lua_pushinteger(L, luaL_makeseed(L)); | ||
1199 | return 1; | ||
1200 | } | ||
1201 | |||
1202 | |||
1151 | static int newstate (lua_State *L) { | 1203 | static int newstate (lua_State *L) { |
1152 | void *ud; | 1204 | void *ud; |
1153 | lua_Alloc f = lua_getallocf(L, &ud); | 1205 | lua_Alloc f = lua_getallocf(L, &ud); |
1154 | lua_State *L1 = lua_newstate(f, ud); | 1206 | lua_State *L1 = lua_newstate(f, ud, 0); |
1155 | if (L1) { | 1207 | if (L1) { |
1156 | lua_atpanic(L1, tpanic); | 1208 | lua_atpanic(L1, tpanic); |
1157 | lua_pushlightuserdata(L, L1); | 1209 | lua_pushlightuserdata(L, L1); |
@@ -1170,31 +1222,15 @@ static lua_State *getstate (lua_State *L) { | |||
1170 | 1222 | ||
1171 | 1223 | ||
1172 | static int loadlib (lua_State *L) { | 1224 | static int loadlib (lua_State *L) { |
1173 | static const luaL_Reg libs[] = { | ||
1174 | {LUA_GNAME, luaopen_base}, | ||
1175 | {"coroutine", luaopen_coroutine}, | ||
1176 | {"debug", luaopen_debug}, | ||
1177 | {"io", luaopen_io}, | ||
1178 | {"os", luaopen_os}, | ||
1179 | {"math", luaopen_math}, | ||
1180 | {"string", luaopen_string}, | ||
1181 | {"table", luaopen_table}, | ||
1182 | {"T", luaB_opentests}, | ||
1183 | {NULL, NULL} | ||
1184 | }; | ||
1185 | lua_State *L1 = getstate(L); | 1225 | lua_State *L1 = getstate(L); |
1186 | int i; | 1226 | int what = luaL_checkinteger(L, 2); |
1187 | luaL_requiref(L1, "package", luaopen_package, 0); | 1227 | luaL_openselectedlibs(L1, what); |
1228 | luaL_requiref(L1, "T", luaB_opentests, 0); | ||
1188 | lua_assert(lua_type(L1, -1) == LUA_TTABLE); | 1229 | lua_assert(lua_type(L1, -1) == LUA_TTABLE); |
1189 | /* 'requiref' should not reload module already loaded... */ | 1230 | /* 'requiref' should not reload module already loaded... */ |
1190 | luaL_requiref(L1, "package", NULL, 1); /* seg. fault if it reloads */ | 1231 | luaL_requiref(L1, "T", NULL, 1); /* seg. fault if it reloads */ |
1191 | /* ...but should return the same module */ | 1232 | /* ...but should return the same module */ |
1192 | lua_assert(lua_compare(L1, -1, -2, LUA_OPEQ)); | 1233 | lua_assert(lua_compare(L1, -1, -2, LUA_OPEQ)); |
1193 | luaL_getsubtable(L1, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE); | ||
1194 | for (i = 0; libs[i].name; i++) { | ||
1195 | lua_pushcfunction(L1, libs[i].func); | ||
1196 | lua_setfield(L1, -2, libs[i].name); | ||
1197 | } | ||
1198 | return 0; | 1234 | return 0; |
1199 | } | 1235 | } |
1200 | 1236 | ||
@@ -1260,7 +1296,7 @@ static int checkpanic (lua_State *L) { | |||
1260 | lua_Alloc f = lua_getallocf(L, &ud); | 1296 | lua_Alloc f = lua_getallocf(L, &ud); |
1261 | b.paniccode = luaL_optstring(L, 2, ""); | 1297 | b.paniccode = luaL_optstring(L, 2, ""); |
1262 | b.L = L; | 1298 | b.L = L; |
1263 | L1 = lua_newstate(f, ud); /* create new state */ | 1299 | L1 = lua_newstate(f, ud, 0); /* create new state */ |
1264 | if (L1 == NULL) { /* error? */ | 1300 | if (L1 == NULL) { /* error? */ |
1265 | lua_pushnil(L); | 1301 | lua_pushnil(L); |
1266 | return 1; | 1302 | return 1; |
@@ -1281,6 +1317,37 @@ static int checkpanic (lua_State *L) { | |||
1281 | } | 1317 | } |
1282 | 1318 | ||
1283 | 1319 | ||
1320 | static int externKstr (lua_State *L) { | ||
1321 | size_t len; | ||
1322 | const char *s = luaL_checklstring(L, 1, &len); | ||
1323 | lua_pushextlstring(L, s, len, NULL, NULL); | ||
1324 | return 1; | ||
1325 | } | ||
1326 | |||
1327 | |||
1328 | /* | ||
1329 | ** Create a buffer with the content of a given string and then | ||
1330 | ** create an external string using that buffer. Use the allocation | ||
1331 | ** function from Lua to create and free the buffer. | ||
1332 | */ | ||
1333 | static int externstr (lua_State *L) { | ||
1334 | size_t len; | ||
1335 | const char *s = luaL_checklstring(L, 1, &len); | ||
1336 | void *ud; | ||
1337 | lua_Alloc allocf = lua_getallocf(L, &ud); /* get allocation function */ | ||
1338 | /* create the buffer */ | ||
1339 | char *buff = cast_charp((*allocf)(ud, NULL, 0, len + 1)); | ||
1340 | if (buff == NULL) { /* memory error? */ | ||
1341 | lua_pushliteral(L, "not enough memory"); | ||
1342 | lua_error(L); /* raise a memory error */ | ||
1343 | } | ||
1344 | /* copy string content to buffer, including ending 0 */ | ||
1345 | memcpy(buff, s, (len + 1) * sizeof(char)); | ||
1346 | /* create external string */ | ||
1347 | lua_pushextlstring(L, buff, len, allocf, ud); | ||
1348 | return 1; | ||
1349 | } | ||
1350 | |||
1284 | 1351 | ||
1285 | /* | 1352 | /* |
1286 | ** {==================================================================== | 1353 | ** {==================================================================== |
@@ -1319,6 +1386,16 @@ static int getnum_aux (lua_State *L, lua_State *L1, const char **pc) { | |||
1319 | (*pc)++; | 1386 | (*pc)++; |
1320 | return res; | 1387 | return res; |
1321 | } | 1388 | } |
1389 | else if (**pc == '!') { | ||
1390 | (*pc)++; | ||
1391 | if (**pc == 'G') | ||
1392 | res = LUA_RIDX_GLOBALS; | ||
1393 | else if (**pc == 'M') | ||
1394 | res = LUA_RIDX_MAINTHREAD; | ||
1395 | else lua_assert(0); | ||
1396 | (*pc)++; | ||
1397 | return res; | ||
1398 | } | ||
1322 | else if (**pc == '-') { | 1399 | else if (**pc == '-') { |
1323 | sig = -1; | 1400 | sig = -1; |
1324 | (*pc)++; | 1401 | (*pc)++; |
@@ -1521,8 +1598,11 @@ static int runC (lua_State *L, lua_State *L1, const char *pc) { | |||
1521 | luaL_loadfile(L1, luaL_checkstring(L1, getnum)); | 1598 | luaL_loadfile(L1, luaL_checkstring(L1, getnum)); |
1522 | } | 1599 | } |
1523 | else if EQ("loadstring") { | 1600 | else if EQ("loadstring") { |
1524 | const char *s = luaL_checkstring(L1, getnum); | 1601 | size_t slen; |
1525 | luaL_loadstring(L1, s); | 1602 | const char *s = luaL_checklstring(L1, getnum, &slen); |
1603 | const char *name = getstring; | ||
1604 | const char *mode = getstring; | ||
1605 | luaL_loadbufferx(L1, s, slen, name, mode); | ||
1526 | } | 1606 | } |
1527 | else if EQ("newmetatable") { | 1607 | else if EQ("newmetatable") { |
1528 | lua_pushboolean(L1, luaL_newmetatable(L1, getstring)); | 1608 | lua_pushboolean(L1, luaL_newmetatable(L1, getstring)); |
@@ -1932,9 +2012,13 @@ static const struct luaL_Reg tests_funcs[] = { | |||
1932 | {"newstate", newstate}, | 2012 | {"newstate", newstate}, |
1933 | {"newuserdata", newuserdata}, | 2013 | {"newuserdata", newuserdata}, |
1934 | {"num2int", num2int}, | 2014 | {"num2int", num2int}, |
2015 | {"makeseed", makeseed}, | ||
1935 | {"pushuserdata", pushuserdata}, | 2016 | {"pushuserdata", pushuserdata}, |
1936 | {"querystr", string_query}, | 2017 | {"querystr", string_query}, |
1937 | {"querytab", table_query}, | 2018 | {"querytab", table_query}, |
2019 | {"queryGCparams", query_GCparams}, | ||
2020 | {"codeparam", test_codeparam}, | ||
2021 | {"applyparam", test_applyparam}, | ||
1938 | {"ref", tref}, | 2022 | {"ref", tref}, |
1939 | {"resume", coresume}, | 2023 | {"resume", coresume}, |
1940 | {"s2d", s2d}, | 2024 | {"s2d", s2d}, |
@@ -1949,6 +2033,8 @@ static const struct luaL_Reg tests_funcs[] = { | |||
1949 | {"udataval", udataval}, | 2033 | {"udataval", udataval}, |
1950 | {"unref", unref}, | 2034 | {"unref", unref}, |
1951 | {"upvalue", upvalue}, | 2035 | {"upvalue", upvalue}, |
2036 | {"externKstr", externKstr}, | ||
2037 | {"externstr", externstr}, | ||
1952 | {NULL, NULL} | 2038 | {NULL, NULL} |
1953 | }; | 2039 | }; |
1954 | 2040 | ||