Free bit 7 of GC 'marked' field

Tables were using this bit to indicate their array sizes were real
('isrealasize'), but this bit can be useful for tests. Instead, they
can use bit 7 of their 'flag' field for that purpose. (There are only
six fast-access metamethods.) This 'flag' field only exists in tables,
so this use does not affect other types.
This commit is contained in:
Roberto Ierusalimschy
2020-08-07 11:21:44 -03:00
parent 68109afcdb
commit 7c3cb71fa4
6 changed files with 31 additions and 7 deletions

View File

@@ -305,6 +305,17 @@ t[Set{1,3,5}] = 1
assert(t[Set{1,3,5}] == undef)
do -- test invalidating flags
local mt = {__eq = true}
local a = setmetatable({10}, mt)
local b = setmetatable({10}, mt)
mt.__eq = nil
assert(a ~= b) -- no metamethod
mt.__eq = function (x,y) return x[1] == y[1] end
assert(a == b) -- must use metamethod now
end
if not T then
(Message or print)('\n >>> testC not active: skipping tests for \z
userdata <<<\n')