[GHC] #8222: CTYPE pragma on newtype is ignored

GHC ghc-devs at haskell.org
Wed Sep 4 09:19:25 CEST 2013


#8222: CTYPE pragma on newtype is ignored
--------------------------+------------------------------------------------
       Reporter:  akio    |             Owner:
           Type:  bug     |            Status:  new
       Priority:  normal  |         Milestone:
      Component:          |           Version:  7.6.3
  Compiler                |  Operating System:  Linux
       Keywords:          |   Type of failure:  Incorrect result at runtime
   Architecture:  x86_64  |         Test Case:
  (amd64)                 |          Blocking:
     Difficulty:          |
  Unknown                 |
     Blocked By:          |
Related Tickets:          |
--------------------------+------------------------------------------------
 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.

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8222>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler




More information about the ghc-tickets mailing list