From 66416963eb9563811ab9eb1ffc0168a096ba851b Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sun, 3 Jul 2016 23:30:52 -0400 Subject: [PATCH] fix python binding linking on msvc (#878) --- appveyor.yml | 1 - bindings/python/src/error_code.cpp | 33 +++++++++++++++++++++--------- bindings/python/src/session.cpp | 27 ++++++++++++++++-------- simulation/Jamfile | 1 + simulation/libsimulator | 2 +- 5 files changed, 44 insertions(+), 20 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 70b93b137..473dbb013 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -23,7 +23,6 @@ environment: - variant: test_release compiler: msvc-14.0 model: 64 - python: 1 linkflags: '"/LIBPATH:C:\\openssl-1.0.1p-vs2015\\lib64"' include: '"c:\\openssl-1.0.1p-vs2015\\include"' - variant: test_debug diff --git a/bindings/python/src/error_code.cpp b/bindings/python/src/error_code.cpp index caea76ba9..e23bbc511 100644 --- a/bindings/python/src/error_code.cpp +++ b/bindings/python/src/error_code.cpp @@ -34,6 +34,17 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include + +namespace boost +{ + // this fixe mysterious link error on msvc + boost::system::error_category const volatile* + get_pointer(boost::system::error_category const volatile* p) + { + return p; + } +} + #include "boost_python.hpp" using namespace boost::python; @@ -42,7 +53,9 @@ using boost::system::error_category; void bind_error_code() { - class_("error_category", no_init) + using boost::noncopyable; + + class_("error_category", no_init) .def("name", &error_category::name) .def("message", &error_category::message) .def(self == self) @@ -56,34 +69,34 @@ void bind_error_code() .def("value", &error_code::value) .def("clear", &error_code::clear) .def("category", &error_code::category - , return_internal_reference<>()) + , return_value_policy()) .def("assign", &error_code::assign) ; def("get_libtorrent_category", &get_libtorrent_category - , return_internal_reference<>()); + , return_value_policy()); def("get_upnp_category", &get_upnp_category - , return_internal_reference<>()); + , return_value_policy()); def("get_http_category", &get_http_category - , return_internal_reference<>()); + , return_value_policy()); def("get_socks_category", &get_socks_category - , return_internal_reference<>()); + , return_value_policy()); #if TORRENT_USE_I2P def("get_i2p_category", &get_i2p_category - , return_internal_reference<>()); + , return_value_policy()); #endif def("get_bdecode_category", &get_bdecode_category - , return_internal_reference<>()); + , return_value_policy()); def("generic_category", &boost::system::generic_category - , return_internal_reference<>()); + , return_value_policy()); def("system_category", &boost::system::system_category - , return_internal_reference<>()); + , return_value_policy()); } diff --git a/bindings/python/src/session.cpp b/bindings/python/src/session.cpp index 686c99193..5a6063ffa 100644 --- a/bindings/python/src/session.cpp +++ b/bindings/python/src/session.cpp @@ -17,13 +17,23 @@ #include // for settings_map() #include #include // for sign_mutable_item - +#include #include #include #include #include #include +namespace boost +{ + // this fixes mysterious link error on msvc + libtorrent::alert const volatile* + get_pointer(libtorrent::alert const volatile* p) + { + return p; + } +} + #include "gil.hpp" #include "bytes.hpp" @@ -323,8 +333,11 @@ namespace alert const* wait_for_alert(lt::session& s, int ms) { - allow_threading_guard guard; - alert const* a = s.wait_for_alert(milliseconds(ms)); + alert const* a; + { + allow_threading_guard guard; + a = s.wait_for_alert(milliseconds(ms)); + } return a; } @@ -415,10 +428,9 @@ namespace } list ret; - for (std::vector::iterator i = alerts.begin() - , end(alerts.end()); i != end; ++i) + for (alert* a : alerts) { - ret.append(boost::python::ptr(*i)); + ret.append(boost::python::ptr(a)); } return ret; } @@ -759,8 +771,7 @@ void bind_session() .def("load_state", &load_state, (arg("entry"), arg("flags") = 0xffffffff)) .def("save_state", &save_state, (arg("entry"), arg("flags") = 0xffffffff)) .def("pop_alerts", &pop_alerts) - .def("wait_for_alert", &wait_for_alert, return_internal_reference<>() - ) + .def("wait_for_alert", &wait_for_alert, return_internal_reference<>()) .def("add_extension", &add_extension) #ifndef TORRENT_NO_DEPRECATE #if TORRENT_USE_I2P diff --git a/simulation/Jamfile b/simulation/Jamfile index c3036a051..5e44398ba 100644 --- a/simulation/Jamfile +++ b/simulation/Jamfile @@ -16,6 +16,7 @@ project setup_dht.cpp create_torrent.cpp utils.cpp + msvc:/wd4275 : default-build multi full diff --git a/simulation/libsimulator b/simulation/libsimulator index 0c796e3e0..1df1d6083 160000 --- a/simulation/libsimulator +++ b/simulation/libsimulator @@ -1 +1 @@ -Subproject commit 0c796e3e0dea7ca05eef3ded2cf3806ef19a1413 +Subproject commit 1df1d608358ed93cc5024ad731df7d047508554f