-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
C types with void explicitly in the parameter list (e.g. void (*)(void)) are assigned the wrong Haskell type #155
Comments
As a workaround you can declare the type without a parameter list, e.g. |
Hi, The current version works as follows. Hspec.it "converts function pointer without a parameter" $ do
shouldBeType
(cty "void (*f)()")
[t| FunPtr (IO ()) |]
Hspec.it "converts void parameter function pointer" $ do
shouldBeType
(cty "void (*f)(void)")
[t| FunPtr (() -> IO ()) |] |
In the above example, there is no need to cast, so what if you changed |
Yes that works as a workaround I agree. However, I think that
Notice how Further more in C, not specifying void in the parameter list technically defines a prototype without information about function parameters. Supporting this in inline-c seems completely unnecessary (and incompatible with C++), however it seems harmless to support the void in the parameter list when most likely any existing use would fail to compile, due to |
As a further more minimal example this program fails to compile with any combination of the 3 lines in main uncommented: #!/usr/bin/env stack
{- stack script
--resolver lts-21.24
--package inline-c
-}
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
module Main where
import Foreign
import qualified Language.C.Inline as C
C.context (C.baseCtx <> C.funCtx)
dummy :: () -> IO ()
dummy () = pure ()
main :: IO ()
main = do
-- wrapped :: FunPtr (() -> IO ()) <- $(C.mkFunPtr [t|() -> IO ()|]) dummy
let unwrapped = $(C.peekFunPtr [t|() -> IO ()|]) (undefined :: FunPtr (() -> IO ()))
-- [C.exp| void { $fun:(void (*dummy)(void))() } |]
pure () With this configuration the error is:
|
At first glance it seems harmless.
|
Going by the documentation on FunPtr I think all of these are also illegal. Certainly the equivalent C types aren't valid, |
When attempting to invoke a function with a void argument like in this snippet:
I get an error like so:
Inspecting the
FunPtr
docs, I see that this is not the expected type for a function pointer of typevoid (*)(void)
instead it should have typeIO ()
or()
. The bug is in buildArr in the antiquoter for$fun:
. I'm working on a fix and will make a PR shortly.The text was updated successfully, but these errors were encountered: