configure: make C++11 <random> a required functionality
Error out if it's missing or broken (Mersenne Twister not present). This ensures that we never have a low-quality random generator in Qt. Change-Id: I0a103569c81b4711a649fffd14ec80649df7087e Reviewed-by: Lars Knoll <lars.knoll@qt.io>bb10
parent
a090076e93
commit
65eed6d597
|
|
@ -459,11 +459,6 @@
|
|||
"condition": "tests.cxx11_future",
|
||||
"output": [ "publicFeature" ]
|
||||
},
|
||||
"cxx11_random": {
|
||||
"label": "C++11 <random>",
|
||||
"condition": "tests.cxx11_random",
|
||||
"output": [ "privateFeature" ]
|
||||
},
|
||||
"eventfd": {
|
||||
"label": "eventfd",
|
||||
"condition": "tests.eventfd",
|
||||
|
|
@ -869,9 +864,9 @@ ensure that the IDEs they use either set QT_LOGGING_TO_CONSOLE to 1
|
|||
or are able to read the logged output from journald, syslog or slog2."
|
||||
},
|
||||
{
|
||||
"type": "warning",
|
||||
"condition": "!config.win32 && !config.darwin && !config.bsd && !features.cxx11_random",
|
||||
"message": "No high-quality PRNG available for QRandomGenerator fallback.\nIf the HW or OS RNG fails, Qt will abort execution."
|
||||
"type": "error",
|
||||
"condition": "!tests.cxx11_random",
|
||||
"message": "C++11 <random> is required and is missing or failed to compile."
|
||||
},
|
||||
{
|
||||
"type": "error",
|
||||
|
|
|
|||
|
|
@ -46,16 +46,15 @@
|
|||
#include <qthreadstorage.h>
|
||||
#include <private/qsimd_p.h>
|
||||
|
||||
#include <random>
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#if QT_CONFIG(getentropy)
|
||||
# include <sys/random.h>
|
||||
#else
|
||||
# if QT_CONFIG(cxx11_random)
|
||||
# include <random>
|
||||
# include "qdeadlinetimer.h"
|
||||
# include "qhashfunctions.h"
|
||||
# endif
|
||||
#elif !defined(Q_OS_BSD4) && !defined(Q_OS_WIN)
|
||||
# include "qdeadlinetimer.h"
|
||||
# include "qhashfunctions.h"
|
||||
|
||||
# if QT_CONFIG(getauxval)
|
||||
# include <sys/auxv.h>
|
||||
|
|
@ -258,7 +257,7 @@ static void fallback_fill(quint32 *ptr, qssize_t left) Q_DECL_NOTHROW
|
|||
// BSDs have arc4random(4) and these work even in chroot(2)
|
||||
arc4random_buf(ptr, left * sizeof(*ptr));
|
||||
}
|
||||
#elif QT_CONFIG(cxx11_random)
|
||||
#else
|
||||
static QBasicAtomicInteger<unsigned> seed = Q_BASIC_ATOMIC_INITIALIZER(0U);
|
||||
static void fallback_update_seed(unsigned value)
|
||||
{
|
||||
|
|
@ -343,12 +342,6 @@ static void fallback_fill(quint32 *ptr, qssize_t left) Q_DECL_NOTHROW
|
|||
|
||||
fallback_update_seed(*ptr);
|
||||
}
|
||||
#else
|
||||
static void fallback_update_seed(unsigned) {}
|
||||
static Q_NORETURN void fallback_fill(quint32 *, qssize_t)
|
||||
{
|
||||
qFatal("Random number generator failed and no high-quality backup available");
|
||||
}
|
||||
#endif
|
||||
|
||||
static qssize_t fill_cpu(quint32 *buffer, qssize_t count) Q_DECL_NOTHROW
|
||||
|
|
|
|||
|
|
@ -34,11 +34,9 @@
|
|||
#include <private/qrandom_p.h>
|
||||
|
||||
#include <algorithm>
|
||||
#if QT_CONFIG(cxx11_random)
|
||||
# include <random>
|
||||
#endif
|
||||
#include <random>
|
||||
|
||||
#if !QT_CONFIG(getentropy) && (QT_CONFIG(cxx11_random) || defined(Q_OS_BSD4) || defined(Q_OS_WIN))
|
||||
#if !QT_CONFIG(getentropy) && (defined(Q_OS_BSD4) || defined(Q_OS_WIN))
|
||||
# define HAVE_FALLBACK_ENGINE
|
||||
#endif
|
||||
|
||||
|
|
@ -468,9 +466,6 @@ template <typename Engine> void seedStdRandomEngine()
|
|||
|
||||
void tst_QRandomGenerator::seedStdRandomEngines()
|
||||
{
|
||||
#if !QT_CONFIG(cxx11_random)
|
||||
QSKIP("<random> not found");
|
||||
#else
|
||||
seedStdRandomEngine<std::default_random_engine>();
|
||||
seedStdRandomEngine<std::minstd_rand0>();
|
||||
seedStdRandomEngine<std::minstd_rand>();
|
||||
|
|
@ -480,7 +475,6 @@ void tst_QRandomGenerator::seedStdRandomEngines()
|
|||
seedStdRandomEngine<std::ranlux48_base>();
|
||||
seedStdRandomEngine<std::ranlux24>();
|
||||
seedStdRandomEngine<std::ranlux48>();
|
||||
#endif
|
||||
}
|
||||
|
||||
void tst_QRandomGenerator::stdUniformIntDistribution_data()
|
||||
|
|
@ -511,9 +505,6 @@ void tst_QRandomGenerator::stdUniformIntDistribution_data()
|
|||
|
||||
void tst_QRandomGenerator::stdUniformIntDistribution()
|
||||
{
|
||||
#if !QT_CONFIG(cxx11_random)
|
||||
QSKIP("<random> not found");
|
||||
#else
|
||||
QFETCH(uint, control);
|
||||
QFETCH(quint32, max);
|
||||
setRNGControl(control & (SkipHWRNG|SkipSystemRNG|SkipMemfill));
|
||||
|
|
@ -575,14 +566,11 @@ void tst_QRandomGenerator::stdUniformIntDistribution()
|
|||
QVERIFY(value <= dist.max());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void tst_QRandomGenerator::stdGenerateCanonical()
|
||||
{
|
||||
#if !QT_CONFIG(cxx11_random)
|
||||
QSKIP("<random> not found");
|
||||
#elif defined(Q_CC_MSVC) && Q_CC_MSVC < 1900
|
||||
#if defined(Q_CC_MSVC) && Q_CC_MSVC < 1900
|
||||
// see https://connect.microsoft.com/VisualStudio/feedback/details/811611
|
||||
QSKIP("MSVC 2013's std::generate_canonical is broken");
|
||||
#else
|
||||
|
|
@ -634,9 +622,6 @@ void tst_QRandomGenerator::stdUniformRealDistribution_data()
|
|||
|
||||
void tst_QRandomGenerator::stdUniformRealDistribution()
|
||||
{
|
||||
#if !QT_CONFIG(cxx11_random)
|
||||
QSKIP("<random> not found");
|
||||
#else
|
||||
QFETCH(uint, control);
|
||||
QFETCH(double, min);
|
||||
QFETCH(double, sup);
|
||||
|
|
@ -663,14 +648,10 @@ void tst_QRandomGenerator::stdUniformRealDistribution()
|
|||
QVERIFY(value < dist.max());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void tst_QRandomGenerator::stdRandomDistributions()
|
||||
{
|
||||
#if !QT_CONFIG(cxx11_random)
|
||||
QSKIP("<random> not found");
|
||||
#else
|
||||
// just a compile check for some of the distributions, besides
|
||||
// std::uniform_int_distribution and std::uniform_real_distribution (tested
|
||||
// above)
|
||||
|
|
@ -695,7 +676,6 @@ void tst_QRandomGenerator::stdRandomDistributions()
|
|||
QVERIFY(discrete(rd) != 0);
|
||||
QVERIFY_3TIMES(discrete(rd) == 3);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
QTEST_APPLESS_MAIN(tst_QRandomGenerator)
|
||||
|
|
|
|||
Loading…
Reference in New Issue