summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiklas Hambüchen <mail@nh2.me>2019-05-17 02:50:03 +0200
committerNiklas Hambüchen <mail@nh2.me>2019-05-17 04:36:32 +0200
commite9da224bce287653f96235bd6ae02da6f8f8b219 (patch)
treed24faa6ac28ceef0aab01127ea531a976a2eabb1
parentc4b80ef9951b533d6bbbb34df8109f3290546296 (diff)
Allow disabling random_r() usage manually. See #279.
This allows building hmatrix against the musl libc, which allows easily linking Haskell programs statically. A feature-detection for random_r() would be even better, but this will do for now.
-rw-r--r--packages/base/hmatrix.cabal8
-rw-r--r--packages/base/src/Internal/C/vector-aux.c8
2 files changed, 12 insertions, 4 deletions
diff --git a/packages/base/hmatrix.cabal b/packages/base/hmatrix.cabal
index 1380a36..c371ae7 100644
--- a/packages/base/hmatrix.cabal
+++ b/packages/base/hmatrix.cabal
@@ -36,6 +36,11 @@ flag disable-default-paths
36 default: False 36 default: False
37 manual: True 37 manual: True
38 38
39flag no-random_r
40 description: When enabled, don't depend on the random_r() C function.
41 default: False
42 manual: True
43
39library 44library
40 45
41 Build-Depends: base >= 4.8 && < 5, 46 Build-Depends: base >= 4.8 && < 5,
@@ -99,6 +104,9 @@ library
99 cc-options: -msse2 104 cc-options: -msse2
100 105
101 106
107 if flag(no-random_r)
108 cc-options: -DNO_RANDOM_R
109
102 if os(OSX) 110 if os(OSX)
103 if flag(openblas) 111 if flag(openblas)
104 if !flag(disable-default-paths) 112 if !flag(disable-default-paths)
diff --git a/packages/base/src/Internal/C/vector-aux.c b/packages/base/src/Internal/C/vector-aux.c
index dcd6c0b..08dc835 100644
--- a/packages/base/src/Internal/C/vector-aux.c
+++ b/packages/base/src/Internal/C/vector-aux.c
@@ -932,20 +932,20 @@ int vectorScan(char * file, int* n, double**pp){
932 932
933//////////////////////////////////////////////////////////////////////////////// 933////////////////////////////////////////////////////////////////////////////////
934 934
935#if defined (__APPLE__) || (__FreeBSD__) 935#if defined (__APPLE__) || (__FreeBSD__) || defined(NO_RANDOM_R)
936/* FreeBSD and Mac OS X do not provide random_r(), thread safety cannot be 936/* FreeBSD and Mac OS X do not provide random_r(), thread safety cannot be
937 guaranteed. 937 guaranteed.
938 For FreeBSD and Mac OS X, nrand48() is much better than random(). 938 For FreeBSD and Mac OS X, nrand48() is much better than random().
939 See: http://www.evanjones.ca/random-thread-safe.html 939 See: http://www.evanjones.ca/random-thread-safe.html
940*/ 940*/
941#pragma message "randomVector is not thread-safe in OSX and FreeBSD" 941#pragma message "randomVector is not thread-safe in OSX and FreeBSD or with NO_RANDOM_R"
942#endif 942#endif
943 943
944#if defined (__APPLE__) || (__FreeBSD__) || defined(_WIN32) || defined(WIN32) 944#if defined (__APPLE__) || (__FreeBSD__) || defined(NO_RANDOM_R) || defined(_WIN32) || defined(WIN32)
945/* Windows use thread-safe random 945/* Windows use thread-safe random
946 See: http://stackoverflow.com/questions/143108/is-windows-rand-s-thread-safe 946 See: http://stackoverflow.com/questions/143108/is-windows-rand-s-thread-safe
947*/ 947*/
948#if defined (__APPLE__) || (__FreeBSD__) 948#if defined (__APPLE__) || (__FreeBSD__) || defined(NO_RANDOM_R)
949 949
950inline double urandom() { 950inline double urandom() {
951 /* the probalility of matching will be theoretically p^3(in fact, it is not) 951 /* the probalility of matching will be theoretically p^3(in fact, it is not)