From 1cebe6466424d024f11f7bc77eb6afd2bad62a84 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Tue, 20 Sep 2022 10:00:55 -0500 Subject: [PATCH] Add some soft test cases for #1037. --- examples/ffi/so.c | 81 +++++++++++++++++++++++++++-------------- examples/ffi/test.janet | 12 ++++-- 2 files changed, 63 insertions(+), 30 deletions(-) diff --git a/examples/ffi/so.c b/examples/ffi/so.c index a5873fb2..2549ed06 100644 --- a/examples/ffi/so.c +++ b/examples/ffi/so.c @@ -8,6 +8,41 @@ #define EXPORTER #endif +/* Structs */ + +typedef struct { + int a, b; + float c, d; +} Split; + +typedef struct { + float c, d; + int a, b; +} SplitFlip; + +typedef struct { + int u, v, w, x, y, z; +} SixInts; + +typedef struct { + int a; + int b; +} intint; + +typedef struct { + int a; + int b; + int c; +} intintint; + +typedef struct { + int64_t a; + int64_t b; + int64_t c; +} big; + +/* Functions */ + EXPORTER int int_fn(int a, int b) { return (a << 2) + b; @@ -73,17 +108,6 @@ double float_fn(float x, float y, float z) { return (x + y) * z; } -typedef struct { - int a; - int b; -} intint; - -typedef struct { - int a; - int b; - int c; -} intintint; - EXPORTER int intint_fn(double x, intint ii) { printf("double: %g\n", x); @@ -104,12 +128,6 @@ intint return_struct(int i) { return ret; } -typedef struct { - int64_t a; - int64_t b; - int64_t c; -} big; - EXPORTER big struct_big(int i, double d) { big ret; @@ -139,16 +157,6 @@ int intintint_fn_2(intintint iii, int i) { return i * (iii.a + iii.b + iii.c); } -typedef struct { - int a, b; - float c, d; -} Split; - -typedef struct { - float c, d; - int a, b; -} SplitFlip; - EXPORTER float split_fn(Split s) { return s.a * s.c + s.b * s.d; @@ -178,3 +186,22 @@ SplitFlip split_flip_ret_fn(int x, float y) { ret.d = y; return ret; } + +EXPORTER +SixInts sixints_fn(void) { + return (SixInts) { + 6666, 1111, 2222, 3333, 4444, 5555 + }; +} + +EXPORTER +int sixints_fn_2(int x, SixInts s) { + return x + s.u + s.v + s.w + s.x + s.y + s.z; +} + +EXPORTER +int sixints_fn_3(SixInts s, int x) { + return x + s.u + s.v + s.w + s.x + s.y + s.z; +} + + diff --git a/examples/ffi/test.janet b/examples/ffi/test.janet index 8c2361f2..40f631f6 100644 --- a/examples/ffi/test.janet +++ b/examples/ffi/test.janet @@ -14,6 +14,9 @@ (def intintint (ffi/struct :int :int :int)) (def big (ffi/struct :s64 :s64 :s64)) +(def split (ffi/struct :int :int :float :float)) +(def split-flip (ffi/struct :float :float :int :int)) +(def six-ints (ffi/struct :int :int :int :int :int :int)) (ffi/defbind int-fn :int [a :int b :int]) (ffi/defbind double-fn :double [a :double b :double c :double]) @@ -45,13 +48,13 @@ j :double]) (ffi/defbind void-fn-2 :void [y :double]) (ffi/defbind intintint-fn-2 :int [iii intintint i :int]) - -(def split (ffi/struct :int :int :float :float)) -(def split-flip (ffi/struct :float :float :int :int)) (ffi/defbind split-fn :float [s split]) (ffi/defbind split-flip-fn :float [s split-flip]) (ffi/defbind split-ret-fn split [x :int y :float]) (ffi/defbind split-flip-ret-fn split-flip [x :int y :float]) +(ffi/defbind sixints-fn six-ints []) +(ffi/defbind sixints-fn-2 :int [x :int s six-ints]) +(ffi/defbind sixints-fn-3 :int [s six-ints x :int]) # # Struct reading and writing @@ -93,6 +96,9 @@ # Call functions # +(tracev (sixints-fn)) +(tracev (sixints-fn-2 100 [1 2 3 4 5 6])) +(tracev (sixints-fn-3 [1 2 3 4 5 6] 200)) (tracev (split-ret-fn 10 12)) (tracev (split-flip-ret-fn 10 12)) (tracev (split-flip-ret-fn 12 10))