From 7d6a97e42bc3328b9c5ec1dabbd7e280e81c3efd Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 20 Dec 2022 11:14:52 -0300 Subject: Dump doesn't need to reuse 'source' All strings are being reused now, including 'source'. --- testes/calls.lua | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'testes') diff --git a/testes/calls.lua b/testes/calls.lua index ee8cce73..cd2696e8 100644 --- a/testes/calls.lua +++ b/testes/calls.lua @@ -487,5 +487,30 @@ do end end + +do -- check reuse of strings in dumps + local str = "|" .. string.rep("X", 50) .. "|" + local foo = load(string.format([[ + local str = "%s" + return { + function () return str end, + function () return str end, + function () return str end + } + ]], str)) + -- count occurrences of 'str' inside the dump + local dump = string.dump(foo) + local _, count = string.gsub(dump, str, {}) + -- there should be only two occurrences: + -- one inside the source, other the string itself. + assert(count == 2) + + if T then -- check reuse of strings in undump + local funcs = load(dump)() + assert(string.format("%p", T.listk(funcs[1])[1]) == + string.format("%p", T.listk(funcs[3])[1])) + end +end + print('OK') return deep -- cgit v1.2.3-55-g6feb