don't use the (now private/internal) utf8 functions from libtorrent in the python binding. i.e. fix the python binding build when linking dynamically against libtorrent

This commit is contained in:
arvidn 2015-06-07 15:16:51 -04:00
parent 0369caae67
commit 27855e17eb
2 changed files with 17 additions and 27 deletions

View File

@ -42,9 +42,7 @@ BOOST_PYTHON_MODULE(libtorrent)
bind_torrent_handle();
bind_session();
bind_torrent_info();
#if TORRENT_USE_WSTRING
bind_unicode_string_conversion();
#endif
bind_torrent_status();
bind_session_settings();
bind_version();

View File

@ -3,14 +3,9 @@
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include <boost/python.hpp>
#include "libtorrent/config.hpp"
#include "libtorrent/utf8.hpp"
#include <string>
#if TORRENT_USE_WSTRING
using namespace boost::python;
using namespace libtorrent;
struct unicode_from_python
{
@ -32,36 +27,35 @@ struct unicode_from_python
static void construct(PyObject* x, converter::rvalue_from_python_stage1_data* data)
{
using libtorrent::wchar_utf8;
void* storage = ((converter::rvalue_from_python_storage<
std::string>*)data)->storage.bytes;
if (PyUnicode_Check(x))
{
std::wstring str;
str.resize(PyUnicode_GetSize(x) + 1, 0);
#if PY_VERSION_HEX >= 0x03020000
int len = PyUnicode_AsWideChar(x, &str[0], str.size());
#else
int len = PyUnicode_AsWideChar((PyUnicodeObject*)x, &str[0], str.size());
#endif
if (len > -1)
PyObject* utf8 = PyUnicode_AsUTF8String(x);
if (utf8 == NULL)
{
assert(len < int(str.size()));
str[len] = 0;
new (storage) std::string();
}
else
{
#if PY_VERSION_HEX >= 0x03000000
new (storage) std::string(PyBytes_AsString(utf8)
, PyBytes_Size(utf8));
#else
new (storage) std::string(PyString_AsString(utf8)
, PyString_Size(utf8));
#endif
Py_DECREF(utf8);
}
else str[str.size()-1] = 0;
std::string utf8;
wchar_utf8(str, utf8);
new (storage) std::string(utf8);
}
else
{
#if PY_VERSION_HEX >= 0x03000000
new (storage) std::string(PyBytes_AsString(x));
new (storage) std::string(PyBytes_AsString(x), PyBytes_Size(x));
#else
new (storage) std::string(PyString_AsString(x));
new (storage) std::string(PyString_AsString(x)
, PyString_Size(x));
#endif
}
data->convertible = storage;
@ -73,5 +67,3 @@ void bind_unicode_string_conversion()
unicode_from_python();
}
#endif // TORRENT_USE_WSTRING