In the Haskell FFI, what is the essential difference between arrays allocated with withArray and newArray? I have function in c that works with newArray but segfaults with withArray. The working code looks bit like this:
a <- newArray items
fficall a
free a
The code that segfaults looks like this:
withArray items fficall
The segfault happens up when the ffi enters a blas function. Since I’m not allowed to show the c-code, the question is, “please show me an example c-function that also segfaults with withArray but not with newArray.”
From what I can see,
newArrayends up callingmallocto do the allocation, whilewithArraycallsallocaArray, which ends up innewAlignedPinnedByteArray#.Perhaps your function is relying on the memory being allocated by
malloc, for example by attempting toreallocorfreeit?