Remove QTextCodec dependency from QCoreGobalData

As we want to move text codecs out of Qt Core, disentangle the
dependency, but moving the global codec data into qtextcodec.*.

Change-Id: Id7498423c7c4f9f42fd00c450947305d2af8c4be
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
This commit is contained in:
Lars Knoll 2020-04-25 11:11:23 +02:00
parent 940665eff5
commit 1cab047d08
6 changed files with 52 additions and 41 deletions

View File

@ -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<int> 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;

View File

@ -53,7 +53,6 @@
#if !defined(QT_BOOTSTRAPPED)
#include <private/qcoreapplication_p.h>
#endif
#include "private/qcoreglobaldata_p.h"
#include "qutfcodec_p.h"
#include "qlatincodec_p.h"
@ -103,6 +102,28 @@ typedef QList<QByteArray>::ConstIterator ByteArrayListConstIt;
Q_GLOBAL_STATIC(QRecursiveMutex, textCodecsMutex);
Q_GLOBAL_STATIC(QTextCodecData, textCodecData)
QTextCodecData::QTextCodecData()
: codecForLocale(nullptr)
{
}
QTextCodecData::~QTextCodecData()
{
codecForLocale = nullptr;
QList<QTextCodec *> tmp = allCodecs;
allCodecs.clear();
codecCache.clear();
for (QList<QTextCodec *>::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<QRecursiveMutex&>()));
@ -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<QByteArray> QTextCodec::availableCodecs()
{
const TextCodecsMutexLocker locker;
QCoreGlobalData *globalData = QCoreGlobalData::instance();
QTextCodecData *globalData = QTextCodecData::instance();
if (globalData->allCodecs.isEmpty())
setup();
@ -656,7 +677,7 @@ QList<int> QTextCodec::availableMibs()
#else
const TextCodecsMutexLocker locker;
QCoreGlobalData *globalData = QCoreGlobalData::instance();
QTextCodecData *globalData = QTextCodecData::instance();
if (globalData->allCodecs.isEmpty())
setup();
@ -683,7 +704,7 @@ QList<int> 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;

View File

@ -117,7 +117,7 @@ protected:
virtual ~QTextCodec();
private:
friend struct QCoreGlobalData;
friend struct QTextCodecData;
};
class Q_CORE_EXPORT QTextEncoder {

View File

@ -53,19 +53,35 @@
#include <QtCore/private/qglobal_p.h>
#include <string.h>
#include <qhash.h>
#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<QByteArray, QTextCodec *> QTextCodecCache;
struct QTextCodecData
{
QTextCodecData();
~QTextCodecData();
QList<QTextCodec*> allCodecs;
QAtomicPointer<QTextCodec> codecForLocale;
QTextCodecCache codecCache;
static QTextCodecData *instance();
};
bool qTextCodecNameMatch(const char *a, const char *b);
#else // without textcodec:

View File

@ -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<QTextCodec *> tmp = allCodecs;
allCodecs.clear();
codecCache.clear();
for (QList<QTextCodec *>::const_iterator it = tmp.constBegin(); it != tmp.constEnd(); ++it)
delete *it;
#endif
}
QCoreGlobalData *QCoreGlobalData::instance()

View File

@ -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<QByteArray, QTextCodec *> QTextCodecCache;
struct QCoreGlobalData {
QCoreGlobalData();
~QCoreGlobalData();
@ -73,12 +68,6 @@ struct QCoreGlobalData {
QMap<QString, QStringList> dirSearchPaths;
QReadWriteLock dirSearchPathsLock;
#if QT_CONFIG(textcodec)
QList<QTextCodec*> allCodecs;
QAtomicPointer<QTextCodec> codecForLocale;
QTextCodecCache codecCache;
#endif
static QCoreGlobalData *instance();
};