#include "support/unicode.h"
#include "support/debug.h"
+#include "support/mutex.h"
#include <iconv.h>
#include <boost/cstdint.hpp>
#include <cerrno>
-#include <iomanip>
#include <map>
#include <ostream>
+//Needed in MSVC
#include <string>
+
using namespace std;
namespace {
iconv_t cd;
string tocode_;
string fromcode_;
+
+ Mutex mutex_; // iconv() is not thread save, see #7240
};
int IconvProcessor::convert(char const * buf, size_t buflen,
char * outbuf, size_t maxoutsize)
{
+ Mutex::Locker lock(&pimpl_->mutex_);
+
if (buflen == 0)
return 0;
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?
// 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" ||