diff options
author | Lars Knoll <lars.knoll@qt.io> | 2020-04-16 12:56:58 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2020-05-10 11:31:50 +0200 |
commit | babcabfbc899d5a72b282f8cf0b510840e91ba0e (patch) | |
tree | d4e89b175401d8daa0ca83675ab6b2f24de109e7 /src/corelib/codecs/qicucodec.cpp | |
parent | a77b19a911c4d6c47c185a8e59ebbcec8b14bcca (diff) |
Clean up state handling for ICU and iconv based codecs
Get rid of the hack for the FreeFunction and instead add a proper
function pointer to clear the data to the ConverterState struct.
Change-Id: I104aae1a4381c69f1a254713ec76e1aeaa862cdc
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/corelib/codecs/qicucodec.cpp')
-rw-r--r-- | src/corelib/codecs/qicucodec.cpp | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/src/corelib/codecs/qicucodec.cpp b/src/corelib/codecs/qicucodec.cpp index 8a6dfc756f..295cbfe97f 100644 --- a/src/corelib/codecs/qicucodec.cpp +++ b/src/corelib/codecs/qicucodec.cpp @@ -60,7 +60,7 @@ typedef QList<QByteArray>::ConstIterator ByteArrayListConstIt; static void qIcuCodecStateFree(QTextCodec::ConverterState *state) { - ucnv_close(static_cast<UConverter *>(state->d)); + ucnv_close(static_cast<UConverter *>(state->d[0])); } bool qTextCodecNameMatch(const char *n, const char *h) @@ -569,18 +569,17 @@ UConverter *QIcuCodec::getConverter(QTextCodec::ConverterState *state) const { UConverter *conv = nullptr; if (state) { - if (!state->d) { + if (!state->d[0]) { // first time - state->flags |= QTextCodec::FreeFunction; - QTextCodecUnalignedPointer::encode(state->state_data, qIcuCodecStateFree); + state->clearFn = qIcuCodecStateFree; UErrorCode error = U_ZERO_ERROR; - state->d = ucnv_open(m_name, &error); - ucnv_setSubstChars(static_cast<UConverter *>(state->d), + state->d[0] = ucnv_open(m_name, &error); + ucnv_setSubstChars(static_cast<UConverter *>(state->d[0]), state->flags & QTextCodec::ConvertInvalidToNull ? "\0" : "?", 1, &error); if (U_FAILURE(error)) qDebug("getConverter(state) ucnv_open failed %s %s", m_name, u_errorName(error)); } - conv = static_cast<UConverter *>(state->d); + conv = static_cast<UConverter *>(state->d[0]); } if (!conv) { // stateless conversion |