diff options
author | Ludovic Courtès <ludo@gnu.org> | 2010-07-28 12:02:50 +0200 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2010-07-28 12:24:25 +0200 |
commit | 7387c231ee382a36a13a04c9f3b247b1667f0397 (patch) | |
tree | acb338f4860e1e37c6c1f678e29115a93330a9a7 | |
parent | 183a2a224b555a29ab311ffcb6abd529a0bdffc1 (diff) | |
download | guile-7387c231ee382a36a13a04c9f3b247b1667f0397.tar.gz |
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.
-rw-r--r-- | module/system/foreign.scm | 7 | ||||
-rw-r--r-- | test-suite/tests/foreign.test | 10 |
2 files changed, 16 insertions, 1 deletions
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)))) |