diff --git a/test/lib/ffi/ffi_err.lua b/test/lib/ffi/err.lua similarity index 63% rename from test/lib/ffi/ffi_err.lua rename to test/lib/ffi/err.lua index bd23658a2d..44723657c0 100644 --- a/test/lib/ffi/ffi_err.lua +++ b/test/lib/ffi/err.lua @@ -1,7 +1,6 @@ local ffi = require("ffi") --- error in FFI metamethod: don't print metamethod frame. -do +do --- error in FFI metamethod: don't print metamethod frame. local ok, err = xpcall(function() local x = (1ll).foo end, debug.traceback) @@ -9,8 +8,7 @@ do assert(not string.find(err, "__index")) end --- tailcall in regular metamethod: keep metamethod frame. -do +do --- tailcall in regular metamethod: keep metamethod frame. local ok, err = xpcall(function() local t = setmetatable({}, {__index = function() return rawget("x") end }) local y = t[1] @@ -19,13 +17,12 @@ do assert(string.find(err, "__index")) end --- error in FFI metamethod: set correct PC. -do +do --- error in FFI metamethod: set correct PC. ffi.cdef[[ -typedef struct { int x; int y; } point; -point strchr(point* op1, point* op2); +typedef struct { int x; int y; } ffi_err_point; +ffi_err_point ffi_err_strchr(ffi_err_point* op1, ffi_err_point* op2) asm("strchr"); ]] - local point = ffi.metatype("point", { __add = ffi.C.strchr }) + local point = ffi.metatype("ffi_err_point", { __add = ffi.C.ffi_err_strchr }) local function foo() local p = point{ 3, 4 } local r = p + p diff --git a/test/lib/ffi/index b/test/lib/ffi/index index 0ccd1ab531..c4091fb727 100644 --- a/test/lib/ffi/index +++ b/test/lib/ffi/index @@ -1,6 +1,10 @@ bit64.lua +bit copy_fill.lua +err.lua +istype.lua jit_array.lua +jit_complex.lua +jit_misc.lua jit_struct.lua meta_tostring.lua redir.lua diff --git a/test/lib/ffi/ffi_istype.lua b/test/lib/ffi/istype.lua similarity index 84% rename from test/lib/ffi/ffi_istype.lua rename to test/lib/ffi/istype.lua index fb538bdd4e..5aba7759e7 100644 --- a/test/lib/ffi/ffi_istype.lua +++ b/test/lib/ffi/istype.lua @@ -1,12 +1,6 @@ local ffi = require("ffi") -ffi.cdef[[ -typedef int arr_t[10]; -typedef const arr_t carr_t; -typedef struct { int x; } struct_t; -]] - -do +do --- 1 local void_t = ffi.typeof("void") assert(ffi.istype(void_t, void_t)) assert(ffi.istype("const void", void_t)) @@ -15,7 +9,7 @@ do assert(ffi.istype("double", 1.5) == false) -- 2nd arg is a number. end -do +do --- 2 local i8_t = ffi.typeof("int8_t") local u8_t = ffi.typeof("uint8_t") local i32_t = ffi.typeof("int32_t") @@ -32,7 +26,7 @@ do assert(ffi.istype("long long", ffi.typeof("int64_t"))) end -do +do --- 3 local ptr_t = ffi.typeof("int *") local p = ptr_t() assert(ffi.istype(ptr_t, ptr_t) == true) @@ -46,9 +40,15 @@ do assert(ffi.istype("void *", ptr_t) == false) end -do - local arr_t = ffi.typeof("arr_t") - local carr_t = ffi.typeof("carr_t") +do --- 4 + ffi.cdef[[ +typedef int istype_arr_t[10]; +typedef const istype_arr_t istype_carr_t; +typedef struct { int x; } istype_struct_t; +]] + + local arr_t = ffi.typeof("istype_arr_t") + local carr_t = ffi.typeof("istype_carr_t") assert(ffi.istype(arr_t, arr_t) == true) assert(ffi.istype("int[10]", arr_t) == true) @@ -60,16 +60,16 @@ do assert(ffi.istype("volatile int[10]", arr_t) == true) assert(ffi.istype(carr_t, arr_t) == true) - local struct_t = ffi.typeof("struct_t") - local structp_t = ffi.typeof("struct_t *") + local struct_t = ffi.typeof("istype_struct_t") + local structp_t = ffi.typeof("istype_struct_t *") assert(ffi.istype(struct_t, struct_t) == true) - assert(ffi.istype("const struct_t", struct_t) == true) + assert(ffi.istype("const istype_struct_t", struct_t) == true) assert(ffi.istype("struct { int x; }", struct_t) == false) assert(ffi.istype(struct_t, structp_t) == true) -- struct ptr is ok for struct. assert(ffi.istype(structp_t, struct_t) == false) end -do +do --- 5 local int_t = ffi.typeof("int") local t = {} for i=1,200 do t[i] = int_t() end @@ -86,4 +86,3 @@ do for i=1,200 do if not ffi.istype(t[i], int_t) then x = x + i end end assert(x == 100) end - diff --git a/test/lib/ffi/ffi_jit_complex.lua b/test/lib/ffi/jit_complex.lua similarity index 77% rename from test/lib/ffi/ffi_jit_complex.lua rename to test/lib/ffi/jit_complex.lua index 4d3191cbe7..3296f0cbfa 100644 --- a/test/lib/ffi/ffi_jit_complex.lua +++ b/test/lib/ffi/jit_complex.lua @@ -4,13 +4,13 @@ local cx = ffi.typeof("complex") local cxf = ffi.typeof("complex float") ffi.cdef[[ -typedef struct cc_t { - struct cc_t *next; +typedef struct jit_complex_chain_t { + struct jit_complex_chain_t *next; complex c; -} cc_t; +} jit_complex_chain_t; ]] -do +do --- field access local c = cx(1, 2) local x for i=1,100 do @@ -19,8 +19,8 @@ do assert(x == 3) end -do - local cp = ffi.new("cc_t") +do --- one element circular chain, named indexing + local cp = ffi.new("jit_complex_chain_t") local p = cp p.next = p p.c = cx(1, 2) @@ -34,8 +34,8 @@ do assert(y == 200) end -do - local cp = ffi.new("cc_t") +do --- one element circular chain, array indexing + local cp = ffi.new("jit_complex_chain_t") local p = cp p.next = p p.c = cx(1, 2) @@ -49,7 +49,7 @@ do assert(y == 200) end -do +do --- one-arg initialiser local ca = ffi.new("complex[?]", 101) for i=1,100 do ca[i] = cx(i) -- handled as init single @@ -63,7 +63,7 @@ do assert(y == 0) end -do +do --- two-arg initialiser local ca = ffi.new("complex[?]", 101) for i=1,100 do ca[i] = cx(i, -i) @@ -77,7 +77,7 @@ do assert(y == -5050) end -do +do --- float<>double conversions local ca = ffi.new("complex[?]", 101) local caf = ffi.new("complex float[?]", 101) for i=1,100 do @@ -93,7 +93,7 @@ do assert(y == -2*5050) end -do +do --- Complex struct field local s = ffi.new("struct { complex x;}") for i=1,100 do s.x = 12.5i @@ -102,10 +102,8 @@ do assert(s.x.im == 12.5) end --- Index overflow for complex is ignored -do +do --- Index overflow for complex is ignored local c = cx(1, 2) local x for i=1e7,1e7+100 do x = c[i] end end - diff --git a/test/lib/ffi/ffi_jit_misc.lua b/test/lib/ffi/jit_misc.lua similarity index 90% rename from test/lib/ffi/ffi_jit_misc.lua rename to test/lib/ffi/jit_misc.lua index 800509afcd..41e4737bc7 100644 --- a/test/lib/ffi/ffi_jit_misc.lua +++ b/test/lib/ffi/jit_misc.lua @@ -1,6 +1,6 @@ local ffi = require("ffi") -do +do --- errno ffi.errno(42) local x = 0 for i=1,100 do x = x + ffi.errno() end @@ -8,7 +8,7 @@ do ffi.errno(0) end -do +do --- string local a = ffi.new("uint8_t[?]", 101) for i=0,99 do a[i] = i end local s @@ -18,7 +18,7 @@ do assert(s == "Z[\\]^_`abc") end -do +do --- fill local a = ffi.new("uint8_t[?]", 100) local x = 0 for i=0,90 do x = x + a[i]; ffi.fill(a+i, 10, i); x = x + a[i] end @@ -31,7 +31,7 @@ do assert(b[103] == (ffi.abi("le") and 0x343434 or 0x34343400)) end -do +do --- copy array elements local a = ffi.new("uint8_t[?]", 100) local b = ffi.new("uint8_t[?]", 100) for i=0,99 do b[i] = i end @@ -43,7 +43,7 @@ do assert(x == 4095) end -do +do --- copy from string local a = ffi.new("uint8_t[?]", 100, 42) for i=0,90 do ffi.copy(a+i, "abc") end local x = 0 @@ -51,7 +51,7 @@ do assert(x == 9276) end -do +do --- copy structures local tp = ffi.typeof("struct { int x, y; }") local a = tp(1, 2) local b = tp(3, 4) @@ -63,7 +63,7 @@ do assert(x == 5050) end -do +do --- init struct from first field, complex local tp = ffi.typeof("struct { complex x, y; }") local cx = ffi.typeof("complex") local a = tp(cx(1, 2), cx(3, 4)) @@ -72,7 +72,7 @@ do assert(x == 5050) end -do +do --- int array as parameterised type local tp = ffi.typeof("int[10]") local a = tp(42) local b = ffi.new(ffi.typeof("struct { $ x; }", tp)) @@ -80,7 +80,7 @@ do assert(b.x[0] == 42 and b.x[9] == 42) end -do +do --- double array as parameterised type local tp = ffi.typeof("double[5]") local a = tp(42) local b = ffi.new(ffi.typeof("struct { $ x; }", tp)) @@ -91,7 +91,7 @@ do assert(b.x[0] == 42 and b.x[4] == 42) end -do +do --- abi local x, y for i=1,100 do x = ffi.abi("32bit"); y = ffi.abi("64bit") end assert(x == ffi.abi("32bit")) @@ -102,9 +102,8 @@ do end end -do +do --- typeof constructed typeof local ct = ffi.typeof("struct { int x; }") local cd = ct() for i=1,100 do assert(ffi.typeof(cd) == ct) end end -