1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-29 14:30:34 +02:00

Fix `parse-c-struct'.

* module/system/foreign.scm (parse-c-struct): Update use of
  `pointer->bytevector' to the new API.

* test-suite/tests/foreign.test ("structs"): New test prefix.
This commit is contained in:
Ludovic Courtès 2010-07-28 12:02:50 +02:00
parent 183a2a224b
commit 7387c231ee
2 changed files with 16 additions and 1 deletions

View file

@ -18,6 +18,7 @@
(define-module (system foreign) (define-module (system foreign)
#:use-module (rnrs bytevectors) #:use-module (rnrs bytevectors)
#:use-module (srfi srfi-1)
#:export (void #:export (void
float double float double
int unsigned-int long unsigned-long size_t int unsigned-int long unsigned-long size_t
@ -124,4 +125,8 @@
(bytevector->pointer bv))) (bytevector->pointer bv)))
(define (parse-c-struct foreign types) (define (parse-c-struct foreign types)
(read-c-struct (pointer->bytevector foreign) 0 types)) (let ((size (fold (lambda (type total)
(+ (sizeof type) total))
0
types)))
(read-c-struct (pointer->bytevector foreign size) 0 types)))

View file

@ -77,3 +77,13 @@
(+ byte (* 256 address))) (+ byte (* 256 address)))
0 0
bytes))))) bytes)))))
(with-test-prefix "structs"
(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))))