From 7387c231ee382a36a13a04c9f3b247b1667f0397 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Wed, 28 Jul 2010 12:02:50 +0200 Subject: [PATCH] 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. --- module/system/foreign.scm | 7 ++++++- test-suite/tests/foreign.test | 10 ++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/module/system/foreign.scm b/module/system/foreign.scm index f07499806..121db6038 100644 --- a/module/system/foreign.scm +++ b/module/system/foreign.scm @@ -18,6 +18,7 @@ (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 @@ -124,4 +125,8 @@ (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))) diff --git a/test-suite/tests/foreign.test b/test-suite/tests/foreign.test index 2cc1e2107..eb1236034 100644 --- a/test-suite/tests/foreign.test +++ b/test-suite/tests/foreign.test @@ -77,3 +77,13 @@ (+ byte (* 256 address))) 0 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))))