
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

Hi Kazu, On Sat, Feb 23, 2013 at 11:42:07AM +0900, Kazu Yamamoto wrote:
I'm now looking into a bug of the poll backend.
Great!
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.
But this is not generic enough. Any suggestions to fix this?
According to my manpage, it's an nfds_t. Is that type as portable as poll is? Thanks Ian

But this is not generic enough. Any suggestions to fix this?
According to my manpage, it's an nfds_t. Is that type as portable as poll is?
If we use nfds_t in C source code, it is portable. But I cannot find a Haskell type to express it in Foreign.C.Types. So, my question is how I can express nfds_t in Haskell? --Kazu

On Sat, Feb 23, 2013 at 11:59:35AM +0900, Kazu Yamamoto wrote:
But this is not generic enough. Any suggestions to fix this?
According to my manpage, it's an nfds_t. Is that type as portable as poll is?
If we use nfds_t in C source code, it is portable. But I cannot find a Haskell type to express it in Foreign.C.Types. So, my question is how I can express nfds_t in Haskell?
The best way is probably to use hsc2hs: make it a .hsc file, and use #type nfds_t It's probably worth making a newtype, or at least a type synonym, for it. Thanks Ian

Ah, I got it. Thanks.
I will make a ticket and send a patch.
Done: http://hackage.haskell.org/trac/ghc/ticket/7714 --Kazu
participants (2)
-
Ian Lynagh
-
Kazu Yamamoto