From c612ed59ab3ba92a0b778d30f21c493341160df2 Mon Sep 17 00:00:00 2001 From: Andy Wingo Date: Tue, 26 Jan 2010 22:55:58 +0100 Subject: [PATCH] add a test for foreign functions taking struct args * test-suite/standalone/test-ffi (f-sum-struct): * test-suite/standalone/test-ffi-lib.c (test_ffi_sum_struct): Add a struct test. Wheee.... --- test-suite/standalone/test-ffi | 10 ++++++++++ test-suite/standalone/test-ffi-lib.c | 14 ++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/test-suite/standalone/test-ffi b/test-suite/standalone/test-ffi index 3a0c5a11c..3e3471a59 100755 --- a/test-suite/standalone/test-ffi +++ b/test-suite/standalone/test-ffi @@ -143,6 +143,16 @@ exec guile -q -s "$0" "$@" (test (f-sum -1 2000 -30000 40000000000) (+ -1 2000 -30000 40000000000)) +;; +;; Structs +;; +(define f-sum-struct + (make-foreign-function int64 (dynamic-func "test_ffi_sum_struct" lib) + (list (list int8 int16 int32 int64)))) +(test (f-sum-struct (make-c-struct (list int8 int16 int32 int64) + (list -1 2000 -30000 40000000000))) + (+ -1 2000 -30000 40000000000)) + ;; Local Variables: ;; mode: scheme diff --git a/test-suite/standalone/test-ffi-lib.c b/test-suite/standalone/test-ffi-lib.c index 176cddf4c..d99910136 100644 --- a/test-suite/standalone/test-ffi-lib.c +++ b/test-suite/standalone/test-ffi-lib.c @@ -192,3 +192,17 @@ scm_t_int64 test_ffi_sum (scm_t_int8 a, scm_t_int16 b, { return d + c + b + a; } + + +struct foo +{ + scm_t_int8 a; + scm_t_int16 b; + scm_t_int32 c; + scm_t_int64 d; +}; +scm_t_int64 test_ffi_sum_struct (struct foo foo); +scm_t_int64 test_ffi_sum_struct (struct foo foo) +{ + return foo.d + foo.c + foo.b + foo.a; +}