Allow passing pinned arrays to DLL imported functions #6067
+1,019
−888
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR builds on #6060, extending the DLL import FFI to allow you to pass
PinnedByteArrayas 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.