fixed race condition in iconv string converter
This commit is contained in:
parent
6db9c5be31
commit
5c20606397
|
@ -72,6 +72,7 @@
|
||||||
incoming connection
|
incoming connection
|
||||||
* added more detailed instrumentation of the disk I/O thread
|
* added more detailed instrumentation of the disk I/O thread
|
||||||
|
|
||||||
|
* fixed race condition in iconv string converter
|
||||||
* fixed error handling in torrent_info constructor
|
* fixed error handling in torrent_info constructor
|
||||||
* fixed bug in torrent_info::remap_files
|
* fixed bug in torrent_info::remap_files
|
||||||
* fix python binding for wait_for_alert
|
* fix python binding for wait_for_alert
|
||||||
|
|
|
@ -55,6 +55,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "libtorrent/utf8.hpp"
|
#include "libtorrent/utf8.hpp"
|
||||||
|
#include "libtorrent/thread.hpp"
|
||||||
|
|
||||||
#if TORRENT_USE_ICONV
|
#if TORRENT_USE_ICONV
|
||||||
#include <iconv.h>
|
#include <iconv.h>
|
||||||
|
@ -646,7 +647,7 @@ namespace libtorrent
|
||||||
char const* in = s.c_str();
|
char const* in = s.c_str();
|
||||||
char* out = &ret[0];
|
char* out = &ret[0];
|
||||||
#ifdef TORRENT_LINUX
|
#ifdef TORRENT_LINUX
|
||||||
// linux seems to have a weird iconv signature
|
// linux (and posix) seems to have a weird iconv signature
|
||||||
#define ICONV_IN_CAST (char**)
|
#define ICONV_IN_CAST (char**)
|
||||||
#else
|
#else
|
||||||
#define ICONV_IN_CAST
|
#define ICONV_IN_CAST
|
||||||
|
@ -666,6 +667,10 @@ namespace libtorrent
|
||||||
|
|
||||||
std::string convert_to_native(std::string const& s)
|
std::string convert_to_native(std::string const& s)
|
||||||
{
|
{
|
||||||
|
static mutex iconv_mutex;
|
||||||
|
// only one thread can use this handle at a time
|
||||||
|
mutex::scoped_lock l(iconv_mutex);
|
||||||
|
|
||||||
// the empty string represents the local dependent encoding
|
// the empty string represents the local dependent encoding
|
||||||
static iconv_t iconv_handle = iconv_open("", "UTF-8");
|
static iconv_t iconv_handle = iconv_open("", "UTF-8");
|
||||||
if (iconv_handle == iconv_t(-1)) return s;
|
if (iconv_handle == iconv_t(-1)) return s;
|
||||||
|
@ -674,6 +679,10 @@ namespace libtorrent
|
||||||
|
|
||||||
std::string convert_from_native(std::string const& s)
|
std::string convert_from_native(std::string const& s)
|
||||||
{
|
{
|
||||||
|
static mutex iconv_mutex;
|
||||||
|
// only one thread can use this handle at a time
|
||||||
|
mutex::scoped_lock l(iconv_mutex);
|
||||||
|
|
||||||
// the empty string represents the local dependent encoding
|
// the empty string represents the local dependent encoding
|
||||||
static iconv_t iconv_handle = iconv_open("UTF-8", "");
|
static iconv_t iconv_handle = iconv_open("UTF-8", "");
|
||||||
if (iconv_handle == iconv_t(-1)) return s;
|
if (iconv_handle == iconv_t(-1)) return s;
|
||||||
|
|
Loading…
Reference in New Issue