]> git.lyx.org Git - lyx.git/blobdiff - src/support/unicode.cpp
Merge branch 'master' of git.lyx.org:lyx
[lyx.git] / src / support / unicode.cpp
index 7f601a86c5e32f684c8a9345fb87ffcb7b20eed4..b48f10609f7fe9315e257575aec432b9d8fcb1dc 100644 (file)
@@ -14,6 +14,7 @@
 
 #include "support/unicode.h"
 #include "support/debug.h"
+#include "support/mutex.h"
 
 #include <iconv.h>
 
@@ -25,6 +26,7 @@
 #include <ostream>
 #include <string>
 
+
 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>();
 
-       RetType const * tmp = reinterpret_cast<RetType const *>(outbuf.data());
+       RetType const * tmp = reinterpret_cast<RetType const *>(&outbuf[0]);
        return vector<RetType>(tmp, tmp + bytes / sizeof(RetType));
 }