Have parse-c-struct' and make-c-struct' support `int', pointers, etc.

Reported by Tristan Colgate <tcolgate@gmail.com>.

* module/system/foreign.scm: Call `load-extension' at compile-time too.
  (compile-time-value): New macro.
  (integer-ref, integer-set): New procedures.
  (define-integer-reader, define-integer-writer): New macros.
  (%read-int, %read-long, %write-int!, %write-long!, %read-unsigned-int,
  %read-unsigned-long, %write-unsigned-int!, %write-unsigned-long!,
  %read-size_t, %write-size_t!, %read-pointer, %write-pointer!): New
  procedures.
  (*writers*): Add writers for `int', `unsigned-int', `long',
  `unsigned-long', `size_t', and `*'.
  (*readers*): Likewise.

* test-suite/tests/foreign.test ("structs")["int8, pointer",
  "unsigned-long, int8, size_t", "long, int, pointer"]: New tests.
This commit is contained in:
Ludovic Courtès 2010-11-11 16:09:22 +01:00
commit fb636a1cce
2 changed files with 115 additions and 4 deletions

View file

@ -187,6 +187,27 @@
(pass-if "alignment constraints honored"
(let ((layout (list int8 double))
(data (list -7 3.14)))
(equal? (parse-c-struct (make-c-struct layout data)
layout)
data)))
(pass-if "int8, pointer"
(let ((layout (list uint8 '*))
(data (list 222 (make-pointer 7777))))
(equal? (parse-c-struct (make-c-struct layout data)
layout)
data)))
(pass-if "unsigned-long, int8, size_t"
(let ((layout (list unsigned-long int8 size_t))
(data (list (expt 2 17) -128 (expt 2 18))))
(equal? (parse-c-struct (make-c-struct layout data)
layout)
data)))
(pass-if "long, int, pointer"
(let ((layout (list long int '*))
(data (list (- (expt 2 17)) -222 (make-pointer 777))))
(equal? (parse-c-struct (make-c-struct layout data)
layout)
data))))