#include "support/unicode.h"
#include "support/debug.h"
+#include "support/mutex.h"
#include <iconv.h>
#include <ostream>
#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?
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));
}