summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2010-01-26 22:55:58 +0100
committerAndy Wingo <wingo@pobox.com>2010-01-26 22:56:42 +0100
commitc612ed59ab3ba92a0b778d30f21c493341160df2 (patch)
tree50754449a66bb9ea1ac4ca514caafcc67db3b7d9
parent75383ddbd77d5981e5ab4ac72818b96d391c9e22 (diff)
downloadguile-c612ed59ab3ba92a0b778d30f21c493341160df2.tar.gz
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....
-rwxr-xr-xtest-suite/standalone/test-ffi10
-rw-r--r--test-suite/standalone/test-ffi-lib.c14
2 files changed, 24 insertions, 0 deletions
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;
+}