diff --git a/bindings/python/Jamfile b/bindings/python/Jamfile index 8488e82f3..f030ec337 100755 --- a/bindings/python/Jamfile +++ b/bindings/python/Jamfile @@ -53,6 +53,7 @@ python-extension libtorrent src/session.cpp src/entry.cpp src/torrent_info.cpp + src/string.cpp src/torrent_handle.cpp src/torrent_status.cpp src/session_settings.cpp diff --git a/bindings/python/Makefile.am b/bindings/python/Makefile.am index 668bb5892..e4b2dd847 100644 --- a/bindings/python/Makefile.am +++ b/bindings/python/Makefile.am @@ -22,6 +22,7 @@ EXTRA_DIST = \ src/peer_info.cpp \ src/session.cpp \ src/session_settings.cpp \ + src/string.cpp \ src/torrent.cpp \ src/torrent_handle.cpp \ src/torrent_info.cpp \ diff --git a/bindings/python/src/module.cpp b/bindings/python/src/module.cpp index 61fcf769e..47576889d 100644 --- a/bindings/python/src/module.cpp +++ b/bindings/python/src/module.cpp @@ -14,6 +14,7 @@ void bind_big_number(); void bind_session(); void bind_entry(); void bind_torrent_info(); +void bind_unicode_string_conversion(); void bind_torrent_handle(); void bind_torrent_status(); void bind_session_settings(); @@ -40,6 +41,7 @@ BOOST_PYTHON_MODULE(libtorrent) bind_entry(); bind_session(); bind_torrent_info(); + bind_unicode_string_conversion(); bind_torrent_handle(); bind_torrent_status(); bind_session_settings(); diff --git a/bindings/python/src/session.cpp b/bindings/python/src/session.cpp index 5ddd64294..d14547395 100644 --- a/bindings/python/src/session.cpp +++ b/bindings/python/src/session.cpp @@ -666,7 +666,9 @@ void bind_session() ; enum_("listen_on_flags_t") +#ifndef TORRENT_NO_DEPRECATE .value("listen_reuse_address", session::listen_reuse_address) +#endif .value("listen_no_system_port", session::listen_no_system_port) ; diff --git a/bindings/python/src/string.cpp b/bindings/python/src/string.cpp new file mode 100644 index 000000000..bb133bfd0 --- /dev/null +++ b/bindings/python/src/string.cpp @@ -0,0 +1,71 @@ +// Copyright Daniel Wallin 2006. Use, modification and distribution is +// subject to the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include +#include "libtorrent/utf8.hpp" +#include + +using namespace boost::python; + +struct unicode_from_python +{ + unicode_from_python() + { + converter::registry::push_back( + &convertible, &construct, type_id() + ); + } + + static void* convertible(PyObject* x) + { +#if PY_VERSION_HEX >= 0x03020000 + return PyBytes_Check(x) ? x : PyUnicode_Check(x) ? x : 0; +#else + return PyString_Check(x) ? x : PyUnicode_Check(x) ? x : 0; +#endif + } + + 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) + { + assert(len < str.size()); + str[len] = 0; + } + else str[str.size()-1] = 0; + + std::string utf8; + int ret = wchar_utf8(str, utf8); + new (storage) std::string(utf8); + } + else + { +#if PY_VERSION_HEX >= 0x03000000 + new (storage) std::string(PyBytes_AsString(x)); +#else + new (storage) std::string(PyString_AsString(x)); +#endif + } + data->convertible = storage; + } +}; + +void bind_unicode_string_conversion() +{ + unicode_from_python(); +} + diff --git a/configure.ac b/configure.ac index cdcbf6b5c..e23e4a018 100644 --- a/configure.ac +++ b/configure.ac @@ -97,10 +97,24 @@ AS_ECHO "Checking for posix thread support:" AX_PTHREAD() LIBS="$PTHREAD_LIBS $LIBS" -CFLAGS="$PTHREAD_CFLAGS $CFLAGS -fvisibility=hidden" -CXXFLAGS="$CXXFLAGS -fvisibility-inlines-hidden" +CFLAGS="$PTHREAD_CFLAGS $CFLAGS" CC="$PTHREAD_CC" +AS_ECHO "Checking for visibility support:" +AC_CACHE_CHECK([for __attribute__((visibility("hidden")))], + ac_cv_hidden_visibility_attribute, [ + echo 'int __attribute__ ((visibility ("hidden"))) foo (void) { return 1; }' > visibility_conftest.c + ac_cv_hidden_visibility_attribute=no + if AC_TRY_COMMAND(${CC-cc} -fvisibility=hidden -S visibility_conftest.c -o visibility_conftest.s 1>&AS_MESSAGE_LOG_FD); + then + AS_ECHO "found" + ac_cv_hidden_visibility_attribute=yes + CXXFLAGS="$CXXFLAGS -fvisibility-inlines-hidden" + CFLAGS="$CFLAGS -fvisibility=hidden" + fi + rm -f visibility_conftest.* +]) + AS_ECHO AS_ECHO "Checking for boost libraries:"