diff --git a/Jamfile b/Jamfile index 0fc982497..4214123a2 100644 --- a/Jamfile +++ b/Jamfile @@ -265,6 +265,7 @@ rule warnings ( properties * ) result += -Wno-weak-vtables ; result += -Wno-sign-compare ; result += -Wno-sign-conversion ; + result += -Wno-conversion ; } if gcc in $(properties) @@ -502,8 +503,8 @@ feature export-extra : off on : composite propagated ; # making it possible to build on windows, especially mingw seems particular # for release builds, disable optimizations as they bump GCC over the edge of # allowed memory usage on travis-ci -variant test_release - : release : production on +variant test_release : release + : production on full shared off on on multi ; @@ -519,7 +520,6 @@ variant test_barebones : debug on on multi ; - # required for openssl on windows lib ssleay32 : : ssleay32 ; lib libeay32 : : libeay32 ; diff --git a/include/libtorrent/alert.hpp b/include/libtorrent/alert.hpp index 06effbf15..ce54939b7 100644 --- a/include/libtorrent/alert.hpp +++ b/include/libtorrent/alert.hpp @@ -208,6 +208,9 @@ namespace libtorrent { alert(); // hidden virtual ~alert(); +#if __cplusplus >= 201103L + alert(alert const& st) = default; +#endif // a timestamp is automatically created in the constructor time_point timestamp() const; diff --git a/include/libtorrent/aux_/session_call.hpp b/include/libtorrent/aux_/session_call.hpp index 60917df3a..957d777a2 100644 --- a/include/libtorrent/aux_/session_call.hpp +++ b/include/libtorrent/aux_/session_call.hpp @@ -63,7 +63,7 @@ template void sync_call_handle(Handle& h, boost::function f) { bool done = false; - session_impl& ses = (session_impl&) h->session(); + session_impl& ses = static_cast(h->session()); ses.get_io_service().dispatch(boost::bind(&aux::fun_wrap , boost::ref(done) , boost::ref(ses.cond) @@ -91,7 +91,7 @@ template void sync_call_ret_handle(Handle& h, Ret& r, boost::function f) { bool done = false; - session_impl& ses = (session_impl&) h->session(); + session_impl& ses = static_cast(h->session()); ses.get_io_service().dispatch(boost::bind(&aux::fun_ret , boost::ref(r) , boost::ref(done) @@ -105,3 +105,4 @@ void sync_call_ret_handle(Handle& h, Ret& r, boost::function f) } } // namespace aux namespace libtorrent #endif // TORRENT_SESSION_CALL_HPP_INCLUDED + diff --git a/include/libtorrent/bencode.hpp b/include/libtorrent/bencode.hpp index 8803867aa..98e6e91c9 100644 --- a/include/libtorrent/bencode.hpp +++ b/include/libtorrent/bencode.hpp @@ -208,7 +208,7 @@ namespace libtorrent write_char(out, 'e'); ret += 2; break; - default: + case entry::undefined_t: // trying to encode a structure with uninitialized values! // TORRENT_ASSERT_VAL(false, e.type()); // do nothing diff --git a/include/libtorrent/bitfield.hpp b/include/libtorrent/bitfield.hpp index 749995e24..1c86df3c3 100644 --- a/include/libtorrent/bitfield.hpp +++ b/include/libtorrent/bitfield.hpp @@ -98,7 +98,7 @@ namespace libtorrent { TORRENT_ASSERT(index >= 0); TORRENT_ASSERT(index < size()); - return (m_buf[index / 32] & htonl((0x80000000 >> (index & 31)))) != 0; + return (m_buf[index / 32] & host_to_network((0x80000000 >> (index & 31)))) != 0; } // set bit at ``index`` to 0 (clear_bit) or 1 (set_bit). @@ -106,13 +106,13 @@ namespace libtorrent { TORRENT_ASSERT(index >= 0); TORRENT_ASSERT(index < size()); - m_buf[index / 32] &= htonl(~(0x80000000 >> (index & 31))); + m_buf[index / 32] &= host_to_network(~(0x80000000 >> (index & 31))); } void set_bit(int index) { TORRENT_ASSERT(index >= 0); TORRENT_ASSERT(index < size()); - m_buf[index / 32] |= htonl((0x80000000 >> (index & 31))); + m_buf[index / 32] |= host_to_network((0x80000000 >> (index & 31))); } // returns true if all bits in the bitfield are set @@ -126,7 +126,7 @@ namespace libtorrent int rest = size() & 31; if (rest > 0) { - boost::uint32_t mask = htonl(0xffffffff << (32-rest)); + boost::uint32_t mask = host_to_network(0xffffffff << (32-rest)); if ((m_buf[words] & mask) != mask) return false; } return true; @@ -223,7 +223,7 @@ namespace libtorrent typedef bool& reference; typedef std::forward_iterator_tag iterator_category; - bool operator*() { return (*buf & htonl(bit)) != 0; } + bool operator*() { return (*buf & host_to_network(bit)) != 0; } const_iterator& operator++() { inc(); return *this; } const_iterator operator++(int) { const_iterator ret(*this); inc(); return ret; } @@ -289,7 +289,7 @@ namespace libtorrent int new_size_words = num_words(); if (val) { - if (old_size_words && b) m_buf[old_size_words - 1] |= htonl((0xffffffff >> b)); + if (old_size_words && b) m_buf[old_size_words - 1] |= host_to_network((0xffffffff >> b)); if (old_size_words < new_size_words) std::memset(m_buf + old_size_words, 0xff , size_t((new_size_words - old_size_words) * 4)); @@ -357,7 +357,7 @@ namespace libtorrent void clear_trailing_bits() { // clear the tail bits in the last byte - if (size() & 31) m_buf[num_words() - 1] &= htonl(0xffffffff << (32 - (size() & 31))); + if (size() & 31) m_buf[num_words() - 1] &= host_to_network(0xffffffff << (32 - (size() & 31))); } void dealloc() diff --git a/include/libtorrent/byteswap.hpp b/include/libtorrent/byteswap.hpp index 0add6a40d..183da9d5f 100644 --- a/include/libtorrent/byteswap.hpp +++ b/include/libtorrent/byteswap.hpp @@ -38,6 +38,10 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/config.hpp" +#include "libtorrent/aux_/disable_warnings_push.hpp" + +#include + #ifdef TORRENT_WINDOWS #include #else @@ -46,5 +50,21 @@ POSSIBILITY OF SUCH DAMAGE. #include #endif +// these need to be within the disabled warnings because on OSX +// the htonl and ntohl macros cause lots of old-style case warnings +inline boost::uint32_t host_to_network(boost::uint32_t x) +{ return htonl(x); } + +inline boost::uint32_t network_to_host(boost::uint32_t x) +{ return ntohl(x); } + +inline boost::uint16_t host_to_network(boost::uint16_t x) +{ return htons(x); } + +inline boost::uint16_t network_to_host(boost::uint16_t x) +{ return ntohs(x); } + +#include "libtorrent/aux_/disable_warnings_pop.hpp" + #endif // TORRENT_BYTESWAP_HPP_INCLUDED diff --git a/include/libtorrent/disk_buffer_holder.hpp b/include/libtorrent/disk_buffer_holder.hpp index e65bc6b47..0aa37fe03 100644 --- a/include/libtorrent/disk_buffer_holder.hpp +++ b/include/libtorrent/disk_buffer_holder.hpp @@ -37,9 +37,14 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/assert.hpp" #include "libtorrent/disk_io_job.hpp" // for block_cache_reference #include + +#include "libtorrent/aux_/disable_warnings_push.hpp" + #include #include +#include "libtorrent/aux_/disable_warnings_pop.hpp" + namespace libtorrent { struct disk_io_thread; diff --git a/include/libtorrent/error_code.hpp b/include/libtorrent/error_code.hpp index dc547664d..874dc12fa 100644 --- a/include/libtorrent/error_code.hpp +++ b/include/libtorrent/error_code.hpp @@ -508,6 +508,10 @@ namespace libtorrent libtorrent_exception(error_code const& s): m_error(s), m_msg(0) {} virtual const char* what() const TORRENT_EXCEPTION_THROW_SPECIFIER; virtual ~libtorrent_exception() TORRENT_EXCEPTION_THROW_SPECIFIER; +#if __cplusplus >= 201103L + libtorrent_exception(libtorrent_exception const& st) = default; + libtorrent_exception& operator=(libtorrent_exception const& st) = default; +#endif error_code error() const { return m_error; } private: error_code m_error; diff --git a/include/libtorrent/file_storage.hpp b/include/libtorrent/file_storage.hpp index 10ce063e9..f92b5ec6e 100644 --- a/include/libtorrent/file_storage.hpp +++ b/include/libtorrent/file_storage.hpp @@ -60,6 +60,10 @@ namespace libtorrent file_entry(); // hidden ~file_entry(); +#if __cplusplus >= 201103L + file_entry(file_entry const& st) = default; + file_entry& operator=(file_entry const& st) = default; +#endif // the full path of this file. The paths are unicode strings // encoded in UTF-8. diff --git a/include/libtorrent/settings_pack.hpp b/include/libtorrent/settings_pack.hpp index 05c08b28b..4df0813af 100644 --- a/include/libtorrent/settings_pack.hpp +++ b/include/libtorrent/settings_pack.hpp @@ -35,8 +35,13 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/entry.hpp" #include + +#include "libtorrent/aux_/disable_warnings_push.hpp" + #include +#include "libtorrent/aux_/disable_warnings_pop.hpp" + // OVERVIEW // // You have some control over session configuration through the session::apply_settings() diff --git a/include/libtorrent/sha1_hash.hpp b/include/libtorrent/sha1_hash.hpp index 184452ccd..8615bf207 100644 --- a/include/libtorrent/sha1_hash.hpp +++ b/include/libtorrent/sha1_hash.hpp @@ -154,16 +154,16 @@ namespace libtorrent // byte order, so they have to be byteswapped before // applying the shift operations, and then byteswapped // back again. - m_number[0] = ntohl(m_number[0]); + m_number[0] = network_to_host(m_number[0]); for (int i = 0; i < number_size - 1; ++i) { m_number[i] <<= n; - m_number[i+1] = ntohl(m_number[i+1]); + m_number[i+1] = network_to_host(m_number[i+1]); m_number[i] |= m_number[i+1] >> (32 - n); - m_number[i] = htonl(m_number[i]); + m_number[i] = host_to_network(m_number[i]); } m_number[number_size-1] <<= n; - m_number[number_size-1] = htonl(m_number[number_size-1]); + m_number[number_size-1] = host_to_network(m_number[number_size-1]); } return *this; } @@ -191,17 +191,17 @@ namespace libtorrent // byte order, so they have to be byteswapped before // applying the shift operations, and then byteswapped // back again. - m_number[number_size-1] = ntohl(m_number[number_size-1]); + m_number[number_size-1] = network_to_host(m_number[number_size-1]); for (int i = number_size - 1; i > 0; --i) { m_number[i] >>= n; - m_number[i-1] = ntohl(m_number[i-1]); + m_number[i-1] = network_to_host(m_number[i-1]); m_number[i] |= (m_number[i-1] << (32 - n)) & 0xffffffff; - m_number[i] = htonl(m_number[i]); + m_number[i] = host_to_network(m_number[i]); } m_number[0] >>= n; - m_number[0] = htonl(m_number[0]); + m_number[0] = host_to_network(m_number[0]); } return *this; } @@ -219,8 +219,8 @@ namespace libtorrent { for (int i = 0; i < number_size; ++i) { - boost::uint32_t lhs = ntohl(m_number[i]); - boost::uint32_t rhs = ntohl(n.m_number[i]); + boost::uint32_t lhs = network_to_host(m_number[i]); + boost::uint32_t rhs = network_to_host(n.m_number[i]); if (lhs < rhs) return true; if (lhs > rhs) return false; } @@ -277,30 +277,30 @@ namespace libtorrent } // accessors for specific bytes - unsigned char& operator[](int i) + boost::uint8_t& operator[](int i) { TORRENT_ASSERT(i >= 0 && i < size); - return reinterpret_cast(m_number)[i]; + return reinterpret_cast(m_number)[i]; } - unsigned char const& operator[](int i) const + boost::uint8_t const& operator[](int i) const { TORRENT_ASSERT(i >= 0 && i < size); - return reinterpret_cast(m_number)[i]; + return reinterpret_cast(m_number)[i]; } - typedef const unsigned char* const_iterator; - typedef unsigned char* iterator; + typedef const boost::uint8_t* const_iterator; + typedef boost::uint8_t* iterator; // start and end iterators for the hash. The value type - // of these iterators is ``unsigned char``. + // of these iterators is ``boost::uint8_t``. const_iterator begin() const - { return reinterpret_cast(m_number); } + { return reinterpret_cast(m_number); } const_iterator end() const - { return reinterpret_cast(m_number) + size; } + { return reinterpret_cast(m_number) + size; } iterator begin() - { return reinterpret_cast(m_number); } + { return reinterpret_cast(m_number); } iterator end() - { return reinterpret_cast(m_number) + size; } + { return reinterpret_cast(m_number) + size; } // return a copy of the 20 bytes representing the sha1-hash as a std::string. // It's still a binary string with 20 binary characters. diff --git a/include/libtorrent/socket.hpp b/include/libtorrent/socket.hpp index a1f2e1cb7..436dfbd6e 100644 --- a/include/libtorrent/socket.hpp +++ b/include/libtorrent/socket.hpp @@ -33,6 +33,8 @@ POSSIBILITY OF SUCH DAMAGE. #ifndef TORRENT_SOCKET_HPP_INCLUDED #define TORRENT_SOCKET_HPP_INCLUDED +#include "libtorrent/config.hpp" + #include "libtorrent/aux_/disable_warnings_push.hpp" // if building as Objective C++, asio's template diff --git a/include/libtorrent/torrent_handle.hpp b/include/libtorrent/torrent_handle.hpp index 84d27df6a..a4ec05a06 100644 --- a/include/libtorrent/torrent_handle.hpp +++ b/include/libtorrent/torrent_handle.hpp @@ -1251,6 +1251,10 @@ namespace libtorrent // hidden torrent_status(); ~torrent_status(); +#if __cplusplus >= 201103L + torrent_status(torrent_status const& st) = default; + torrent_status& operator=(torrent_status const& st) = default; +#endif // compres if the torrent status objects come from the same torrent. i.e. // only the torrent_handle field is compared. diff --git a/src/http_seed_connection.cpp b/src/http_seed_connection.cpp index 84bea377f..29107b8d6 100644 --- a/src/http_seed_connection.cpp +++ b/src/http_seed_connection.cpp @@ -174,7 +174,7 @@ namespace libtorrent request += "GET "; request += using_proxy ? m_url : m_path; request += "?info_hash="; - request += escape_string((char const*)&t->torrent_file().info_hash()[0], 20); + request += escape_string(reinterpret_cast(&t->torrent_file().info_hash()[0]), 20); request += "&piece="; request += to_string(r.piece).elems; diff --git a/src/lsd.cpp b/src/lsd.cpp index 32310221b..5fcb8932b 100644 --- a/src/lsd.cpp +++ b/src/lsd.cpp @@ -71,7 +71,7 @@ int render_lsd_packet(char* dst, int len, int listen_port } } // anonymous namespace -static error_code ec; +static error_code dummy; lsd::lsd(io_service& ios, peer_callback_t const& cb #ifndef TORRENT_DISABLE_LOGGING @@ -79,9 +79,9 @@ lsd::lsd(io_service& ios, peer_callback_t const& cb #endif ) : m_callback(cb) - , m_socket(udp::endpoint(address_v4::from_string("239.192.152.143", ec), 6771)) + , m_socket(udp::endpoint(address_v4::from_string("239.192.152.143", dummy), 6771)) #if TORRENT_USE_IPV6 - , m_socket6(udp::endpoint(address_v6::from_string("ff15::efc0:988f", ec), 6771)) + , m_socket6(udp::endpoint(address_v6::from_string("ff15::efc0:988f", dummy), 6771)) #endif #ifndef TORRENT_DISABLE_LOGGING , m_log_cb(log) diff --git a/src/torrent_handle.cpp b/src/torrent_handle.cpp index 5e7ea29de..6603289c2 100644 --- a/src/torrent_handle.cpp +++ b/src/torrent_handle.cpp @@ -144,31 +144,31 @@ namespace libtorrent #define TORRENT_ASYNC_CALL(x) \ boost::shared_ptr t = m_torrent.lock(); \ if (!t) return; \ - session_impl& ses = (session_impl&) t->session(); \ + session_impl& ses = static_cast(t->session()); \ ses.get_io_service().dispatch(boost::bind(&torrent:: x, t)) #define TORRENT_ASYNC_CALL1(x, a1) \ boost::shared_ptr t = m_torrent.lock(); \ if (!t) return; \ - session_impl& ses = (session_impl&) t->session(); \ + session_impl& ses = static_cast(t->session()); \ ses.get_io_service().dispatch(boost::bind(&torrent:: x, t, a1)) #define TORRENT_ASYNC_CALL2(x, a1, a2) \ boost::shared_ptr t = m_torrent.lock(); \ if (!t) return; \ - session_impl& ses = (session_impl&) t->session(); \ + session_impl& ses = static_cast(t->session()); \ ses.get_io_service().dispatch(boost::bind(&torrent:: x, t, a1, a2)) #define TORRENT_ASYNC_CALL3(x, a1, a2, a3) \ boost::shared_ptr t = m_torrent.lock(); \ if (!t) return; \ - session_impl& ses = (session_impl&) t->session(); \ + session_impl& ses = static_cast(t->session()); \ ses.get_io_service().dispatch(boost::bind(&torrent:: x, t, a1, a2, a3)) #define TORRENT_ASYNC_CALL4(x, a1, a2, a3, a4) \ boost::shared_ptr t = m_torrent.lock(); \ if (!t) return; \ - session_impl& ses = (session_impl&) t->session(); \ + session_impl& ses = static_cast(t->session()); \ ses.get_io_service().dispatch(boost::bind(&torrent:: x, t, a1, a2, a3, a4)) #define TORRENT_SYNC_CALL(x) \ @@ -716,7 +716,7 @@ namespace libtorrent if (t) { bool done = false; - session_impl& ses = (session_impl&) t->session(); + session_impl& ses = static_cast(t->session()); storage_error ec; ses.get_io_service().dispatch(boost::bind(&aux::fun_wrap, boost::ref(done), boost::ref(ses.cond) , boost::ref(ses.mut), boost::function(boost::bind( @@ -774,7 +774,7 @@ namespace libtorrent boost::shared_ptr t = m_torrent.lock(); if (!t || !t->has_storage()) return; - session_impl& ses = (session_impl&) t->session(); + session_impl& ses = static_cast(t->session()); ses.disk_thread().files().get_status(&status, &t->storage()); } diff --git a/src/torrent_peer.cpp b/src/torrent_peer.cpp index 004a71bc9..533596d06 100644 --- a/src/torrent_peer.cpp +++ b/src/torrent_peer.cpp @@ -82,8 +82,8 @@ namespace libtorrent if (e1.port() > e2.port()) swap(e1, e2); boost::uint32_t p; - reinterpret_cast(&p)[0] = htons(e1.port()); - reinterpret_cast(&p)[1] = htons(e2.port()); + reinterpret_cast(&p)[0] = host_to_network(e1.port()); + reinterpret_cast(&p)[1] = host_to_network(e2.port()); ret = crc32c_32(p); } #if TORRENT_USE_IPV6 diff --git a/test/test_pe_crypto.cpp b/test/test_pe_crypto.cpp index 8469915c4..3bbf7a16e 100644 --- a/test/test_pe_crypto.cpp +++ b/test/test_pe_crypto.cpp @@ -82,14 +82,15 @@ void test_transfer(libtorrent::settings_pack::enc_policy policy session_proxy p1; session_proxy p2; - lt::session ses1(fingerprint("LT", 0, 1, 0, 0), std::make_pair(48800, 49000), "0.0.0.0", 0); - lt::session ses2(fingerprint("LT", 0, 1, 0, 0), std::make_pair(49800, 50000), "0.0.0.0", 0); settings_pack s; s.set_int(settings_pack::out_enc_policy, settings_pack::pe_enabled); s.set_int(settings_pack::in_enc_policy, settings_pack::pe_enabled); s.set_int(settings_pack::allowed_enc_level, settings_pack::pe_both); - ses2.apply_settings(s); + + s.set_str(settings_pack::listen_interfaces, "0.0.0.0:48800"); + + lt::session ses2(s, 0); fprintf(stderr, " Session2 \n"); display_settings(s); @@ -98,7 +99,10 @@ void test_transfer(libtorrent::settings_pack::enc_policy policy s.set_int(settings_pack::in_enc_policy, policy); s.set_int(settings_pack::allowed_enc_level, level); s.set_bool(settings_pack::prefer_rc4, pref_rc4); - ses1.apply_settings(s); + + s.set_str(settings_pack::listen_interfaces, "0.0.0.0:49800"); + + lt::session ses1(s, 0); fprintf(stderr, " Session1 \n"); display_settings(s); diff --git a/test/test_privacy.cpp b/test/test_privacy.cpp index db89cb6de..0ef20b16d 100644 --- a/test/test_privacy.cpp +++ b/test/test_privacy.cpp @@ -111,6 +111,7 @@ session_proxy test_proxy(settings_pack::proxy_type_t proxy_type, int flags) sett.set_bool(settings_pack::enable_upnp, false); sett.set_bool(settings_pack::enable_natpmp, false); sett.set_bool(settings_pack::enable_lsd, false); + sett.set_bool(settings_pack::enable_dht, true); // since multiple sessions may exist simultaneously (because of the // pipelining of the tests) they actually need to use different ports @@ -119,7 +120,6 @@ session_proxy test_proxy(settings_pack::proxy_type_t proxy_type, int flags) snprintf(iface, sizeof(iface), "127.0.0.1:%d", listen_port); listen_port += (libtorrent::random() % 10) + 1; sett.set_str(settings_pack::listen_interfaces, iface); - sett.set_bool(settings_pack::enable_dht, true); // if we don't do this, the peer connection test // will be delayed by several seconds, by first diff --git a/test/test_trackers_extension.cpp b/test/test_trackers_extension.cpp index dd632cd99..2fe12eb68 100644 --- a/test/test_trackers_extension.cpp +++ b/test/test_trackers_extension.cpp @@ -57,8 +57,18 @@ TORRENT_TEST(trackers_extension) session_proxy p1; session_proxy p2; - lt::session ses1(fingerprint("LT", 0, 1, 0, 0), std::make_pair(48130, 49000), "0.0.0.0", 0); - lt::session ses2(fingerprint("LT", 0, 1, 0, 0), std::make_pair(49130, 50000), "0.0.0.0", 0); + settings_pack s; + s.set_bool(settings_pack::enable_upnp, false); + s.set_bool(settings_pack::enable_natpmp, false); + s.set_bool(settings_pack::enable_lsd, false); + s.set_bool(settings_pack::enable_dht, false); + s.set_str(settings_pack::listen_interfaces, "0.0.0.0:48130"); + + lt::session ses1(s, 0); + + s.set_str(settings_pack::listen_interfaces, "0.0.0.0:49130"); + lt::session ses2(s, 0); + ses1.add_extension(create_lt_trackers_plugin); ses2.add_extension(create_lt_trackers_plugin); @@ -71,6 +81,7 @@ TORRENT_TEST(trackers_extension) torrent_handle tor1 = ses1.add_torrent(atp, ec); atp.trackers.push_back("http://test.non-existent.com/announce"); torrent_handle tor2 = ses2.add_torrent(atp, ec); + tor2.connect_peer(tcp::endpoint(address_v4::from_string("127.0.0.1"), ses1.listen_port())); // trackers are NOT supposed to be exchanged for torrents that we