[GHC] #11983: Can't use IntPtr or WordPtr in a foreign import
#11983: Can't use IntPtr or WordPtr in a foreign import -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: RyanGlScott Type: bug | Status: new Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.0.1 (FFI) | Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: GHC rejects Unknown/Multiple | valid program Test Case: | Blocked By: Blocking: | Related Tickets: #3008, #5529 Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- Despite the [http://hackage.haskell.org/package/base-4.8.2.0/docs/Foreign- Ptr.html#t:IntPtr docs claiming] that you can use `IntPtr` and `WordPtr` to convert to and from `intptr_t` and `uintptr_t`, you can't actually do so in a `foreign import` as of GHC 7.6. Here's a minimal example: {{{#!hs -- Example.hs {-# LANGUAGE ForeignFunctionInterface #-} module Example where {-# INCLUDE example.h #-} import Foreign.Ptr foreign import ccall "intptr_example" intPtrExample :: IntPtr -> IO () foreign import ccall "uintptr_example" wordPtrExample :: WordPtr -> IO () }}} {{{#!c // example.h #ifndef EXAMPLE_H #define EXAMPLE_H #include <stdint.h> void intptr_example(intptr_t); void uintptr_example(uintptr_t); #endif // EXAMPLE_H }}} {{{#!c // example.c #include <stdint.h> #include "example.h" void intptr_example(intptr_t i) {} void uintptr_example(uintptr_t u) {} }}} This appears to be a consequence of #3008, which prevents `newtype`s from being used as FFI types unless their constructors are exported. #5529 fixed this problem for the datatypes in `Foreign.C.Types` and `System.Posix.Types` by simply exporting their constructors, so I think all that's needed to fix this particular example is to export the constructors for `IntPtr` and `WordPtr`. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11983> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11983: Can't use IntPtr or WordPtr in a foreign import -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: RyanGlScott Type: bug | Status: patch Priority: normal | Milestone: 8.2.1 Component: Compiler (FFI) | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: #3008, #5529 | Differential Rev(s): Phab:D2142 Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * status: new => patch * differential: => Phab:D2142 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11983#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11983: Can't use IntPtr or WordPtr in a foreign import -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: RyanGlScott Type: bug | Status: patch Priority: normal | Milestone: 8.2.1 Component: Compiler (FFI) | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: #3008, #5529 | Differential Rev(s): Phab:D2142 Wiki Page: | -------------------------------------+------------------------------------- Comment (by Ben Gamari <ben@…>): In [changeset:"a28611b14930c9fd73b0028857e1ea8c0e64a38a/ghc" a28611b/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="a28611b14930c9fd73b0028857e1ea8c0e64a38a" Export constructors for IntPtr and WordPtr This finishes what #5529 started by exporting the constructors for `IntPtr` and `WordPtr` from `Foreign.Ptr`, allowing them to be used in `foreign` declarations. Fixes #11983. Test Plan: `make TEST=T11983` Reviewers: simonpj, hvr, bgamari, austin Reviewed By: simonpj Subscribers: simonpj, thomie Differential Revision: https://phabricator.haskell.org/D2142 GHC Trac Issues: #11983 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11983#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11983: Can't use IntPtr or WordPtr in a foreign import -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: RyanGlScott Type: bug | Status: closed Priority: normal | Milestone: 8.2.1 Component: Compiler (FFI) | Version: 8.0.1 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: #3008, #5529 | Differential Rev(s): Phab:D2142 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: patch => closed * resolution: => fixed -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11983#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC