* 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.
(define-module (system foreign)
#:use-module (rnrs bytevectors)
+ #:use-module (srfi srfi-1)
#:export (void
float double
int unsigned-int long unsigned-long size_t
(bytevector->pointer bv)))
(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)))
(+ byte (* 256 address)))
0
bytes)))))
+
+\f
+(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))))