X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fsupport%2Funicode.cpp;h=95415a5538e45ad11a4ed4695c5b277ae79024c3;hb=12554c93d81f75f87c34040fd7737048d3518d6d;hp=7f601a86c5e32f684c8a9345fb87ffcb7b20eed4;hpb=d5a41946a6848e2869b6ca2c2d4f6fdbc76ae338;p=lyx.git diff --git a/src/support/unicode.cpp b/src/support/unicode.cpp index 7f601a86c5..95415a5538 100644 --- a/src/support/unicode.cpp +++ b/src/support/unicode.cpp @@ -14,17 +14,19 @@ #include "support/unicode.h" #include "support/debug.h" +#include "support/mutex.h" #include #include #include -#include #include #include +//Needed in MSVC #include + using namespace std; namespace { @@ -64,6 +66,8 @@ struct IconvProcessor::Impl iconv_t cd; string tocode_; string fromcode_; + + Mutex mutex_; // iconv() is not thread save, see #7240 }; @@ -120,6 +124,8 @@ bool IconvProcessor::init() int IconvProcessor::convert(char const * buf, size_t buflen, char * outbuf, size_t maxoutsize) { + Mutex::Locker lock(&pimpl_->mutex_); + if (buflen == 0) return 0; @@ -230,13 +236,13 @@ iconv_convert(IconvProcessor & processor, InType const * buf, size_t buflen) if (outbuf.size() < maxoutbufsize) outbuf.resize(maxoutbufsize); - int bytes = processor.convert(inbuf, inbytesleft, outbuf.data(), outbuf.size()); + int bytes = processor.convert(inbuf, inbytesleft, &outbuf[0], outbuf.size()); if (bytes <= 0) // Conversion failed // FIXME Maybe throw an exception and handle that in the caller? return vector(); - RetType const * tmp = reinterpret_cast(outbuf.data()); + RetType const * tmp = reinterpret_cast(&outbuf[0]); return vector(tmp, tmp + bytes / sizeof(RetType)); } @@ -371,7 +377,6 @@ int max_encoded_bytes(std::string const & encoding) // The CJK encodings use (different) multibyte representation as well. // All other encodings encode one UCS4 code point in one byte // (and can therefore only encode a subset of UCS4) - // Note that BIG5 and SJIS do not work with LaTeX (see lib/encodings). // Furthermore, all encodings that use shifting (like SJIS) do not work with // iconv_codecvt_facet. if (encoding == "UTF-8" ||