aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2012-01-20 16:32:13 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2012-01-20 16:32:13 -0200
commit81ed85ecfbec8607c12e8f7f9731a376eaeb2d0a (patch)
treec7b41ef1d99b1a992f760f1af1e2092e3bb08622
parent7dcc02b1652b005a6a93bd46deb4d99a032b6142 (diff)
downloadlua-81ed85ecfbec8607c12e8f7f9731a376eaeb2d0a.tar.gz
lua-81ed85ecfbec8607c12e8f7f9731a376eaeb2d0a.tar.bz2
lua-81ed85ecfbec8607c12e8f7f9731a376eaeb2d0a.zip
BUG: memory hoarding when creating Lua hooks for coroutines
BUG: Lexical gets confused with some combination of arithmetic operators and hexadecimal numbers
-rw-r--r--bugs127
1 files changed, 125 insertions, 2 deletions
diff --git a/bugs b/bugs
index f2bce7c1..8708dd92 100644
--- a/bugs
+++ b/bugs
@@ -1880,8 +1880,8 @@ patch = [[
1880+++ lundump.c 2008/04/04 19:51:41 2.7.1.4 1880+++ lundump.c 2008/04/04 19:51:41 2.7.1.4
1881@@ -1,5 +1,5 @@ 1881@@ -1,5 +1,5 @@
1882 /* 1882 /*
1883-** $Id: bugs,v 1.110 2011/08/17 20:38:51 roberto Exp roberto $ 1883-** $Id: bugs,v 1.111 2011/10/21 19:34:23 roberto Exp roberto $
1884+** $Id: bugs,v 1.110 2011/08/17 20:38:51 roberto Exp roberto $ 1884+** $Id: bugs,v 1.111 2011/10/21 19:34:23 roberto Exp roberto $
1885 ** load precompiled Lua chunks 1885 ** load precompiled Lua chunks
1886 ** See Copyright Notice in lua.h 1886 ** See Copyright Notice in lua.h
1887 */ 1887 */
@@ -2407,3 +2407,126 @@ patch = [[
2407 2407
2408]] 2408]]
2409} 2409}
2410
2411
2412-----------------------------------------------------------------
2413-- Lua 5.2.0
2414
2415Bug{
2416what = [[memory hoarding when creating Lua hooks for coroutines]],
2417report = [[Arseny Vakhrushev, 2012/01/16]],
2418since = [[5.1]],
2419example = [[
2420collectgarbage(); print(collectgarbage'count' * 1024)
2421
2422for i = 1, 100 do
2423 local co = coroutine.create(function () end)
2424 local x = {}
2425 for j=1,1000 do x[j] = j end
2426 debug.sethook(co, function () return x end, 'l')
2427end
2428
2429collectgarbage(); print(collectgarbage'count' * 1024)
2430-- value should back to near the original level
2431]],
2432patch = [[
2433-- For 5.2
2434
2435--- ldblib.c 2011/10/24 14:54:05 1.131
2436+++ ldblib.c 2012/01/18 02:36:59
2437@@ -253,14 +253,15 @@
2438 }
2439
2440
2441-#define gethooktable(L) luaL_getsubtable(L, LUA_REGISTRYINDEX, HOOKKEY);
2442+#define gethooktable(L) luaL_getsubtable(L, LUA_REGISTRYINDEX, HOOKKEY)
2443
2444
2445 static void hookf (lua_State *L, lua_Debug *ar) {
2446 static const char *const hooknames[] =
2447 {"call", "return", "line", "count", "tail call"};
2448 gethooktable(L);
2449- lua_rawgetp(L, -1, L);
2450+ lua_pushthread(L);
2451+ lua_rawget(L, -2);
2452 if (lua_isfunction(L, -1)) {
2453 lua_pushstring(L, hooknames[(int)ar->event]);
2454 if (ar->currentline >= 0)
2455@@ -306,10 +307,15 @@
2456 count = luaL_optint(L, arg+3, 0);
2457 func = hookf; mask = makemask(smask, count);
2458 }
2459- gethooktable(L);
2460+ if (gethooktable(L) == 0) { /* creating hook table? */
2461+ lua_pushstring(L, "k");
2462+ lua_setfield(L, -2, "__mode"); /** hooktable.__mode = "k" */
2463+ lua_pushvalue(L, -1);
2464+ lua_setmetatable(L, -2); /* setmetatable(hooktable) = hooktable */
2465+ }
2466+ lua_pushthread(L1); lua_xmove(L1, L, 1);
2467 lua_pushvalue(L, arg+1);
2468- lua_rawsetp(L, -2, L1); /* set new hook */
2469- lua_pop(L, 1); /* remove hook table */
2470+ lua_rawset(L, -3); /* set new hook */
2471 lua_sethook(L1, func, mask, count); /* set hooks */
2472 return 0;
2473 }
2474@@ -325,7 +331,8 @@
2475 lua_pushliteral(L, "external hook");
2476 else {
2477 gethooktable(L);
2478- lua_rawgetp(L, -1, L1); /* get hook */
2479+ lua_pushthread(L1); lua_xmove(L1, L, 1);
2480+ lua_rawget(L, -2); /* get hook */
2481 lua_remove(L, -2); /* remove hook table */
2482 }
2483 lua_pushstring(L, unmakemask(mask, buff));
2484]]
2485}
2486
2487Bug{
2488what = [[Lexical gets confused with some combination of arithmetic
2489operators and hexadecimal numbers]],
2490report = [[Alexandra Barros, 2012/01/17]],
2491since = [[5.2.0]],
2492example = [[print(0xE+1)]],
2493patch = [[
2494--- llex.c 2011/11/30 12:43:51 2.59
2495+++ llex.c 2012/01/20 18:22:50
2496@@ -223,12 +223,19 @@
2497
2498 /* LUA_NUMBER */
2499 static void read_numeral (LexState *ls, SemInfo *seminfo) {
2500+ const char *expo = "Ee";
2501+ int first = ls->current;
2502 lua_assert(lisdigit(ls->current));
2503- do {
2504- save_and_next(ls);
2505- if (check_next(ls, "EePp")) /* exponent part? */
2506+ save_and_next(ls);
2507+ if (first == '0' && check_next(ls, "Xx")) /* hexadecimal? */
2508+ expo = "Pp";
2509+ for (;;) {
2510+ if (check_next(ls, expo)) /* exponent part? */
2511 check_next(ls, "+-"); /* optional exponent sign */
2512- } while (lislalnum(ls->current) || ls->current == '.');
2513+ if (lisxdigit(ls->current) || ls->current == '.')
2514+ save_and_next(ls);
2515+ else break;
2516+ }
2517 save(ls, '\0');
2518 buffreplace(ls, '.', ls->decpoint); /* follow locale for decimal point */
2519 if (!buff2d(ls->buff, &seminfo->r)) /* format error? */
2520]]
2521}
2522
2523--[=[
2524Bug{
2525what = [[ ]],
2526report = [[ ]],
2527since = [[ ]],
2528example = [[ ]],
2529patch = [[
2530]]
2531}
2532]=]