Skip to content
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

Add support for marshalling unsigned long long (CULLong) #243

Merged
merged 1 commit into from
Sep 28, 2019
Merged
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
6 changes: 4 additions & 2 deletions src/C2HS/CHS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -524,13 +524,15 @@ showCHSModule (CHSModule fragments) pureHaskell =
showFrags _ _ [] = id
showFrags pureHs state (CHSVerb s pos : frags) =
let
(fname,line) = (posFile pos, posRow pos)
generated = isBuiltinPos pos
emitNow = state == Emit ||
(state == Wait && not (null s) && head s == '\n')
nextState = if generated then Wait else NoLine
in
(if emitNow then
(if emitNow && isSourcePos pos
then
let (fname,line) = (posFile pos, posRow pos)
in
showString ("\n{-# LINE " ++ show (line `max` 0) ++ " " ++
show fname ++ " #-}\n")
else id)
Expand Down
2 changes: 2 additions & 0 deletions src/C2HS/Gen/Bind.hs
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,8 @@ isIntegralHsType "CInt" = True
isIntegralHsType "CUInt" = True
isIntegralHsType "CLong" = True
isIntegralHsType "CULong" = True
isIntegralHsType "CLLong" = True
isIntegralHsType "CULLong" = True
isIntegralHsType _ = False

-- | check for floating Haskell types
Expand Down
12 changes: 12 additions & 0 deletions tests/bugs/issue-242/Issue242.chs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Main where
import Foreign.C.Types(CULLong)
#include "issue242.h"

{# fun echoCULLong as ^ {`CULLong'} -> `CULLong' #}

main :: IO ()
main = do
let input :: CULLong
input = 1
output <- echoCULLong input
putStrLn (show output)
7 changes: 7 additions & 0 deletions tests/bugs/issue-242/issue242.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <stdlib.h>

#include "issue242.h"

unsigned long long int echoCULLong (unsigned long long int i) {
return i;
}
1 change: 1 addition & 0 deletions tests/bugs/issue-242/issue242.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
unsigned long long int echoCULLong (unsigned long long int i);
4 changes: 4 additions & 0 deletions tests/test-bugs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ tests =
, testCase "Issue #180" issue180
, testCase "Issue #192" issue192
, testCase "Issue #230" issue230
, testCase "Issue #242" issue242
] ++
-- Some tests that won't work on Windows.
if os /= "cygwin32" && os /= "mingw32"
Expand All @@ -115,6 +116,9 @@ call_capital = c2hsShelly $ chdir "tests/bugs/call_capital" $ do
let expected = ["upper C();", "lower c();", "upper C();"]
liftIO $ assertBool "" (T.lines res == expected)

issue242 :: Assertion
issue242 = expect_issue 242 ["1"]

issue230 :: Assertion
issue230 = expect_issue 230 ["1", "2", "3", "4.0", "5", "6", "True", "8.0"]

Expand Down