Better handling of size limit when resizing a table
Avoid silent conversions from int to unsigned int when calling 'luaH_resize'; avoid silent conversions from lua_Integer to int in 'table.create'; MAXASIZE corrected for the new implementation of arrays; 'luaH_resize' checks explicitly whether new size respects MAXASIZE. (Even constructors were bypassing that check.)
This commit is contained in:
@@ -3,33 +3,6 @@
|
||||
|
||||
print "testing (parts of) table library"
|
||||
|
||||
do print "testing 'table.create'"
|
||||
collectgarbage()
|
||||
local m = collectgarbage("count") * 1024
|
||||
local t = table.create(10000)
|
||||
local memdiff = collectgarbage("count") * 1024 - m
|
||||
assert(memdiff > 10000 * 4)
|
||||
for i = 1, 20 do
|
||||
assert(#t == i - 1)
|
||||
t[i] = 0
|
||||
end
|
||||
for i = 1, 20 do t[#t + 1] = i * 10 end
|
||||
assert(#t == 40 and t[39] == 190)
|
||||
assert(not T or T.querytab(t) == 10000)
|
||||
t = nil
|
||||
collectgarbage()
|
||||
m = collectgarbage("count") * 1024
|
||||
t = table.create(0, 1024)
|
||||
memdiff = collectgarbage("count") * 1024 - m
|
||||
assert(memdiff > 1024 * 12)
|
||||
assert(not T or select(2, T.querytab(t)) == 1024)
|
||||
end
|
||||
|
||||
|
||||
print "testing unpack"
|
||||
|
||||
local unpack = table.unpack
|
||||
|
||||
local maxI = math.maxinteger
|
||||
local minI = math.mininteger
|
||||
|
||||
@@ -40,6 +13,38 @@ local function checkerror (msg, f, ...)
|
||||
end
|
||||
|
||||
|
||||
do print "testing 'table.create'"
|
||||
local N = 10000
|
||||
collectgarbage()
|
||||
local m = collectgarbage("count") * 1024
|
||||
local t = table.create(N)
|
||||
local memdiff = collectgarbage("count") * 1024 - m
|
||||
assert(memdiff > N * 4)
|
||||
for i = 1, 20 do
|
||||
assert(#t == i - 1)
|
||||
t[i] = 0
|
||||
end
|
||||
for i = 1, 20 do t[#t + 1] = i * 10 end
|
||||
assert(#t == 40 and t[39] == 190)
|
||||
assert(not T or T.querytab(t) == N)
|
||||
t = nil
|
||||
collectgarbage()
|
||||
m = collectgarbage("count") * 1024
|
||||
t = table.create(0, 1024)
|
||||
memdiff = collectgarbage("count") * 1024 - m
|
||||
assert(memdiff > 1024 * 12)
|
||||
assert(not T or select(2, T.querytab(t)) == 1024)
|
||||
|
||||
checkerror("table overflow", table.create, (1<<31) + 1)
|
||||
checkerror("table overflow", table.create, 0, (1<<31) + 1)
|
||||
end
|
||||
|
||||
|
||||
print "testing unpack"
|
||||
|
||||
local unpack = table.unpack
|
||||
|
||||
|
||||
checkerror("wrong number of arguments", table.insert, {}, 2, 3, 4)
|
||||
|
||||
local x,y,z,a,n
|
||||
|
||||
Reference in New Issue
Block a user