1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-20 11:40:18 +02:00

FFI: Honor alignment constraints in `parse-c-struct'.

* module/system/foreign.scm (parse-c-struct): Honor alignment
  constraints for TYPE.

* test-suite/tests/foreign.test ("structs")["alignment constraints
  honored"]: New test.
This commit is contained in:
Ludovic Courtès 2010-11-08 23:08:48 +01:00
parent 8a6b693817
commit 1f864a1685
2 changed files with 9 additions and 1 deletions

View file

@ -132,7 +132,8 @@
(define (parse-c-struct foreign types)
(let ((size (fold (lambda (type total)
(+ (sizeof type) total))
(+ (sizeof type)
(align total (alignof type))))
0
types)))
(read-c-struct (pointer->bytevector foreign size) 0 types)))

View file

@ -180,6 +180,13 @@
(pass-if "parse-c-struct"
(let ((layout (list int64 uint8))
(data (list -300 43)))
(equal? (parse-c-struct (make-c-struct layout data)
layout)
data)))
(pass-if "alignment constraints honored"
(let ((layout (list int8 double))
(data (list -7 3.14)))
(equal? (parse-c-struct (make-c-struct layout data)
layout)
data))))