]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Unlink ottery from torch to fix build on some platforms
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 2 Mar 2018 19:20:22 +0000 (19:20 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 2 Mar 2018 19:20:22 +0000 (19:20 +0000)
contrib/torch/torch7/CMakeLists.txt
contrib/torch/torch7/lib/TH/CMakeLists.txt
contrib/torch/torch7/lib/TH/THRandom.c

index aa848905a43857fded1ed89ffd22a5020a8206a0..7519e85d7df41affa7cd7dada5275ee9e9717e51 100644 (file)
@@ -63,7 +63,6 @@ SET(luasrc init.lua File.lua Tensor.lua CmdLine.lua FFInterface.lua Tester.lua T
 ADD_TORCH_PACKAGE(torch "${src}" "${luasrc}")
 
 TARGET_LINK_LIBRARIES(torch luaT TH)
-TARGET_LINK_LIBRARIES(torch ottery)
 
 IF(LUALIB)
   TARGET_LINK_LIBRARIES(torch ${LUALIB})
index c76d26e069663c4fd0ba4086470a7fdf13b375d1..2b71bc3d085eb2da8cc1e5e6e485d5649ff547a6 100644 (file)
@@ -291,8 +291,6 @@ IF(NOT MSVC)
   TARGET_LINK_LIBRARIES(TH m)
 ENDIF(NOT MSVC)
 
-TARGET_LINK_LIBRARIES(TH ottery)
-
 # Is __thread supported?
 IF(NOT MSVC)
   CHECK_C_SOURCE_COMPILES("static __thread int x = 1; int main() { return x; }" C_HAS_THREAD)
index 0dca555fd75ba14fd977832a28b5badb86e7c865..86d721e7b65ea45e6a60115b4803b23d9c31e663 100644 (file)
@@ -1,6 +1,5 @@
 #include "THGeneral.h"
 #include "THRandom.h"
-#include "ottery.h"
 
 /* Code for the Mersenne Twister random generator.... */
 #define n _MERSENNE_STATE_N
@@ -45,9 +44,35 @@ int THGenerator_isValid(THGenerator *_generator)
   return 0;
 }
 
+#ifndef _WIN32
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+static unsigned long readURandomLong()
+{
+  int randDev = open("/dev/urandom", O_RDONLY);
+  unsigned long randValue;
+  if (randDev < 0) {
+    THError("Unable to open /dev/urandom");
+  }
+  ssize_t readBytes = read(randDev, &randValue, sizeof(randValue));
+  if (readBytes < sizeof(randValue)) {
+    THError("Unable to read from /dev/urandom");
+  }
+  close(randDev);
+  return randValue;
+}
+#endif // _WIN32
+
 unsigned long THRandom_seed(THGenerator *_generator)
 {
-  unsigned long s = ottery_rand_uint64();
+#ifdef _WIN32
+  unsigned long s = (unsigned long)time(0);
+#else
+  unsigned long s = readURandomLong();
+#endif
   THRandom_manualSeed(_generator, s);
   return s;
 }