1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-21 11:10:21 +02:00

FFI: Return the right alignment for structures.

* libguile/foreign.c (scm_alignof): Fix handling of structure alignment.
  Reported by Aidan Gauland <aidalgol@no8wireless.co.nz>.

* test-suite/tests/foreign.test ("structs")["alignof { int8, double,
  int8 }", "int8, { int8, double, int8 }, int16"]: New tests.
This commit is contained in:
Ludovic Courtès 2011-03-10 22:24:23 +01:00
parent dd36ce77cd
commit d82f8518b9
2 changed files with 30 additions and 2 deletions

View file

@ -228,6 +228,11 @@
(>= (sizeof layout)
(reduce + 0.0 (map sizeof layout)))))
(pass-if "alignof { int8, double, int8 }"
;; alignment of the most strictly aligned component
(let ((layout (list int8 double int8)))
(= (alignof layout) (alignof double))))
(pass-if "parse-c-struct"
(let ((layout (list int64 uint8))
(data (list -300 43)))
@ -266,6 +271,13 @@
(pass-if "int8, pointer, short, double"
(let ((layout (list int8 '* short double))
(data (list 77 %null-pointer -42 3.14)))
(equal? (parse-c-struct (make-c-struct layout data)
layout)
data)))
(pass-if "int8, { int8, double, int8 }, int16"
(let ((layout (list int8 (list int8 double int8) int16))
(data (list 77 (list 42 4.2 55) 88)))
(equal? (parse-c-struct (make-c-struct layout data)
layout)
data))))