diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2022-05-20 07:28:09 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2022-05-20 07:28:09 -0700 |
commit | 0cff857c70c0f770259066d29a720f4404770558 (patch) | |
tree | 24de009609878bf6eebe62d90856687e7876082a /ffi.c | |
parent | c6619399afc67006f7fa63d895d38a6c7008a6af (diff) | |
download | txr-0cff857c70c0f770259066d29a720f4404770558.tar.gz txr-0cff857c70c0f770259066d29a720f4404770558.tar.bz2 txr-0cff857c70c0f770259066d29a720f4404770558.zip |
ffi: pack bugfix and tests.
* ffi.c (ffi_transform_pack): Fix: return the original syntax in
the situation when no cases are recognized, rather than
the cdr of the syntax. When the struct/union syntax has no
members, return the original syntax to indicate no transformation
took place.
* txr.1: Document the feature that pack on a typedef name or struct
name with no members will do the alignment adjustment only, without
the syntactic transformation.
* tests/017/pack-align.tl: New file.
Diffstat (limited to 'ffi.c')
-rw-r--r-- | ffi.c | 19 |
1 files changed, 10 insertions, 9 deletions
@@ -3925,15 +3925,16 @@ static val ffi_struct_init(val slot_init, val strct) static val ffi_transform_pack(val syntax, val align) { - val op = pop(&syntax); + val args = syntax; + val op = pop(&args); if (op == struct_s || op == union_s) { - val name = pop(&syntax); + val name = pop(&args); val iter; list_collect_decl (packed, ptail); - for (iter = syntax; iter; iter = cdr(iter)) { + for (iter = args; iter; iter = cdr(iter)) { val slot_spec = car(iter); val slot = car(slot_spec); val type = cadr(slot_spec); @@ -3945,14 +3946,14 @@ static val ffi_transform_pack(val syntax, val align) list(slot, packed_type, nao))); } - return cons(op, cons(name, packed)); + return if3(packed, cons(op, cons(name, packed)), syntax); } else if (op == align_s) { - if (length(syntax) == one) { - val type = car(syntax); + if (length(syntax) == two) { + val type = car(args); return list(align_s, list(pack_s, align, type, nao), nao); - } else if (length(syntax) == two) { - val align = car(syntax); - val type = cadr(syntax); + } else if (length(syntax) == three) { + val align = car(args); + val type = cadr(args); return list(align_s, align, list(pack_s, align, type, nao), nao); } } |