Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions inline-c/src/Language/C/Inline/Context.hs
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,17 @@ convertType purity cTypes = runMaybeT . go
-- We cannot convert standalone prototypes
mzero

buildArr :: [TH.Type] -> TH.Type -> TH.Q TH.Type
buildArr [] hsRetType =
case purity of
Pure -> [t| $(return hsRetType) |]
IO -> [t| IO $(return hsRetType) |]
buildArr [TH.TupleT 0] hsRetType =
case purity of
Pure -> [t| $(return hsRetType) |]
IO -> [t| IO $(return hsRetType) |]
buildArr (TH.TupleT 0 : hsPars) hsRetType =
fail "C function can only have void parameter as the only parameter"
buildArr (hsPar : hsPars) hsRetType =
[t| $(return hsPar) -> $(buildArr hsPars hsRetType) |]

Expand Down
4 changes: 4 additions & 0 deletions inline-c/test/Language/C/Inline/ContextSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ spec = do
shouldBeType
(cty "int (*f)(unsigned char, float)")
[t| FunPtr (CUChar -> CFloat -> IO CInt) |]
Hspec.it "converts void parameter function pointer" $ do
shouldBeType
(cty "void (*f)(void)")
[t| FunPtr (IO ()) |]
Hspec.it "converts complicated function pointers (1)" $ do
-- pointer to function returning pointer to function returning int
shouldBeType
Expand Down
Loading