diff --git a/Jamfile b/Jamfile index 9ee39df66..2193df710 100644 --- a/Jamfile +++ b/Jamfile @@ -104,7 +104,7 @@ rule linking ( properties * ) # the system library. Only add this include path # if we're not using openssl (which we're most # likely not if we're using libgcrypt) - result += gcrypt /opt/local/include ; + result += gcrypt ; } # socket functions on windows require winsock libraries @@ -520,10 +520,10 @@ lib gcc : : gcc static ; lib libiconv : : iconv shared /usr/local/lib ; # openssl on linux/bsd/macos etc. -lib gcrypt : : gcrypt shared /opt/local/lib ; +lib gcrypt : : gcrypt shared /opt/local/lib /usr/local/lib : : /opt/local/include /usr/local/include ; lib z : : shared z /usr/lib ; -lib crypto : : crypto shared /usr/lib z ; -lib ssl : : ssl shared crypto /opt/local/lib ; +lib crypto : : crypto shared /usr/lib z : : /usr/include /opt/local/include ; +lib ssl : : ssl shared crypto /opt/local/lib /usr/local/lib : : /opt/local/include /usr/local/include ; lib dl : : shared dl ; # time functions used on linux require librt diff --git a/appveyor.yml b/appveyor.yml index b32ab1693..25c108f8b 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -95,7 +95,7 @@ cache: build_script: # examples - cd %ROOT_DIRECTORY%\examples -- b2.exe --hash -j2 %compiler% address-model=%model% variant=%variant% linkflags=%linkflags% include=%include% link=shared +- b2.exe --hash warnings-as-errors=on -j2 %compiler% address-model=%model% variant=%variant% linkflags=%linkflags% include=%include% link=shared # test - cd %ROOT_DIRECTORY%\test diff --git a/examples/bt-get2.cpp b/examples/bt-get2.cpp index 1b20a377d..f6092c50a 100644 --- a/examples/bt-get2.cpp +++ b/examples/bt-get2.cpp @@ -85,7 +85,7 @@ int main(int argc, char const* argv[]) , std::istream_iterator()}; lt::error_code ec; - lt::add_torrent_params atp = lt::read_resume_data(&buf[0], buf.size(), ec); + lt::add_torrent_params atp = lt::read_resume_data(&buf[0], int(buf.size()), ec); atp.url = argv[1]; atp.save_path = "."; // save in current dir ses.async_add_torrent(atp); diff --git a/examples/client_test.cpp b/examples/client_test.cpp index e0188eaac..2bc1d4af9 100644 --- a/examples/client_test.cpp +++ b/examples/client_test.cpp @@ -139,7 +139,7 @@ struct set_keypress bool sleep_and_input(int* c, int sleep) { - libtorrent::time_point start = libtorrent::clock_type::now(); + libtorrent::time_point const start = libtorrent::clock_type::now(); int ret = 0; retry: fd_set set; @@ -569,7 +569,7 @@ bool disable_storage = false; bool quit = false; -void signal_handler(int signo) +void signal_handler(int) { // make the main loop terminate quit = true; @@ -646,19 +646,9 @@ void print_settings(int const start, int const num } } -// monitored_dir is true if this torrent is added because -// it was found in the directory that is monitored. If it -// is, it should be remembered so that it can be removed -// if it's no longer in that directory. void add_torrent(libtorrent::session& ses , handles_t& files - , std::set& non_files - , std::string torrent - , int allocation_mode - , std::string const& save_path - , bool monitored_dir - , int torrent_upload_limit - , int torrent_download_limit) + , std::string torrent) { using namespace libtorrent; static int counter = 0; @@ -760,12 +750,7 @@ bool filter_fun(std::string const& p) void scan_dir(std::string const& dir_path , libtorrent::session& ses - , handles_t& files - , std::set& non_files - , int allocation_mode - , std::string const& save_path - , int torrent_upload_limit - , int torrent_download_limit) + , handles_t& files) { std::set valid; @@ -794,8 +779,7 @@ void scan_dir(std::string const& dir_path // the file has been added to the dir, start // downloading it. - add_torrent(ses, files, non_files, file, allocation_mode - , save_path, true, torrent_upload_limit, torrent_download_limit); + add_torrent(ses, files, file); valid.insert(file); } @@ -956,6 +940,12 @@ bool handle_alert(libtorrent::session& ses, libtorrent::alert* a return true; } +#ifdef _MSC_VER +// it seems msvc makes the definitions of 'p' escape the if-statement here +#pragma warning(push) +#pragma warning(disable: 4456) +#endif + if (metadata_received_alert* p = alert_cast(a)) { // if we have a monitor dir, save the .torrent file we just received in it @@ -1018,7 +1008,7 @@ bool handle_alert(libtorrent::session& ses, libtorrent::alert* a int peer_port = atoi(port); error_code ec; if (peer_port > 0) - h.connect_peer(tcp::endpoint(address::from_string(ip, ec), peer_port)); + h.connect_peer(tcp::endpoint(address::from_string(ip, ec), boost::uint16_t(peer_port))); } } @@ -1098,12 +1088,16 @@ bool handle_alert(libtorrent::session& ses, libtorrent::alert* a return true; } return false; + +#ifdef _MSC_VER +#pragma warning(pop) +#endif + } void print_piece(libtorrent::partial_piece_info* pp , libtorrent::cached_piece_info* cs , std::vector const& peers - , torrent_status const* ts , std::string& out) { using namespace libtorrent; @@ -1121,7 +1115,7 @@ void print_piece(libtorrent::partial_piece_info* pp int index = pp ? peer_index(pp->blocks[j].peer(), peers) % 36 : -1; char chr = '+'; if (index >= 0) - chr = (index < 10)?'0' + index:'A' + index - 10; + chr = char((index < 10)?'0' + index:'A' + index - 10); bool snubbed = index >= 0 ? ((peers[index].flags & peer_info::snubbed) != 0) : false; char const* color = ""; @@ -1140,7 +1134,7 @@ void print_piece(libtorrent::partial_piece_info* pp { if (pp->blocks[j].num_peers > 1) color = esc("1;7"); else color = snubbed ? esc("35;7") : esc("33;7"); - chr = '0' + (pp->blocks[j].bytes_progress * 10 / pp->blocks[j].block_size); + chr = char('0' + (pp->blocks[j].bytes_progress * 10 / pp->blocks[j].block_size)); } else if (pp->blocks[j].state == block_info::finished) color = esc("32;7"); else if (pp->blocks[j].state == block_info::writing) color = esc("36;7"); @@ -1159,15 +1153,6 @@ void print_piece(libtorrent::partial_piece_info* pp } out += esc("0"); out += "]"; -/* - char const* cache_kind_str[] = {"read", "write", "read-volatile"}; - snprintf(str, sizeof(str), " %3d cache age: %-5.1f state: %s%s\n" - , cs ? cs->next_to_hash : 0 - , cs ? (total_milliseconds(clock_type::now() - cs->last_use) / 1000.f) : 0.f - , cs ? cache_kind_str[cs->kind] : "N/A" - , ts && ts->pieces.size() ? (ts->pieces[piece] ? " have" : " dont-have") : ""); - out += str; -*/ } int main(int argc, char* argv[]) @@ -1354,6 +1339,10 @@ int main(int argc, char* argv[]) case 'Q': share_mode = true; --i; break; case 't': poll_interval = atoi(arg); break; case 'F': refresh_delay = atoi(arg); break; + case 'a': allocation_mode = (arg == std::string("sparse")) + ? libtorrent::storage_mode_sparse + : libtorrent::storage_mode_allocate; + break; case 'x': { FILE* filter = fopen(arg, "r"); @@ -1500,9 +1489,7 @@ int main(int argc, char* argv[]) } // if it's a torrent file, open it as usual - add_torrent(ses, files, non_files, i->c_str() - , allocation_mode, save_path, false - , torrent_upload_limit, torrent_download_limit); + add_torrent(ses, files, i->c_str()); } // main loop @@ -1556,9 +1543,9 @@ int main(int argc, char* argv[]) { // escape code, read another character #ifdef WIN32 - int c = _getch(); + c = _getch(); #else - int c = getc(stdin); + c = getc(stdin); if (c == EOF) { break; } if (c != '[') continue; c = getc(stdin); @@ -1678,12 +1665,12 @@ int main(int argc, char* argv[]) , boost::bind(&handles_t::value_type::second, _1) == st.handle); if (i != files.end()) { - error_code ec; + error_code err; std::string path; if (is_absolute_path(i->first)) path = i->first; else path = path_append(monitor_dir, i->first); if (::remove(path.c_str()) < 0) - printf("failed to delete .torrent file: %s\n", ec.message().c_str()); + printf("failed to delete .torrent file: %s\n", err.message().c_str()); files.erase(i); } if (st.handle.is_valid()) @@ -1710,14 +1697,13 @@ int main(int argc, char* argv[]) if (c == 'R') { // save resume data for all torrents - std::vector torrents; - ses.get_torrent_status(&torrents, &yes, 0); - for (std::vector::iterator i = torrents.begin() - , end(torrents.end()); i != end; ++i) + std::vector torr; + ses.get_torrent_status(&torr, &yes, 0); + for (torrent_status const& st : torr) { - if (i->need_save_resume) + if (st.need_save_resume) { - i->handle.save_resume_data(); + st.handle.save_resume_data(); ++num_outstanding_resume_data; } } @@ -1835,7 +1821,6 @@ int main(int argc, char* argv[]) // loop through the alert queue to see if anything has happened. std::vector alerts; ses.pop_alerts(&alerts); - std::string now = timestamp(); for (std::vector::iterator i = alerts.begin() , end(alerts.end()); i != end; ++i) { @@ -1938,7 +1923,7 @@ int main(int argc, char* argv[]) if (print_trackers) { std::vector tr = h.trackers(); - time_point now = clock_type::now(); + time_point const now = clock_type::now(); for (std::vector::iterator i = tr.begin() , end(tr.end()); i != end; ++i) { @@ -1987,7 +1972,7 @@ int main(int argc, char* argv[]) < boost::bind(&partial_piece_info::piece_index, _2)); if (ppi != queue.end() && ppi->piece_index == i->piece) pp = &*ppi; - print_piece(pp, &*i, peers, &s, out); + print_piece(pp, &*i, peers, out); int num_blocks = pp ? pp->blocks_in_piece : int(i->blocks.size()); p += num_blocks + 8; @@ -2015,7 +2000,7 @@ int main(int argc, char* argv[]) { if (pos + 3 >= terminal_height) break; - print_piece(&*i, 0, peers, &s, out); + print_piece(&*i, 0, peers, out); int num_blocks = i->blocks_in_piece; p += num_blocks + 8; @@ -2155,9 +2140,7 @@ int main(int argc, char* argv[]) if (!monitor_dir.empty() && next_dir_scan < clock_type::now()) { - scan_dir(monitor_dir, ses, files, non_files - , allocation_mode, save_path, torrent_upload_limit - , torrent_download_limit); + scan_dir(monitor_dir, ses, files); next_dir_scan = clock_type::now() + seconds(poll_interval); } } @@ -2200,7 +2183,7 @@ int main(int argc, char* argv[]) std::vector alerts; ses.pop_alerts(&alerts); - std::string now = timestamp(); + std::string const now = timestamp(); for (std::vector::iterator i = alerts.begin() , end(alerts.end()); i != end; ++i) { diff --git a/examples/connection_tester.cpp b/examples/connection_tester.cpp index a100699e7..bff466f52 100644 --- a/examples/connection_tester.cpp +++ b/examples/connection_tester.cpp @@ -261,7 +261,7 @@ struct peer_conn , boost::bind(&peer_conn::on_handshake, this, h, _1, _2)); } - void on_handshake(char* h, error_code const& ec, size_t bytes_transferred) + void on_handshake(char* h, error_code const& ec, size_t) { free(h); if (ec) @@ -275,7 +275,7 @@ struct peer_conn , boost::bind(&peer_conn::on_handshake2, this, _1, _2)); } - void on_handshake2(error_code const& ec, size_t bytes_transferred) + void on_handshake2(error_code const& ec, size_t) { if (ec) { @@ -331,7 +331,7 @@ struct peer_conn } } - void on_have_all_sent(error_code const& ec, size_t bytes_transferred) + void on_have_all_sent(error_code const& ec, size_t) { if (ec) { @@ -376,7 +376,7 @@ struct peer_conn } else { - TORRENT_ASSERT(false); + TORRENT_ASSERT_FAIL(); } } char msg[] = "\0\0\0\xd\x06" @@ -404,7 +404,7 @@ struct peer_conn return true; } - void on_req_sent(char* m, error_code const& ec, size_t bytes_transferred) + void on_req_sent(char* m, error_code const& ec, size_t) { free(m); if (ec) @@ -465,7 +465,7 @@ struct peer_conn , boost::bind(&peer_conn::on_msg_length, this, _1, _2)); } - void on_msg_length(error_code const& ec, size_t bytes_transferred) + void on_msg_length(error_code const& ec, size_t) { if ((ec == boost::asio::error::operation_aborted || ec == boost::asio::error::bad_descriptor) && restarting) @@ -671,7 +671,6 @@ struct peer_conn { fprintf(stderr, "received invalid block. piece %d block %d\n", piece, start / 0x4000); exit(1); - return false; } } return true; @@ -831,8 +830,10 @@ void generate_data(char const* path, torrent_info const& ti) boost::scoped_ptr st(default_storage_constructor(params)); - storage_error error; - st->initialize(error); + { + storage_error error; + st->initialize(error); + } boost::uint32_t piece[0x4000 / 4]; for (int i = 0; i < ti.num_pieces(); ++i) @@ -974,8 +975,8 @@ int main(int argc, char* argv[]) const int piece_size = 1024 * 1024; libtorrent::create_torrent t(fs, piece_size); sha1_hash zero(0); - for (int i = 0; i < fs.num_pieces(); ++i) - t.set_hash(i, zero); + for (int k = 0; k < fs.num_pieces(); ++k) + t.set_hash(k, zero); buf.clear(); @@ -1024,12 +1025,12 @@ int main(int argc, char* argv[]) fprintf(stderr, "ERROR RESOLVING %s: %s\n", destination_ip, ec.message().c_str()); return 1; } - tcp::endpoint ep(addr, destination_port); + tcp::endpoint ep(addr, boost::uint16_t(destination_port)); #if !defined __APPLE__ // apparently darwin doesn't seems to let you bind to // loopback on any other IP than 127.0.0.1 - unsigned long ip = addr.to_ulong(); + boost::uint32_t const ip = addr.to_ulong(); if ((ip & 0xff000000) == 0x7f000000) { local_bind = true; diff --git a/include/libtorrent/alert_types.hpp b/include/libtorrent/alert_types.hpp index 9f960df9a..53f3f1b31 100644 --- a/include/libtorrent/alert_types.hpp +++ b/include/libtorrent/alert_types.hpp @@ -2423,6 +2423,9 @@ namespace libtorrent private: int m_array_idx; int m_num_blocks; +#else + picker_log_alert(aux::stack_allocator& alloc) + : peer_alert(alloc, torrent_handle(), tcp::endpoint(), peer_id()) {} #endif // TORRENT_DISABLE_LOGGING }; diff --git a/include/libtorrent/assert.hpp b/include/libtorrent/assert.hpp index 28ec64dd6..05532aaba 100644 --- a/include/libtorrent/assert.hpp +++ b/include/libtorrent/assert.hpp @@ -95,15 +95,26 @@ extern char const* libtorrent_assert_log; #define TORRENT_ASSERT_VAL(x, y) \ do { if (x) {} else { std::stringstream __s__; __s__ << #y ": " << y; \ assert_fail(#x, __LINE__, __FILE__, TORRENT_FUNCTION, __s__.str().c_str(), 0); } } TORRENT_WHILE_0 + +#define TORRENT_ASSERT_FAIL_VAL(y) \ + do { std::stringstream __s__; __s__ << #y ": " << y; \ + assert_fail("", __LINE__, __FILE__, TORRENT_FUNCTION, __s__.str().c_str(), 0); } TORRENT_WHILE_0 + #else #define TORRENT_ASSERT_VAL(x, y) TORRENT_ASSERT(x) +#define TORRENT_ASSERT_FAIL_VAL(x) TORRENT_ASSERT_FAIL() #endif +#define TORRENT_ASSERT_FAIL() \ + assert_fail("", __LINE__, __FILE__, TORRENT_FUNCTION, 0, 0) + #else #include #define TORRENT_ASSERT_PRECOND(x) assert(x) #define TORRENT_ASSERT(x) assert(x) #define TORRENT_ASSERT_VAL(x, y) assert(x) +#define TORRENT_ASSERT_FAIL_VAL(x) assert(false) +#define TORRENT_ASSERT_FAIL() assert(false) #endif #else // TORRENT_USE_ASSERTS @@ -111,6 +122,8 @@ extern char const* libtorrent_assert_log; #define TORRENT_ASSERT_PRECOND(a) do {} TORRENT_WHILE_0 #define TORRENT_ASSERT(a) do {} TORRENT_WHILE_0 #define TORRENT_ASSERT_VAL(a, b) do {} TORRENT_WHILE_0 +#define TORRENT_ASSERT_FAIL_VAL(a) do {} TORRENT_WHILE_0 +#define TORRENT_ASSERT_FAIL() do {} TORRENT_WHILE_0 #endif // TORRENT_USE_ASSERTS diff --git a/include/libtorrent/aux_/disable_warnings_push.hpp b/include/libtorrent/aux_/disable_warnings_push.hpp index e124fd308..07acc5049 100644 --- a/include/libtorrent/aux_/disable_warnings_push.hpp +++ b/include/libtorrent/aux_/disable_warnings_push.hpp @@ -74,5 +74,7 @@ POSSIBILITY OF SUCH DAMAGE. #ifdef _MSC_VER #pragma warning(push, 1) +// warning C4005: macro redefinition +#pragma warning( disable : 4005 ) #endif diff --git a/include/libtorrent/aux_/io.hpp b/include/libtorrent/aux_/io.hpp index cfddb9310..157774b58 100644 --- a/include/libtorrent/aux_/io.hpp +++ b/include/libtorrent/aux_/io.hpp @@ -149,7 +149,7 @@ namespace libtorrent { namespace aux for (int i = 0; i < len; ++i) view[i] = str[i]; - view = array_view(view.data() + len, view.size() - len); + view = array_view(view.data() + len, int(view.size()) - len); return len; } diff --git a/include/libtorrent/aux_/session_impl.hpp b/include/libtorrent/aux_/session_impl.hpp index 4d64578cd..e7f43502b 100644 --- a/include/libtorrent/aux_/session_impl.hpp +++ b/include/libtorrent/aux_/session_impl.hpp @@ -871,7 +871,7 @@ namespace libtorrent #endif #ifdef TORRENT_USE_OPENSSL - ssl::context* ssl_ctx() { return &m_ssl_ctx; } + ssl::context* ssl_ctx() override { return &m_ssl_ctx; } void on_incoming_utp_ssl(boost::shared_ptr const& s); void ssl_handshake(error_code const& ec, boost::shared_ptr s); #endif diff --git a/include/libtorrent/fingerprint.hpp b/include/libtorrent/fingerprint.hpp index 78f302661..d14f901f0 100644 --- a/include/libtorrent/fingerprint.hpp +++ b/include/libtorrent/fingerprint.hpp @@ -118,7 +118,7 @@ namespace libtorrent { if (v >= 0 && v < 10) return char('0' + v); else if (v >= 10) return char('A' + (v - 10)); - TORRENT_ASSERT(false); + TORRENT_ASSERT_FAIL(); return '0'; } diff --git a/include/libtorrent/heterogeneous_queue.hpp b/include/libtorrent/heterogeneous_queue.hpp index 805803e9c..5d4640469 100644 --- a/include/libtorrent/heterogeneous_queue.hpp +++ b/include/libtorrent/heterogeneous_queue.hpp @@ -35,10 +35,14 @@ POSSIBILITY OF SUCH DAMAGE. #include +#include "libtorrent/aux_/disable_warnings_push.hpp" + #include #include #include +#include "libtorrent/aux_/disable_warnings_pop.hpp" + #include "libtorrent/assert.hpp" namespace libtorrent { diff --git a/include/libtorrent/invariant_check.hpp b/include/libtorrent/invariant_check.hpp index 60c260b6a..4ee84179e 100644 --- a/include/libtorrent/invariant_check.hpp +++ b/include/libtorrent/invariant_check.hpp @@ -44,7 +44,7 @@ namespace libtorrent } TORRENT_CATCH_ALL { - TORRENT_ASSERT(false); + TORRENT_ASSERT_FAIL(); } } @@ -59,7 +59,7 @@ namespace libtorrent } TORRENT_CATCH_ALL { - TORRENT_ASSERT(false); + TORRENT_ASSERT_FAIL(); } } diff --git a/include/libtorrent/kademlia/node.hpp b/include/libtorrent/kademlia/node.hpp index 7bfbe40da..0111a8f28 100644 --- a/include/libtorrent/kademlia/node.hpp +++ b/include/libtorrent/kademlia/node.hpp @@ -250,6 +250,13 @@ public: std::map const& m_nodes; private: +#ifdef _MSC_VER +#pragma warning(push) +// warning: default constructor could not be generated +#pragma warning(disable: 4510) +// warning: struct can never be instantiated +#pragma warning(disable: 4610) +#endif struct protocol_descriptor { udp protocol; @@ -257,6 +264,9 @@ private: char const* nodes_key; }; +#ifdef _MSC_VER +#pragma warning(pop) +#endif static protocol_descriptor const& map_protocol_to_descriptor(udp protocol); dht_observer* m_observer; diff --git a/include/libtorrent/piece_picker.hpp b/include/libtorrent/piece_picker.hpp index dadbe3abf..c8d06c3c7 100644 --- a/include/libtorrent/piece_picker.hpp +++ b/include/libtorrent/piece_picker.hpp @@ -621,7 +621,7 @@ namespace libtorrent std::set have_peers; #endif - enum + enum : boost::uint32_t { // index is set to this to indicate that we have the // piece. There is no entry for the piece in the diff --git a/include/libtorrent/socket_type.hpp b/include/libtorrent/socket_type.hpp index dcd2d6a95..9220a3ff7 100644 --- a/include/libtorrent/socket_type.hpp +++ b/include/libtorrent/socket_type.hpp @@ -117,7 +117,7 @@ POSSIBILITY OF SUCH DAMAGE. get()->x; break; \ TORRENT_SOCKTYPE_I2P_FORWARD(x) \ TORRENT_SOCKTYPE_SSL_FORWARD(x) \ - default: TORRENT_ASSERT(false); \ + default: TORRENT_ASSERT_FAIL(); \ } #define TORRENT_SOCKTYPE_FORWARD_RET(x, def) \ @@ -132,7 +132,7 @@ POSSIBILITY OF SUCH DAMAGE. return get()->x; \ TORRENT_SOCKTYPE_I2P_FORWARD_RET(x, def) \ TORRENT_SOCKTYPE_SSL_FORWARD_RET(x, def) \ - default: TORRENT_ASSERT(false); return def; \ + default: TORRENT_ASSERT_FAIL(); return def; \ } namespace libtorrent diff --git a/include/libtorrent/utp_socket_manager.hpp b/include/libtorrent/utp_socket_manager.hpp index fe86fb2e4..608d90efd 100644 --- a/include/libtorrent/utp_socket_manager.hpp +++ b/include/libtorrent/utp_socket_manager.hpp @@ -104,7 +104,7 @@ namespace libtorrent int loss_multiplier() const { return m_sett.get_int(settings_pack::utp_loss_multiplier); } void mtu_for_dest(address const& addr, int& link_mtu, int& utp_mtu); - int num_sockets() const { return m_utp_sockets.size(); } + int num_sockets() const { return int(m_utp_sockets.size()); } void defer_ack(utp_socket_impl* s); void subscribe_drained(utp_socket_impl* s); diff --git a/include/libtorrent/utp_stream.hpp b/include/libtorrent/utp_stream.hpp index d3bdf9dfa..7696cf099 100644 --- a/include/libtorrent/utp_stream.hpp +++ b/include/libtorrent/utp_stream.hpp @@ -364,7 +364,7 @@ public: TORRENT_ASSERT(!m_read_handler); if (m_read_handler) { - TORRENT_ASSERT(false); // we should never do this! + TORRENT_ASSERT_FAIL(); // we should never do this! m_io_service.post(boost::bind(handler, boost::asio::error::operation_not_supported, 0)); return; } diff --git a/include/libtorrent/web_connection_base.hpp b/include/libtorrent/web_connection_base.hpp index ada328bcd..ef43f8016 100644 --- a/include/libtorrent/web_connection_base.hpp +++ b/include/libtorrent/web_connection_base.hpp @@ -109,7 +109,7 @@ namespace libtorrent void write_have(int) {} void write_dont_have(int) {} void write_piece(peer_request const&, disk_buffer_holder&) - { TORRENT_ASSERT(false); } + { TORRENT_ASSERT_FAIL(); } void write_keepalive() {} void on_connected(); void write_reject_request(peer_request const&) {} diff --git a/src/bt_peer_connection.cpp b/src/bt_peer_connection.cpp index 93d6e189e..e94fcea91 100644 --- a/src/bt_peer_connection.cpp +++ b/src/bt_peer_connection.cpp @@ -2001,7 +2001,7 @@ namespace libtorrent else if (packet_type <= msg_extended) counter = counters::num_incoming_extended; else - TORRENT_ASSERT(false); + TORRENT_ASSERT_FAIL(); stats_counters().inc_stats_counter(counter); } diff --git a/src/choker.cpp b/src/choker.cpp index 1927e1f92..d6d79488b 100644 --- a/src/choker.cpp +++ b/src/choker.cpp @@ -405,7 +405,7 @@ namespace libtorrent } else { - TORRENT_ASSERT(false); + TORRENT_ASSERT_FAIL(); int pieces = sett.get_int(settings_pack::seeding_piece_quota); std::partial_sort(peers.begin(), peers.begin() diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index 5aed6e14e..b644cc96a 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -89,8 +89,12 @@ namespace libtorrent #define TORRENT_PIECE_ASSERT(cond, piece) \ do { if (!(cond)) { assert_print_piece(piece); assert_fail(#cond, __LINE__, __FILE__, TORRENT_FUNCTION, 0); } } TORRENT_WHILE_0 +#define TORRENT_PIECE_ASSERT_FAIL(piece) \ + do { assert_print_piece(piece); assert_fail("", __LINE__, __FILE__, TORRENT_FUNCTION, 0); } TORRENT_WHILE_0 + #else #define TORRENT_PIECE_ASSERT(cond, piece) do {} TORRENT_WHILE_0 +#define TORRENT_PIECE_ASSERT_FAIL(piece) do {} TORRENT_WHILE_0 #endif // TORRENT_USE_ASSERTS namespace { @@ -1297,7 +1301,7 @@ namespace libtorrent { // the piece is supposed to be allocated when the // disk job is allocated - TORRENT_ASSERT(false); + TORRENT_ASSERT_FAIL(); return ret; } TORRENT_PIECE_ASSERT(pe->outstanding_read == 1, pe); @@ -2997,7 +3001,7 @@ namespace libtorrent // we should always be able to evict the piece, since // this is a fence job - TORRENT_PIECE_ASSERT(false, pe); + TORRENT_PIECE_ASSERT_FAIL(pe); return retry_job; } diff --git a/src/entry.cpp b/src/entry.cpp index a46bc986c..1c7c5f475 100644 --- a/src/entry.cpp +++ b/src/entry.cpp @@ -611,7 +611,7 @@ namespace libtorrent { // currently, only swapping entries of the same type or where one // of the entries is uninitialized is supported. - TORRENT_ASSERT(false); + TORRENT_ASSERT_FAIL(); } } diff --git a/src/instantiate_connection.cpp b/src/instantiate_connection.cpp index 0512b6cf8..3f19bef38 100644 --- a/src/instantiate_connection.cpp +++ b/src/instantiate_connection.cpp @@ -140,7 +140,7 @@ namespace libtorrent } else { - TORRENT_ASSERT_VAL(false, ps.type); + TORRENT_ASSERT_FAIL_VAL(ps.type); return false; } return true; diff --git a/src/ip_filter.cpp b/src/ip_filter.cpp index fa3f78b28..e9db6fc67 100644 --- a/src/ip_filter.cpp +++ b/src/ip_filter.cpp @@ -51,7 +51,7 @@ namespace libtorrent } #endif else - TORRENT_ASSERT(false); + TORRENT_ASSERT_FAIL(); } int ip_filter::access(address const& addr) const diff --git a/src/kademlia/dht_tracker.cpp b/src/kademlia/dht_tracker.cpp index ffdcfd362..e8ec8c2e5 100644 --- a/src/kademlia/dht_tracker.cpp +++ b/src/kademlia/dht_tracker.cpp @@ -637,7 +637,8 @@ namespace libtorrent { namespace dht m_send_quota -= int(m_send_buf.size()); error_code ec; - m_send_fun(addr, aux::array_view(&m_send_buf[0], m_send_buf.size()), ec, 0); + m_send_fun(addr, aux::array_view(&m_send_buf[0] + , int(m_send_buf.size())), ec, 0); if (ec) { m_counters.inc_stats_counter(counters::dht_messages_out_dropped); diff --git a/src/kademlia/node.cpp b/src/kademlia/node.cpp index 32b1875d5..836da6eca 100644 --- a/src/kademlia/node.cpp +++ b/src/kademlia/node.cpp @@ -1234,7 +1234,7 @@ node::protocol_descriptor const& node::map_protocol_to_descriptor(udp protocol) return descriptors[i]; } - TORRENT_ASSERT(false); + TORRENT_ASSERT_FAIL(); throw std::out_of_range("unknown protocol"); } diff --git a/src/part_file.cpp b/src/part_file.cpp index 45c1ffcd6..f85d052cc 100644 --- a/src/part_file.cpp +++ b/src/part_file.cpp @@ -296,7 +296,7 @@ namespace libtorrent TORRENT_UNUSED(ec); // not implemented - TORRENT_ASSERT(false); + TORRENT_ASSERT_FAIL(); } void part_file::export_file(file& f, boost::int64_t offset, boost::int64_t size, error_code& ec) diff --git a/src/peer_class_set.cpp b/src/peer_class_set.cpp index f11ae1b1f..f2f7e482a 100644 --- a/src/peer_class_set.cpp +++ b/src/peer_class_set.cpp @@ -43,7 +43,7 @@ namespace libtorrent != m_class.begin() + m_size) return; if (m_size >= m_class.size() - 1) { - TORRENT_ASSERT(false); + TORRENT_ASSERT_FAIL(); return; } m_class[m_size] = c; diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 77f063b84..686c2b19b 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -3033,7 +3033,7 @@ namespace libtorrent if (j->ret == -1 && j->error.ec == boost::system::errc::operation_canceled) { - TORRENT_ASSERT(false); // how do we get here? + TORRENT_ASSERT_FAIL(); // how do we get here? picker.mark_as_canceled(block_finished, peer_info_struct()); return; } diff --git a/src/piece_picker.cpp b/src/piece_picker.cpp index d1f59932f..917ab59e4 100644 --- a/src/piece_picker.cpp +++ b/src/piece_picker.cpp @@ -2488,7 +2488,7 @@ get_out: fprintf(stderr, "\n"); } - TORRENT_ASSERT(false); + TORRENT_ASSERT_FAIL(); } } diff --git a/src/session.cpp b/src/session.cpp index 1566cdf13..167702881 100644 --- a/src/session.cpp +++ b/src/session.cpp @@ -336,13 +336,6 @@ namespace libtorrent void session::start(int flags, settings_pack const& pack, io_service* ios) { -#if defined _MSC_VER && defined TORRENT_DEBUG - // workaround for microsoft's - // hardware exceptions that makes - // it hard to debug stuff - ::_set_se_translator(straight_to_debugger); -#endif - bool const internal_executor = ios == NULL; if (internal_executor) diff --git a/src/session_impl.cpp b/src/session_impl.cpp index e3d244a6a..3ac928c60 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -2312,7 +2312,7 @@ namespace aux { #ifndef TORRENT_DISABLE_DHT if (m_dht && buf.size() > 20 && buf.front() == 'd' && buf.back() == 'e') { - handled = m_dht->incoming_packet(packet.from, buf.data(), buf.size()); + handled = m_dht->incoming_packet(packet.from, buf.data(), int(buf.size())); } #endif diff --git a/src/settings_pack.cpp b/src/settings_pack.cpp index 9479348d9..867227959 100644 --- a/src/settings_pack.cpp +++ b/src/settings_pack.cpp @@ -712,7 +712,7 @@ namespace libtorrent return i != m_bools.end() && i->first == name; } } - TORRENT_ASSERT(false); + TORRENT_ASSERT_FAIL(); return false; } diff --git a/src/socket_type.cpp b/src/socket_type.cpp index a96b75733..c6fd3a95a 100644 --- a/src/socket_type.cpp +++ b/src/socket_type.cpp @@ -218,7 +218,7 @@ namespace libtorrent get >()->~ssl_stream(); break; #endif - default: TORRENT_ASSERT(false); + default: TORRENT_ASSERT_FAIL(); } m_type = 0; } @@ -272,7 +272,7 @@ namespace libtorrent , *static_cast(userdata)); break; #endif - default: TORRENT_ASSERT(false); + default: TORRENT_ASSERT_FAIL(); } m_type = type; diff --git a/src/storage.cpp b/src/storage.cpp index 8ea01244a..9883868e0 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -211,7 +211,7 @@ namespace libtorrent detail::write_uint8(flags, ptr); std::unique_lock l(disk_access_mutex); - int ret = fwrite(event, 1, sizeof(event), g_access_log); + int const ret = int(fwrite(event, 1, sizeof(event), g_access_log)); l.unlock(); if (ret != sizeof(event)) { @@ -762,7 +762,7 @@ namespace libtorrent #if defined TORRENT_DEBUG_FILE_LEAKS print_open_files("delete-files idle assert failed", m_files.name().c_str()); #endif - TORRENT_ASSERT(false); + TORRENT_ASSERT_FAIL(); } #endif diff --git a/src/torrent.cpp b/src/torrent.cpp index 0808ceb88..3af351a7a 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -384,7 +384,7 @@ namespace libtorrent // we might want to do a full check to see if we have // all the pieces. This is low priority since almost // no one uses merkle torrents - TORRENT_ASSERT(false); + TORRENT_ASSERT_FAIL(); } } @@ -1622,7 +1622,7 @@ namespace libtorrent // wrap the PEM certificate in a BIO, for openssl to read BIO* bp = BIO_new_mem_buf( const_cast(static_cast(cert.c_str())) - , cert.size()); + , int(cert.size())); // parse the certificate into OpenSSL's internal // representation @@ -5867,7 +5867,7 @@ namespace libtorrent peer_iterator i = sorted_find(m_connections, p); if (i == m_connections.end()) { - TORRENT_ASSERT(false); + TORRENT_ASSERT_FAIL(); return; } @@ -7639,7 +7639,7 @@ namespace libtorrent TORRENT_LIST_NAME(torrent_downloading_auto_managed); TORRENT_LIST_NAME(torrent_seeding_auto_managed); TORRENT_LIST_NAME(torrent_checking_auto_managed); - default: TORRENT_ASSERT_VAL(false, idx); + default: TORRENT_ASSERT_FAIL_VAL(idx); } #undef TORRENT_LIST_NAME return ""; @@ -7758,7 +7758,7 @@ namespace libtorrent ++ret; TORRENT_ASSERT(p->associated_torrent().lock().get() == this); #if TORRENT_USE_ASSERTS - int num_conns = m_connections.size(); + int const num_conns = int(m_connections.size()); #endif p->disconnect(ec, op_bittorrent); TORRENT_ASSERT(int(m_connections.size()) == num_conns - 1); @@ -8355,7 +8355,7 @@ namespace libtorrent if (!p.is_choked() && !p.ignore_unchoke_slots()) ++num_uploads; torrent* associated_torrent = p.associated_torrent().lock().get(); if (associated_torrent != this && associated_torrent != 0) - TORRENT_ASSERT(false); + TORRENT_ASSERT_FAIL(); } TORRENT_ASSERT(num_uploads == int(m_num_uploads)); TORRENT_ASSERT(seeds == int(m_num_seeds)); @@ -8399,7 +8399,7 @@ namespace libtorrent , k->timed_out ? "timed-out" : "", k->busy ? "busy": ""); } } - TORRENT_ASSERT(false); + TORRENT_ASSERT_FAIL(); } } } @@ -8421,12 +8421,12 @@ namespace libtorrent if (m_peer_list && m_peer_list->begin_peer() != m_peer_list->end_peer()) { peer_list::const_iterator i = m_peer_list->begin_peer(); - peer_list::const_iterator prev = i++; + peer_list::const_iterator p = i++; peer_list::const_iterator end(m_peer_list->end_peer()); peer_address_compare cmp; - for (; i != end; ++i, ++prev) + for (; i != end; ++i, ++p) { - TORRENT_ASSERT(!cmp(*i, *prev)); + TORRENT_ASSERT(!cmp(*i, *p)); } } #endif @@ -10974,7 +10974,7 @@ namespace libtorrent return true; default: // unexpected state - TORRENT_ASSERT_VAL(false, st); + TORRENT_ASSERT_FAIL_VAL(st); return false; } } diff --git a/src/tracker_manager.cpp b/src/tracker_manager.cpp index 9871c9799..b9635ee7f 100644 --- a/src/tracker_manager.cpp +++ b/src/tracker_manager.cpp @@ -466,6 +466,6 @@ namespace libtorrent int tracker_manager::num_requests() const { std::lock_guard l(m_mutex); - return m_http_conns.size() + m_udp_conns.size(); + return int(m_http_conns.size() + m_udp_conns.size()); } } diff --git a/src/udp_socket.cpp b/src/udp_socket.cpp index 7ac61e9e1..451140433 100644 --- a/src/udp_socket.cpp +++ b/src/udp_socket.cpp @@ -170,14 +170,14 @@ udp_socket::udp_socket(io_service& ios) int udp_socket::read(array_view pkts, error_code& ec) { - int const num = pkts.size(); + int const num = int(pkts.size()); int ret = 0; packet p; while (ret < num) { - int const len = m_socket.receive_from(boost::asio::buffer(*m_buf) - , p.from, 0, ec); + int const len = int(m_socket.receive_from(boost::asio::buffer(*m_buf) + , p.from, 0, ec)); if (ec == error::would_block || ec == error::try_again @@ -334,7 +334,7 @@ void udp_socket::wrap(char const* hostname, int const port, array_view& buf) using namespace libtorrent::detail; // the minimum socks5 header size - int const size = buf.size(); + int const size = int(buf.size()); if (size <= 10) return false; char* p = buf.data(); @@ -728,7 +728,7 @@ void socks5::connect2(error_code const& e) { // in this case we need to read more data from the socket // no IPv6 support for UDP socks5 - TORRENT_ASSERT(false); + TORRENT_ASSERT_FAIL(); return; } diff --git a/src/udp_tracker_connection.cpp b/src/udp_tracker_connection.cpp index d2d4449c4..e495fdba7 100644 --- a/src/udp_tracker_connection.cpp +++ b/src/udp_tracker_connection.cpp @@ -598,7 +598,7 @@ namespace libtorrent resp.min_interval = 60; resp.incomplete = aux::read_int32(buf); resp.complete = aux::read_int32(buf); - int const num_peers = buf.size() / 6; + int const num_peers = int(buf.size()) / 6; if ((buf.size() % 6) != 0) { fail(error_code(errors::invalid_tracker_response_length)); @@ -768,16 +768,18 @@ namespace libtorrent if (!m_hostname.empty()) { m_man.send_hostname(m_hostname.c_str() - , m_target.port(), aux::array_view(buf, sizeof(buf) - out.size()), ec + , m_target.port(), aux::array_view(buf + , int(sizeof(buf) - out.size())), ec , udp_socket::tracker_connection); } else { - m_man.send(m_target, aux::array_view(buf, sizeof(buf) - out.size()), ec + m_man.send(m_target, aux::array_view(buf + , int(sizeof(buf) - out.size())), ec , udp_socket::tracker_connection); } m_state = action_announce; - sent_bytes(sizeof(buf) - out.size() + 28); // assuming UDP/IP header + sent_bytes(int(sizeof(buf) - out.size()) + 28); // assuming UDP/IP header ++m_attempts; if (ec) { diff --git a/src/utp_stream.cpp b/src/utp_stream.cpp index 42e3b88f2..e9a079612 100644 --- a/src/utp_stream.cpp +++ b/src/utp_stream.cpp @@ -750,7 +750,7 @@ bool utp_incoming_packet(utp_socket_impl* s , udp::endpoint const& ep, time_point receive_time) { return s->incoming_packet( - aux::array_view(reinterpret_cast(p.data()), p.size()) + aux::array_view(reinterpret_cast(p.data()), int(p.size())) , ep, receive_time); } @@ -2426,7 +2426,7 @@ void utp_socket_impl::ack_packet(packet* p, time_point const& receive_time rtt = 100000; // the clock for this platform is not monotonic! - TORRENT_ASSERT(false); + TORRENT_ASSERT_FAIL(); } UTP_LOGV("%8p: acked packet %d (%d bytes) (rtt:%u)\n" @@ -2947,7 +2947,7 @@ bool utp_socket_impl::incoming_packet(aux::array_view buf // look for extended headers boost::uint8_t const* ptr = buf.data(); - int const size = buf.size(); + int const size = int(buf.size()); ptr += sizeof(utp_header); unsigned int extension = ph->extension; diff --git a/test/bittorrent_peer.cpp b/test/bittorrent_peer.cpp index 27b6d16e0..c0393d3f4 100644 --- a/test/bittorrent_peer.cpp +++ b/test/bittorrent_peer.cpp @@ -217,7 +217,7 @@ bool peer_conn::write_request() } else { - TORRENT_ASSERT(false); + TORRENT_ASSERT_FAIL(); } } char msg[] = "\0\0\0\xd\x06" diff --git a/test/test_receive_buffer.cpp b/test/test_receive_buffer.cpp index 841750263..cc6380673 100644 --- a/test/test_receive_buffer.cpp +++ b/test/test_receive_buffer.cpp @@ -39,12 +39,12 @@ using namespace libtorrent; struct allocator : buffer_allocator_interface { void free_disk_buffer(char*) {} - char* allocate_disk_buffer(char const*) { TORRENT_ASSERT(false); return NULL; } + char* allocate_disk_buffer(char const*) { TORRENT_ASSERT_FAIL(); return NULL; } char* allocate_disk_buffer(bool& , boost::shared_ptr - , char const*) { TORRENT_ASSERT(false); return NULL; } + , char const*) { TORRENT_ASSERT_FAIL(); return NULL; } char* async_allocate_disk_buffer(char const* - , boost::function const&) { TORRENT_ASSERT(false); return NULL; } + , boost::function const&) { TORRENT_ASSERT_FAIL(); return NULL; } void reclaim_block(block_cache_reference ref) {} };