Fix `parse-c-struct'.
authorLudovic Courtès <ludo@gnu.org>
Wed, 28 Jul 2010 10:02:50 +0000 (12:02 +0200)
committerLudovic Courtès <ludo@gnu.org>
Wed, 28 Jul 2010 10:24:25 +0000 (12:24 +0200)
* 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
test-suite/tests/foreign.test

index f074998..121db60 100644 (file)
@@ -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
     (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)))
index 2cc1e21..eb12360 100644 (file)
                        (+ 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))))