diff --git a/test/ffi/ffiTest.c b/test/ffi/ffiTest.c index 8f8d82e0..50463c5e 100644 --- a/test/ffi/ffiTest.c +++ b/test/ffi/ffiTest.c @@ -319,4 +319,19 @@ void manyargs(ManyArgs0 a0, int8_t (*a1)[7], int8_t a2[4], int8_t* mut) { *mut++ = a1[1][6]; *mut++ = a2[0]; *mut++ = a2[3]; +} + +typedef struct StructOfPtrs { + void* ptr1; + int32_t* ptr2; + int32_t* ptrs[2]; +} StructOfPtrs; + + +StructOfPtrs operateOnStructOfPtrs(StructOfPtrs arg, StructOfPtrs ptr[2]) { + return (StructOfPtrs) { + .ptr1 = arg.ptr2, + .ptr2 = ptr[0].ptr1, + .ptrs = {arg.ptrs[0], ptr[1].ptrs[1]} + }; } \ No newline at end of file diff --git a/test/ffi/test.bqn b/test/ffi/test.bqn index b45e23f3..f4bd6712 100644 --- a/test/ffi/test.bqn +++ b/test/ffi/test.bqn @@ -123,6 +123,15 @@ Section "# nested" •Show F ⟨fn, ↕10⟩ } +Section "# Struct of pointers" +{ + malloc ← "lib.so" •FFI ⟨"*u8", "malloc", ">u64"⟩ + p ← Malloc 100 + sop ← "{*,*i32,[2]*}" + f ← "lib.so"•FFI ⟨sop, "operateOnStructOfPtrs", sop, "[2]"∾sop⟩ + •Show {(𝕩.Cast "u8").Sub p}⚇0 F {(p.Add 𝕩).Cast ""}⚇0 ⟨1,2,3‿4⟩⊸+⚇0 ⟨10, 20‿30⟩ +} + # erroring: diff --git a/test/ffi/test.expected b/test/ffi/test.expected index abae41e1..1fc364e0 100644 --- a/test/ffi/test.expected +++ b/test/ffi/test.expected @@ -133,3 +133,6 @@ text # nested ⟨ 3 4 5 6 0 ⟩ ⟨ 123 ⟨ 0 1 2 30 4 5 6 7 8 9 ⟩ ⟩ + +# Struct of pointers +⟨ 12 21 ⟨ 13 34 ⟩ ⟩