mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-24 02:42:48 +00:00
kdecore: do not rely on compiler feature to detect null output
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
366c36f02a
commit
63dcefb9cd
4 changed files with 1 additions and 97 deletions
|
@ -766,45 +766,6 @@ void kClearDebugConfig()
|
|||
}
|
||||
}
|
||||
|
||||
// static
|
||||
bool KDebug::hasNullOutput(QtMsgType type,
|
||||
bool condition,
|
||||
int area,
|
||||
bool enableByDefault)
|
||||
{
|
||||
if (!condition) {
|
||||
return true;
|
||||
}
|
||||
if (kDebug_data.isDestroyed()) {
|
||||
// kDebugStream() will generate a warning anyway, so we don't.
|
||||
return false;
|
||||
}
|
||||
KDebugPrivate *const d = kDebug_data;
|
||||
QMutexLocker locker(&d->mutex);
|
||||
|
||||
if (type == QtDebugMsg) {
|
||||
int *entries = d->m_nullOutputYesNoCache;
|
||||
for (int i = 0; i < 8; i += 2) {
|
||||
if (entries[i] == area) {
|
||||
return entries[i + 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
KDebugPrivate::Cache::Iterator it = d->areaData(type, area, enableByDefault);
|
||||
const bool ret = it->mode[d->level(type)] == KDebugPrivate::NoOutput;
|
||||
|
||||
// cache result for next time...
|
||||
if (type == QtDebugMsg) {
|
||||
int *entries = d->m_nullOutputYesNoCache;
|
||||
int idx = (qrand() % 4) * 2;
|
||||
entries[idx] = area;
|
||||
entries[idx + 1] = ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int KDebug::registerArea(const QByteArray& areaName, bool enabled)
|
||||
{
|
||||
// TODO for optimization: static int s_lastAreaNumber = 1;
|
||||
|
|
|
@ -220,19 +220,6 @@ public:
|
|||
inline QDebug operator()(bool cond, int area = KDE_DEFAULT_DEBUG_AREA)
|
||||
{ if (cond) return operator()(area); return kDebugDevNull(); }
|
||||
|
||||
/// @internal
|
||||
static KDECORE_EXPORT bool hasNullOutput(QtMsgType type,
|
||||
bool condition,
|
||||
int area,
|
||||
bool enableByDefault);
|
||||
|
||||
/// @internal
|
||||
static inline bool hasNullOutputQtDebugMsg(int area = KDE_DEFAULT_DEBUG_AREA)
|
||||
{ return hasNullOutput(QtDebugMsg, true, area, KDE_DEBUG_ENABLED_BY_DEFAULT); }
|
||||
/// @internal
|
||||
static inline bool hasNullOutputQtDebugMsg(bool condition, int area = KDE_DEFAULT_DEBUG_AREA)
|
||||
{ return hasNullOutput(QtDebugMsg, condition, area, KDE_DEBUG_ENABLED_BY_DEFAULT); }
|
||||
|
||||
/**
|
||||
* @since 4.4
|
||||
* Register a debug area dynamically.
|
||||
|
@ -264,14 +251,7 @@ public:
|
|||
|
||||
|
||||
#if !defined(KDE_NO_DEBUG_OUTPUT)
|
||||
/* __VA_ARGS__ should work with any supported GCC version and MSVC > 2005 */
|
||||
# if defined(Q_CC_GNU)
|
||||
# define kDebug(...) for (bool _k_kDebugDoOutput_ = !KDebug::hasNullOutputQtDebugMsg(__VA_ARGS__); \
|
||||
Q_UNLIKELY(_k_kDebugDoOutput_); _k_kDebugDoOutput_ = false) \
|
||||
KDebug(QtDebugMsg, __FILE__, __LINE__, Q_FUNC_INFO)(__VA_ARGS__)
|
||||
# else
|
||||
# define kDebug KDebug(QtDebugMsg, __FILE__, __LINE__, Q_FUNC_INFO)
|
||||
# endif
|
||||
# define kDebug KDebug(QtDebugMsg, __FILE__, __LINE__, Q_FUNC_INFO)
|
||||
#else
|
||||
# define kDebug while (false) kDebug
|
||||
#endif
|
||||
|
|
|
@ -50,13 +50,9 @@ void KDebugTest::initTestCase()
|
|||
config.group("qttest").writeEntry("WarnOutput", 0 /*FileOutput*/);
|
||||
config.sync();
|
||||
|
||||
//QCOMPARE(KDebug::hasNullOutput(QtDebugMsg, true, 0, false), false);
|
||||
|
||||
// Test for crash that used to happen when using an unknown area after only dynamic areas
|
||||
KDebug::registerArea("somearea"); // gets number 1
|
||||
KDebug::registerArea("someotherarea"); // gets number 2
|
||||
QCOMPARE(KDebug::hasNullOutput(QtDebugMsg, true, 4242, false), false); // unknown area -> area 0 is being used
|
||||
|
||||
kClearDebugConfig();
|
||||
}
|
||||
|
||||
|
@ -213,38 +209,6 @@ void KDebugTest::testDisableAll()
|
|||
disableAll(false);
|
||||
}
|
||||
|
||||
void KDebugTest::testHasNullOutput()
|
||||
{
|
||||
// When compiling in debug mode:
|
||||
QCOMPARE(KDebug::hasNullOutput(QtDebugMsg, true, 0, true), false);
|
||||
QCOMPARE(KDebug::hasNullOutput(QtDebugMsg, true, 180, true), false);
|
||||
QCOMPARE(KDebug::hasNullOutput(QtDebugMsg, true, 293, true), false);
|
||||
QCOMPARE(KDebug::hasNullOutput(QtDebugMsg, true, 4242, true), false);
|
||||
|
||||
kClearDebugConfig(); // force dropping the cache
|
||||
|
||||
// When compiling in release mode:
|
||||
QCOMPARE(KDebug::hasNullOutput(QtDebugMsg, true, 0, false), false); // controlled by "InfoOutput" key
|
||||
QCOMPARE(KDebug::hasNullOutput(QtDebugMsg, true, 180, false), false); // controlled by "InfoOutput" key
|
||||
QCOMPARE(KDebug::hasNullOutput(QtDebugMsg, true, 293, false), false); // no config -> the default is being used
|
||||
QCOMPARE(KDebug::hasNullOutput(QtDebugMsg, true, 4242, false), false); // unknown area -> area 0 is being used
|
||||
|
||||
// And if we really have no config for area 0 (the app name)
|
||||
KConfig config("kdebugrc");
|
||||
config.deleteGroup("qttest");
|
||||
config.sync();
|
||||
kClearDebugConfig();
|
||||
|
||||
QCOMPARE(KDebug::hasNullOutput(QtDebugMsg, true, 0, false), true);
|
||||
QCOMPARE(KDebug::hasNullOutput(QtDebugMsg, true, 293, false), true);
|
||||
QCOMPARE(KDebug::hasNullOutput(QtDebugMsg, true, 4242, false), true);
|
||||
|
||||
// Restore to normal for future tests
|
||||
config.group("qttest").writeEntry("InfoOutput", 0 /*FileOutput*/);
|
||||
config.sync();
|
||||
kClearDebugConfig();
|
||||
}
|
||||
|
||||
void KDebugTest::testNoMainComponentData()
|
||||
{
|
||||
// This test runs kdebug_qcoreapptest and checks its output
|
||||
|
|
|
@ -36,7 +36,6 @@ private Q_SLOTS:
|
|||
void testDynamicArea();
|
||||
void testDisabledDynamicArea();
|
||||
void testDisableAll();
|
||||
void testHasNullOutput();
|
||||
void testNoMainComponentData();
|
||||
void testMultipleThreads();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue