Re: [PATCH] [base] CLK_TCK issue for QNXNTO

Stephen Paul Weber <[email protected]>
Newsgroups gmane.comp.lang.haskell.cvs.ghc
Message-ID <[email protected]>
Somebody claiming to be Stephen Paul Weber wrote:
>Somebody claiming to be Stephen Paul Weber wrote:
>>When I try to build base for QNXNTO (BlackBerry 10) using my 
>>cross-compiler I get an error about "test_array is not of static 
>>size" or similar.
>Looking up CLK_TCK in the QNXNTO time.h:
>
>/* CLK_TCK removed in 1003.1-2001 */
># define CLK_TCK _sysconf(3) /* 3 == _SC_CLK_TCK */

The attached patch solves this in a non-QNX-specific way that I think is a 
good way forward, but I am of course open to any other suggestions.

-- 
Stephen Paul Weber, @singpolyma
See <http://singpolyma.net> for how I prefer to be contacted
edition right joseph

_______________________________________________
Cvs-ghc mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/cvs-ghc
0001-Move-CLK_TCK-check-out-to-a-C-file.patch (text/x-diff, 2.4 KB)
>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/System/CPUTime.hsc
+++ b/System/CPUTime.hsc
@@ -43,11 +43,6 @@ import Foreign.C
 import System.IO.Unsafe (unsafePerformIO)
 #endif
 
--- For _SC_CLK_TCK
-#if HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
 -- For struct rusage
 #if !defined(mingw32_HOST_OS) && !defined(irix_HOST_OS)
 # if HAVE_SYS_RESOURCE_H
@@ -60,11 +55,6 @@ import System.IO.Unsafe (unsafePerformIO)
 #include <windows.h>
 #endif
 
--- for CLK_TCK
-#if HAVE_TIME_H
-#include <time.h>
-#endif
-
 -- for struct tms
 #if HAVE_SYS_TIMES_H
 #include <sys/times.h>
@@ -185,13 +175,8 @@ cpuTimePrecision = round ((1000000000000::Integer) % fromIntegral (clockTicks))
 #endif
 
 #ifdef __GLASGOW_HASKELL__
+foreign import ccall unsafe clk_tck :: CLong
+
 clockTicks :: Int
-clockTicks =
-#if defined(CLK_TCK)
-    (#const CLK_TCK)
-#else
-    unsafePerformIO (sysconf (#const _SC_CLK_TCK) >>= return . fromIntegral)
-foreign import ccall unsafe sysconf :: CInt -> IO CLong
-#endif
+clockTicks = fromIntegral clk_tck
 #endif /* __GLASGOW_HASKELL__ */
-
diff --git a/base.cabal b/base.cabal
index 28ccdd6..05ca157 100644
--- a/base.cabal
+++ b/base.cabal
@@ -223,6 +223,7 @@ Library {
         cbits/inputReady.c
         cbits/primFloat.c
         cbits/md5.c
+        cbits/sysconf.c
     include-dirs: include
     includes:    HsBase.h
     install-includes:    HsBase.h HsBaseConfig.h EventConfig.h WCsubst.h consUtils.h Typeable.h
diff --git a/cbits/sysconf.c b/cbits/sysconf.c
new file mode 100644
index 0000000..bbf7853
--- /dev/null
+++ b/cbits/sysconf.c
@@ -0,0 +1,19 @@
+#include "HsBaseConfig.h"
+
+/* For _SC_CLK_TCK */
+#if HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+/* for CLK_TCK */
+#if HAVE_TIME_H
+#include <time.h>
+#endif
+
+long clk_tck(void) {
+#if defined(CLK_TCK)
+    return (CLK_TCK);
+#else
+    return sysconf(_SC_CLK_TCK);
+#endif
+}
-- 
1.7.10.4
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.