From 3b57e37e4821ddce4756428956b7e9f4969efa4c Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Fri, 10 Nov 2023 12:35:48 -0300 Subject: Fixed buffers save long strings as external. --- testes/api.lua | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'testes') diff --git a/testes/api.lua b/testes/api.lua index 181c1d53..7d64cb22 100644 --- a/testes/api.lua +++ b/testes/api.lua @@ -528,13 +528,15 @@ do local N = 1000 -- create a somewhat "large" source for i = 1, N do source[i] = "X = X + 1; " end + -- add a long string to the source + source[#source + 1] = string.format("Y = '%s'", string.rep("a", N)); source = table.concat(source) -- give chunk an explicit name to avoid using source as name source = load(source, "name1") -- dump without debug information source = string.dump(source, true) - -- each "X=X+1" generates 4 opcodes with 4 bytes each - assert(#source > N * 4 * 4) + -- each "X=X+1" generates 4 opcodes with 4 bytes each, plus the string + assert(#source > N * 4 * 4 + N) collectgarbage(); collectgarbage() local m1 = collectgarbage"count" * 1024 -- load dump using fixed buffer @@ -544,9 +546,11 @@ do ]], source) collectgarbage() local m2 = collectgarbage"count" * 1024 - -- load used fewer than 300 bytes - assert(m2 > m1 and m2 - m1 < 300) - X = 0; code(); assert(X == N); X = nil + -- load used fewer than 350 bytes. Code alone has more than 3*N bytes, + -- and string literal has N bytes. Both were not loaded. + assert(m2 > m1 and m2 - m1 < 350) + X = 0; code(); assert(X == N and Y == string.rep("a", N)) + X = nil; Y = nil end -- cgit v1.2.3-55-g6feb