diff options
author | Lars Knoll <lars.knoll@nokia.com> | 2010-04-12 08:50:29 (GMT) |
---|---|---|
committer | Lars Knoll <lars.knoll@nokia.com> | 2010-04-12 08:53:57 (GMT) |
commit | a321fd32ae1008736246b90ff0b149af498970ac (patch) | |
tree | 3802895295a104aa2c1f7a191a322d2716e590de | |
parent | d5d013b46ef2ea51172d364e8b32a82cb216056a (diff) | |
download | Qt-a321fd32ae1008736246b90ff0b149af498970ac.zip Qt-a321fd32ae1008736246b90ff0b149af498970ac.tar.gz Qt-a321fd32ae1008736246b90ff0b149af498970ac.tar.bz2 |
econd half of the crash fix for codecs on Symbian
Ensure that we do not try to use any codecs if we don't have a
cleanup stack available on Symbian.
Task-number: QT-3255
Reviewed-by: Iain
-rw-r--r-- | src/corelib/codecs/qtextcodec.cpp | 34 | ||||
-rw-r--r-- | src/corelib/codecs/qtextcodec.h | 5 |
2 files changed, 37 insertions, 2 deletions
diff --git a/src/corelib/codecs/qtextcodec.cpp b/src/corelib/codecs/qtextcodec.cpp index 1a08cca..18538e3 100644 --- a/src/corelib/codecs/qtextcodec.cpp +++ b/src/corelib/codecs/qtextcodec.cpp @@ -103,6 +103,7 @@ Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader, (QTextCodecFactoryInterface_iid, QLatin1String("/codecs"))) #endif + static char qtolower(register char c) { if (c >= 'A' && c <= 'Z') return c + 0x20; return c; } static bool qisalnum(register char c) @@ -217,6 +218,19 @@ QTextCodecCleanup::~QTextCodecCleanup() Q_GLOBAL_STATIC(QTextCodecCleanup, createQTextCodecCleanup) +bool QTextCodec::validCodecs() +{ +#ifdef Q_OS_SYMBIAN + // If we don't have a trap handler, we're outside of the main() function, + // ie. in global constructors or destructors. Don't use codecs in this + // case as it would lead to crashes because we don't have a cleanup stack on Symbian + return (User::TrapHandler() != NULL); +#else + return true; +#endif +} + + #if defined(Q_OS_WIN32) || defined(Q_OS_WINCE) class QWindowsLocalCodec: public QTextCodec { @@ -672,6 +686,9 @@ static void setup() return; #ifdef Q_OS_SYMBIAN + // If we don't have a trap handler, we're outside of the main() function, + // ie. in global constructors or destructors. Don't create codecs in this + // case as it would lead to crashes because of a missing cleanup stack on Symbian if (User::TrapHandler() == NULL) return; #endif @@ -969,6 +986,9 @@ QTextCodec *QTextCodec::codecForName(const QByteArray &name) #endif setup(); + if (!validCodecs()) + return 0; + static QHash <QByteArray, QTextCodec *> cache; if (clearCaches & 0x1) { cache.clear(); @@ -1010,6 +1030,9 @@ QTextCodec* QTextCodec::codecForMib(int mib) #endif setup(); + if (!validCodecs()) + return 0; + static QHash <int, QTextCodec *> cache; if (clearCaches & 0x2) { cache.clear(); @@ -1057,6 +1080,10 @@ QList<QByteArray> QTextCodec::availableCodecs() setup(); QList<QByteArray> codecs; + + if (!validCodecs()) + return codecs; + for (int i = 0; i < all->size(); ++i) { codecs += all->at(i)->name(); codecs += all->at(i)->aliases(); @@ -1095,6 +1122,10 @@ QList<int> QTextCodec::availableMibs() setup(); QList<int> codecs; + + if (!validCodecs()) + return codecs; + for (int i = 0; i < all->size(); ++i) codecs += all->at(i)->mibEnum(); @@ -1145,6 +1176,9 @@ void QTextCodec::setCodecForLocale(QTextCodec *c) QTextCodec* QTextCodec::codecForLocale() { + if (!validCodecs()) + return 0; + if (localeMapper) return localeMapper; diff --git a/src/corelib/codecs/qtextcodec.h b/src/corelib/codecs/qtextcodec.h index 169fe82..e82f8a4 100644 --- a/src/corelib/codecs/qtextcodec.h +++ b/src/corelib/codecs/qtextcodec.h @@ -145,12 +145,13 @@ public: private: friend class QTextCodecCleanup; static QTextCodec *cftr; + static bool validCodecs(); }; Q_DECLARE_OPERATORS_FOR_FLAGS(QTextCodec::ConversionFlags) -inline QTextCodec* QTextCodec::codecForTr() { return cftr; } + inline QTextCodec* QTextCodec::codecForTr() { return validCodecs() ? cftr : 0; } inline void QTextCodec::setCodecForTr(QTextCodec *c) { cftr = c; } -inline QTextCodec* QTextCodec::codecForCStrings() { return QString::codecForCStrings; } +inline QTextCodec* QTextCodec::codecForCStrings() { return validCodecs() ? QString::codecForCStrings : 0; } inline void QTextCodec::setCodecForCStrings(QTextCodec *c) { QString::codecForCStrings = c; } class Q_CORE_EXPORT QTextEncoder { |