From 6d042a178fba32d10ec23c98fb2fd284397ccddc Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 13 Nov 2023 13:12:33 -0300 Subject: Auxiliary buffer uses external strings The buffer system from the auxiliary library reuses its buffer as external memory when closing long strings. --- testes/gc.lua | 3 --- testes/locals.lua | 10 ++-------- 2 files changed, 2 insertions(+), 11 deletions(-) (limited to 'testes') diff --git a/testes/gc.lua b/testes/gc.lua index 03093e34..3c928d7c 100644 --- a/testes/gc.lua +++ b/testes/gc.lua @@ -460,10 +460,7 @@ do -- tests for string keys in weak tables a[string.rep("a", 2^22)] = 25 -- long string key -> number value a[string.rep("b", 2^22)] = {} -- long string key -> colectable value a[{}] = 14 -- colectable key - assert(collectgarbage("count") > m + 2^13) -- 2^13 == 2 * 2^22 in KB collectgarbage() - assert(collectgarbage("count") >= m + 2^12 and - collectgarbage("count") < m + 2^13) -- one key was collected local k, v = next(a) -- string key with number value preserved assert(k == string.rep("a", 2^22) and v == 25) assert(next(a, k) == nil) -- everything else cleared diff --git a/testes/locals.lua b/testes/locals.lua index 2c48546d..090d846b 100644 --- a/testes/locals.lua +++ b/testes/locals.lua @@ -728,14 +728,8 @@ if rawget(_G, "T") then -- first buffer was released by 'toclose' assert(T.totalmem() - m <= extra) - -- error in creation of final string - T.totalmem(m + 2 * lim + extra) - assert(not pcall(table.concat, a)) - -- second buffer was released by 'toclose' - assert(T.totalmem() - m <= extra) - - -- userdata, buffer, buffer, final string - T.totalmem(m + 4*lim + extra) + -- userdata, buffer, final string + T.totalmem(m + 2*lim + extra) assert(#table.concat(a) == 2*lim) T.totalmem(0) -- remove memory limit -- cgit v1.2.3-55-g6feb