summaryrefslogtreecommitdiffstats
path: root/ffi.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2022-05-20 07:28:09 -0700
committerKaz Kylheku <kaz@kylheku.com>2022-05-20 07:28:09 -0700
commit0cff857c70c0f770259066d29a720f4404770558 (patch)
tree24de009609878bf6eebe62d90856687e7876082a /ffi.c
parentc6619399afc67006f7fa63d895d38a6c7008a6af (diff)
downloadtxr-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.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/ffi.c b/ffi.c
index 8f482e9a..13e8769b 100644
--- a/ffi.c
+++ b/ffi.c
@@ -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);
}
}