Skip to content

Conversation

@dolio
Copy link
Contributor

@dolio dolio commented Dec 18, 2025

This PR builds on #6060, extending the DLL import FFI to allow you to pass PinnedByteArray as an argument. The array is automatically handled to get the underlying pointer, so no more complex machinery in unison is necessary.

Importantly, this doesn't allow importing functions that return arrays/pointers. I'm not sure there's actually a way to create the right Haskell type given a C pointer (aside from copying). And to properly handle returned C pointers, we need to wrap Haskell's system for associating finalizers to pointers (ForeignPtr), so that any deallocation procedure can be performed on garbage collection. I suppose this isn't strictly the case, but any use of C pointers would have to be very short lived, so I'm leaving it for when I do the above work.

I added an additional test case that fills a unison-allocated pinned array with bytes from 1 to 32 using a C loop.

Should be merged after #6060.

@aryairani
Copy link
Contributor

aryairani commented Dec 19, 2025

After merging #6060, there's a merge conflict here now; not sure whether store a i p does inside or outside of the do.
I'm giving merging it a shot.

@aryairani aryairani merged commit b715d59 into trunk Dec 19, 2025
44 of 45 checks passed
@aryairani aryairani deleted the topic/ffi-array-types branch December 19, 2025 20:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants