1
0
mirror of https://github.com/janet-lang/janet synced 2024-12-01 04:19:55 +00:00

Fix trailing :pack-all or :pack in struct.

This commit is contained in:
Calvin Rose 2022-06-19 13:02:26 -05:00
parent c1a0352592
commit cfaae47cea
3 changed files with 17 additions and 5 deletions

View File

@ -346,6 +346,7 @@ static JanetFFIStruct *build_struct_type(int32_t argc, const Janet *argv) {
if (janet_keyeq(argv[j], "pack") || janet_keyeq(argv[j], "pack-all")) {
pack_one = 1;
j++;
if (j == argc) break;
}
st->fields[i].type = decode_ffi_type(argv[j]);
size_t el_size = type_size(st->fields[i].type);

View File

@ -28,16 +28,27 @@
(assert (= (thunk) 1) "delay 3")
(assert (= counter 1) "delay 4")
(def has-ffi (dyn 'ffi/native))
# FFI check
(compwhen (dyn 'ffi/native)
(compwhen has-ffi
(ffi/context))
(compwhen (dyn 'ffi/native)
(compwhen has-ffi
(ffi/defbind memcpy :ptr [dest :ptr src :ptr n :size]))
(compwhen (dyn 'ffi/native)
(compwhen has-ffi
(def buffer1 @"aaaa")
(def buffer2 @"bbbb")
(memcpy buffer1 buffer2 4)
(assert (= (string buffer1) "bbbb") "ffi 1 - memcpy"))
(compwhen has-ffi
(assert (= 8 (ffi/size [:int :char])) "size unpacked struct 1")
(assert (= 5 (ffi/size [:pack :int :char])) "size packed struct 1")
(assert (= 5 (ffi/size [:int :pack-all :char])) "size packed struct 2")
(assert (= 4 (ffi/align [:int :char])) "align 1")
(assert (= 1 (ffi/align [:pack :int :char])) "align 2")
(assert (= 1 (ffi/align [:int :char :pack-all])) "align 3")
(assert (= 26 (ffi/size [:char :pack :int @[:char 21]])) "array struct size"))
(end-suite)