Use Q_UNLIKELY for every qFatal()/qCritical()

If, after checking a condition, we issue a qFatal()
or a qCritical(), by definition that check is
unlikely to be true.

Tell the compiler so it can move the error handling
code out of the normal code path to increase the
effective icache size.

Moved conditional code around where possible so that
we could always use Q_UNLIKELY, instead of having to
revert to Q_LIKELY here and there.

In some cases, simplified the expressions newly wrapped
in Q_UNLIKELY as a drive-by.

Change-Id: I67537d62b04bc6977d69254690c5ebbdf98bfd6d
Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
This commit is contained in:
Marc Mutz 2015-11-12 10:16:22 +01:00
parent 14d189f787
commit 51089a5742
72 changed files with 203 additions and 208 deletions

View File

@ -560,7 +560,7 @@ static int doSpawn(pid_t *ppid, const posix_spawn_file_actions_t *file_actions,
qWarning("ThreadCtl(): failed to chdir to %s", oldWorkingDir);
# ifdef Q_OS_QNX
if (ThreadCtl(_NTO_TCTL_THREADS_CONT, 0) == -1)
if (Q_UNLIKELY(ThreadCtl(_NTO_TCTL_THREADS_CONT, 0) == -1))
qFatal("ThreadCtl(): cannot resume threads: %s", qPrintable(qt_error_string(errno)));
# endif
}

View File

@ -417,7 +417,7 @@ QCoreApplicationPrivate::QCoreApplicationPrivate(int &aargc, char **aargv, uint
QCoreApplicationPrivate::is_app_closing = false;
# if defined(Q_OS_UNIX)
if (!setuidAllowed && (geteuid() != getuid()))
if (Q_UNLIKELY(!setuidAllowed && (geteuid() != getuid())))
qFatal("FATAL: The application binary appears to be running setuid, this is a security hole.");
# endif // Q_OS_UNIX

View File

@ -135,7 +135,7 @@ QEventDispatcherUNIXPrivate::QEventDispatcherUNIXPrivate()
}
#endif
if (pipefail)
if (Q_UNLIKELY(pipefail))
qFatal("QEventDispatcherUNIXPrivate(): Can not continue without a thread pipe");
sn_highest = -1;

View File

@ -667,7 +667,7 @@ void QEventDispatcherWin32::installMessageHook()
#ifndef Q_OS_WINCE
// setup GetMessage hook needed to drive our posted events
d->getMessageHook = SetWindowsHookEx(WH_GETMESSAGE, (HOOKPROC) qt_GetMessageHook, NULL, GetCurrentThreadId());
if (!d->getMessageHook) {
if (Q_UNLIKELY(!d->getMessageHook)) {
int errorCode = GetLastError();
qFatal("Qt: INTERNAL ERROR: failed to install GetMessage hook: %d, %s",
errorCode, qPrintable(qt_error_string(errorCode)));

View File

@ -1074,7 +1074,7 @@ int QMetaType::registerNormalizedType(const NS(QByteArray) &normalizedTypeName,
previousFlags = QMetaType::typeFlags(idx);
}
if (previousSize != size) {
if (Q_UNLIKELY(previousSize != size)) {
qFatal("QMetaType::registerType: Binary compatibility break "
"-- Size mismatch for type '%s' [%i]. Previously registered "
"size %i, now registering size %i.",
@ -1084,7 +1084,7 @@ int QMetaType::registerNormalizedType(const NS(QByteArray) &normalizedTypeName,
// these flags cannot change in a binary compatible way:
const int binaryCompatibilityFlag = PointerToQObject | IsEnumeration | SharedPointerToQObject
| WeakPointerToQObject | TrackingPointerToQObject;
if ((previousFlags ^ flags) & binaryCompatibilityFlag) {
if (Q_UNLIKELY((previousFlags ^ flags) & binaryCompatibilityFlag)) {
const char *msg = "QMetaType::registerType: Binary compatibility break. "
"\nType flags for type '%s' [%i] don't match. Previously "

View File

@ -203,7 +203,7 @@ QObjectPrivate::QObjectPrivate(int version)
// This allows incompatible versions to be loaded, possibly for testing.
Q_UNUSED(version);
#else
if (version != QObjectPrivateVersion)
if (Q_UNLIKELY(version != QObjectPrivateVersion))
qFatal("Cannot mix incompatible Qt library (version 0x%x) with this library (version 0x%x)",
version, QObjectPrivateVersion);
#endif

View File

@ -682,17 +682,17 @@ void QHashData::dump()
void QHashData::checkSanity()
{
if (fakeNext)
if (Q_UNLIKELY(fakeNext))
qFatal("Fake next isn't 0");
for (int i = 0; i < numBuckets; ++i) {
Node *n = buckets[i];
Node *p = n;
if (!n)
if (Q_UNLIKELY(!n))
qFatal("%d: Bucket entry is 0", i);
if (n != reinterpret_cast<Node *>(this)) {
while (n != reinterpret_cast<Node *>(this)) {
if (!n->next)
if (Q_UNLIKELY(!n->next))
qFatal("%d: Next of %p is 0, should be %p", i, n, this);
n = n->next;
}

View File

@ -1508,7 +1508,7 @@ void QtSharedPointer::internalSafetyCheckAdd(const void *d_ptr, const volatile v
//qDebug("Adding d=%p value=%p", d_ptr, ptr);
const void *other_d_ptr = kp->dataPointers.value(ptr, 0);
if (other_d_ptr) {
if (Q_UNLIKELY(other_d_ptr)) {
# ifdef BACKTRACE_SUPPORTED
printBacktrace(knownPointers()->dPointers.value(other_d_ptr).backtrace);
# endif
@ -1539,7 +1539,7 @@ void QtSharedPointer::internalSafetyCheckRemove(const void *d_ptr)
QMutexLocker lock(&kp->mutex);
QHash<const void *, Data>::iterator it = kp->dPointers.find(d_ptr);
if (it == kp->dPointers.end()) {
if (Q_UNLIKELY(it == kp->dPointers.end())) {
qFatal("QSharedPointer: internal self-check inconsistency: pointer %p was not tracked. "
"To use QT_SHAREDPOINTER_TRACK_POINTERS, you have to enable it throughout "
"in your code.", d_ptr);
@ -1566,10 +1566,10 @@ void QtSharedPointer::internalSafetyCheckCleanCheck()
KnownPointers *const kp = knownPointers();
Q_ASSERT_X(kp, "internalSafetyCheckSelfCheck()", "Called after global statics deletion!");
if (kp->dPointers.size() != kp->dataPointers.size())
if (Q_UNLIKELY(kp->dPointers.size() != kp->dataPointers.size()))
qFatal("Internal consistency error: the number of pointers is not equal!");
if (!kp->dPointers.isEmpty())
if (Q_UNLIKELY(!kp->dPointers.isEmpty()))
qFatal("Pointer cleaning failed: %d entries remaining", kp->dPointers.size());
# endif
}

View File

@ -685,7 +685,7 @@ void qDetectCpuFeatures()
#else
bool runningOnValgrind = false;
#endif
if (!runningOnValgrind && (minFeature != 0 && (f & minFeature) != minFeature)) {
if (Q_UNLIKELY(!runningOnValgrind && minFeature != 0 && (f & minFeature) != minFeature)) {
quint64 missing = minFeature & ~f;
fprintf(stderr, "Incompatible processor. This Qt build requires the following features:\n ");
for (int i = 0; i < features_count; ++i) {

View File

@ -130,11 +130,11 @@ void (*qdbus_resolve_conditionally(const char *name))()
void (*qdbus_resolve_me(const char *name))()
{
#ifndef QT_NO_LIBRARY
if (!qdbus_loadLibDBus())
if (Q_UNLIKELY(!qdbus_loadLibDBus()))
qFatal("Cannot find libdbus-1 in your system to resolve symbol '%s'.", name);
QFunctionPointer ptr = qdbus_libdbus->resolve(name);
if (!ptr)
if (Q_UNLIKELY(!ptr))
qFatal("Cannot resolve '%s' in your libdbus-1.", name);
return ptr;

View File

@ -868,7 +868,7 @@ void QDBusConnectionPrivate::deliverCall(QObject *object, int /*flags*/, const Q
*reinterpret_cast<const QDBusArgument *>(arg.constData());
QVariant &out = auxParameters[auxParameters.count() - 1];
if (!QDBusMetaType::demarshall(in, out.userType(), out.data()))
if (Q_UNLIKELY(!QDBusMetaType::demarshall(in, out.userType(), out.data())))
qFatal("Internal error: demarshalling function for type '%s' (%d) failed!",
out.typeName(), out.userType());

View File

@ -190,7 +190,7 @@ void QDBusPendingCallPrivate::setMetaTypes(int count, const int *types)
sig.reserve(count + count / 2);
for (int i = 0; i < count; ++i) {
const char *typeSig = QDBusMetaType::typeToSignature(types[i]);
if (!typeSig) {
if (Q_UNLIKELY(!typeSig)) {
qFatal("QDBusPendingReply: type %s is not registered with QtDBus",
QMetaType::typeName(types[i]));
}

View File

@ -64,7 +64,7 @@ QT_BEGIN_NAMESPACE
static bool qt_pixmap_thread_test()
{
if (!QCoreApplication::instance()) {
if (Q_UNLIKELY(!QCoreApplication::instance())) {
qFatal("QPixmap: Must construct a QGuiApplication before a QPixmap");
return false;
}

View File

@ -1065,9 +1065,7 @@ static void init_platform(const QString &pluginArgument, const QString &platform
// Create the platform integration.
QGuiApplicationPrivate::platform_integration = QPlatformIntegrationFactory::create(name, arguments, argc, argv, platformPluginPath);
if (QGuiApplicationPrivate::platform_integration) {
QGuiApplicationPrivate::platform_name = new QString(name);
} else {
if (Q_UNLIKELY(!QGuiApplicationPrivate::platform_integration)) {
QStringList keys = QPlatformIntegrationFactory::keys(platformPluginPath);
QString fatalMessage
@ -1087,6 +1085,8 @@ static void init_platform(const QString &pluginArgument, const QString &platform
return;
}
QGuiApplicationPrivate::platform_name = new QString(name);
// Many platforms have created QScreens at this point. Finish initializing
// QHighDpiScaling to be prepared for early calls to qt_defaultDpi().
if (QGuiApplication::primaryScreen()) {
@ -1414,16 +1414,16 @@ void QGuiApplicationPrivate::init()
if (loadTestability) {
QLibrary testLib(QStringLiteral("qttestability"));
if (testLib.load()) {
if (Q_UNLIKELY(!testLib.load())) {
qCritical() << "Library qttestability load failed:" << testLib.errorString();
} else {
typedef void (*TasInitialize)(void);
TasInitialize initFunction = (TasInitialize)testLib.resolve("qt_testability_init");
if (initFunction) {
initFunction();
} else {
if (Q_UNLIKELY(!initFunction)) {
qCritical() << "Library qttestability resolve failed!";
} else {
initFunction();
}
} else {
qCritical() << "Library qttestability load failed:" << testLib.errorString();
}
}
#else

View File

@ -948,7 +948,7 @@ bool QOpenGLContext::makeCurrent(QSurface *surface)
if (!isValid())
return false;
if (thread() != QThread::currentThread())
if (Q_UNLIKELY(thread() != QThread::currentThread()))
qFatal("Cannot make QOpenGLContext current in a different thread");
if (!surface) {

View File

@ -212,7 +212,7 @@ void QWindowPrivate::init()
// If your application aborts here, you are probably creating a QWindow
// before the screen list is populated.
if (!parentWindow && !topLevelScreen) {
if (Q_UNLIKELY(!parentWindow && !topLevelScreen)) {
qFatal("Cannot create window: no screens available");
exit(1);
}

View File

@ -191,7 +191,7 @@ QOpenGLEngineSharedShaders::QOpenGLEngineSharedShaders(QOpenGLContext* context)
#if defined(QT_DEBUG)
// Check that all the elements have been filled:
for (int i = 0; i < TotalSnippetCount; ++i) {
if (qShaderSnippets[i] == 0) {
if (Q_UNLIKELY(!qShaderSnippets[i])) {
qFatal("Shader snippet for %s (#%d) is missing!",
snippetNameStr(SnippetName(i)).constData(), i);
}
@ -240,11 +240,11 @@ QOpenGLEngineSharedShaders::QOpenGLEngineSharedShaders(QOpenGLContext* context)
simpleShaderProg->link();
if (simpleShaderProg->isLinked()) {
if (Q_UNLIKELY(!simpleShaderProg->isLinked())) {
qCritical("Errors linking simple shader: %s", qPrintable(simpleShaderProg->log()));
} else {
if (!inCache)
simpleShaderCache.store(simpleShaderProg, context);
} else {
qCritical("Errors linking simple shader: %s", qPrintable(simpleShaderProg->log()));
}
// Compile the blit shader:
@ -281,11 +281,11 @@ QOpenGLEngineSharedShaders::QOpenGLEngineSharedShaders(QOpenGLContext* context)
}
blitShaderProg->link();
if (blitShaderProg->isLinked()) {
if (Q_UNLIKELY(!blitShaderProg->isLinked())) {
qCritical("Errors linking blit shader: %s", qPrintable(blitShaderProg->log()));
} else {
if (!inCache)
blitShaderCache.store(blitShaderProg, context);
} else {
qCritical("Errors linking blit shader: %s", qPrintable(blitShaderProg->log()));
}
#ifdef QT_GL_SHARED_SHADER_DEBUG

View File

@ -5795,7 +5795,9 @@ QOpenGLES3Helper::QOpenGLES3Helper()
{
m_supportedVersion = qMakePair(2, 0);
if (init()) {
if (Q_UNLIKELY(!init())) {
qFatal("Failed to load libGLESv2");
} else {
const QPair<int, int> contextVersion = QOpenGLContext::currentContext()->format().version();
qCDebug(lcGLES3, "Resolving OpenGL ES 3.0 entry points");
@ -5993,8 +5995,6 @@ QOpenGLES3Helper::QOpenGLES3Helper()
}
m_supportedVersion = qMakePair(3, 1);
}
} else {
qFatal("Failed to load libGLESv2");
}
}

View File

@ -1339,7 +1339,7 @@ QString QFontDatabase::styleString(const QFontInfo &fontInfo)
*/
QFontDatabase::QFontDatabase()
{
if (!qApp || !QGuiApplicationPrivate::platformIntegration())
if (Q_UNLIKELY(!qApp || !QGuiApplicationPrivate::platformIntegration()))
qFatal("QFontDatabase: Must construct a QGuiApplication before accessing QFontDatabase");
QMutexLocker locker(fontDatabaseMutex());

View File

@ -263,7 +263,7 @@ void QHttpNetworkConnectionPrivate::prepareRequest(HttpMessagePair &messagePair)
request.setContentLength(uploadByteDevice->size());
} else if (request.contentLength() != -1 && uploadByteDevice->size() == -1) {
// everything OK, the user supplied us the contentLength
} else if (request.contentLength() == -1 && uploadByteDevice->size() == -1) {
} else if (Q_UNLIKELY(request.contentLength() == -1 && uploadByteDevice->size() == -1)) {
qFatal("QHttpNetworkConnectionPrivate: Neither content-length nor upload device size were given");
}
}

View File

@ -993,7 +993,7 @@ void QNetworkReplyHttpImplPrivate::initCacheSaveDevice()
q->connect(cacheSaveDevice, SIGNAL(aboutToClose()), SLOT(_q_cacheSaveDeviceAboutToClose()));
if (!cacheSaveDevice || (cacheSaveDevice && !cacheSaveDevice->isOpen())) {
if (cacheSaveDevice && !cacheSaveDevice->isOpen())
if (Q_UNLIKELY(cacheSaveDevice && !cacheSaveDevice->isOpen()))
qCritical("QNetworkReplyImpl: network cache returned a device that is not open -- "
"class %s probably needs to be fixed",
managerPrivate->networkCache->metaObject()->className());
@ -2216,7 +2216,7 @@ void QNetworkReplyHttpImplPrivate::setCachingEnabled(bool enable)
return; // nothing to do either!
if (enable) {
if (bytesDownloaded) {
if (Q_UNLIKELY(bytesDownloaded)) {
qDebug() << "setCachingEnabled: " << bytesDownloaded << " bytesDownloaded";
// refuse to enable in this case
qCritical("QNetworkReplyImpl: backend error: caching was enabled after some bytes had been written");

View File

@ -515,7 +515,7 @@ void QNetworkReplyImplPrivate::setCachingEnabled(bool enable)
return; // nothing to do either!
if (enable) {
if (bytesDownloaded) {
if (Q_UNLIKELY(bytesDownloaded)) {
// refuse to enable in this case
qCritical("QNetworkReplyImpl: backend error: caching was enabled after some bytes had been written");
return;
@ -604,7 +604,7 @@ void QNetworkReplyImplPrivate::initCacheSaveDevice()
cacheSaveDevice = networkCache()->prepare(metaData);
if (!cacheSaveDevice || (cacheSaveDevice && !cacheSaveDevice->isOpen())) {
if (cacheSaveDevice && !cacheSaveDevice->isOpen())
if (Q_UNLIKELY(cacheSaveDevice && !cacheSaveDevice->isOpen()))
qCritical("QNetworkReplyImpl: network cache returned a device that is not open -- "
"class %s probably needs to be fixed",
networkCache()->metaObject()->className());
@ -678,7 +678,7 @@ void QNetworkReplyImplPrivate::appendDownstreamData(QIODevice *data)
return;
// read until EOF from data
if (copyDevice) {
if (Q_UNLIKELY(copyDevice)) {
qCritical("QNetworkReplyImpl: copy from QIODevice already in progress -- "
"backend probly needs to be fixed");
return;

View File

@ -188,7 +188,7 @@ QGLEngineSharedShaders::QGLEngineSharedShaders(const QGLContext* context)
#if defined(QT_DEBUG)
// Check that all the elements have been filled:
for (int i = 0; i < TotalSnippetCount; ++i) {
if (qShaderSnippets[i] == 0) {
if (Q_UNLIKELY(!qShaderSnippets[i])) {
qFatal("Shader snippet for %s (#%d) is missing!",
snippetNameStr(SnippetName(i)).constData(), i);
}
@ -237,11 +237,11 @@ QGLEngineSharedShaders::QGLEngineSharedShaders(const QGLContext* context)
simpleShaderProg->link();
if (simpleShaderProg->isLinked()) {
if (Q_UNLIKELY(!simpleShaderProg->isLinked())) {
qCritical("Errors linking simple shader: %s", qPrintable(simpleShaderProg->log()));
} else {
if (!inCache)
simpleShaderCache.store(simpleShaderProg, context);
} else {
qCritical("Errors linking simple shader: %s", qPrintable(simpleShaderProg->log()));
}
// Compile the blit shader:
@ -278,11 +278,11 @@ QGLEngineSharedShaders::QGLEngineSharedShaders(const QGLContext* context)
}
blitShaderProg->link();
if (blitShaderProg->isLinked()) {
if (Q_UNLIKELY(!blitShaderProg->isLinked())) {
qCritical("Errors linking blit shader: %s", qPrintable(blitShaderProg->log()));
} else {
if (!inCache)
blitShaderCache.store(blitShaderProg, context);
} else {
qCritical("Errors linking blit shader: %s", qPrintable(blitShaderProg->log()));
}
#ifdef QT_GL_SHARED_SHADER_DEBUG

View File

@ -85,18 +85,18 @@ QLibInputHandler::QLibInputHandler(const QString &key, const QString &spec)
Q_UNUSED(spec);
m_udev = udev_new();
if (!m_udev)
if (Q_UNLIKELY(!m_udev))
qFatal("Failed to get udev context for libinput");
m_li = libinput_udev_create_context(&liInterface, Q_NULLPTR, m_udev);
if (!m_li)
if (Q_UNLIKELY(!m_li))
qFatal("Failed to get libinput context");
libinput_log_set_handler(m_li, liLogHandler);
if (qLcLibInput().isDebugEnabled())
libinput_log_set_priority(m_li, LIBINPUT_LOG_PRIORITY_DEBUG);
if (libinput_udev_assign_seat(m_li, "seat0"))
if (Q_UNLIKELY(libinput_udev_assign_seat(m_li, "seat0")))
qFatal("Failed to assign seat");
m_liFd = libinput_get_fd(m_li);

View File

@ -487,7 +487,7 @@ static jboolean startQtApplication(JNIEnv *env, jobject /*object*/, jstring para
// Obtain a handle to the main library (the library that contains the main() function).
// This library should already be loaded, and calling dlopen() will just return a reference to it.
m_mainLibraryHnd = dlopen(m_applicationParams.first().data(), 0);
if (m_mainLibraryHnd == nullptr) {
if (Q_UNLIKELY(!m_mainLibraryHnd)) {
qCritical() << "dlopen failed:" << dlerror();
return false;
}
@ -497,7 +497,7 @@ static jboolean startQtApplication(JNIEnv *env, jobject /*object*/, jstring para
m_main = (Main)dlsym(RTLD_DEFAULT, "main");
}
if (!m_main) {
if (Q_UNLIKELY(!m_main)) {
qCritical() << "dlsym failed:" << dlerror();
qCritical() << "Could not find main method";
return false;

View File

@ -339,7 +339,7 @@ QAndroidInputContext::QAndroidInputContext()
: QPlatformInputContext(), m_composingTextStart(-1), m_blockUpdateSelection(false), m_batchEditNestingLevel(0), m_focusObject(0)
{
jclass clazz = QJNIEnvironmentPrivate::findClass(QtNativeInputConnectionClassName);
if (clazz == NULL) {
if (Q_UNLIKELY(!clazz)) {
qCritical() << "Native registration unable to find class '"
<< QtNativeInputConnectionClassName
<< '\'';
@ -347,7 +347,7 @@ QAndroidInputContext::QAndroidInputContext()
}
QJNIEnvironmentPrivate env;
if (env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])) < 0) {
if (Q_UNLIKELY(env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])) < 0)) {
qCritical() << "RegisterNatives failed for '"
<< QtNativeInputConnectionClassName
<< '\'';
@ -355,7 +355,7 @@ QAndroidInputContext::QAndroidInputContext()
}
clazz = QJNIEnvironmentPrivate::findClass(QtExtractedTextClassName);
if (clazz == NULL) {
if (Q_UNLIKELY(!clazz)) {
qCritical() << "Native registration unable to find class '"
<< QtExtractedTextClassName
<< '\'';
@ -364,43 +364,43 @@ QAndroidInputContext::QAndroidInputContext()
m_extractedTextClass = static_cast<jclass>(env->NewGlobalRef(clazz));
m_classConstructorMethodID = env->GetMethodID(m_extractedTextClass, "<init>", "()V");
if (m_classConstructorMethodID == NULL) {
if (Q_UNLIKELY(!m_classConstructorMethodID)) {
qCritical() << "GetMethodID failed";
return;
}
m_partialEndOffsetFieldID = env->GetFieldID(m_extractedTextClass, "partialEndOffset", "I");
if (m_partialEndOffsetFieldID == NULL) {
if (Q_UNLIKELY(!m_partialEndOffsetFieldID)) {
qCritical() << "Can't find field partialEndOffset";
return;
}
m_partialStartOffsetFieldID = env->GetFieldID(m_extractedTextClass, "partialStartOffset", "I");
if (m_partialStartOffsetFieldID == NULL) {
if (Q_UNLIKELY(!m_partialStartOffsetFieldID)) {
qCritical() << "Can't find field partialStartOffset";
return;
}
m_selectionEndFieldID = env->GetFieldID(m_extractedTextClass, "selectionEnd", "I");
if (m_selectionEndFieldID == NULL) {
if (Q_UNLIKELY(!m_selectionEndFieldID)) {
qCritical() << "Can't find field selectionEnd";
return;
}
m_selectionStartFieldID = env->GetFieldID(m_extractedTextClass, "selectionStart", "I");
if (m_selectionStartFieldID == NULL) {
if (Q_UNLIKELY(!m_selectionStartFieldID)) {
qCritical() << "Can't find field selectionStart";
return;
}
m_startOffsetFieldID = env->GetFieldID(m_extractedTextClass, "startOffset", "I");
if (m_startOffsetFieldID == NULL) {
if (Q_UNLIKELY(!m_startOffsetFieldID)) {
qCritical() << "Can't find field startOffset";
return;
}
m_textFieldID = env->GetFieldID(m_extractedTextClass, "text", "Ljava/lang/String;");
if (m_textFieldID == NULL) {
if (Q_UNLIKELY(!m_textFieldID)) {
qCritical() << "Can't find field text";
return;
}

View File

@ -47,7 +47,7 @@ void QAndroidPlatformFontDatabase::populateFontDatabase()
QString fontpath = fontDir();
QDir dir(fontpath);
if (!dir.exists()) {
if (Q_UNLIKELY(!dir.exists())) {
qFatal("QFontDatabase: Cannot find font directory %s - is Qt installed correctly?",
qPrintable(fontpath));
}

View File

@ -120,14 +120,14 @@ QAndroidPlatformIntegration::QAndroidPlatformIntegration(const QStringList &para
m_androidPlatformNativeInterface = new QAndroidPlatformNativeInterface();
m_eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
if (m_eglDisplay == EGL_NO_DISPLAY)
if (Q_UNLIKELY(m_eglDisplay == EGL_NO_DISPLAY))
qFatal("Could not open egl display");
EGLint major, minor;
if (!eglInitialize(m_eglDisplay, &major, &minor))
if (Q_UNLIKELY(!eglInitialize(m_eglDisplay, &major, &minor)))
qFatal("Could not initialize egl display");
if (!eglBindAPI(EGL_OPENGL_ES_API))
if (Q_UNLIKELY(!eglBindAPI(EGL_OPENGL_ES_API)))
qFatal("Could not bind GL_ES API");
m_primaryScreen = new QAndroidPlatformScreen();

View File

@ -175,7 +175,7 @@ void QAndroidPlatformOpenGLWindow::createEgl(EGLConfig config)
m_androidSurfaceObject = QJNIObjectPrivate();
m_eglSurface = eglCreateWindowSurface(m_eglDisplay, config, m_nativeWindow, NULL);
m_format = q_glFormatFromConfig(m_eglDisplay, config, window()->requestedFormat());
if (m_eglSurface == EGL_NO_SURFACE) {
if (Q_UNLIKELY(m_eglSurface == EGL_NO_SURFACE)) {
EGLint error = eglGetError();
eglTerminate(m_eglDisplay);
qFatal("EGL Error : Could not create the egl surface: error = 0x%x\n", error);

View File

@ -203,12 +203,12 @@ QJsonObject AndroidStyle::loadStyleData()
QJsonParseError error;
QJsonDocument document = QJsonDocument::fromJson(f.readAll(), &error);
if (document.isNull()) {
if (Q_UNLIKELY(document.isNull())) {
qCritical() << error.errorString();
return QJsonObject();
}
if (!document.isObject()) {
if (Q_UNLIKELY(!document.isObject())) {
qCritical() << "Style.json does not contain a valid style.";
return QJsonObject();
}

View File

@ -51,7 +51,7 @@ public:
HRESULT hr = QWindowsDirect2DContext::instance()->d2dDevice()->CreateDeviceContext(
D2D1_DEVICE_CONTEXT_OPTIONS_NONE,
&deviceContext);
if (FAILED(hr))
if (Q_UNLIKELY(FAILED(hr)))
qFatal("%s: Couldn't create Direct2D Device Context: %#x", __FUNCTION__, hr);
}

View File

@ -77,7 +77,7 @@ void QEglFSKmsIntegration::platformInit()
qCDebug(qLcEglfsKmsDebug) << "Found the following video devices:" << devices;
d->deleteLater();
if (devices.isEmpty())
if (Q_UNLIKELY(devices.isEmpty()))
qFatal("Could not find DRM device!");
m_devicePath = devices.first();
@ -85,7 +85,7 @@ void QEglFSKmsIntegration::platformInit()
}
m_device = new QEglFSKmsDevice(this, m_devicePath);
if (!m_device->open())
if (Q_UNLIKELY(!m_device->open()))
qFatal("Could not open device %s - aborting!", qPrintable(m_devicePath));
}

View File

@ -52,20 +52,20 @@ QEglFSKmsEglDeviceIntegration::QEglFSKmsEglDeviceIntegration()
void QEglFSKmsEglDeviceIntegration::platformInit()
{
if (!query_egl_device())
if (Q_UNLIKELY(!query_egl_device()))
qFatal("Could not set up EGL device!");
const char *deviceName = m_funcs->query_device_string(m_egl_device, EGL_DRM_DEVICE_FILE_EXT);
if (!deviceName)
if (Q_UNLIKELY(!deviceName))
qFatal("Failed to query device name from EGLDevice");
qCDebug(qLcEglfsKmsDebug, "Opening %s", deviceName);
m_dri_fd = drmOpen(deviceName, Q_NULLPTR);
if (m_dri_fd < 0)
if (Q_UNLIKELY(m_dri_fd < 0))
qFatal("Could not open DRM device");
if (!setup_kms())
if (Q_UNLIKELY(!setup_kms()))
qFatal("Could not set up KMS on device %s!", m_device.constData());
qCDebug(qLcEglfsKmsDebug, "DRM/KMS initialized");
@ -100,14 +100,14 @@ EGLDisplay QEglFSKmsEglDeviceIntegration::createDisplay(EGLNativeDisplayType nat
display = eglGetDisplay(nativeDisplay);
}
if (display == EGL_NO_DISPLAY)
if (Q_UNLIKELY(display == EGL_NO_DISPLAY))
qFatal("Could not get EGL display");
EGLint major, minor;
if (!eglInitialize(display, &major, &minor))
if (Q_UNLIKELY(!eglInitialize(display, &major, &minor)))
qFatal("Could not initialize egl display");
if (!eglBindAPI(EGL_OPENGL_ES_API))
if (Q_UNLIKELY(!eglBindAPI(EGL_OPENGL_ES_API)))
qFatal("Failed to bind EGL_OPENGL_ES_API\n");
return display;
@ -255,8 +255,8 @@ QEglFSWindow *QEglFSKmsEglDeviceIntegration::createWindow(QWindow *window) const
QEglJetsonTK1Window *eglWindow = new QEglJetsonTK1Window(window, this);
m_funcs->initialize(eglWindow->screen()->display());
if (!(m_funcs->has_egl_output_base && m_funcs->has_egl_output_drm && m_funcs->has_egl_stream
&& m_funcs->has_egl_stream_producer_eglsurface && m_funcs->has_egl_stream_consumer_egloutput))
if (Q_UNLIKELY(!(m_funcs->has_egl_output_base && m_funcs->has_egl_output_drm && m_funcs->has_egl_stream &&
m_funcs->has_egl_stream_producer_eglsurface && m_funcs->has_egl_stream_consumer_egloutput)))
qFatal("Required extensions missing!");
return eglWindow;
@ -298,7 +298,7 @@ void QEglFSKmsEglDeviceIntegration::waitForVSync(QPlatformSurface *) const
-1, 0, 0,
&m_drm_connector->connector_id, 1,
const_cast<const drmModeModeInfoPtr>(&m_drm_mode));
if (ret)
if (Q_UNLIKELY(ret))
qFatal("drmModeSetCrtc failed");
}
}
@ -367,7 +367,7 @@ bool QEglFSKmsEglDeviceIntegration::setup_kms()
}
}
if (crtc == 0)
if (Q_UNLIKELY(crtc == 0))
qFatal("No suitable CRTC available");
m_drm_connector = connector;
@ -387,7 +387,7 @@ bool QEglFSKmsEglDeviceIntegration::setup_kms()
bool QEglFSKmsEglDeviceIntegration::query_egl_device()
{
m_funcs = new QEGLStreamConvenience;
if (!m_funcs->has_egl_device_base)
if (Q_UNLIKELY(!m_funcs->has_egl_device_base))
qFatal("EGL_EXT_device_base missing");
EGLint num_devices = 0;

View File

@ -172,7 +172,7 @@ void QEglFSX11Integration::sendConnectionEvent(xcb_atom_t a)
void QEglFSX11Integration::platformInit()
{
m_display = XOpenDisplay(0);
if (!m_display)
if (Q_UNLIKELY(!m_display))
qFatal("Could not open display");
XSetEventQueueOwner(DISPLAY, XCBOwnsEventQueue);

View File

@ -155,7 +155,7 @@ void QEGLDeviceIntegration::platformInit()
framebuffer = qt_safe_open(fbDev, O_RDONLY);
if (framebuffer == -1) {
if (Q_UNLIKELY(framebuffer == -1)) {
qWarning("EGLFS: Failed to open %s", fbDev.constData());
qFatal("EGLFS: Can't continue without a display");
}

View File

@ -118,11 +118,11 @@ void QEglFSIntegration::initialize()
qt_egl_device_integration()->platformInit();
m_display = qt_egl_device_integration()->createDisplay(nativeDisplay());
if (m_display == EGL_NO_DISPLAY)
if (Q_UNLIKELY(m_display == EGL_NO_DISPLAY))
qFatal("Could not open egl display");
EGLint major, minor;
if (!eglInitialize(m_display, &major, &minor))
if (Q_UNLIKELY(!eglInitialize(m_display, &major, &minor)))
qFatal("Could not initialize egl display");
m_inputContext = QPlatformInputContextFactory::create();

View File

@ -102,17 +102,15 @@ void QEglFSWindow::create()
QEglFSScreen *screen = this->screen();
QOpenGLCompositor *compositor = QOpenGLCompositor::instance();
if (screen->primarySurface() != EGL_NO_SURFACE) {
if (isRaster() && compositor->targetWindow()) {
m_format = compositor->targetWindow()->format();
if (Q_UNLIKELY(!isRaster() || !compositor->targetWindow())) {
#if !defined(Q_OS_ANDROID) || defined(Q_OS_ANDROID_NO_SDK)
// We can have either a single OpenGL window or multiple raster windows.
// Other combinations cannot work.
qFatal("EGLFS: OpenGL windows cannot be mixed with others.");
#endif
return;
}
#if !defined(Q_OS_ANDROID) || defined(Q_OS_ANDROID_NO_SDK)
// We can have either a single OpenGL window or multiple raster windows.
// Other combinations cannot work.
qFatal("EGLFS: OpenGL windows cannot be mixed with others.");
#endif
m_format = compositor->targetWindow()->format();
return;
}
@ -122,7 +120,7 @@ void QEglFSWindow::create()
resetSurface();
if (m_surface == EGL_NO_SURFACE) {
if (Q_UNLIKELY(m_surface == EGL_NO_SURFACE)) {
EGLint error = eglGetError();
eglTerminate(screen->display());
qFatal("EGL Error : Could not create the egl surface: error = 0x%x\n", error);
@ -135,7 +133,7 @@ void QEglFSWindow::create()
context->setShareContext(qt_gl_global_share_context());
context->setFormat(m_format);
context->setScreen(window()->screen());
if (!context->create())
if (Q_UNLIKELY(!context->create()))
qFatal("EGLFS: Failed to create compositing context");
compositor->setTarget(context, window());
}

View File

@ -127,7 +127,7 @@ QHaikuWindow::QHaikuWindow(QWindow *window)
m_window = haikuWindow;
if (!m_window)
if (Q_UNLIKELY(!m_window))
qFatal("QHaikuWindow: failed to create window");
setGeometry(rect);

View File

@ -129,7 +129,7 @@ namespace
// Which we verify, just in case
struct rlimit stackLimit = {0, 0};
if (getrlimit(RLIMIT_STACK, &stackLimit) == 0 && stackSize > stackLimit.rlim_cur)
if (Q_UNLIKELY(getrlimit(RLIMIT_STACK, &stackLimit) == 0 && stackSize > stackLimit.rlim_cur))
qFatal("Unexpectedly exceeded stack limit");
return stackSize;
@ -250,7 +250,7 @@ static void __attribute__((noinline, noreturn)) user_main_trampoline()
unsigned int bufferSize = [arg lengthOfBytesUsingEncoding:cStringEncoding] + 1;
argv[i] = reinterpret_cast<char *>(malloc(bufferSize));
if (![arg getCString:argv[i] maxLength:bufferSize encoding:cStringEncoding])
if (Q_UNLIKELY(![arg getCString:argv[i] maxLength:bufferSize encoding:cStringEncoding]))
qFatal("Could not convert argv[%d] to C string", i);
}

View File

@ -70,7 +70,7 @@ QIOSIntegration::QIOSIntegration()
, m_accessibility(0)
, m_debugWindowManagement(false)
{
if (![UIApplication sharedApplication]) {
if (Q_UNLIKELY(![UIApplication sharedApplication])) {
qFatal("Error: You are creating QApplication before calling UIApplicationMain.\n" \
"If you are writing a native iOS application, and only want to use Qt for\n" \
"parts of the application, a good place to create QApplication is from within\n" \

View File

@ -74,19 +74,19 @@ QMinimalEglScreen::QMinimalEglScreen(EGLNativeDisplayType display)
EGLint major, minor;
if (!eglBindAPI(EGL_OPENGL_ES_API)) {
if (Q_UNLIKELY(!eglBindAPI(EGL_OPENGL_ES_API))) {
qWarning("Could not bind GL_ES API\n");
qFatal("EGL error");
}
m_dpy = eglGetDisplay(display);
if (m_dpy == EGL_NO_DISPLAY) {
if (Q_UNLIKELY(m_dpy == EGL_NO_DISPLAY)) {
qWarning("Could not open egl display\n");
qFatal("EGL error");
}
qWarning("Opened display %p\n", m_dpy);
if (!eglInitialize(m_dpy, &major, &minor)) {
if (Q_UNLIKELY(!eglInitialize(m_dpy, &major, &minor))) {
qWarning("Could not initialize egl display\n");
qFatal("EGL error");
}
@ -135,9 +135,9 @@ void QMinimalEglScreen::createAndSetPlatformContext()
EGLNativeWindowType eglWindow = 0;
#ifdef Q_OPENKODE
if (kdInitializeNV() == KD_ENOTINITIALIZED) {
if (Q_UNLIKELY(kdInitializeNV() == KD_ENOTINITIALIZED))
qFatal("Did not manage to initialize openkode");
}
KDWindow *window = kdCreateWindow(m_dpy,config,0);
kdRealizeWindow(window,&eglWindow);
@ -148,7 +148,7 @@ void QMinimalEglScreen::createAndSetPlatformContext()
#endif
m_surface = eglCreateWindowSurface(m_dpy, config, eglWindow, NULL);
if (m_surface == EGL_NO_SURFACE) {
if (Q_UNLIKELY(m_surface == EGL_NO_SURFACE)) {
qWarning("Could not create the egl surface: error = 0x%x\n", eglGetError());
eglTerminate(m_dpy);
qFatal("EGL error");

View File

@ -100,7 +100,7 @@ void QMirClientClipboard::onDBusClipboardGetContentsFinished(QDBusPendingCallWat
Q_ASSERT(call == mPendingGetContentsCall.data());
QDBusPendingReply<QByteArray> reply = *call;
if (reply.isError()) {
if (Q_UNLIKELY(reply.isError())) {
qCritical("QMirClientClipboard - Failed to get system clipboard contents via D-Bus. %s, %s",
qPrintable(reply.error().name()), qPrintable(reply.error().message()));
// TODO: Might try again later a number of times...
@ -114,7 +114,7 @@ void QMirClientClipboard::onDBusClipboardGetContentsFinished(QDBusPendingCallWat
void QMirClientClipboard::onDBusClipboardSetContentsFinished(QDBusPendingCallWatcher *call)
{
QDBusPendingReply<void> reply = *call;
if (reply.isError()) {
if (Q_UNLIKELY(reply.isError())) {
qCritical("QMirClientClipboard - Failed to set the system clipboard contents via D-Bus. %s, %s",
qPrintable(reply.error().name()), qPrintable(reply.error().message()));
// TODO: Might try again later a number of times...
@ -148,9 +148,8 @@ void QMirClientClipboard::setupDBus()
"com.canonical.QtMir.Clipboard",
"ContentsChanged",
this, SLOT(updateMimeData(QByteArray)));
if (!ok) {
if (Q_UNLIKELY(!ok))
qCritical("QMirClientClipboard - Failed to connect to ContentsChanged signal form the D-Bus system clipboard.");
}
mDBusClipboard = new QDBusInterface("com.canonical.QtMir",
"/com/canonical/QtMir/Clipboard",

View File

@ -95,7 +95,7 @@ QMirClientClientIntegration::QMirClientClientIntegration()
// Create new application instance
mInstance = u_application_instance_new_from_description_with_options(mDesc, mOptions);
if (mInstance == nullptr)
if (Q_UNLIKELY(!mInstance))
qFatal("QMirClientClientIntegration: connection to Mir server failed. Check that a Mir server is\n"
"running, and the correct socket is being used and is accessible. The shell may have\n"
"rejected the incoming connection, so check its log file");

View File

@ -143,7 +143,7 @@ static Window createDummyWindow(QOffscreenX11Info *x11, XVisualInfo *visualInfo)
static Window createDummyWindow(QOffscreenX11Info *x11, GLXFBConfig config)
{
XVisualInfo *visualInfo = glXGetVisualFromFBConfig(x11->display(), config);
if (!visualInfo)
if (Q_UNLIKELY(!visualInfo))
qFatal("Could not initialize GLX");
Window window = createDummyWindow(x11, visualInfo);
XFree(visualInfo);
@ -177,7 +177,7 @@ QOffscreenX11GLXContext::QOffscreenX11GLXContext(QOffscreenX11Info *x11, QOpenGL
d->window = createDummyWindow(x11, config);
} else {
XVisualInfo *visualInfo = qglx_findVisualInfo(x11->display(), 0, &d->format);
if (!visualInfo)
if (Q_UNLIKELY(!visualInfo))
qFatal("Could not initialize GLX");
d->context = glXCreateContext(x11->display(), visualInfo, d->shareContext, true);
if (!d->context && d->shareContext) {

View File

@ -96,9 +96,8 @@ void QOpenWFDPort::attach()
mPhysicalSize = QSizeF(physicalWFDSize[0],physicalWFDSize[1]);
WFDint numAvailablePipelines = wfdGetPortAttribi(mDevice->handle(),mPort,WFD_PORT_PIPELINE_ID_COUNT);
if (!numAvailablePipelines) {
if (Q_UNLIKELY(!numAvailablePipelines))
qFatal("Not possible to make screen that is not possible to create WFPort with no pipline");
}
WFDint pipeIds[numAvailablePipelines];
wfdGetPortAttribiv(mDevice->handle(),mPort,WFD_PORT_BINDABLE_PIPELINE_IDS,numAvailablePipelines,pipeIds);
@ -109,9 +108,9 @@ void QOpenWFDPort::attach()
mDevice-> addToUsedPipelineSet(mPipelineId,this);
mPipeline = wfdCreatePipeline(mDevice->handle(),mPipelineId,WFD_NONE);
if (mPipeline == WFD_INVALID_HANDLE) {
if (Q_UNLIKELY(mPipeline == WFD_INVALID_HANDLE))
qFatal("Failed to create pipeline for port %p", this);
}
break;
}
}

View File

@ -76,7 +76,7 @@ QQnxBuffer::QQnxBuffer(screen_buffer_t buffer)
screen_get_buffer_property_pv(buffer, SCREEN_PROPERTY_POINTER, (void **)&dataPtr),
"Failed to query buffer pointer");
if (dataPtr == 0)
if (Q_UNLIKELY(!dataPtr))
qFatal("QQNX: buffer pointer is NULL, errno=%d", errno);
// Get format of buffer
@ -131,13 +131,13 @@ void QQnxBuffer::invalidateInCache()
qBufferDebug() << Q_FUNC_INFO;
// Verify native buffer exists
if (m_buffer == 0)
if (Q_UNLIKELY(!m_buffer))
qFatal("QQNX: can't invalidate cache for null buffer");
// Evict buffer's data from cache
errno = 0;
int result = msync(m_image.bits(), m_image.height() * m_image.bytesPerLine(), MS_INVALIDATE | MS_CACHE_ONLY);
if (result != 0)
if (Q_UNLIKELY(result != 0))
qFatal("QQNX: failed to invalidate cache, errno=%d", errno);
}

View File

@ -59,7 +59,7 @@ QQnxEglWindow::QQnxEglWindow(QWindow *window, screen_context_t context, bool nee
// Set window usage
const int val = SCREEN_USAGE_OPENGL_ES2;
const int result = screen_set_window_property_iv(nativeHandle(), SCREEN_PROPERTY_USAGE, &val);
if (result != 0)
if (Q_UNLIKELY(result != 0))
qFatal("QQnxEglWindow: failed to set window alpha usage, errno=%d", errno);
m_requestedBufferSize = shouldMakeFullScreen() ? screen()->geometry().size() : window->geometry().size();
@ -106,7 +106,7 @@ void QQnxEglWindow::destroyEGLSurface()
// Destroy EGL surface if it exists
if (m_eglSurface != EGL_NO_SURFACE) {
EGLBoolean eglResult = eglDestroySurface(platformOpenGLContext()->getEglDisplay(), m_eglSurface);
if (eglResult != EGL_TRUE)
if (Q_UNLIKELY(eglResult != EGL_TRUE))
qFatal("QQNX: failed to destroy EGL surface, err=%d", eglGetError());
}
@ -118,12 +118,12 @@ void QQnxEglWindow::swapEGLBuffers()
qEglWindowDebug() << Q_FUNC_INFO;
// Set current rendering API
EGLBoolean eglResult = eglBindAPI(EGL_OPENGL_ES_API);
if (eglResult != EGL_TRUE)
if (Q_UNLIKELY(eglResult != EGL_TRUE))
qFatal("QQNX: failed to set EGL API, err=%d", eglGetError());
// Post EGL surface to window
eglResult = eglSwapBuffers(m_platformOpenGLContext->getEglDisplay(), m_eglSurface);
if (eglResult != EGL_TRUE)
if (Q_UNLIKELY(eglResult != EGL_TRUE))
qFatal("QQNX: failed to swap EGL buffers, err=%d", eglGetError());
windowPosted();
@ -178,15 +178,15 @@ int QQnxEglWindow::pixelFormat() const
const QSurfaceFormat format = m_platformOpenGLContext->format();
// Extract size of color channels from window format
const int redSize = format.redBufferSize();
if (redSize == -1)
if (Q_UNLIKELY(redSize == -1))
qFatal("QQnxWindow: red size not defined");
const int greenSize = format.greenBufferSize();
if (greenSize == -1)
if (Q_UNLIKELY(greenSize == -1))
qFatal("QQnxWindow: green size not defined");
const int blueSize = format.blueBufferSize();
if (blueSize == -1)
if (Q_UNLIKELY(blueSize == -1))
qFatal("QQnxWindow: blue size not defined");
// select matching native format

View File

@ -61,7 +61,7 @@ QQnxGLContext::QQnxGLContext(QOpenGLContext *glContext)
// Set current rendering API
EGLBoolean eglResult = eglBindAPI(EGL_OPENGL_ES_API);
if (eglResult != EGL_TRUE)
if (Q_UNLIKELY(eglResult != EGL_TRUE))
qFatal("QQNX: failed to set EGL API, err=%d", eglGetError());
// Get colour channel sizes from window format
@ -113,7 +113,7 @@ QQnxGLContext::QQnxGLContext(QOpenGLContext *glContext)
// Select EGL config based on requested window format
m_eglConfig = q_configFromGLFormat(ms_eglDisplay, format);
if (m_eglConfig == 0)
if (Q_UNLIKELY(m_eglConfig == 0))
qFatal("QQnxGLContext: failed to find EGL config");
QQnxGLContext *glShareContext = static_cast<QQnxGLContext*>(m_glContext->shareHandle());
@ -121,7 +121,7 @@ QQnxGLContext::QQnxGLContext(QOpenGLContext *glContext)
m_eglContext = eglCreateContext(ms_eglDisplay, m_eglConfig, m_eglShareContext,
contextAttrs(format));
if (m_eglContext == EGL_NO_CONTEXT) {
if (Q_UNLIKELY(m_eglContext == EGL_NO_CONTEXT)) {
checkEGLError("eglCreateContext");
qFatal("QQnxGLContext: failed to create EGL context, err=%d", eglGetError());
}
@ -170,13 +170,13 @@ void QQnxGLContext::initializeContext()
// Initialize connection to EGL
ms_eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
if (ms_eglDisplay == EGL_NO_DISPLAY) {
if (Q_UNLIKELY(ms_eglDisplay == EGL_NO_DISPLAY)) {
checkEGLError("eglGetDisplay");
qFatal("QQnxGLContext: failed to obtain EGL display");
}
EGLBoolean eglResult = eglInitialize(ms_eglDisplay, 0, 0);
if (eglResult != EGL_TRUE) {
if (Q_UNLIKELY(eglResult != EGL_TRUE)) {
checkEGLError("eglInitialize");
qFatal("QQnxGLContext: failed to initialize EGL display, err=%d", eglGetError());
}
@ -198,7 +198,7 @@ bool QQnxGLContext::makeCurrent(QPlatformSurface *surface)
// Set current rendering API
EGLBoolean eglResult = eglBindAPI(EGL_OPENGL_ES_API);
if (eglResult != EGL_TRUE)
if (Q_UNLIKELY(eglResult != EGL_TRUE))
qFatal("QQnxGLContext: failed to set EGL API, err=%d", eglGetError());
QQnxEglWindow *platformWindow = dynamic_cast<QQnxEglWindow*>(surface);
@ -227,12 +227,12 @@ void QQnxGLContext::doneCurrent()
// set current rendering API
EGLBoolean eglResult = eglBindAPI(EGL_OPENGL_ES_API);
if (eglResult != EGL_TRUE)
if (Q_UNLIKELY(eglResult != EGL_TRUE))
qFatal("QQNX: failed to set EGL API, err=%d", eglGetError());
// clear curent EGL context and unbind EGL surface
eglResult = eglMakeCurrent(ms_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
if (eglResult != EGL_TRUE)
if (Q_UNLIKELY(eglResult != EGL_TRUE))
qFatal("QQNX: failed to clear current EGL context, err=%d", eglGetError());
}
@ -252,7 +252,7 @@ QFunctionPointer QQnxGLContext::getProcAddress(const QByteArray &procName)
// Set current rendering API
EGLBoolean eglResult = eglBindAPI(EGL_OPENGL_ES_API);
if (eglResult != EGL_TRUE)
if (Q_UNLIKELY(eglResult != EGL_TRUE))
qFatal("QQNX: failed to set EGL API, err=%d", eglGetError());
// Lookup EGL extension function pointer

View File

@ -44,8 +44,8 @@ void qScreenCheckError(int rc, const char *funcInfo, const char *message, bool c
rc = screen_flush_context(QQnxIntegration::screenContext(), 0);
}
if (rc) {
if (critical)
if (Q_UNLIKELY(rc)) {
if (Q_UNLIKELY(critical))
qCritical("%s - Screen: %s - Error: %s (%i)", funcInfo, message, strerror(errno), errno);
else
qWarning("%s - Screen: %s - Error: %s (%i)", funcInfo, message, strerror(errno), errno);

View File

@ -530,29 +530,28 @@ static bool imfAvailable()
if ( p_imf_client_init == 0 ) {
void *handle = dlopen("libinput_client.so.1", 0);
if ( handle ) {
p_imf_client_init = (int32_t (*)()) dlsym(handle, "imf_client_init");
p_imf_client_disconnect = (void (*)()) dlsym(handle, "imf_client_disconnect");
p_ictrl_open_session = (const input_session_t *(*)(connection_interface_t *))dlsym(handle, "ictrl_open_session");
p_ictrl_close_session = (void (*)(input_session_t *))dlsym(handle, "ictrl_close_session");
p_ictrl_dispatch_event = (int32_t (*)(event_t *))dlsym(handle, "ictrl_dispatch_event");
p_vkb_init_selection_service = (int32_t (*)())dlsym(handle, "vkb_init_selection_service");
p_ictrl_get_num_active_sessions = (int32_t (*)())dlsym(handle, "ictrl_get_num_active_sessions");
} else {
if (Q_UNLIKELY(!handle)) {
qCritical() << Q_FUNC_INFO << "libinput_client.so.1 is not present - IMF services are disabled.";
s_imfDisabled = true;
return false;
}
p_imf_client_init = (int32_t (*)()) dlsym(handle, "imf_client_init");
p_imf_client_disconnect = (void (*)()) dlsym(handle, "imf_client_disconnect");
p_ictrl_open_session = (const input_session_t *(*)(connection_interface_t *))dlsym(handle, "ictrl_open_session");
p_ictrl_close_session = (void (*)(input_session_t *))dlsym(handle, "ictrl_close_session");
p_ictrl_dispatch_event = (int32_t (*)(event_t *))dlsym(handle, "ictrl_dispatch_event");
p_vkb_init_selection_service = (int32_t (*)())dlsym(handle, "vkb_init_selection_service");
p_ictrl_get_num_active_sessions = (int32_t (*)())dlsym(handle, "ictrl_get_num_active_sessions");
if ( p_imf_client_init && p_ictrl_open_session && p_ictrl_dispatch_event ) {
s_imfReady = true;
} else {
if (Q_UNLIKELY(!p_imf_client_init || !p_ictrl_open_session || !p_ictrl_dispatch_event)) {
p_ictrl_open_session = 0;
p_ictrl_dispatch_event = 0;
s_imfDisabled = true;
qCritical() << Q_FUNC_INFO << "libinput_client.so.1 did not contain the correct symbols, library mismatch? IMF services are disabled.";
return false;
}
s_imfReady = true;
}
return s_imfReady;
@ -581,7 +580,7 @@ QQnxInputContext::QQnxInputContext(QQnxIntegration *integration, QQnxAbstractVir
Q_ASSERT(sInputContextInstance == 0);
sInputContextInstance = this;
if (p_imf_client_init() != 0) {
if (Q_UNLIKELY(p_imf_client_init() != 0)) {
s_imfInitFailed = true;
qCritical("imf_client_init failed - IMF services will be unavailable");
}

View File

@ -425,7 +425,7 @@ void QQnxIntegration::createDisplays()
&displayCount);
Q_SCREEN_CRITICALERROR(result, "Failed to query display count");
if (displayCount < 1) {
if (Q_UNLIKELY(displayCount < 1)) {
// Never happens, even if there's no display, libscreen returns 1
qFatal("QQnxIntegration: displayCount=%d", displayCount);
}

View File

@ -102,7 +102,7 @@ void QQnxNavigatorEventNotifier::parsePPS(const QByteArray &ppsData, QByteArray
QList<QByteArray> lines = ppsData.split('\n');
// validate pps object
if (lines.size() == 0 || lines.at(0) != "@control")
if (Q_UNLIKELY(lines.empty() || lines.at(0) != "@control"))
qFatal("QQNX: unrecognized pps object, data=%s", ppsData.constData());
// parse pps object attributes and extract values
@ -160,7 +160,7 @@ void QQnxNavigatorEventNotifier::replyPPS(const QByteArray &res, const QByteArra
// send pps message to navigator
errno = 0;
int bytes = write(m_fd, ppsData.constData(), ppsData.size());
if (bytes == -1)
if (Q_UNLIKELY(bytes == -1))
qFatal("QQNX: failed to write navigator pps, errno=%d", errno);
}
@ -198,7 +198,7 @@ void QQnxNavigatorEventNotifier::readData()
// attempt to read pps data
errno = 0;
int bytes = qt_safe_read(m_fd, buffer, ppsBufferSize - 1);
if (bytes == -1)
if (Q_UNLIKELY(bytes == -1))
qFatal("QQNX: failed to read navigator pps, errno=%d", errno);
// check if pps data was received

View File

@ -100,7 +100,7 @@ bool QQnxNavigatorPps::sendPpsMessage(const QByteArray &message, const QByteArra
// send pps message to navigator
errno = 0;
int bytes = qt_safe_write(m_fd, ppsMessage.constData(), ppsMessage.size());
if (bytes == -1)
if (Q_UNLIKELY(bytes == -1))
qFatal("QQNX: failed to write navigator pps, errno=%d", errno);
// allocate buffer for pps data
@ -110,7 +110,7 @@ bool QQnxNavigatorPps::sendPpsMessage(const QByteArray &message, const QByteArra
do {
errno = 0;
bytes = qt_safe_read(m_fd, buffer, ppsBufferSize - 1);
if (bytes == -1)
if (Q_UNLIKELY(bytes == -1))
qFatal("QQNX: failed to read navigator pps, errno=%d", errno);
} while (bytes == 0);
@ -125,7 +125,7 @@ bool QQnxNavigatorPps::sendPpsMessage(const QByteArray &message, const QByteArra
parsePPS(ppsData, responseFields);
if (responseFields.contains("res") && responseFields.value("res") == message) {
if (responseFields.contains("err")) {
if (Q_UNLIKELY(responseFields.contains("err"))) {
qCritical() << "navigator responded with error: " << responseFields.value("err");
return false;
}
@ -142,7 +142,7 @@ void QQnxNavigatorPps::parsePPS(const QByteArray &ppsData, QHash<QByteArray, QBy
QList<QByteArray> lines = ppsData.split('\n');
// validate pps object
if (lines.size() == 0 || lines.at(0) != "@control")
if (Q_UNLIKELY(lines.empty() || lines.at(0) != "@control"))
qFatal("QQNX: unrecognized pps object, data=%s", ppsData.constData());
// parse pps object attributes and extract values

View File

@ -61,7 +61,7 @@ QQnxRasterWindow::QQnxRasterWindow(QWindow *window, screen_context_t context, bo
const int val = SCREEN_USAGE_NATIVE | SCREEN_USAGE_READ | SCREEN_USAGE_WRITE;
const int result = screen_set_window_property_iv(nativeHandle(), SCREEN_PROPERTY_USAGE, &val);
if (result != 0)
if (Q_UNLIKELY(result != 0))
qFatal("QQnxRasterWindow: failed to set window alpha usage, errno=%d", errno);
}

View File

@ -579,12 +579,12 @@ void QQnxScreenEventHandler::handlePropertyEvent(screen_event_t event)
errno = 0;
screen_window_t window = 0;
if (screen_get_event_property_pv(event, SCREEN_PROPERTY_WINDOW, (void**)&window) != 0)
if (Q_UNLIKELY(screen_get_event_property_pv(event, SCREEN_PROPERTY_WINDOW, (void**)&window) != 0))
qFatal("QQnx: failed to query window property, errno=%d", errno);
errno = 0;
int property;
if (screen_get_event_property_iv(event, SCREEN_PROPERTY_NAME, &property) != 0)
if (Q_UNLIKELY(screen_get_event_property_iv(event, SCREEN_PROPERTY_NAME, &property) != 0))
qFatal("QQnx: failed to query window property, errno=%d", errno);
switch (property) {
@ -601,7 +601,7 @@ void QQnxScreenEventHandler::handleKeyboardFocusPropertyEvent(screen_window_t wi
{
errno = 0;
int focus = 0;
if (window && screen_get_window_property_iv(window, SCREEN_PROPERTY_KEYBOARD_FOCUS, &focus) != 0)
if (Q_UNLIKELY(window && screen_get_window_property_iv(window, SCREEN_PROPERTY_KEYBOARD_FOCUS, &focus) != 0))
qFatal("QQnx: failed to query keyboard focus property, errno=%d", errno);
QWindow *focusWindow = QQnxIntegration::window(window);

View File

@ -127,7 +127,7 @@ bool QQnxVirtualKeyboardPps::connect()
}
m_buffer = new char[ms_bufferSize];
if (!m_buffer) {
if (Q_UNLIKELY(!m_buffer)) {
qCritical("QQnxVirtualKeyboard: Unable to allocate buffer of %d bytes. "
"Size is unavailable.", ms_bufferSize);
return false;
@ -170,7 +170,7 @@ void QQnxVirtualKeyboardPps::ppsDataReady()
return;
// nread is the real space necessary, not the amount read.
if (static_cast<size_t>(nread) > ms_bufferSize - 1) {
if (Q_UNLIKELY(static_cast<size_t>(nread) > ms_bufferSize - 1)) {
qCritical("QQnxVirtualKeyboard: Keyboard buffer size too short; need %u.", nread + 1);
connect(); // reconnect
return;
@ -184,7 +184,7 @@ void QQnxVirtualKeyboardPps::ppsDataReady()
#endif
const char *value;
if (pps_decoder_get_string(m_decoder, "error", &value) == PPS_DECODER_OK) {
if (Q_UNLIKELY(pps_decoder_get_string(m_decoder, "error", &value) == PPS_DECODER_OK)) {
qCritical("QQnxVirtualKeyboard: Keyboard PPS decoder error: %s", value ? value : "[null]");
return;
}
@ -214,11 +214,11 @@ void QQnxVirtualKeyboardPps::handleKeyboardInfoMessage()
{
int newHeight = 0;
if (pps_decoder_push(m_decoder, "dat") != PPS_DECODER_OK) {
if (Q_UNLIKELY(pps_decoder_push(m_decoder, "dat") != PPS_DECODER_OK)) {
qCritical("QQnxVirtualKeyboard: Keyboard PPS dat object not found");
return;
}
if (pps_decoder_get_int(m_decoder, "size", &newHeight) != PPS_DECODER_OK) {
if (Q_UNLIKELY(pps_decoder_get_int(m_decoder, "size", &newHeight) != PPS_DECODER_OK)) {
qCritical("QQnxVirtualKeyboard: Keyboard PPS size field not found");
return;
}

View File

@ -372,7 +372,7 @@ void QQnxWindow::setBufferSize(const QSize &size)
screen_get_window_property_iv(m_window, SCREEN_PROPERTY_RENDER_BUFFER_COUNT, &bufferCount),
"Failed to query render buffer count");
if (bufferCount != MAX_BUFFER_COUNT) {
if (Q_UNLIKELY(bufferCount != MAX_BUFFER_COUNT)) {
qFatal("QQnxWindow: invalid buffer count. Expected = %d, got = %d.",
MAX_BUFFER_COUNT, bufferCount);
}
@ -450,10 +450,10 @@ void QQnxWindow::removeFromParent()
qWindowDebug() << Q_FUNC_INFO << "window =" << window();
// Remove from old Hierarchy position
if (m_parentWindow) {
if (m_parentWindow->m_childWindows.removeAll(this))
m_parentWindow = 0;
else
if (Q_UNLIKELY(!m_parentWindow->m_childWindows.removeAll(this)))
qFatal("QQnxWindow: Window Hierarchy broken; window has parent, but parent hasn't got child.");
else
m_parentWindow = 0;
} else if (m_screen) {
m_screen->removeWindow(this);
}

View File

@ -187,7 +187,7 @@ void QWindowsUser32DLL::init()
// MinGW (g++ 3.4.5) accepts only C casts.
setLayeredWindowAttributes = (SetLayeredWindowAttributes)(library.resolve("SetLayeredWindowAttributes"));
updateLayeredWindow = (UpdateLayeredWindow)(library.resolve("UpdateLayeredWindow"));
if (!setLayeredWindowAttributes || !updateLayeredWindow)
if (Q_UNLIKELY(!setLayeredWindowAttributes || !updateLayeredWindow))
qFatal("This version of Windows is not supported (User32.dll is missing the symbols 'SetLayeredWindowAttributes', 'UpdateLayeredWindow').");
updateLayeredWindowIndirect = (UpdateLayeredWindowIndirect)(library.resolve("UpdateLayeredWindowIndirect"));

View File

@ -1582,7 +1582,7 @@ LOGFONT QWindowsFontDatabase::fontDefToLOGFONT(const QFontDef &request)
lf.lfPitchAndFamily = DEFAULT_PITCH | hint;
QString fam = request.family;
if (fam.size() >= LF_FACESIZE) {
if (Q_UNLIKELY(fam.size() >= LF_FACESIZE)) {
qCritical("%s: Family name '%s' is too long.", __FUNCTION__, qPrintable(fam));
fam.truncate(LF_FACESIZE - 1);
}

View File

@ -96,7 +96,7 @@ static inline HBITMAP createDIB(HDC hdc, int width, int height,
void *bits = 0;
HBITMAP bitmap = CreateDIBSection(hdc, reinterpret_cast<BITMAPINFO *>(&bmi),
DIB_RGB_COLORS, &bits, 0, 0);
if (!bitmap || !bits)
if (Q_UNLIKELY(!bitmap || !bits))
qFatal("%s: CreateDIBSection failed.", __FUNCTION__);
*bitsIn = (uchar*)bits;

View File

@ -55,7 +55,7 @@ struct WinRTEGLDisplay
{
WinRTEGLDisplay() {
eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
if (eglDisplay == EGL_NO_DISPLAY)
if (Q_UNLIKELY(eglDisplay == EGL_NO_DISPLAY))
qCritical("Failed to initialize EGL display: 0x%x", eglGetError());
}
~WinRTEGLDisplay() {
@ -114,10 +114,10 @@ void QWinRTEGLContext::initialize()
EGL_NONE,
};
g->eglDisplay = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, EGL_DEFAULT_DISPLAY, displayAttributes);
if (g->eglDisplay == EGL_NO_DISPLAY)
if (Q_UNLIKELY(g->eglDisplay == EGL_NO_DISPLAY))
qCritical("Failed to initialize EGL display: 0x%x", eglGetError());
if (!eglInitialize(g->eglDisplay, nullptr, nullptr))
if (Q_UNLIKELY(!eglInitialize(g->eglDisplay, nullptr, nullptr)))
qCritical("Failed to initialize EGL: 0x%x", eglGetError());
d->eglConfig = q_configFromGLFormat(g->eglDisplay, d->format);

View File

@ -180,7 +180,7 @@ QWinRTWindow::~QWinRTWindow()
EGLBoolean value = eglDestroySurface(d->display, d->surface);
d->surface = EGL_NO_SURFACE;
if (value == EGL_FALSE)
if (Q_UNLIKELY(value == EGL_FALSE))
qCritical("Failed to destroy EGL window surface: 0x%x", eglGetError());
}
@ -321,7 +321,7 @@ void QWinRTWindow::createEglSurface(EGLDisplay display, EGLConfig config)
d->surface = eglCreateWindowSurface(display, config,
reinterpret_cast<EGLNativeWindowType>(winId()),
nullptr);
if (d->surface == EGL_NO_SURFACE)
if (Q_UNLIKELY(d->surface == EGL_NO_SURFACE))
qCritical("Failed to create EGL window surface: 0x%x", eglGetError());
return S_OK;
});

View File

@ -99,7 +99,7 @@ static Window createDummyWindow(Display *dpy, XVisualInfo *visualInfo, int scree
static Window createDummyWindow(Display *dpy, GLXFBConfig config, int screenNumber, Window rootWin)
{
XVisualInfo *visualInfo = glXGetVisualFromFBConfig(dpy, config);
if (!visualInfo)
if (Q_UNLIKELY(!visualInfo))
qFatal("Could not initialize GLX");
Window window = createDummyWindow(dpy, visualInfo, screenNumber, rootWin);
XFree(visualInfo);
@ -301,7 +301,7 @@ void QGLXContext::init(QXcbScreen *screen, QPlatformOpenGLContext *share)
// Note that m_format gets updated with the used surface format
visualInfo = qglx_findVisualInfo(m_display, screen->screenNumber(), &m_format);
if (!visualInfo)
if (Q_UNLIKELY(!visualInfo))
qFatal("Could not initialize GLX");
m_context = glXCreateContext(m_display, visualInfo, m_shareContext, true);
if (!m_context && m_shareContext) {

View File

@ -521,7 +521,7 @@ QXcbConnection::QXcbConnection(QXcbNativeInterface *nativeInterface, bool canGra
m_connection = xcb_connect(m_displayName.constData(), &m_primaryScreenNumber);
#endif //XCB_USE_XLIB
if (!m_connection || xcb_connection_has_error(m_connection))
if (Q_UNLIKELY(!m_connection || xcb_connection_has_error(m_connection)))
qFatal("QXcbConnection: Could not connect to display %s", m_displayName.constData());
@ -553,7 +553,7 @@ QXcbConnection::QXcbConnection(QXcbNativeInterface *nativeInterface, bool canGra
initializeXFixes();
initializeScreens();
if (m_screens.isEmpty())
if (Q_UNLIKELY(m_screens.isEmpty()))
qFatal("QXcbConnection: no screens available");
initializeXRender();

View File

@ -395,7 +395,7 @@ void QXcbWindow::create()
if (!visualInfo)
visualInfo = static_cast<XVisualInfo *>(createVisual());
if (!visualInfo && window()->surfaceType() == QSurface::OpenGLSurface)
if (Q_UNLIKELY(!visualInfo && window()->surfaceType() == QSurface::OpenGLSurface))
qFatal("Could not initialize OpenGL");
if (!visualInfo && window()->surfaceType() == QSurface::RasterGLSurface) {

View File

@ -695,7 +695,7 @@ QPrinter::QPrinter(const QPrinterInfo& printer, PrinterMode mode)
void QPrinterPrivate::init(const QPrinterInfo &printer, QPrinter::PrinterMode mode)
{
if (!QCoreApplication::instance()) {
if (Q_UNLIKELY(!QCoreApplication::instance())) {
qFatal("QPrinter: Must construct a QCoreApplication before a QPrinter");
return;
}

View File

@ -1910,7 +1910,7 @@ void QIBaseDriver::qHandleEventNotification(void *updatedResultBuffer)
(isc_callback)qEventCallback,
#endif
eBuffer->resultBuffer);
if (status[0] == 1 && status[1]) {
if (Q_UNLIKELY(status[0] == 1 && status[1])) {
qCritical("QIBaseDriver::qHandleEventNotification: could not resubscribe to '%s'",
qPrintable(i.key()));
}

View File

@ -96,7 +96,7 @@ qint64 QBenchmarkValgrindUtils::extractResult(const QString &fileName)
break;
}
}
if (!valSeen)
if (Q_UNLIKELY(!valSeen))
qFatal("Failed to extract result");
return val;
}

View File

@ -2132,7 +2132,7 @@ public:
int t = timeout.load();
if (!t)
break;
if (!waitCondition.wait(&mutex, t)) {
if (Q_UNLIKELY(!waitCondition.wait(&mutex, t))) {
stackTrace();
qFatal("Test function timed out");
}
@ -2256,12 +2256,12 @@ void *fetchData(QTestData *data, const char *tagName, int typeId)
int idx = data->parent()->indexOf(tagName);
if (idx == -1 || idx >= data->dataCount()) {
if (Q_UNLIKELY(idx == -1 || idx >= data->dataCount())) {
qFatal("QFETCH: Requested testdata '%s' not available, check your _data function.",
tagName);
}
if (typeId != data->parent()->elementTypeId(idx)) {
if (Q_UNLIKELY(typeId != data->parent()->elementTypeId(idx))) {
qFatal("Requested type '%s' does not match available type '%s'.",
QMetaType::typeName(typeId),
QMetaType::typeName(data->parent()->elementTypeId(idx)));
@ -2940,7 +2940,7 @@ int QTest::qExec(QObject *testObject, int argc, char **argv)
#ifdef QTESTLIB_USE_VALGRIND
if (QBenchmarkGlobalData::current->mode() == QBenchmarkGlobalData::CallgrindParentProcess) {
if (!qApp)
if (Q_UNLIKELY(!qApp))
qFatal("QtTest: -callgrind option is not available with QTEST_APPLESS_MAIN");
const QStringList origAppArgs(QCoreApplication::arguments());

View File

@ -124,7 +124,7 @@ private:
if (![XCTestProbe isTesting])
return;
if (!([NSDate timeIntervalSinceReferenceDate] > 0))
if (Q_UNLIKELY(!([NSDate timeIntervalSinceReferenceDate] > 0)))
qFatal("error: Device date '%s' is bad, likely set to update automatically. Please correct.",
[[NSDate date] description].UTF8String);

View File

@ -304,7 +304,7 @@ int main(int argc, char *argv[])
{
// rcc uses a QHash to store files in the resource system.
// we must force a certain hash order when testing or tst_rcc will fail, see QTBUG-25078
if (!qEnvironmentVariableIsEmpty("QT_RCC_TEST") && !qt_qhash_seed.testAndSetRelaxed(-1, 0))
if (Q_UNLIKELY(!qEnvironmentVariableIsEmpty("QT_RCC_TEST") && !qt_qhash_seed.testAndSetRelaxed(-1, 0)))
qFatal("Cannot force QHash seed for testing as requested");
return QT_PREPEND_NAMESPACE(runRcc)(argc, argv);

View File

@ -289,7 +289,7 @@ QWidgetPrivate::QWidgetPrivate(int version)
, qd_hd(0)
#endif
{
if (!qApp) {
if (Q_UNLIKELY(!qApp)) {
qFatal("QWidget: Must construct a QApplication before a QWidget");
return;
}
@ -299,7 +299,7 @@ QWidgetPrivate::QWidgetPrivate(int version)
// This allows incompatible versions to be loaded, possibly for testing.
Q_UNUSED(version);
#else
if (version != QObjectPrivateVersion)
if (Q_UNLIKELY(version != QObjectPrivateVersion))
qFatal("Cannot mix incompatible Qt library (version 0x%x) with this library (version 0x%x)",
version, QObjectPrivateVersion);
#endif
@ -1116,7 +1116,7 @@ void QWidgetPrivate::adjustFlags(Qt::WindowFlags &flags, QWidget *w)
void QWidgetPrivate::init(QWidget *parentWidget, Qt::WindowFlags f)
{
Q_Q(QWidget);
if (!qobject_cast<QApplication *>(QCoreApplication::instance()))
if (Q_UNLIKELY(!qobject_cast<QApplication *>(QCoreApplication::instance())))
qFatal("QWidget: Cannot create a QWidget without QApplication");
Q_ASSERT(allWidgets);