Skip to content

Commit

Permalink
Add tests for allocation of variable-sized cdata
Browse files Browse the repository at this point in the history
  • Loading branch information
corsix committed Oct 12, 2016
1 parent 6fe6fbe commit 7897e7f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
41 changes: 41 additions & 0 deletions test/lib/ffi/cdata_var.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
local ffi = require("ffi")

do --- byte array allocations
local typ = ffi.typeof"uint8_t[?]"
for i = 4, 20 do
for d = -3, 3 do
local sz = 2^i + d
assert(ffi.sizeof(typ, sz) == sz)
local mem = ffi.new(typ, sz)
assert(ffi.sizeof(mem) == sz)
mem[0] = 0x21
mem[1] = 0x32
mem[2] = 0x43
mem[sz-3] = 0x54
mem[sz-2] = 0x65
mem[sz-1] = 0x76
assert(mem[0] == 0x21)
assert(mem[1] == 0x32)
assert(mem[2] == 0x43)
assert(mem[sz-3] == 0x54)
assert(mem[sz-2] == 0x65)
assert(mem[sz-1] == 0x76)
end
end
end

do --- int array allocations
local typ = ffi.typeof"int32_t[?]"
for i = 2, 17 do
for d = -2, 2 do
local sz = 2^i + d
assert(ffi.sizeof(typ, sz) == sz*4)
local mem = ffi.new(typ, sz)
assert(ffi.sizeof(mem) == sz*4)
mem[0] = -3
mem[sz-1] = -4
assert(mem[0] == -3)
assert(mem[sz-1] == -4)
end
end
end
1 change: 1 addition & 0 deletions test/lib/ffi/index
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
bit64.lua +luajit>=2.1
cdata_var.lua
copy_fill.lua
err.lua
istype.lua
Expand Down

0 comments on commit 7897e7f

Please sign in to comment.