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

Check C methods exit code on unix platforms. #66

Merged
merged 3 commits into from
Jan 21, 2021
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
12 changes: 5 additions & 7 deletions System/Clock.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import Control.Applicative ((<$>), (<*>))
import Data.Int
import Data.Word
import Data.Typeable (Typeable)
import Foreign.C
import Foreign.Ptr
import Foreign.Storable
import Foreign.Marshal.Alloc
Expand Down Expand Up @@ -127,12 +128,9 @@ foreign import ccall unsafe hs_clock_win32_getres_monotonic :: Ptr TimeSpec -> I
foreign import ccall unsafe hs_clock_win32_getres_realtime :: Ptr TimeSpec -> IO ()
foreign import ccall unsafe hs_clock_win32_getres_processtime :: Ptr TimeSpec -> IO ()
foreign import ccall unsafe hs_clock_win32_getres_threadtime :: Ptr TimeSpec -> IO ()
#elif defined(__MACH__) && defined(__APPLE__)
foreign import ccall unsafe hs_clock_darwin_gettime :: #{type clock_id_t} -> Ptr TimeSpec -> IO ()
foreign import ccall unsafe hs_clock_darwin_getres :: #{type clock_id_t} -> Ptr TimeSpec -> IO ()
#else
foreign import ccall unsafe clock_gettime :: #{type clockid_t} -> Ptr TimeSpec -> IO ()
foreign import ccall unsafe clock_getres :: #{type clockid_t} -> Ptr TimeSpec -> IO ()
foreign import ccall unsafe clock_gettime :: #{type clockid_t} -> Ptr TimeSpec -> IO CInt
foreign import ccall unsafe clock_getres :: #{type clockid_t} -> Ptr TimeSpec -> IO CInt
#endif

#if !defined(_WIN32)
Expand Down Expand Up @@ -174,7 +172,7 @@ getTime Realtime = allocaAndPeek hs_clock_win32_gettime_realtime
getTime ProcessCPUTime = allocaAndPeek hs_clock_win32_gettime_processtime
getTime ThreadCPUTime = allocaAndPeek hs_clock_win32_gettime_threadtime
#else
getTime clk = allocaAndPeek $! clock_gettime $! clockToConst clk
getTime clk = allocaAndPeek $! throwErrnoIfMinus1_ "clock_gettime" . clock_gettime (clockToConst clk)
#endif

#if defined(_WIN32)
Expand All @@ -183,7 +181,7 @@ getRes Realtime = allocaAndPeek hs_clock_win32_getres_realtime
getRes ProcessCPUTime = allocaAndPeek hs_clock_win32_getres_processtime
getRes ThreadCPUTime = allocaAndPeek hs_clock_win32_getres_threadtime
#else
getRes clk = allocaAndPeek $! clock_getres $! clockToConst clk
getRes clk = allocaAndPeek $! throwErrnoIfMinus1_ "clock_getres" . clock_getres (clockToConst clk)
#endif

-- | TimeSpec structure
Expand Down
9 changes: 5 additions & 4 deletions clock.cabal
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
cabal-version: >= 1.10
name: clock
version: 0.8
stability: stable
Expand Down Expand Up @@ -49,7 +50,6 @@ homepage: https://github.com/corsis/clock
bug-reports: https://github.com/corsis/clock/issues
category: System
build-type: Simple
cabal-version: >= 1.8


source-repository head
Expand All @@ -63,11 +63,12 @@ flag llvm


library
default-language: Haskell2010
if impl (ghc < 7.6)
build-depends: base >= 4.4 && <= 5, ghc-prim
build-depends: base >= 2 && <= 5
exposed-modules: System.Clock
extensions: DeriveGeneric
default-extensions: DeriveGeneric
DeriveDataTypeable
ForeignFunctionInterface
ScopedTypeVariables
Expand All @@ -82,8 +83,7 @@ library


test-suite test
-- default-language:
-- Haskell2010
default-language: Haskell2010
type:
exitcode-stdio-1.0
hs-source-dirs:
Expand All @@ -97,6 +97,7 @@ test-suite test
, clock

benchmark benchmarks
default-language: Haskell2010
type:
exitcode-stdio-1.0
hs-source-dirs:
Expand Down