diff --git a/src/corelib/codecs/qicucodec.cpp b/src/corelib/codecs/qicucodec.cpp index 295cbfe97f..6feb8a2070 100644 --- a/src/corelib/codecs/qicucodec.cpp +++ b/src/corelib/codecs/qicucodec.cpp @@ -43,7 +43,6 @@ #include "qutfcodec_p.h" #include "qlatincodec_p.h" #include "qsimplecodec_p.h" -#include "private/qcoreglobaldata_p.h" #include "qdebug.h" #include "unicode/ucnv.h" @@ -436,7 +435,7 @@ QList QIcuCodec::availableMibs() QTextCodec *QIcuCodec::defaultCodecUnlocked() { - QCoreGlobalData *globalData = QCoreGlobalData::instance(); + QTextCodecData *globalData = QTextCodecData::instance(); if (!globalData) return nullptr; QTextCodec *c = globalData->codecForLocale.loadAcquire(); @@ -491,7 +490,7 @@ QTextCodec *QIcuCodec::codecForNameUnlocked(const char *name) standardName = "windows-949"; } - QCoreGlobalData *globalData = QCoreGlobalData::instance(); + QTextCodecData *globalData = QTextCodecData::instance(); QTextCodecCache *cache = &globalData->codecCache; QTextCodec *codec; diff --git a/src/corelib/codecs/qtextcodec.cpp b/src/corelib/codecs/qtextcodec.cpp index 72f9dcc0a8..be585d0407 100644 --- a/src/corelib/codecs/qtextcodec.cpp +++ b/src/corelib/codecs/qtextcodec.cpp @@ -53,7 +53,6 @@ #if !defined(QT_BOOTSTRAPPED) #include #endif -#include "private/qcoreglobaldata_p.h" #include "qutfcodec_p.h" #include "qlatincodec_p.h" @@ -103,6 +102,28 @@ typedef QList::ConstIterator ByteArrayListConstIt; Q_GLOBAL_STATIC(QRecursiveMutex, textCodecsMutex); +Q_GLOBAL_STATIC(QTextCodecData, textCodecData) + +QTextCodecData::QTextCodecData() + : codecForLocale(nullptr) +{ +} + +QTextCodecData::~QTextCodecData() +{ + codecForLocale = nullptr; + QList tmp = allCodecs; + allCodecs.clear(); + codecCache.clear(); + for (QList::const_iterator it = tmp.constBegin(); it != tmp.constEnd(); ++it) + delete *it; +} + +QTextCodecData *QTextCodecData::instance() +{ + return textCodecData(); +} + class TextCodecsMutexLocker { using Lock = decltype(qt_unique_lock(std::declval())); @@ -166,7 +187,7 @@ static void setup(); // setCodecForLocale(0) is called at the same time. static QTextCodec *setupLocaleMapper() { - QCoreGlobalData *globalData = QCoreGlobalData::instance(); + QTextCodecData *globalData = QTextCodecData::instance(); QTextCodec *locale = nullptr; @@ -477,7 +498,7 @@ QTextCodec::QTextCodec() { const TextCodecsMutexLocker locker; - QCoreGlobalData *globalInstance = QCoreGlobalData::instance(); + QTextCodecData *globalInstance = QTextCodecData::instance(); if (globalInstance->allCodecs.isEmpty()) setup(); @@ -493,7 +514,7 @@ QTextCodec::QTextCodec() */ QTextCodec::~QTextCodec() { - QCoreGlobalData *globalData = QCoreGlobalData::instance(); + QTextCodecData *globalData = QTextCodecData::instance(); if (!globalData) return; @@ -534,7 +555,7 @@ QTextCodec *QTextCodec::codecForName(const QByteArray &name) const TextCodecsMutexLocker locker; - QCoreGlobalData *globalData = QCoreGlobalData::instance(); + QTextCodecData *globalData = QTextCodecData::instance(); if (!globalData) return nullptr; setup(); @@ -578,7 +599,7 @@ QTextCodec* QTextCodec::codecForMib(int mib) { const TextCodecsMutexLocker locker; - QCoreGlobalData *globalData = QCoreGlobalData::instance(); + QTextCodecData *globalData = QTextCodecData::instance(); if (!globalData) return nullptr; if (globalData->allCodecs.isEmpty()) @@ -624,7 +645,7 @@ QList QTextCodec::availableCodecs() { const TextCodecsMutexLocker locker; - QCoreGlobalData *globalData = QCoreGlobalData::instance(); + QTextCodecData *globalData = QTextCodecData::instance(); if (globalData->allCodecs.isEmpty()) setup(); @@ -656,7 +677,7 @@ QList QTextCodec::availableMibs() #else const TextCodecsMutexLocker locker; - QCoreGlobalData *globalData = QCoreGlobalData::instance(); + QTextCodecData *globalData = QTextCodecData::instance(); if (globalData->allCodecs.isEmpty()) setup(); @@ -683,7 +704,7 @@ QList QTextCodec::availableMibs() */ void QTextCodec::setCodecForLocale(QTextCodec *c) { - QCoreGlobalData::instance()->codecForLocale.storeRelease(c); + QTextCodecData::instance()->codecForLocale.storeRelease(c); } /*! @@ -697,7 +718,7 @@ void QTextCodec::setCodecForLocale(QTextCodec *c) QTextCodec* QTextCodec::codecForLocale() { - QCoreGlobalData *globalData = QCoreGlobalData::instance(); + QTextCodecData *globalData = QTextCodecData::instance(); if (!globalData) return nullptr; diff --git a/src/corelib/codecs/qtextcodec.h b/src/corelib/codecs/qtextcodec.h index 84e875c91f..17dbd08a3b 100644 --- a/src/corelib/codecs/qtextcodec.h +++ b/src/corelib/codecs/qtextcodec.h @@ -117,7 +117,7 @@ protected: virtual ~QTextCodec(); private: - friend struct QCoreGlobalData; + friend struct QTextCodecData; }; class Q_CORE_EXPORT QTextEncoder { diff --git a/src/corelib/codecs/qtextcodec_p.h b/src/corelib/codecs/qtextcodec_p.h index ef5758619d..d4b22c4754 100644 --- a/src/corelib/codecs/qtextcodec_p.h +++ b/src/corelib/codecs/qtextcodec_p.h @@ -53,19 +53,35 @@ #include #include +#include +#if QT_CONFIG(textcodec) +#include "qtextcodec.h" +#endif QT_BEGIN_NAMESPACE #if QT_CONFIG(textcodec) -#include "qtextcodec.h" - #if defined(Q_OS_MAC) || defined(Q_OS_ANDROID) || defined(Q_OS_QNX) || defined(Q_OS_WASM) #define QT_LOCALE_IS_UTF8 #endif typedef void (*QTextCodecStateFreeFunction)(QTextCodec::ConverterState*); +typedef QHash QTextCodecCache; + +struct QTextCodecData +{ + QTextCodecData(); + ~QTextCodecData(); + + QList allCodecs; + QAtomicPointer codecForLocale; + QTextCodecCache codecCache; + + static QTextCodecData *instance(); +}; + bool qTextCodecNameMatch(const char *a, const char *b); #else // without textcodec: diff --git a/src/corelib/kernel/qcoreglobaldata.cpp b/src/corelib/kernel/qcoreglobaldata.cpp index 7ff222f170..4df5a40e39 100644 --- a/src/corelib/kernel/qcoreglobaldata.cpp +++ b/src/corelib/kernel/qcoreglobaldata.cpp @@ -38,31 +38,17 @@ ****************************************************************************/ #include "qcoreglobaldata_p.h" -#if QT_CONFIG(textcodec) -#include "qtextcodec.h" -#endif QT_BEGIN_NAMESPACE Q_GLOBAL_STATIC(QCoreGlobalData, globalInstance) QCoreGlobalData::QCoreGlobalData() -#if QT_CONFIG(textcodec) - : codecForLocale(nullptr) -#endif { } QCoreGlobalData::~QCoreGlobalData() { -#if QT_CONFIG(textcodec) - codecForLocale = nullptr; - QList tmp = allCodecs; - allCodecs.clear(); - codecCache.clear(); - for (QList::const_iterator it = tmp.constBegin(); it != tmp.constEnd(); ++it) - delete *it; -#endif } QCoreGlobalData *QCoreGlobalData::instance() diff --git a/src/corelib/kernel/qcoreglobaldata_p.h b/src/corelib/kernel/qcoreglobaldata_p.h index fda6b52b6e..2b9677efd9 100644 --- a/src/corelib/kernel/qcoreglobaldata_p.h +++ b/src/corelib/kernel/qcoreglobaldata_p.h @@ -57,15 +57,10 @@ #include "QtCore/qreadwritelock.h" #include "QtCore/qhash.h" #include "QtCore/qbytearray.h" -#if QT_CONFIG(textcodec) -#include "QtCore/qtextcodec.h" -#endif #include "QtCore/qmutex.h" QT_BEGIN_NAMESPACE -typedef QHash QTextCodecCache; - struct QCoreGlobalData { QCoreGlobalData(); ~QCoreGlobalData(); @@ -73,12 +68,6 @@ struct QCoreGlobalData { QMap dirSearchPaths; QReadWriteLock dirSearchPathsLock; -#if QT_CONFIG(textcodec) - QList allCodecs; - QAtomicPointer codecForLocale; - QTextCodecCache codecCache; -#endif - static QCoreGlobalData *instance(); };