Ticket #7519: 0001-Move-CLK_TCK-check-out-to-a-C-file.patch

File 0001-Move-CLK_TCK-check-out-to-a-C-file.patch, 2.4 KB (added by singpolyma, 2 years ago)
  • System/CPUTime.hsc

    >From 3690bb13bf0879c9112d47fd2195b9f2683e1b07 Mon Sep 17 00:00:00 2001
    From: Stephen Paul Weber <[email protected]>
    Date: Tue, 11 Dec 2012 19:10:38 -0500
    Subject: [PATCH] Move CLK_TCK check out to a C file
    
    This removes the assumption that CLK_TCK is a constant (which is not
    true on QNXNTO).
    ---
     System/CPUTime.hsc |   21 +++------------------
     base.cabal         |    1 +
     cbits/sysconf.c    |   19 +++++++++++++++++++
     3 files changed, 23 insertions(+), 18 deletions(-)
     create mode 100644 cbits/sysconf.c
    
    diff --git a/System/CPUTime.hsc b/System/CPUTime.hsc
    index 8934a7e..4d988a7 100644
    a b import Foreign.C 
    4343import System.IO.Unsafe (unsafePerformIO) 
    4444#endif 
    4545 
    46 -- For _SC_CLK_TCK 
    47 #if HAVE_UNISTD_H 
    48 #include <unistd.h> 
    49 #endif 
    50  
    5146-- For struct rusage 
    5247#if !defined(mingw32_HOST_OS) && !defined(irix_HOST_OS) 
    5348# if HAVE_SYS_RESOURCE_H 
    import System.IO.Unsafe (unsafePerformIO) 
    6055#include <windows.h> 
    6156#endif 
    6257 
    63 -- for CLK_TCK 
    64 #if HAVE_TIME_H 
    65 #include <time.h> 
    66 #endif 
    67  
    6858-- for struct tms 
    6959#if HAVE_SYS_TIMES_H 
    7060#include <sys/times.h> 
    cpuTimePrecision = round ((1000000000000::Integer) % fromIntegral (clockTicks)) 
    185175#endif 
    186176 
    187177#ifdef __GLASGOW_HASKELL__ 
     178foreign import ccall unsafe clk_tck :: CLong 
     179 
    188180clockTicks :: Int 
    189 clockTicks = 
    190 #if defined(CLK_TCK) 
    191     (#const CLK_TCK) 
    192 #else 
    193     unsafePerformIO (sysconf (#const _SC_CLK_TCK) >>= return . fromIntegral) 
    194 foreign import ccall unsafe sysconf :: CInt -> IO CLong 
    195 #endif 
     181clockTicks = fromIntegral clk_tck 
    196182#endif /* __GLASGOW_HASKELL__ */ 
    197  
  • base.cabal

    diff --git a/base.cabal b/base.cabal
    index 28ccdd6..05ca157 100644
    a b Library { 
    223223        cbits/inputReady.c 
    224224        cbits/primFloat.c 
    225225        cbits/md5.c 
     226        cbits/sysconf.c 
    226227    include-dirs: include 
    227228    includes:    HsBase.h 
    228229    install-includes:    HsBase.h HsBaseConfig.h EventConfig.h WCsubst.h consUtils.h Typeable.h 
  • new file cbits/sysconf.c

    diff --git a/cbits/sysconf.c b/cbits/sysconf.c
    new file mode 100644
    index 0000000..bbf7853
    - +  
     1#include "HsBaseConfig.h" 
     2 
     3/* For _SC_CLK_TCK */ 
     4#if HAVE_UNISTD_H 
     5#include <unistd.h> 
     6#endif 
     7 
     8/* for CLK_TCK */ 
     9#if HAVE_TIME_H 
     10#include <time.h> 
     11#endif 
     12 
     13long clk_tck(void) { 
     14#if defined(CLK_TCK) 
     15    return (CLK_TCK); 
     16#else 
     17    return sysconf(_SC_CLK_TCK); 
     18#endif 
     19}