return (ucnv_compareNames(name.constData(), name2.constData()) == 0);
}
-static QList<QTextCodec*> *all = Q_NULLPTR;
-#ifdef Q_DEBUG_TEXTCODEC
-static bool destroying_is_ok = false;
-#endif
-
static QTextCodec *localeMapper = Q_NULLPTR;
QTextCodec *QTextCodec::cftr = Q_NULLPTR;
+#ifndef QT_NO_THREAD
+Q_GLOBAL_STATIC_WITH_ARGS(QMutex, textCodecsMutex, (QMutex::Recursive))
+#endif
-
-class QTextCodecCleanup
+class QTextCodecCleanup : public QList<QTextCodec*>
{
public:
~QTextCodecCleanup();
*/
QTextCodecCleanup::~QTextCodecCleanup()
{
- if (!all)
- return;
-
-#ifdef Q_DEBUG_TEXTCODEC
- destroying_is_ok = true;
-#endif
-
- QList<QTextCodec *> *myAll = all;
- all = Q_NULLPTR; // Otherwise the d'tor destroys the iterator
- for (QList<QTextCodec *>::const_iterator it = myAll->constBegin()
- ; it != myAll->constEnd(); ++it) {
- delete *it;
+ for (int i = 0; i < this->size(); i++) {
+ delete this->at(i);
}
- delete myAll;
localeMapper = Q_NULLPTR;
-
-#ifdef Q_DEBUG_TEXTCODEC
- destroying_is_ok = false;
-#endif
}
-
-Q_GLOBAL_STATIC(QTextCodecCleanup, createQTextCodecCleanup)
+Q_GLOBAL_STATIC(QTextCodecCleanup, qGlobalQTextCodec)
static QTextCodec *checkForCodec(const QByteArray &name) {
QTextCodec *c = QTextCodec::codecForName(name);
localeMapper = QTextCodec::codecForName("ISO-8859-1");
}
-#ifndef QT_NO_THREAD
-Q_GLOBAL_STATIC_WITH_ARGS(QMutex, textCodecsMutex, (QMutex::Recursive))
-#endif
-
-// textCodecsMutex need to be locked to enter this function
-static void setup()
-{
- if (all)
- return;
-
-
-#ifdef Q_DEBUG_TEXTCODEC
- if (Q_UNLIKELY(destroying_is_ok))
- qWarning("QTextCodec: Creating new codec during codec cleanup");
-#endif
- all = new QList<QTextCodec*>;
- // create the cleanup object to cleanup all codecs on exit
- (void) createQTextCodecCleanup();
-}
-
/*!
\enum QTextCodec::ConversionFlag
#ifndef QT_NO_THREAD
QMutexLocker locker(textCodecsMutex());
#endif
- setup();
- all->append(this);
+ qGlobalQTextCodec()->append(this);
}
#ifndef QT_NO_THREAD
QMutexLocker locker(textCodecsMutex());
#endif
-#ifdef Q_DEBUG_TEXTCODEC
- if (Q_UNLIKELY(!destroying_is_ok))
- qWarning("QTextCodec::~QTextCodec: Called by application");
-#endif
- if (all) {
- all->removeAll(this);
- }
+ qGlobalQTextCodec()->removeAll(this);
}
/*!
#ifndef QT_NO_THREAD
QMutexLocker locker(textCodecsMutex());
#endif
- setup();
- for (int i = 0; i < all->size(); ++i) {
- QTextCodec *cursor = all->at(i);
+ for (int i = 0; i < qGlobalQTextCodec()->size(); ++i) {
+ QTextCodec *cursor = qGlobalQTextCodec()->at(i);
if (nameMatch(cursor->name(), name)) {
return cursor;
}
#ifndef QT_NO_THREAD
QMutexLocker locker(textCodecsMutex());
#endif
- setup();
- for (int i = 0; i < all->size(); ++i) {
- QTextCodec *cursor = all->at(i);
+ for (int i = 0; i < qGlobalQTextCodec()->size(); ++i) {
+ QTextCodec *cursor = qGlobalQTextCodec()->at(i);
if (cursor->mibEnum() == mib) {
return cursor;
}