diff --git a/include/libtorrent/config.hpp b/include/libtorrent/config.hpp index 0ea2d97aa..b1fd0e320 100644 --- a/include/libtorrent/config.hpp +++ b/include/libtorrent/config.hpp @@ -87,11 +87,6 @@ POSSIBILITY OF SUCH DAMAGE. #elif defined __SUNPRO_CC -// SunPRO seems to have an overly-strict -// definition of POD types and doesn't -// seem to allow std::array in unions -#define TORRENT_BROKEN_UNIONS 1 - #define TORRENT_COMPLETE_TYPES_REQUIRED 1 // ======= MSVC ========= @@ -104,10 +99,6 @@ POSSIBILITY OF SUCH DAMAGE. // class X needs to have dll-interface to be used by clients of class Y #pragma warning(disable:4251) -#if (defined(_MSC_VER) && _MSC_VER < 1310) -#define TORRENT_COMPLETE_TYPES_REQUIRED 1 -#endif - // deprecation markup is only enabled when libtorrent // headers are included by clients, not while building // libtorrent itself @@ -386,10 +377,6 @@ POSSIBILITY OF SUCH DAMAGE. #define TORRENT_USE_LOCALE 0 #endif -#ifndef TORRENT_BROKEN_UNIONS -#define TORRENT_BROKEN_UNIONS 0 -#endif - #ifndef TORRENT_USE_WSTRING #if !defined BOOST_NO_STD_WSTRING #define TORRENT_USE_WSTRING 1 @@ -488,25 +475,6 @@ POSSIBILITY OF SUCH DAMAGE. # endif #endif -#if defined _MSC_VER && _MSC_VER <= 1200 -// this is here to provide a standard-conforming for -// keyword for old versions of msvc. The pragmas are -// there to silence the warning it produces by using -// a constant as conditional -#define for \ - __pragma( warning(push) ) \ - __pragma( warning(disable:4127) ) \ - if (false) {} else \ - __pragma( warning(pop) ) - for -#endif - -#if TORRENT_BROKEN_UNIONS -#define TORRENT_UNION struct -#else -#define TORRENT_UNION union -#endif - #if defined __GNUC__ #define TORRENT_FUNCTION __PRETTY_FUNCTION__ #else diff --git a/include/libtorrent/kademlia/observer.hpp b/include/libtorrent/kademlia/observer.hpp index 59089da76..887e98237 100644 --- a/include/libtorrent/kademlia/observer.hpp +++ b/include/libtorrent/kademlia/observer.hpp @@ -146,7 +146,7 @@ private: node_id m_id; - TORRENT_UNION addr_t + union addr_t { #if TORRENT_USE_IPV6 address_v6::bytes_type v6; diff --git a/include/libtorrent/torrent_handle.hpp b/include/libtorrent/torrent_handle.hpp index f81c6d689..6de7bd1be 100644 --- a/include/libtorrent/torrent_handle.hpp +++ b/include/libtorrent/torrent_handle.hpp @@ -101,7 +101,7 @@ namespace libtorrent }; private: - TORRENT_UNION addr_t + union addr_t { address_v4::bytes_type v4; #if TORRENT_USE_IPV6 diff --git a/include/libtorrent/union_endpoint.hpp b/include/libtorrent/union_endpoint.hpp index e317ef92d..36e0a1224 100644 --- a/include/libtorrent/union_endpoint.hpp +++ b/include/libtorrent/union_endpoint.hpp @@ -92,7 +92,7 @@ namespace libtorrent #endif } - TORRENT_UNION addr_t + union addr_t { address_v4::bytes_type v4; #if TORRENT_USE_IPV6 diff --git a/include/libtorrent/utp_stream.hpp b/include/libtorrent/utp_stream.hpp index d6ab0acf6..1b2db7578 100644 --- a/include/libtorrent/utp_stream.hpp +++ b/include/libtorrent/utp_stream.hpp @@ -52,8 +52,6 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/aux_/disable_warnings_pop.hpp" -#define CCONTROL_TARGET 100 - namespace libtorrent { #ifndef TORRENT_UTP_LOG_ENABLE diff --git a/simulation/test_optimistic_unchoke.cpp b/simulation/test_optimistic_unchoke.cpp index dd3006493..df9daff61 100644 --- a/simulation/test_optimistic_unchoke.cpp +++ b/simulation/test_optimistic_unchoke.cpp @@ -37,6 +37,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "settings.hpp" #include "utils.hpp" #include "simulator/utils.hpp" +#include "setup_transfer.hpp" // for addr() #include "libtorrent/alert.hpp" #include "libtorrent/alert_types.hpp" diff --git a/simulation/test_socks5.cpp b/simulation/test_socks5.cpp index c59770d6b..7068b61ca 100644 --- a/simulation/test_socks5.cpp +++ b/simulation/test_socks5.cpp @@ -38,6 +38,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "simulator/http_server.hpp" #include "settings.hpp" #include "create_torrent.hpp" +#include "setup_transfer.hpp" // for addr() #include "simulator/simulator.hpp" #include "setup_swarm.hpp" #include "utils.hpp" diff --git a/simulation/test_transfer.cpp b/simulation/test_transfer.cpp index d1dd175e6..5d5959fe2 100644 --- a/simulation/test_transfer.cpp +++ b/simulation/test_transfer.cpp @@ -46,6 +46,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "simulator/utils.hpp" #include "setup_swarm.hpp" #include "utils.hpp" +#include "setup_transfer.hpp" // for addr() using namespace sim; diff --git a/simulation/utils.cpp b/simulation/utils.cpp index e5368380c..567c31b27 100644 --- a/simulation/utils.cpp +++ b/simulation/utils.cpp @@ -117,11 +117,6 @@ void set_proxy(lt::session& ses, int proxy_type, int flags, bool proxy_peer_conn ses.apply_settings(p); } -lt::address addr(char const* str) -{ - return lt::address::from_string(str); -} - void print_alerts(lt::session& ses , std::function on_alert) { diff --git a/simulation/utils.hpp b/simulation/utils.hpp index 35f52d17d..84b29b712 100644 --- a/simulation/utils.hpp +++ b/simulation/utils.hpp @@ -42,9 +42,6 @@ namespace libtorrent namespace lt = libtorrent; -// construct an address from string -lt::address addr(char const* str); - void utp_only(lt::session& ses); void enable_enc(lt::session& ses); void filter_ips(lt::session& ses); diff --git a/src/create_torrent.cpp b/src/create_torrent.cpp index 47a295d58..20dc22d40 100644 --- a/src/create_torrent.cpp +++ b/src/create_torrent.cpp @@ -53,8 +53,6 @@ POSSIBILITY OF SUCH DAMAGE. using namespace std::placeholders; -#define MAX_SYMLINK_PATH 200 - namespace libtorrent { @@ -96,6 +94,8 @@ namespace libtorrent #ifndef TORRENT_WINDOWS std::string get_symlink_path_impl(char const* path) { + constexpr int MAX_SYMLINK_PATH = 200; + char buf[MAX_SYMLINK_PATH]; std::string f = convert_to_native(path); int char_read = readlink(f.c_str(),buf,MAX_SYMLINK_PATH); diff --git a/src/file.cpp b/src/file.cpp index b9d23b480..d7eaf1ebe 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -941,11 +941,11 @@ namespace libtorrent #if defined(TORRENT_WINDOWS) || defined(TORRENT_OS2) #define TORRENT_SEPARATOR_CHAR '\\' - bool need_sep = branch[branch.size()-1] != '\\' + bool const need_sep = branch[branch.size()-1] != '\\' && branch[branch.size()-1] != '/'; #else #define TORRENT_SEPARATOR_CHAR '/' - bool need_sep = branch[branch.size()-1] != '/'; + bool const need_sep = branch[branch.size()-1] != '/'; #endif if (need_sep) branch += TORRENT_SEPARATOR_CHAR; @@ -960,10 +960,10 @@ namespace libtorrent #if defined(TORRENT_WINDOWS) || defined(TORRENT_OS2) #define TORRENT_SEPARATOR "\\" - bool need_sep = lhs[lhs.size()-1] != '\\' && lhs[lhs.size()-1] != '/'; + bool const need_sep = lhs[lhs.size()-1] != '\\' && lhs[lhs.size()-1] != '/'; #else #define TORRENT_SEPARATOR "/" - bool need_sep = lhs[lhs.size()-1] != '/'; + bool const need_sep = lhs[lhs.size()-1] != '/'; #endif std::string ret; int target_size = int(lhs.size() + rhs.size() + 2); diff --git a/src/http_connection.cpp b/src/http_connection.cpp index b7cc1d2a2..fc0738788 100644 --- a/src/http_connection.cpp +++ b/src/http_connection.cpp @@ -531,10 +531,6 @@ void http_connection::on_resolve(error_code const& e std::random_shuffle(m_endpoints.begin(), m_endpoints.end(), randint); - // The following statement causes msvc to crash (ICE). Since it's not - // necessary in the vast majority of cases, just ignore the endpoint - // order for windows -#if !defined _MSC_VER || _MSC_VER > 1310 // sort the endpoints so that the ones with the same IP version as our // bound listen socket are first. So that when contacting a tracker, // we'll talk to it from the same IP that we're listening on @@ -542,7 +538,6 @@ void http_connection::on_resolve(error_code const& e std::partition(m_endpoints.begin(), m_endpoints.end() , [this] (tcp::endpoint const& ep) { return ep.address().is_v4() == m_bind_addr.is_v4(); }); -#endif connect(); } diff --git a/test/setup_transfer.cpp b/test/setup_transfer.cpp index cf265efcf..adcb5af81 100644 --- a/test/setup_transfer.cpp +++ b/test/setup_transfer.cpp @@ -934,3 +934,30 @@ tcp::endpoint ep(char const* ip, int port) TEST_CHECK(!ec); return ret; } + +libtorrent::address addr(char const* ip) +{ + lt::error_code ec; + auto ret = lt::address::from_string(ip, ec); + TEST_CHECK(!ec); + return ret; +} + +libtorrent::address_v4 addr4(char const* ip) +{ + lt::error_code ec; + auto ret = lt::address_v4::from_string(ip, ec); + TEST_CHECK(!ec); + return ret; +} + +#if TORRENT_USE_IPV6 +libtorrent::address_v6 addr6(char const* ip) +{ + lt::error_code ec; + auto ret = lt::address_v6::from_string(ip, ec); + TEST_CHECK(!ec); + return ret; +} +#endif + diff --git a/test/setup_transfer.hpp b/test/setup_transfer.hpp index 4cf1260e3..76f09b9fe 100644 --- a/test/setup_transfer.hpp +++ b/test/setup_transfer.hpp @@ -107,6 +107,11 @@ EXPORT void stop_proxy(int port); EXPORT void stop_all_proxies(); EXPORT libtorrent::tcp::endpoint ep(char const* ip, int port); +EXPORT libtorrent::address addr(char const* ip); +EXPORT libtorrent::address_v4 addr4(char const* ip); +#if TORRENT_USE_IPV6 +EXPORT libtorrent::address_v6 addr6(char const* ip); +#endif #endif diff --git a/test/test_ip_filter.cpp b/test/test_ip_filter.cpp index 29aa50ea3..83b7ecadb 100644 --- a/test/test_ip_filter.cpp +++ b/test/test_ip_filter.cpp @@ -31,6 +31,7 @@ POSSIBILITY OF SUCH DAMAGE. */ #include "libtorrent/ip_filter.hpp" +#include "setup_transfer.hpp" // for addr() #include #include "test.hpp" @@ -57,10 +58,6 @@ bool compare(ip_range const& lhs && lhs.flags == rhs.flags; } -#define IP(x) address::from_string(x, ec) -#define IP4(x) address_v4::from_string(x, ec) -#define IP6(x) address_v6::from_string(x, ec) - template void test_rules_invariant(std::vector > const& r, ip_filter const& f) { @@ -71,13 +68,13 @@ void test_rules_invariant(std::vector > const& r, ip_filter const& f error_code ec; if (sizeof(r.front().first) == sizeof(address_v4)) { - TEST_CHECK(r.front().first == IP("0.0.0.0")); - TEST_CHECK(r.back().last == IP("255.255.255.255")); + TEST_CHECK(r.front().first == addr("0.0.0.0")); + TEST_CHECK(r.back().last == addr("255.255.255.255")); } else { - TEST_CHECK(r.front().first == IP("::0")); - TEST_CHECK(r.back().last == IP("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff")); + TEST_CHECK(r.front().first == addr("::0")); + TEST_CHECK(r.back().last == addr("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff")); } for (iterator i(r.begin()), j(boost::next(r.begin())) @@ -99,15 +96,15 @@ TORRENT_TEST(ip_filter) // **** test joining of ranges at the end **** ip_range expected1[] = { - {IP4("0.0.0.0"), IP4("0.255.255.255"), 0} - , {IP4("1.0.0.0"), IP4("3.0.0.0"), ip_filter::blocked} - , {IP4("3.0.0.1"), IP4("255.255.255.255"), 0} + {addr4("0.0.0.0"), addr4("0.255.255.255"), 0} + , {addr4("1.0.0.0"), addr4("3.0.0.0"), ip_filter::blocked} + , {addr4("3.0.0.1"), addr4("255.255.255.255"), 0} }; { ip_filter f; - f.add_rule(IP("1.0.0.0"), IP("2.0.0.0"), ip_filter::blocked); - f.add_rule(IP("2.0.0.1"), IP("3.0.0.0"), ip_filter::blocked); + f.add_rule(addr("1.0.0.0"), addr("2.0.0.0"), ip_filter::blocked); + f.add_rule(addr("2.0.0.1"), addr("3.0.0.0"), ip_filter::blocked); #if TORRENT_USE_IPV6 range = boost::get<0>(f.export_filter()); @@ -125,8 +122,8 @@ TORRENT_TEST(ip_filter) { ip_filter f; - f.add_rule(IP("2.0.0.1"), IP("3.0.0.0"), ip_filter::blocked); - f.add_rule(IP("1.0.0.0"), IP("2.0.0.0"), ip_filter::blocked); + f.add_rule(addr("2.0.0.1"), addr("3.0.0.0"), ip_filter::blocked); + f.add_rule(addr("1.0.0.0"), addr("2.0.0.0"), ip_filter::blocked); #if TORRENT_USE_IPV6 range = boost::get<0>(f.export_filter()); @@ -145,8 +142,8 @@ TORRENT_TEST(ip_filter) { ip_filter f; - f.add_rule(IP("2.0.0.1"), IP("3.0.0.0"), ip_filter::blocked); - f.add_rule(IP("1.0.0.0"), IP("2.4.0.0"), ip_filter::blocked); + f.add_rule(addr("2.0.0.1"), addr("3.0.0.0"), ip_filter::blocked); + f.add_rule(addr("1.0.0.0"), addr("2.4.0.0"), ip_filter::blocked); #if TORRENT_USE_IPV6 range = boost::get<0>(f.export_filter()); @@ -165,8 +162,8 @@ TORRENT_TEST(ip_filter) { ip_filter f; - f.add_rule(IP("1.0.0.0"), IP("2.4.0.0"), ip_filter::blocked); - f.add_rule(IP("2.0.0.1"), IP("3.0.0.0"), ip_filter::blocked); + f.add_rule(addr("1.0.0.0"), addr("2.4.0.0"), ip_filter::blocked); + f.add_rule(addr("2.0.0.1"), addr("3.0.0.0"), ip_filter::blocked); #if TORRENT_USE_IPV6 range = boost::get<0>(f.export_filter()); @@ -185,12 +182,12 @@ TORRENT_TEST(ip_filter) { ip_filter f; - f.add_rule(IP("1.0.0.0"), IP("2.0.0.0"), ip_filter::blocked); - f.add_rule(IP("3.0.0.0"), IP("4.0.0.0"), ip_filter::blocked); - f.add_rule(IP("5.0.0.0"), IP("6.0.0.0"), ip_filter::blocked); - f.add_rule(IP("7.0.0.0"), IP("8.0.0.0"), ip_filter::blocked); + f.add_rule(addr("1.0.0.0"), addr("2.0.0.0"), ip_filter::blocked); + f.add_rule(addr("3.0.0.0"), addr("4.0.0.0"), ip_filter::blocked); + f.add_rule(addr("5.0.0.0"), addr("6.0.0.0"), ip_filter::blocked); + f.add_rule(addr("7.0.0.0"), addr("8.0.0.0"), ip_filter::blocked); - f.add_rule(IP("1.0.1.0"), IP("9.0.0.0"), ip_filter::blocked); + f.add_rule(addr("1.0.1.0"), addr("9.0.0.0"), ip_filter::blocked); #if TORRENT_USE_IPV6 range = boost::get<0>(f.export_filter()); @@ -202,9 +199,9 @@ TORRENT_TEST(ip_filter) TEST_CHECK(range.size() == 3); ip_range expected[] = { - {IP4("0.0.0.0"), IP4("0.255.255.255"), 0} - , {IP4("1.0.0.0"), IP4("9.0.0.0"), ip_filter::blocked} - , {IP4("9.0.0.1"), IP4("255.255.255.255"), 0} + {addr4("0.0.0.0"), addr4("0.255.255.255"), 0} + , {addr4("1.0.0.0"), addr4("9.0.0.0"), ip_filter::blocked} + , {addr4("9.0.0.1"), addr4("255.255.255.255"), 0} }; TEST_CHECK(std::equal(range.begin(), range.end(), expected, &compare)); @@ -215,12 +212,12 @@ TORRENT_TEST(ip_filter) { ip_filter f; - f.add_rule(IP("1.0.0.0"), IP("2.0.0.0"), ip_filter::blocked); - f.add_rule(IP("3.0.0.0"), IP("4.0.0.0"), ip_filter::blocked); - f.add_rule(IP("5.0.0.0"), IP("6.0.0.0"), ip_filter::blocked); - f.add_rule(IP("7.0.0.0"), IP("8.0.0.0"), ip_filter::blocked); + f.add_rule(addr("1.0.0.0"), addr("2.0.0.0"), ip_filter::blocked); + f.add_rule(addr("3.0.0.0"), addr("4.0.0.0"), ip_filter::blocked); + f.add_rule(addr("5.0.0.0"), addr("6.0.0.0"), ip_filter::blocked); + f.add_rule(addr("7.0.0.0"), addr("8.0.0.0"), ip_filter::blocked); - f.add_rule(IP("0.0.1.0"), IP("7.0.4.0"), ip_filter::blocked); + f.add_rule(addr("0.0.1.0"), addr("7.0.4.0"), ip_filter::blocked); #if TORRENT_USE_IPV6 range = boost::get<0>(f.export_filter()); @@ -232,9 +229,9 @@ TORRENT_TEST(ip_filter) TEST_CHECK(range.size() == 3); ip_range expected[] = { - {IP4("0.0.0.0"), IP4("0.0.0.255"), 0} - , {IP4("0.0.1.0"), IP4("8.0.0.0"), ip_filter::blocked} - , {IP4("8.0.0.1"), IP4("255.255.255.255"), 0} + {addr4("0.0.0.0"), addr4("0.0.0.255"), 0} + , {addr4("0.0.1.0"), addr4("8.0.0.0"), ip_filter::blocked} + , {addr4("8.0.0.1"), addr4("255.255.255.255"), 0} }; TEST_CHECK(std::equal(range.begin(), range.end(), expected, &compare)); @@ -247,15 +244,15 @@ TORRENT_TEST(ip_filter) ip_range expected2[] = { - {IP6("::0"), IP6("0:ffff:ffff:ffff:ffff:ffff:ffff:ffff"), 0} - , {IP6("1::"), IP6("3::"), ip_filter::blocked} - , {IP6("3::1"), IP6("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"), 0} + {addr6("::0"), addr6("0:ffff:ffff:ffff:ffff:ffff:ffff:ffff"), 0} + , {addr6("1::"), addr6("3::"), ip_filter::blocked} + , {addr6("3::1"), addr6("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"), 0} }; { ip_filter f; - f.add_rule(IP("2::1"), IP("3::"), ip_filter::blocked); - f.add_rule(IP("1::"), IP("2::"), ip_filter::blocked); + f.add_rule(addr("2::1"), addr("3::"), ip_filter::blocked); + f.add_rule(addr("1::"), addr("2::"), ip_filter::blocked); std::vector > range; range = boost::get<1>(f.export_filter());