I am trying to represent Haskell vector arbitrary nested pairs (i.e. Vector (Int64, (Int64, (...))) ) as a 2-d array in C (i.e. int64_t** ), first indexed as a vector component , then the tuple component.
Here is my C function:
void test(int64_t** y, int32_t vecSize int16_t tupSize, int64_t* tup) { printf("Tup vals: "); for(int i = 0; i < tupSize; i++) { printf("%" PRId64 ",",tup[i]); } printf("\n"); printf("vec\n"); for(int i = 0; i < vecSize; i++) { printf("%d: (", i); for(int j = 0; j < tupSize; j++) { printf("%" PRId64 ",", y[i][j]); } printf(")\n"); } }
On the Haskell side, I have:
{-
Will print
Moduli: 10,11, vec Segmentation fault
which makes me think that my Storable (a,b) instance is fine: I get a pointer to (Int64,Int64) and then drop it on Ptr Int64 and read the data only in order. C. The question is what goes wrong with the vector? I'm trying to do the same thing: create a Vector (Int64, Int64) , get a pointer like Ptr (Int64, Int64) and pass it to Ptr (Ptr Int64) . Why do I get segfault when I try to access an array in C, and what is the correct way to marshal it?
source share