diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-02-07 13:39:54 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-02-07 13:39:54 -0300 |
commit | 0c9bec0d38ed3d2c45d7be4e764a0bcffef98be1 (patch) | |
tree | 05fd1ba56705dc0a1728e1bedda7961cc96414c1 /testes | |
parent | c31d6774ac7db4cfbc548ce507ae65ab6036f873 (diff) | |
download | lua-0c9bec0d38ed3d2c45d7be4e764a0bcffef98be1.tar.gz lua-0c9bec0d38ed3d2c45d7be4e764a0bcffef98be1.tar.bz2 lua-0c9bec0d38ed3d2c45d7be4e764a0bcffef98be1.zip |
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.)
Diffstat (limited to 'testes')
-rw-r--r-- | testes/sort.lua | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/testes/sort.lua b/testes/sort.lua index 7e566a5a..442b3129 100644 --- a/testes/sort.lua +++ b/testes/sort.lua | |||
@@ -3,19 +3,30 @@ | |||
3 | 3 | ||
4 | print "testing (parts of) table library" | 4 | print "testing (parts of) table library" |
5 | 5 | ||
6 | local maxI = math.maxinteger | ||
7 | local minI = math.mininteger | ||
8 | |||
9 | |||
10 | local function checkerror (msg, f, ...) | ||
11 | local s, err = pcall(f, ...) | ||
12 | assert(not s and string.find(err, msg)) | ||
13 | end | ||
14 | |||
15 | |||
6 | do print "testing 'table.create'" | 16 | do print "testing 'table.create'" |
17 | local N = 10000 | ||
7 | collectgarbage() | 18 | collectgarbage() |
8 | local m = collectgarbage("count") * 1024 | 19 | local m = collectgarbage("count") * 1024 |
9 | local t = table.create(10000) | 20 | local t = table.create(N) |
10 | local memdiff = collectgarbage("count") * 1024 - m | 21 | local memdiff = collectgarbage("count") * 1024 - m |
11 | assert(memdiff > 10000 * 4) | 22 | assert(memdiff > N * 4) |
12 | for i = 1, 20 do | 23 | for i = 1, 20 do |
13 | assert(#t == i - 1) | 24 | assert(#t == i - 1) |
14 | t[i] = 0 | 25 | t[i] = 0 |
15 | end | 26 | end |
16 | for i = 1, 20 do t[#t + 1] = i * 10 end | 27 | for i = 1, 20 do t[#t + 1] = i * 10 end |
17 | assert(#t == 40 and t[39] == 190) | 28 | assert(#t == 40 and t[39] == 190) |
18 | assert(not T or T.querytab(t) == 10000) | 29 | assert(not T or T.querytab(t) == N) |
19 | t = nil | 30 | t = nil |
20 | collectgarbage() | 31 | collectgarbage() |
21 | m = collectgarbage("count") * 1024 | 32 | m = collectgarbage("count") * 1024 |
@@ -23,6 +34,9 @@ do print "testing 'table.create'" | |||
23 | memdiff = collectgarbage("count") * 1024 - m | 34 | memdiff = collectgarbage("count") * 1024 - m |
24 | assert(memdiff > 1024 * 12) | 35 | assert(memdiff > 1024 * 12) |
25 | assert(not T or select(2, T.querytab(t)) == 1024) | 36 | assert(not T or select(2, T.querytab(t)) == 1024) |
37 | |||
38 | checkerror("table overflow", table.create, (1<<31) + 1) | ||
39 | checkerror("table overflow", table.create, 0, (1<<31) + 1) | ||
26 | end | 40 | end |
27 | 41 | ||
28 | 42 | ||
@@ -30,15 +44,6 @@ print "testing unpack" | |||
30 | 44 | ||
31 | local unpack = table.unpack | 45 | local unpack = table.unpack |
32 | 46 | ||
33 | local maxI = math.maxinteger | ||
34 | local minI = math.mininteger | ||
35 | |||
36 | |||
37 | local function checkerror (msg, f, ...) | ||
38 | local s, err = pcall(f, ...) | ||
39 | assert(not s and string.find(err, msg)) | ||
40 | end | ||
41 | |||
42 | 47 | ||
43 | checkerror("wrong number of arguments", table.insert, {}, 2, 3, 4) | 48 | checkerror("wrong number of arguments", table.insert, {}, 2, 3, 4) |
44 | 49 | ||