[GHC] #10505: more specific types in the generated *_stub.h files

#10505: more specific types in the generated *_stub.h files -------------------------------------+------------------------------------- Reporter: imz | Owner: Type: feature | Status: new request | Milestone: Priority: normal | Version: 7.6.1 Component: Compiler | Operating System: Linux (FFI) | Type of failure: Other Keywords: | Blocked By: Architecture: | Related Tickets: #2979, #8222 Unknown/Multiple | Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Having a declaration like: {{{#!hs foreign export ccall "respond" respond :: CWString -> IO CWString }}} all the types in the corresponding `_stub.h` are `HsPtr`. Wouldn't it be possible to write more specific types reflecting my expectations, i.e., `wchar_t *`? It would be nice in order to signal automatically to the C code which uses the Haskell functions that the types of the Haskell functions changed. In simple cases, one could simply include the stub.h, and get automatically an error if the C code doesn't match the new types. I've tried using a CTYPE pragma (cf. #2979 , #8222 ) on a newtype to get such results: {{{#!hs newtype {-# CTYPE "wchar_t *" #-} CWString' = CWString' CWString foreign export ccall "respond" respond :: CWString' -> IO CWString }}} but that still produces `HsPtr`. (Well, I see, the CTYPE pragma was mostly intended for imports rather than exports.) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10505 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10505: more specific types in the generated *_stub.h files -------------------------------------+------------------------------------- Reporter: imz | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler (FFI) | Version: 7.6.1 Resolution: | Keywords: Operating System: Linux | Architecture: Type of failure: Other | Unknown/Multiple Blocked By: | Test Case: Related Tickets: #2979, #8222 | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by imz): The same problem and wish as mine are illustrated in http://stackoverflow.com/q/23629000/94687 by an attempt to use a Haskell function on Strings . The solutions so far: Either manual editing of the `.h` file (which may result in inconsistencies with the real code, and which is additional burden), or casting in the C code (which opens the door wide for inconsistencies with the real Haskell code). -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10505#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10505: more specific types in the generated *_stub.h files -------------------------------------+------------------------------------- Reporter: imz | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler (FFI) | Version: 7.6.1 Resolution: | Keywords: Operating System: Linux | Architecture: Type of failure: Other | Unknown/Multiple Blocked By: | Test Case: Related Tickets: #2979, #8222 | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Description changed by imz: Old description:
Having a declaration like:
{{{#!hs foreign export ccall "respond" respond :: CWString -> IO CWString }}}
all the types in the corresponding `_stub.h` are `HsPtr`.
Wouldn't it be possible to write more specific types reflecting my expectations, i.e., `wchar_t *`?
It would be nice in order to signal automatically to the C code which uses the Haskell functions that the types of the Haskell functions changed. In simple cases, one could simply include the stub.h, and get automatically an error if the C code doesn't match the new types.
I've tried using a CTYPE pragma (cf. #2979 , #8222 ) on a newtype to get such results:
{{{#!hs newtype {-# CTYPE "wchar_t *" #-} CWString' = CWString' CWString foreign export ccall "respond" respond :: CWString' -> IO CWString }}}
but that still produces `HsPtr`. (Well, I see, the CTYPE pragma was mostly intended for imports rather than exports.)
New description: Having a declaration like: {{{#!hs foreign export ccall "respond" respond :: CWString -> IO CWString }}} all the types in the corresponding `_stub.h` are `HsPtr`. Wouldn't it be possible to write more specific types reflecting my expectations, i.e., `wchar_t *`? It would be nice in order to signal automatically to the C code which uses the Haskell functions that the types of the Haskell functions changed. In simple cases, one could simply include the stub.h, and get automatically an error if the C code doesn't match the new types. I've tried using a CTYPE pragma (cf. #2979 , #8222 , and https://mail.haskell.org/pipermail/haskell/2012-February/023155.html ) on a newtype to get such results: {{{#!hs newtype {-# CTYPE "wchar_t *" #-} CWString' = CWString' CWString foreign export ccall "respond" respond :: CWString' -> IO CWString }}} but that still produces `HsPtr`. (Well, I see, the CTYPE pragma was mostly intended for imports rather than exports.) -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10505#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC