From 0fed6e67db6104fb6e8ef5183ee4837cd4d9e42a Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Fri, 2 Mar 2018 19:20:22 +0000 Subject: [Minor] Unlink ottery from torch to fix build on some platforms --- contrib/torch/torch7/CMakeLists.txt | 1 - contrib/torch/torch7/lib/TH/CMakeLists.txt | 2 -- contrib/torch/torch7/lib/TH/THRandom.c | 29 +++++++++++++++++++++++++++-- 3 files changed, 27 insertions(+), 5 deletions(-) (limited to 'contrib') diff --git a/contrib/torch/torch7/CMakeLists.txt b/contrib/torch/torch7/CMakeLists.txt index aa848905a..7519e85d7 100644 --- a/contrib/torch/torch7/CMakeLists.txt +++ b/contrib/torch/torch7/CMakeLists.txt @@ -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}) diff --git a/contrib/torch/torch7/lib/TH/CMakeLists.txt b/contrib/torch/torch7/lib/TH/CMakeLists.txt index c76d26e06..2b71bc3d0 100644 --- a/contrib/torch/torch7/lib/TH/CMakeLists.txt +++ b/contrib/torch/torch7/lib/TH/CMakeLists.txt @@ -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) diff --git a/contrib/torch/torch7/lib/TH/THRandom.c b/contrib/torch/torch7/lib/TH/THRandom.c index 0dca555fd..86d721e7b 100644 --- a/contrib/torch/torch7/lib/TH/THRandom.c +++ b/contrib/torch/torch7/lib/TH/THRandom.c @@ -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 +#include +#include +#include + +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; } -- cgit v1.2.3