QLogging: deduplicate calling of isFatal()/qt_message_fatal()

Just roll everything up into qt_message().

Pick-to: 6.6
Change-Id: I2b24e1d3cad44897906efffd177fb9867131b795
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Kai Köhne <kai.koehne@qt.io>
This commit is contained in:
Thiago Macieira 2023-08-28 19:26:11 -07:00
parent 3bdb5e9cc9
commit 88e9ce201b

View File

@ -367,11 +367,13 @@ static inline void convert_to_wchar_t_elided(wchar_t *d, size_t space, const cha
\internal
*/
Q_NEVER_INLINE
static QString qt_message(QtMsgType msgType, const QMessageLogContext &context, const char *msg, va_list ap)
static void qt_message(QtMsgType msgType, const QMessageLogContext &context, const char *msg, va_list ap)
{
QString buf = QString::vasprintf(msg, ap);
qt_message_print(msgType, context, buf);
return buf;
if (isFatal(msgType))
qt_message_fatal(msgType, context, buf);
}
#undef qDebug
@ -385,11 +387,8 @@ void QMessageLogger::debug(const char *msg, ...) const
{
va_list ap;
va_start(ap, msg); // use variable arg list
const QString message = qt_message(QtDebugMsg, context, msg, ap);
qt_message(QtDebugMsg, context, msg, ap);
va_end(ap);
if (isFatal(QtDebugMsg))
qt_message_fatal(QtDebugMsg, context, message);
}
@ -405,11 +404,8 @@ void QMessageLogger::info(const char *msg, ...) const
{
va_list ap;
va_start(ap, msg); // use variable arg list
const QString message = qt_message(QtInfoMsg, context, msg, ap);
qt_message(QtInfoMsg, context, msg, ap);
va_end(ap);
if (isFatal(QtInfoMsg))
qt_message_fatal(QtInfoMsg, context, message);
}
/*!
@ -444,11 +440,8 @@ void QMessageLogger::debug(const QLoggingCategory &cat, const char *msg, ...) co
va_list ap;
va_start(ap, msg); // use variable arg list
const QString message = qt_message(QtDebugMsg, ctxt, msg, ap);
qt_message(QtDebugMsg, ctxt, msg, ap);
va_end(ap);
if (isFatal(QtDebugMsg))
qt_message_fatal(QtDebugMsg, ctxt, message);
}
/*!
@ -471,11 +464,8 @@ void QMessageLogger::debug(QMessageLogger::CategoryFunction catFunc,
va_list ap;
va_start(ap, msg); // use variable arg list
const QString message = qt_message(QtDebugMsg, ctxt, msg, ap);
qt_message(QtDebugMsg, ctxt, msg, ap);
va_end(ap);
if (isFatal(QtDebugMsg))
qt_message_fatal(QtDebugMsg, ctxt, message);
}
#ifndef QT_NO_DEBUG_STREAM
@ -555,11 +545,8 @@ void QMessageLogger::info(const QLoggingCategory &cat, const char *msg, ...) con
va_list ap;
va_start(ap, msg); // use variable arg list
const QString message = qt_message(QtInfoMsg, ctxt, msg, ap);
qt_message(QtInfoMsg, ctxt, msg, ap);
va_end(ap);
if (isFatal(QtInfoMsg))
qt_message_fatal(QtInfoMsg, ctxt, message);
}
/*!
@ -582,11 +569,8 @@ void QMessageLogger::info(QMessageLogger::CategoryFunction catFunc,
va_list ap;
va_start(ap, msg); // use variable arg list
const QString message = qt_message(QtInfoMsg, ctxt, msg, ap);
qt_message(QtInfoMsg, ctxt, msg, ap);
va_end(ap);
if (isFatal(QtInfoMsg))
qt_message_fatal(QtInfoMsg, ctxt, message);
}
#ifndef QT_NO_DEBUG_STREAM
@ -648,11 +632,8 @@ void QMessageLogger::warning(const char *msg, ...) const
{
va_list ap;
va_start(ap, msg); // use variable arg list
const QString message = qt_message(QtWarningMsg, context, msg, ap);
qt_message(QtWarningMsg, context, msg, ap);
va_end(ap);
if (isFatal(QtWarningMsg))
qt_message_fatal(QtWarningMsg, context, message);
}
/*!
@ -673,11 +654,8 @@ void QMessageLogger::warning(const QLoggingCategory &cat, const char *msg, ...)
va_list ap;
va_start(ap, msg); // use variable arg list
const QString message = qt_message(QtWarningMsg, ctxt, msg, ap);
qt_message(QtWarningMsg, ctxt, msg, ap);
va_end(ap);
if (isFatal(QtWarningMsg))
qt_message_fatal(QtWarningMsg, ctxt, message);
}
/*!
@ -700,11 +678,8 @@ void QMessageLogger::warning(QMessageLogger::CategoryFunction catFunc,
va_list ap;
va_start(ap, msg); // use variable arg list
const QString message = qt_message(QtWarningMsg, ctxt, msg, ap);
qt_message(QtWarningMsg, ctxt, msg, ap);
va_end(ap);
if (isFatal(QtWarningMsg))
qt_message_fatal(QtWarningMsg, ctxt, message);
}
#ifndef QT_NO_DEBUG_STREAM
@ -764,11 +739,8 @@ void QMessageLogger::critical(const char *msg, ...) const
{
va_list ap;
va_start(ap, msg); // use variable arg list
const QString message = qt_message(QtCriticalMsg, context, msg, ap);
qt_message(QtCriticalMsg, context, msg, ap);
va_end(ap);
if (isFatal(QtCriticalMsg))
qt_message_fatal(QtCriticalMsg, context, message);
}
/*!
@ -789,11 +761,8 @@ void QMessageLogger::critical(const QLoggingCategory &cat, const char *msg, ...)
va_list ap;
va_start(ap, msg); // use variable arg list
const QString message = qt_message(QtCriticalMsg, ctxt, msg, ap);
qt_message(QtCriticalMsg, ctxt, msg, ap);
va_end(ap);
if (isFatal(QtCriticalMsg))
qt_message_fatal(QtCriticalMsg, ctxt, message);
}
/*!
@ -816,11 +785,8 @@ void QMessageLogger::critical(QMessageLogger::CategoryFunction catFunc,
va_list ap;
va_start(ap, msg); // use variable arg list
const QString message = qt_message(QtCriticalMsg, ctxt, msg, ap);
qt_message(QtCriticalMsg, ctxt, msg, ap);
va_end(ap);
if (isFatal(QtCriticalMsg))
qt_message_fatal(QtCriticalMsg, ctxt, message);
}
#ifndef QT_NO_DEBUG_STREAM
@ -884,14 +850,14 @@ void QMessageLogger::fatal(const QLoggingCategory &cat, const char *msg, ...) co
ctxt.copyContextFrom(context);
ctxt.category = cat.categoryName();
QString message;
va_list ap;
va_start(ap, msg); // use variable arg list
QT_TERMINATE_ON_EXCEPTION(message = qt_message(QtFatalMsg, ctxt, msg, ap));
QT_TERMINATE_ON_EXCEPTION(qt_message(QtFatalMsg, ctxt, msg, ap));
va_end(ap);
qt_message_fatal(QtCriticalMsg, ctxt, message);
#ifndef Q_CC_MSVC_ONLY
Q_UNREACHABLE();
#endif
}
/*!
@ -910,14 +876,14 @@ void QMessageLogger::fatal(QMessageLogger::CategoryFunction catFunc,
ctxt.copyContextFrom(context);
ctxt.category = cat.categoryName();
QString message;
va_list ap;
va_start(ap, msg); // use variable arg list
QT_TERMINATE_ON_EXCEPTION(message = qt_message(QtFatalMsg, ctxt, msg, ap));
QT_TERMINATE_ON_EXCEPTION(qt_message(QtFatalMsg, ctxt, msg, ap));
va_end(ap);
qt_message_fatal(QtFatalMsg, ctxt, message);
#ifndef Q_CC_MSVC_ONLY
Q_UNREACHABLE();
#endif
}
/*!
@ -928,14 +894,14 @@ void QMessageLogger::fatal(QMessageLogger::CategoryFunction catFunc,
*/
void QMessageLogger::fatal(const char *msg, ...) const noexcept
{
QString message;
va_list ap;
va_start(ap, msg); // use variable arg list
QT_TERMINATE_ON_EXCEPTION(message = qt_message(QtFatalMsg, context, msg, ap));
QT_TERMINATE_ON_EXCEPTION(qt_message(QtFatalMsg, context, msg, ap));
va_end(ap);
qt_message_fatal(QtFatalMsg, context, message);
#ifndef Q_CC_MSVC_ONLY
Q_UNREACHABLE();
#endif
}
#ifndef QT_NO_DEBUG_STREAM