mirror of
https://github.com/janet-lang/janet
synced 2024-11-28 19:19:53 +00:00
Fix trailing :pack-all or :pack in struct.
This commit is contained in:
parent
c1a0352592
commit
cfaae47cea
@ -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")) {
|
if (janet_keyeq(argv[j], "pack") || janet_keyeq(argv[j], "pack-all")) {
|
||||||
pack_one = 1;
|
pack_one = 1;
|
||||||
j++;
|
j++;
|
||||||
|
if (j == argc) break;
|
||||||
}
|
}
|
||||||
st->fields[i].type = decode_ffi_type(argv[j]);
|
st->fields[i].type = decode_ffi_type(argv[j]);
|
||||||
size_t el_size = type_size(st->fields[i].type);
|
size_t el_size = type_size(st->fields[i].type);
|
||||||
|
@ -303,8 +303,8 @@ static JanetTable *handleattr(JanetCompiler *c, int32_t argn, const Janet *argv)
|
|||||||
int32_t i;
|
int32_t i;
|
||||||
JanetTable *tab = janet_table(2);
|
JanetTable *tab = janet_table(2);
|
||||||
const char *binding_name = janet_type(argv[0]) == JANET_SYMBOL
|
const char *binding_name = janet_type(argv[0]) == JANET_SYMBOL
|
||||||
? ((const char *)janet_unwrap_symbol(argv[0]))
|
? ((const char *)janet_unwrap_symbol(argv[0]))
|
||||||
: "<multiple bindings>";
|
: "<multiple bindings>";
|
||||||
for (i = 1; i < argn - 1; i++) {
|
for (i = 1; i < argn - 1; i++) {
|
||||||
Janet attr = argv[i];
|
Janet attr = argv[i];
|
||||||
switch (janet_type(attr)) {
|
switch (janet_type(attr)) {
|
||||||
|
@ -28,16 +28,27 @@
|
|||||||
(assert (= (thunk) 1) "delay 3")
|
(assert (= (thunk) 1) "delay 3")
|
||||||
(assert (= counter 1) "delay 4")
|
(assert (= counter 1) "delay 4")
|
||||||
|
|
||||||
|
(def has-ffi (dyn 'ffi/native))
|
||||||
|
|
||||||
# FFI check
|
# FFI check
|
||||||
(compwhen (dyn 'ffi/native)
|
(compwhen has-ffi
|
||||||
(ffi/context))
|
(ffi/context))
|
||||||
(compwhen (dyn 'ffi/native)
|
(compwhen has-ffi
|
||||||
(ffi/defbind memcpy :ptr [dest :ptr src :ptr n :size]))
|
(ffi/defbind memcpy :ptr [dest :ptr src :ptr n :size]))
|
||||||
(compwhen (dyn 'ffi/native)
|
(compwhen has-ffi
|
||||||
(def buffer1 @"aaaa")
|
(def buffer1 @"aaaa")
|
||||||
(def buffer2 @"bbbb")
|
(def buffer2 @"bbbb")
|
||||||
(memcpy buffer1 buffer2 4)
|
(memcpy buffer1 buffer2 4)
|
||||||
(assert (= (string buffer1) "bbbb") "ffi 1 - memcpy"))
|
(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)
|
(end-suite)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user