summaryrefslogtreecommitdiffstats
path: root/src/corelib/global
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/global')
-rw-r--r--src/corelib/global/qconfig-bootstrapped.h14
-rw-r--r--src/corelib/global/qglobal.h2
-rw-r--r--src/corelib/global/qglobal_p.h73
-rw-r--r--src/corelib/global/qnamespace.qdoc4
-rw-r--r--src/corelib/global/qrandom.cpp53
5 files changed, 108 insertions, 38 deletions
diff --git a/src/corelib/global/qconfig-bootstrapped.h b/src/corelib/global/qconfig-bootstrapped.h
index 95095f4b76..2164d7f21f 100644
--- a/src/corelib/global/qconfig-bootstrapped.h
+++ b/src/corelib/global/qconfig-bootstrapped.h
@@ -66,8 +66,7 @@
#define QT_NO_USING_NAMESPACE
#define QT_NO_DEPRECATED
-#define QT_CRYPTOGRAPHICHASH_ONLY_SHA1
-#define QT_NO_DATASTREAM
+// Keep feature-test macros in alphabetic order by feature name:
#define QT_FEATURE_alloca 1
#define QT_FEATURE_alloca_h -1
#ifdef _WIN32
@@ -75,9 +74,13 @@
#else
# define QT_FEATURE_alloca_malloc_h -1
#endif
+#define QT_CRYPTOGRAPHICHASH_ONLY_SHA1
#define QT_FEATURE_cxx11_random (QT_HAS_INCLUDE(<random>) ? 1 : -1)
+#define QT_NO_DATASTREAM
+#define QT_FEATURE_datetimeparser -1
#define QT_FEATURE_getauxval (QT_HAS_INCLUDE(<sys/auxv.h>) ? 1 : -1)
#define QT_FEATURE_getentropy -1
+#define QT_NO_GEOM_VARIANT
#define QT_FEATURE_iconv -1
#define QT_FEATURE_icu -1
#define QT_FEATURE_journald -1
@@ -86,20 +89,19 @@
#define QT_FEATURE_library -1
#define QT_NO_QOBJECT
#define QT_FEATURE_process -1
-#define QT_NO_SYSTEMLOCALE
#define QT_FEATURE_renameat2 -1
+#define QT_FEATURE_sharedmemory -1
#define QT_FEATURE_slog2 -1
#define QT_FEATURE_statx -1
#define QT_FEATURE_syslog -1
+#define QT_NO_SYSTEMLOCALE
+#define QT_FEATURE_systemsemaphore -1
#define QT_FEATURE_temporaryfile 1
#define QT_NO_THREAD
#define QT_FEATURE_timezone -1
#define QT_FEATURE_topleveldomain -1
#define QT_NO_TRANSLATION
#define QT_FEATURE_translation -1
-#define QT_NO_GEOM_VARIANT
-#define QT_FEATURE_sharedmemory -1
-#define QT_FEATURE_systemsemaphore -1
#ifdef QT_BUILD_QMAKE
#define QT_FEATURE_commandlineparser -1
diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h
index c9ec46c67f..e49bace002 100644
--- a/src/corelib/global/qglobal.h
+++ b/src/corelib/global/qglobal.h
@@ -357,7 +357,7 @@ typedef double qreal;
#if !defined(QT_NAMESPACE) && defined(__cplusplus) && !defined(Q_QDOC)
extern "C"
#endif
-Q_CORE_EXPORT Q_DECL_CONST_FUNCTION const char *qVersion() Q_DECL_NOTHROW;
+Q_CORE_EXPORT Q_DECL_CONST_FUNCTION const char *qVersion(void) Q_DECL_NOTHROW;
#if defined(__cplusplus)
diff --git a/src/corelib/global/qglobal_p.h b/src/corelib/global/qglobal_p.h
index b1d2836783..0f092e9006 100644
--- a/src/corelib/global/qglobal_p.h
+++ b/src/corelib/global/qglobal_p.h
@@ -1,5 +1,6 @@
/****************************************************************************
**
+** Copyright (C) 2017 The Qt Company Ltd.
** Copyright (C) 2015 Intel Corporation.
** Contact: https://www.qt.io/licensing/
**
@@ -59,5 +60,77 @@
#include <QtCore/private/qtcore-config_p.h>
#endif
+#if defined(__cplusplus)
+#if !QT_HAS_BUILTIN(__builtin_available)
+#include <initializer_list>
+#include <QtCore/qoperatingsystemversion.h>
+#include <QtCore/qversionnumber.h>
+
+QT_BEGIN_NAMESPACE
+
+struct qt_clang_builtin_available_os_version_data {
+ QOperatingSystemVersion::OSType type;
+ const char *version;
+};
+
+static inline bool qt_clang_builtin_available(
+ const std::initializer_list<qt_clang_builtin_available_os_version_data> &versions)
+{
+ for (auto it = versions.begin(); it != versions.end(); ++it) {
+ if (QOperatingSystemVersion::currentType() == it->type) {
+ const auto current = QOperatingSystemVersion::current();
+ return QVersionNumber(
+ current.majorVersion(),
+ current.minorVersion(),
+ current.microVersion()) >= QVersionNumber::fromString(
+ QString::fromLatin1(it->version));
+ }
+ }
+
+ // Result is true if the platform is not any of the checked ones; this matches behavior of
+ // LLVM __builtin_available and @available constructs
+ return true;
+}
+
+QT_END_NAMESPACE
+
+#define QT_AVAILABLE_OS_VER(os, ver) \
+ QT_PREPEND_NAMESPACE(qt_clang_builtin_available_os_version_data){\
+ QT_PREPEND_NAMESPACE(QOperatingSystemVersion)::os, #ver}
+#define QT_AVAILABLE_CAT(L, R) QT_AVAILABLE_CAT_(L, R)
+#define QT_AVAILABLE_CAT_(L, R) L ## R
+#define QT_AVAILABLE_EXPAND(...) QT_AVAILABLE_OS_VER(__VA_ARGS__)
+#define QT_AVAILABLE_SPLIT(os_ver) QT_AVAILABLE_EXPAND(QT_AVAILABLE_CAT(QT_AVAILABLE_SPLIT_, os_ver))
+#define QT_AVAILABLE_SPLIT_macOS MacOS,
+#define QT_AVAILABLE_SPLIT_iOS IOS,
+#define QT_AVAILABLE_SPLIT_tvOS TvOS,
+#define QT_AVAILABLE_SPLIT_watchOS WatchOS,
+#define QT_BUILTIN_AVAILABLE0(e) \
+ QT_PREPEND_NAMESPACE(qt_clang_builtin_available)({})
+#define QT_BUILTIN_AVAILABLE1(a, e) \
+ QT_PREPEND_NAMESPACE(qt_clang_builtin_available)({QT_AVAILABLE_SPLIT(a)})
+#define QT_BUILTIN_AVAILABLE2(a, b, e) \
+ QT_PREPEND_NAMESPACE(qt_clang_builtin_available)({QT_AVAILABLE_SPLIT(a), \
+ QT_AVAILABLE_SPLIT(b)})
+#define QT_BUILTIN_AVAILABLE3(a, b, c, e) \
+ QT_PREPEND_NAMESPACE(qt_clang_builtin_available)({QT_AVAILABLE_SPLIT(a), \
+ QT_AVAILABLE_SPLIT(b), \
+ QT_AVAILABLE_SPLIT(c)})
+#define QT_BUILTIN_AVAILABLE4(a, b, c, d, e) \
+ QT_PREPEND_NAMESPACE(qt_clang_builtin_available)({QT_AVAILABLE_SPLIT(a), \
+ QT_AVAILABLE_SPLIT(b), \
+ QT_AVAILABLE_SPLIT(c), \
+ QT_AVAILABLE_SPLIT(d)})
+#define QT_BUILTIN_AVAILABLE_ARG(arg0, arg1, arg2, arg3, arg4, arg5, ...) arg5
+#define QT_BUILTIN_AVAILABLE_CHOOSER(...) QT_BUILTIN_AVAILABLE_ARG(__VA_ARGS__, \
+ QT_BUILTIN_AVAILABLE4, \
+ QT_BUILTIN_AVAILABLE3, \
+ QT_BUILTIN_AVAILABLE2, \
+ QT_BUILTIN_AVAILABLE1, \
+ QT_BUILTIN_AVAILABLE0, )
+#define __builtin_available(...) QT_BUILTIN_AVAILABLE_CHOOSER(__VA_ARGS__)(__VA_ARGS__)
+#endif // !QT_HAS_BUILTIN(__builtin_available)
+#endif // defined(__cplusplus)
+
#endif // QGLOBAL_P_H
diff --git a/src/corelib/global/qnamespace.qdoc b/src/corelib/global/qnamespace.qdoc
index e74ba4026a..e64fb221d3 100644
--- a/src/corelib/global/qnamespace.qdoc
+++ b/src/corelib/global/qnamespace.qdoc
@@ -2959,10 +2959,10 @@
This enum specifies the coordinate system.
- \value DeviceCoordinates Coordinates are relative to the upper-left corner
+ \value DeviceCoordinates Coordinates are relative to the top-left corner
of the object's paint device.
- \value LogicalCoordinates Coordinates are relative to the upper-left corner
+ \value LogicalCoordinates Coordinates are relative to the top-left corner
of the object.
*/
diff --git a/src/corelib/global/qrandom.cpp b/src/corelib/global/qrandom.cpp
index 22d23ae6fa..d77ec8075a 100644
--- a/src/corelib/global/qrandom.cpp
+++ b/src/corelib/global/qrandom.cpp
@@ -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>
@@ -95,7 +94,7 @@ DECLSPEC_IMPORT BOOLEAN WINAPI SystemFunction036(PVOID RandomBuffer, ULONG Rando
QT_BEGIN_NAMESPACE
#if defined(Q_PROCESSOR_X86) && QT_COMPILER_SUPPORTS_HERE(RDRND)
-static qssize_t qt_random_cpu(void *buffer, qssize_t count);
+static qssize_t qt_random_cpu(void *buffer, qssize_t count) Q_DECL_NOTHROW;
# ifdef Q_PROCESSOR_X86_64
# define _rdrandXX_step _rdrand64_step
@@ -103,7 +102,7 @@ static qssize_t qt_random_cpu(void *buffer, qssize_t count);
# define _rdrandXX_step _rdrand32_step
# endif
-static QT_FUNCTION_TARGET(RDRND) qssize_t qt_random_cpu(void *buffer, qssize_t count)
+static QT_FUNCTION_TARGET(RDRND) qssize_t qt_random_cpu(void *buffer, qssize_t count) Q_DECL_NOTHROW
{
unsigned *ptr = reinterpret_cast<unsigned *>(buffer);
unsigned *end = ptr + count;
@@ -215,7 +214,7 @@ class SystemRandom
{
public:
enum { EfficientBufferFill = true };
- static qssize_t fillBuffer(void *buffer, qssize_t count)
+ static qssize_t fillBuffer(void *buffer, qssize_t count) Q_DECL_NOTHROW
{
auto RtlGenRandom = SystemFunction036;
return RtlGenRandom(buffer, ULONG(count)) ? count: 0;
@@ -226,7 +225,7 @@ class SystemRandom
{
public:
enum { EfficientBufferFill = false };
- static qssize_t fillBuffer(void *, qssize_t)
+ static qssize_t fillBuffer(void *, qssize_t) Q_DECL_NOTHROW
{
// always use the fallback
return 0;
@@ -260,7 +259,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)
{
@@ -314,7 +313,7 @@ static void fallback_fill(quint32 *ptr, qssize_t left) Q_DECL_NOTHROW
// (other ELF-based systems don't seem to have AT_RANDOM)
ulong auxvSeed = getauxval(AT_RANDOM);
if (auxvSeed) {
- memcpy(scratch, reinterpret_cast<void *>(auxvSeed), 16);
+ memcpy(end, reinterpret_cast<void *>(auxvSeed), 16);
end += 4; // 7 to 10
}
# endif
@@ -345,15 +344,9 @@ 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)
+static qssize_t fill_cpu(quint32 *buffer, qssize_t count) Q_DECL_NOTHROW
{
#if defined(Q_PROCESSOR_X86) && QT_COMPILER_SUPPORTS_HERE(RDRND)
if (qCpuHasFeature(RDRND) && (uint(qt_randomdevice_control) & SkipHWRNG) == 0)
@@ -366,6 +359,7 @@ static qssize_t fill_cpu(quint32 *buffer, qssize_t count)
}
static void fill_internal(quint32 *buffer, qssize_t count)
+ Q_DECL_NOEXCEPT_EXPR(noexcept(SystemRandom::fillBuffer(buffer, count)))
{
if (Q_UNLIKELY(uint(qt_randomdevice_control) & SetRandomData)) {
uint value = uint(qt_randomdevice_control) & RandomDataMask;
@@ -389,6 +383,7 @@ static void fill_internal(quint32 *buffer, qssize_t count)
}
static Q_NEVER_INLINE void fill(void *buffer, void *bufferEnd)
+ Q_DECL_NOEXCEPT_EXPR(noexcept(fill_internal(static_cast<quint32 *>(buffer), 1)))
{
struct ThreadState {
enum {
@@ -461,7 +456,7 @@ static Q_NEVER_INLINE void fill(void *buffer, void *bufferEnd)
The class can generate 32-bit or 64-bit quantities, or fill an array of
those. The most common way of generating new values is to call the generate(),
- get64() or fillRange() functions. One would use it as:
+ generate64() or fillRange() functions. One would use it as:
\code
quint32 value = QRandomGenerator::generate();
@@ -626,7 +621,7 @@ static Q_NEVER_INLINE void fill(void *buffer, void *bufferEnd)
quantities, one can write:
\code
- std::generate(begin, end, []() { return get64(); });
+ std::generate(begin, end, []() { return QRandomGenerator::generate64(); });
\endcode
If the range refers to contiguous memory (such as an array or the data from
@@ -678,14 +673,14 @@ static Q_NEVER_INLINE void fill(void *buffer, void *bufferEnd)
QRandomGenerator::fillRange(array);
\endcode
- It would have also been possible to make one call to get64() and then split
+ It would have also been possible to make one call to generate64() and then split
the two halves of the 64-bit value.
\sa generate()
*/
/*!
- \fn qreal QRandomGenerator::generateReal()
+ \fn qreal QRandomGenerator::generateDouble()
Generates one random qreal in the canonical range [0, 1) (that is,
inclusive of zero and exclusive of 1).
@@ -700,7 +695,7 @@ static Q_NEVER_INLINE void fill(void *buffer, void *bufferEnd)
\c{\l{http://en.cppreference.com/w/cpp/numeric/random/uniform_real_distribution}{std::uniform_real_distribution}}
with parameters 0 and 1.
- \sa generate(), get64(), bounded()
+ \sa generate(), generate64(), bounded()
*/
/*!
@@ -738,7 +733,7 @@ static Q_NEVER_INLINE void fill(void *buffer, void *bufferEnd)
Note that this function cannot be used to obtain values in the full 32-bit
range of quint32. Instead, use generate().
- \sa generate(), get64(), generateDouble()
+ \sa generate(), generate64(), generateDouble()
*/
/*!
@@ -751,7 +746,7 @@ static Q_NEVER_INLINE void fill(void *buffer, void *bufferEnd)
Note that this function cannot be used to obtain values in the full 32-bit
range of int. Instead, use generate() and cast to int.
- \sa generate(), get64(), generateDouble()
+ \sa generate(), generate64(), generateDouble()
*/
/*!
@@ -775,7 +770,7 @@ static Q_NEVER_INLINE void fill(void *buffer, void *bufferEnd)
Note that this function cannot be used to obtain values in the full 32-bit
range of quint32. Instead, use generate().
- \sa generate(), get64(), generateDouble()
+ \sa generate(), generate64(), generateDouble()
*/
/*!
@@ -788,7 +783,7 @@ static Q_NEVER_INLINE void fill(void *buffer, void *bufferEnd)
Note that this function cannot be used to obtain values in the full 32-bit
range of int. Instead, use generate() and cast to int.
- \sa generate(), get64(), generateDouble()
+ \sa generate(), generate64(), generateDouble()
*/
/*!
@@ -896,7 +891,7 @@ static Q_NEVER_INLINE void fill(void *buffer, void *bufferEnd)
int value = QRandomGenerator::generate() & std::numeric_limits<int>::max();
\endcode
- \sa get64(), generateDouble()
+ \sa generate64(), generateDouble()
*/
quint32 QRandomGenerator::generate()
{