[Haskell-iPhone] Pointers coming back into haskell from FFI on iPhone getting destroyed

Mike Rotondo mrotondo at gmail.com
Tue Sep 11 12:02:43 CEST 2012


Hi there fellow adventurers,

I'm currently working on getting
distributed-process<http://hackage.haskell.org/package/distributed-process>
working
on iOS, and I'm running into some issues that I think are rooted in the
ghc-ios fork, rather than in the networking code that I've been puzzling
through. I'm making a call to Network.Socket.getAddrInfo, which does an FFI
call to getaddrinfo, the POSIX function. This function takes a double
pointer to a struct that it fills in with information about a network
address, and this struct contains a pointer to another struct. Here's where
things go awry: This nested pointer is intact and valid when the c function
(getaddrinfo) returns (I'm calling it from a wrapper function so I can
inspect the contents before we return to Haskell), but once Haskell gets
control-flow back, the nested pointer has been over-written, either with
NULL (usually) or a pointer to some faraway & invalid memory, either of
which cause EXC_BAD_ACCESS when haskell tries to #peek values out of the
nested struct.

Because I can see that the C function is completing successfully, and that
its pointers and contents are all valid before Haskell gets them, I suspect
that there is some underlying issue with the way iOS/ARM is handling the
pointers when they are returned to Haskell. I'm going to try to set up a
minimal repro tomorrow so I can investigate further, but in the meantime,
does anyone who has worked on implementing this ghc fork have a clue what
might be going wrong?

Thanks much,
Mike R
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/iphone/attachments/20120911/b2567c2a/attachment.htm>


More information about the iPhone mailing list