FFI to poll()

Kazu Yamamoto ( 山本和彦 ) kazu at iij.ad.jp
Sat Feb 23 03:42:07 CET 2013


Hello,

I'm now looking into a bug of the poll backend.

base/GHC/Event/Poll.hsc declares FFI to poll() as follows:

	foreign import ccall safe "poll.h poll"
	    c_poll :: Ptr PollFd -> CULong -> CInt -> IO CInt

The second argument is defined unsigned long on Linux. However, it is
unsigned int on Mac and FreeBSD. I think this is a source of the bug
which I'm looking into.

A simple fix is like this:

#if defined(freebsd_HOST_OS) || defined(darwin_HOST_OS)
foreign import ccall safe "poll.h poll"
    c_poll :: Ptr PollFd -> CUInt -> CInt -> IO CInt
#else
foreign import ccall safe "poll.h poll"
    c_poll :: Ptr PollFd -> CULong -> CInt -> IO CInt
#endif

But this is not generic enough. Any suggestions to fix this?

--Kazu



More information about the ghc-devs mailing list