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:
parent
183a2a224b
commit
7387c231ee
2 changed files with 16 additions and 1 deletions
|
@ -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)))
|
||||
|
|
|
@ -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))))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue