CTYPE pragma on newtype is ignored
User's guide includes an example where a CTYPE pragma is used for a newtype.
newtype {-# CTYPE "useconds_t" #-} T = ...
However, in the following program, the CTYPE pragma seems to be ignored:
{-# LANGUAGE CApiFFI #-}
import Foreign.Ptr
foreign import capi unsafe "sys/socket.h CMSG_DATA"
c_CMSG_DATA :: Ptr Cmsg -> Ptr a
newtype {-# CTYPE "sys/socket.h" "struct cmsghdr" #-} Cmsg = Cmsg ()
main = return ()
Save this as capi.hs
, then compile it like:
ghc capi.hs -fforce-recomp -keep-tmp-files -tmpdir .
Then GHC creates a C file:
#define IN_STG_CODE 0
#include "Rts.h"
#include "Stg.h"
#ifdef __cplusplus
extern "C" {
#endif
#include <sys/socket.h>
void* ghczuwrapperZC0ZCmainZCMainZCCMSGzuDATA(void* a1) {return CMSG_DATA(a1);}
#ifdef __cplusplus
}
#endif
The argument type of the wrapper function is void *
, but it should be struct cmsghdr *
.
If I replace newtype
with data
in capi.hs, the wrapper function gets the correct type.
I can see this problem in HEAD and in 7.6.3.
Trac metadata
Trac field | Value |
---|---|
Version | 7.6.3 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |