From fba0762353b930e9f9e9eba359ecacdb30557d3b Mon Sep 17 00:00:00 2001 From: arvidn Date: Wed, 18 Nov 2015 19:51:17 -0500 Subject: [PATCH 1/3] fix some msvc warnings --- include/libtorrent/aux_/session_impl.hpp | 5 ++--- include/libtorrent/aux_/session_interface.hpp | 4 ++-- include/libtorrent/bandwidth_socket.hpp | 2 +- include/libtorrent/bencode.hpp | 2 +- include/libtorrent/block_cache.hpp | 4 ++-- include/libtorrent/broadcast_socket.hpp | 2 +- include/libtorrent/disk_buffer_holder.hpp | 2 +- include/libtorrent/disk_interface.hpp | 2 +- include/libtorrent/disk_job_pool.hpp | 2 +- include/libtorrent/disk_observer.hpp | 2 +- include/libtorrent/entry.hpp | 2 +- include/libtorrent/kademlia/dht_observer.hpp | 4 ++-- include/libtorrent/peer_class.hpp | 1 - include/libtorrent/peer_class_set.hpp | 2 +- include/libtorrent/peer_connection.hpp | 5 ++++- include/libtorrent/peer_connection_interface.hpp | 2 +- include/libtorrent/resolve_links.hpp | 2 +- include/libtorrent/resolver_interface.hpp | 2 +- include/libtorrent/session_handle.hpp | 2 +- include/libtorrent/sha1_hash.hpp | 4 ++-- include/libtorrent/storage.hpp | 2 +- include/libtorrent/torrent.hpp | 6 +++--- include/libtorrent/torrent_peer_allocator.hpp | 2 +- include/libtorrent/udp_socket.hpp | 2 +- include/libtorrent/uncork_interface.hpp | 4 +++- include/libtorrent/utp_stream.hpp | 6 +++--- src/disk_buffer_pool.cpp | 2 ++ src/file.cpp | 12 +++++++----- src/magnet_uri.cpp | 6 +++--- 29 files changed, 51 insertions(+), 44 deletions(-) diff --git a/include/libtorrent/aux_/session_impl.hpp b/include/libtorrent/aux_/session_impl.hpp index 7bf75c791..3095dbd4b 100644 --- a/include/libtorrent/aux_/session_impl.hpp +++ b/include/libtorrent/aux_/session_impl.hpp @@ -260,7 +260,7 @@ namespace libtorrent std::string const& collection) const TORRENT_OVERRIDE TORRENT_FINAL; #endif boost::weak_ptr find_disconnect_candidate_torrent() const TORRENT_OVERRIDE TORRENT_FINAL; - int num_torrents() const TORRENT_OVERRIDE TORRENT_FINAL { return m_torrents.size(); } + int num_torrents() const TORRENT_OVERRIDE TORRENT_FINAL { return int(m_torrents.size()); } void insert_torrent(sha1_hash const& ih, boost::shared_ptr const& t , std::string uuid); @@ -458,8 +458,7 @@ namespace libtorrent bool preemptive_unchoke() const; int num_uploads() const { return int(m_stats_counters[counters::num_peers_up_unchoked]); } - int num_connections() const - { return m_connections.size(); } + int num_connections() const { return int(m_connections.size()); } int peak_up_rate() const { return m_peak_up_rate; } diff --git a/include/libtorrent/aux_/session_interface.hpp b/include/libtorrent/aux_/session_interface.hpp index 4d6a8b9cd..64913cd6d 100644 --- a/include/libtorrent/aux_/session_interface.hpp +++ b/include/libtorrent/aux_/session_interface.hpp @@ -107,7 +107,7 @@ namespace libtorrent { namespace aux // This is the basic logging and debug interface offered by the session. // a release build with logging disabled (which is the default) will // not have this class at all - struct session_logger + struct TORRENT_EXTRA_EXPORT session_logger { #ifndef TORRENT_DISABLE_LOGGING virtual void session_log(char const* fmt, ...) const TORRENT_FORMAT(2,3) = 0; @@ -128,7 +128,7 @@ namespace libtorrent { namespace aux // TOOD: 2 make this interface a lot smaller. It could be split up into // several smaller interfaces. Each subsystem could then limit the size // of the mock object to test it. - struct session_interface + struct TORRENT_EXTRA_EXPORT session_interface : buffer_allocator_interface #if !defined TORRENT_DISABLE_LOGGING || TORRENT_USE_ASSERTS , session_logger diff --git a/include/libtorrent/bandwidth_socket.hpp b/include/libtorrent/bandwidth_socket.hpp index ed4ba8154..80e8602b3 100644 --- a/include/libtorrent/bandwidth_socket.hpp +++ b/include/libtorrent/bandwidth_socket.hpp @@ -36,7 +36,7 @@ POSSIBILITY OF SUCH DAMAGE. namespace libtorrent { - struct bandwidth_socket + struct TORRENT_EXTRA_EXPORT bandwidth_socket { virtual void assign_bandwidth(int channel, int amount) = 0; virtual bool is_disconnecting() const = 0; diff --git a/include/libtorrent/bencode.hpp b/include/libtorrent/bencode.hpp index a27aebdcf..1de991ceb 100644 --- a/include/libtorrent/bencode.hpp +++ b/include/libtorrent/bencode.hpp @@ -94,7 +94,7 @@ namespace libtorrent #ifndef TORRENT_NO_DEPRECATE // thrown by bdecode() if the provided bencoded buffer does not contain // valid encoding. - struct TORRENT_EXPORT invalid_encoding: std::exception + struct invalid_encoding: std::exception { // hidden virtual const char* what() const TORRENT_EXCEPTION_THROW_SPECIFIER diff --git a/include/libtorrent/block_cache.hpp b/include/libtorrent/block_cache.hpp index dac2485ef..9b9e6afe6 100644 --- a/include/libtorrent/block_cache.hpp +++ b/include/libtorrent/block_cache.hpp @@ -360,12 +360,12 @@ namespace libtorrent // returns a range of all pieces. This migh be a very // long list, use carefully std::pair all_pieces() const; - int num_pieces() const { return m_pieces.size(); } + int num_pieces() const { return int(m_pieces.size()); } list_iterator write_lru_pieces() const { return m_lru[cached_piece_entry::write_lru].iterate(); } - int num_write_lru_pieces() const { return m_lru[cached_piece_entry::write_lru].size(); } + int num_write_lru_pieces() const { return int(m_lru[cached_piece_entry::write_lru].size()); } // mark this piece for deletion. If there are no outstanding // requests to this piece, it's removed immediately, and the diff --git a/include/libtorrent/broadcast_socket.hpp b/include/libtorrent/broadcast_socket.hpp index 35bd81c18..d484c30ad 100644 --- a/include/libtorrent/broadcast_socket.hpp +++ b/include/libtorrent/broadcast_socket.hpp @@ -79,7 +79,7 @@ namespace libtorrent void send(char const* buffer, int size, error_code& ec, int flags = 0); void close(); - int num_send_sockets() const { return m_unicast_sockets.size(); } + int num_send_sockets() const { return int(m_unicast_sockets.size()); } void enable_ip_broadcast(bool e); private: diff --git a/include/libtorrent/disk_buffer_holder.hpp b/include/libtorrent/disk_buffer_holder.hpp index 0aa37fe03..161f234cb 100644 --- a/include/libtorrent/disk_buffer_holder.hpp +++ b/include/libtorrent/disk_buffer_holder.hpp @@ -50,7 +50,7 @@ namespace libtorrent struct disk_io_thread; struct disk_observer; - struct buffer_allocator_interface + struct TORRENT_EXTRA_EXPORT buffer_allocator_interface { virtual char* allocate_disk_buffer(char const* category) = 0; virtual void free_disk_buffer(char* b) = 0; diff --git a/include/libtorrent/disk_interface.hpp b/include/libtorrent/disk_interface.hpp index ab0656703..0aea0a213 100644 --- a/include/libtorrent/disk_interface.hpp +++ b/include/libtorrent/disk_interface.hpp @@ -50,7 +50,7 @@ namespace libtorrent struct add_torrent_params; struct cache_status; - struct disk_interface + struct TORRENT_EXTRA_EXPORT disk_interface { virtual void async_read(piece_manager* storage, peer_request const& r , boost::function const& handler, void* requester diff --git a/include/libtorrent/disk_job_pool.hpp b/include/libtorrent/disk_job_pool.hpp index f6158eb2b..c67fbe002 100644 --- a/include/libtorrent/disk_job_pool.hpp +++ b/include/libtorrent/disk_job_pool.hpp @@ -46,7 +46,7 @@ namespace libtorrent { struct disk_io_job; - struct disk_job_pool + struct TORRENT_EXTRA_EXPORT disk_job_pool { disk_job_pool(); ~disk_job_pool(); diff --git a/include/libtorrent/disk_observer.hpp b/include/libtorrent/disk_observer.hpp index 2e746e7e7..c91810c41 100644 --- a/include/libtorrent/disk_observer.hpp +++ b/include/libtorrent/disk_observer.hpp @@ -37,7 +37,7 @@ POSSIBILITY OF SUCH DAMAGE. namespace libtorrent { - struct disk_observer + struct TORRENT_EXTRA_EXPORT disk_observer { // called when the disk cache size has dropped // below the low watermark again and we can diff --git a/include/libtorrent/entry.hpp b/include/libtorrent/entry.hpp index 5c3181739..5603b5d52 100644 --- a/include/libtorrent/entry.hpp +++ b/include/libtorrent/entry.hpp @@ -88,7 +88,7 @@ namespace libtorrent // thrown by any accessor function of entry if the accessor // function requires a type different than the actual type // of the entry object. - struct TORRENT_EXPORT type_error: std::runtime_error + struct type_error : std::runtime_error { // internal type_error(const char* error): std::runtime_error(error) {} diff --git a/include/libtorrent/kademlia/dht_observer.hpp b/include/libtorrent/kademlia/dht_observer.hpp index ba9c9d389..6bf067183 100644 --- a/include/libtorrent/kademlia/dht_observer.hpp +++ b/include/libtorrent/kademlia/dht_observer.hpp @@ -39,7 +39,7 @@ POSSIBILITY OF SUCH DAMAGE. namespace libtorrent { namespace dht { - struct dht_logger + struct TORRENT_EXTRA_EXPORT dht_logger { enum module_t { @@ -64,7 +64,7 @@ namespace libtorrent { namespace dht ~dht_logger() {} }; - struct dht_observer : dht_logger + struct TORRENT_EXTRA_EXPORT dht_observer : dht_logger { virtual void set_external_address(address const& addr , address const& source) = 0; diff --git a/include/libtorrent/peer_class.hpp b/include/libtorrent/peer_class.hpp index e985dcbee..946795fe0 100644 --- a/include/libtorrent/peer_class.hpp +++ b/include/libtorrent/peer_class.hpp @@ -128,7 +128,6 @@ namespace libtorrent struct TORRENT_EXTRA_EXPORT peer_class_pool { - peer_class_t new_peer_class(std::string const& label); void decref(peer_class_t c); void incref(peer_class_t c); diff --git a/include/libtorrent/peer_class_set.hpp b/include/libtorrent/peer_class_set.hpp index 55bbb173a..db4d0f8e5 100644 --- a/include/libtorrent/peer_class_set.hpp +++ b/include/libtorrent/peer_class_set.hpp @@ -40,7 +40,7 @@ namespace libtorrent { // this represents an object that can have many peer classes applied // to it. Most notably, peer connections and torrents derive from this. - struct peer_class_set + struct TORRENT_EXTRA_EXPORT peer_class_set { peer_class_set() : m_size(0) {} void add_class(peer_class_pool& pool, peer_class_t c); diff --git a/include/libtorrent/peer_connection.hpp b/include/libtorrent/peer_connection.hpp index 9532937ac..32cf2491f 100644 --- a/include/libtorrent/peer_connection.hpp +++ b/include/libtorrent/peer_connection.hpp @@ -175,7 +175,7 @@ namespace libtorrent // internal inline void nop(char*, void*, block_cache_reference) {} - struct peer_connection_hot_members + struct TORRENT_EXTRA_EXPORT peer_connection_hot_members { // if tor is set, this is an outgoing connection peer_connection_hot_members( @@ -1274,8 +1274,11 @@ namespace libtorrent m_need_uncork = true; } ~cork() { if (m_need_uncork) m_pc.uncork_socket(); } + private: peer_connection& m_pc; bool m_need_uncork; + + cork& operator=(cork const&); }; } diff --git a/include/libtorrent/peer_connection_interface.hpp b/include/libtorrent/peer_connection_interface.hpp index f2569695e..9bee7867e 100644 --- a/include/libtorrent/peer_connection_interface.hpp +++ b/include/libtorrent/peer_connection_interface.hpp @@ -45,7 +45,7 @@ namespace libtorrent struct peer_info; // TODO: make this interface smaller! - struct peer_connection_interface + struct TORRENT_EXTRA_EXPORT peer_connection_interface { virtual tcp::endpoint const& remote() const = 0; virtual tcp::endpoint local_endpoint() const = 0; diff --git a/include/libtorrent/resolve_links.hpp b/include/libtorrent/resolve_links.hpp index 9e4dec038..8484c8205 100644 --- a/include/libtorrent/resolve_links.hpp +++ b/include/libtorrent/resolve_links.hpp @@ -53,7 +53,7 @@ namespace libtorrent // in other torrents. struct TORRENT_EXTRA_EXPORT resolve_links { - struct link_t + struct TORRENT_EXTRA_EXPORT link_t { boost::shared_ptr ti; std::string save_path; diff --git a/include/libtorrent/resolver_interface.hpp b/include/libtorrent/resolver_interface.hpp index 838128cf7..66ade6c9c 100644 --- a/include/libtorrent/resolver_interface.hpp +++ b/include/libtorrent/resolver_interface.hpp @@ -46,7 +46,7 @@ POSSIBILITY OF SUCH DAMAGE. namespace libtorrent { -struct resolver_interface +struct TORRENT_EXTRA_EXPORT resolver_interface { typedef boost::function const&)> callback_t; diff --git a/include/libtorrent/session_handle.hpp b/include/libtorrent/session_handle.hpp index 4386eddce..5b4e544fd 100644 --- a/include/libtorrent/session_handle.hpp +++ b/include/libtorrent/session_handle.hpp @@ -73,7 +73,7 @@ namespace libtorrent : m_impl(impl) {} - bool is_valid() const { return m_impl; } + bool is_valid() const { return m_impl != NULL; } // TODO: 2 the ip filter should probably be saved here too diff --git a/include/libtorrent/sha1_hash.hpp b/include/libtorrent/sha1_hash.hpp index 41bf91521..731d34a5b 100644 --- a/include/libtorrent/sha1_hash.hpp +++ b/include/libtorrent/sha1_hash.hpp @@ -136,7 +136,7 @@ namespace libtorrent sha1_hash& operator<<=(int n) { TORRENT_ASSERT(n >= 0); - const size_t num_words = size_t(n) / 32; + const int num_words = n / 32; if (num_words >= number_size) { std::memset(m_number, 0, size); @@ -175,7 +175,7 @@ namespace libtorrent sha1_hash& operator>>=(int n) { TORRENT_ASSERT(n >= 0); - const size_t num_words = size_t(n) / 32; + const int num_words = n / 32; if (num_words >= number_size) { std::memset(m_number, 0, size_t(size)); diff --git a/include/libtorrent/storage.hpp b/include/libtorrent/storage.hpp index 68aab65f6..36e860032 100644 --- a/include/libtorrent/storage.hpp +++ b/include/libtorrent/storage.hpp @@ -625,7 +625,7 @@ namespace libtorrent void add_piece(cached_piece_entry* p); void remove_piece(cached_piece_entry* p); bool has_piece(cached_piece_entry const* p) const; - int num_pieces() const { return m_cached_pieces.size(); } + int num_pieces() const { return int(m_cached_pieces.size()); } boost::unordered_set const& cached_pieces() const { return m_cached_pieces; } private: diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 8aa006403..271f16c84 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -177,7 +177,7 @@ namespace libtorrent std::vector restart_piece; }; - struct torrent_hot_members + struct TORRENT_EXTRA_EXPORT torrent_hot_members { torrent_hot_members(aux::session_interface& ses , add_torrent_params const& p, int block_size); @@ -1018,7 +1018,7 @@ namespace libtorrent bool are_files_checked() const { return m_files_checked; } bool valid_storage() const - { return m_storage.get(); } + { return m_storage.get() != NULL; } // parses the info section from the given // bencoded tree and moves the torrent @@ -1107,7 +1107,7 @@ namespace libtorrent #endif int num_time_critical_pieces() const - { return m_time_critical_pieces.size(); } + { return int(m_time_critical_pieces.size()); } private: diff --git a/include/libtorrent/torrent_peer_allocator.hpp b/include/libtorrent/torrent_peer_allocator.hpp index a298d94b8..af0ca9249 100644 --- a/include/libtorrent/torrent_peer_allocator.hpp +++ b/include/libtorrent/torrent_peer_allocator.hpp @@ -45,7 +45,7 @@ POSSIBILITY OF SUCH DAMAGE. namespace libtorrent { - struct torrent_peer_allocator_interface + struct TORRENT_EXTRA_EXPORT torrent_peer_allocator_interface { enum peer_type_t { diff --git a/include/libtorrent/udp_socket.hpp b/include/libtorrent/udp_socket.hpp index cb3c47c2a..83442e970 100644 --- a/include/libtorrent/udp_socket.hpp +++ b/include/libtorrent/udp_socket.hpp @@ -46,7 +46,7 @@ POSSIBILITY OF SUCH DAMAGE. namespace libtorrent { - struct udp_socket_observer + struct TORRENT_EXTRA_EXPORT udp_socket_observer { // return true if the packet was handled (it won't be // propagated to the next observer) diff --git a/include/libtorrent/uncork_interface.hpp b/include/libtorrent/uncork_interface.hpp index 7e2653d2c..ce01e10a7 100644 --- a/include/libtorrent/uncork_interface.hpp +++ b/include/libtorrent/uncork_interface.hpp @@ -33,6 +33,8 @@ POSSIBILITY OF SUCH DAMAGE. #ifndef TORRENT_UNCORK_INTERFACE_HPP #define TORRENT_UNCORK_INTERFACE_HPP +#include "libtorrent/export.hpp" + namespace libtorrent { // the uncork interface is used by the disk_io_thread @@ -45,7 +47,7 @@ namespace libtorrent // kernel per system call. // uncorking refers to releasing the "cork" in the peers // preventing them to issue sends - struct uncork_interface + struct TORRENT_EXTRA_EXPORT uncork_interface { virtual void do_delayed_uncork() = 0; protected: diff --git a/include/libtorrent/utp_stream.hpp b/include/libtorrent/utp_stream.hpp index e248c4823..f98bd5254 100644 --- a/include/libtorrent/utp_stream.hpp +++ b/include/libtorrent/utp_stream.hpp @@ -313,7 +313,7 @@ public: m_connect_handler = handler; do_connect(endpoint); } - + template void async_read_some(Mutable_Buffers const& buffers, Handler const& handler) { @@ -329,7 +329,7 @@ public: m_io_service.post(boost::bind(handler, boost::asio::error::operation_not_supported, 0)); return; } - int bytes_added = 0; + std::size_t bytes_added = 0; for (typename Mutable_Buffers::const_iterator i = buffers.begin() , end(buffers.end()); i != end; ++i) { @@ -465,7 +465,7 @@ public: return; } - int bytes_added = 0; + std::size_t bytes_added = 0; for (typename Const_Buffers::const_iterator i = buffers.begin() , end(buffers.end()); i != end; ++i) { diff --git a/src/disk_buffer_pool.cpp b/src/disk_buffer_pool.cpp index 40c988748..aeff5ddb4 100644 --- a/src/disk_buffer_pool.cpp +++ b/src/disk_buffer_pool.cpp @@ -463,6 +463,8 @@ namespace libtorrent void disk_buffer_pool::set_settings(aux::session_settings const& sett , error_code& ec) { + TORRENT_UNUSED(ec); + mutex::scoped_lock l(m_pool_mutex); // 0 cache_buffer_chunk_size means 'automatic' (i.e. diff --git a/src/file.cpp b/src/file.cpp index ab445cbeb..695fcc71d 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -309,10 +309,10 @@ namespace libtorrent { int bufs_size(file::iovec_t const* bufs, int num_bufs) { - int size = 0; + std::size_t size = 0; for (file::iovec_t const* i = bufs, *end(bufs + num_bufs); i < end; ++i) size += i->iov_len; - return size; + return int(size); } #ifdef TORRENT_WINDOWS @@ -341,6 +341,8 @@ namespace libtorrent ec.clear(); #ifdef TORRENT_WINDOWS + TORRENT_UNUSED(flags); + #if TORRENT_USE_WSTRING && defined TORRENT_WINDOWS #define GetFileAttributesEx_ GetFileAttributesExW std::wstring f = convert_to_wstring(inf); @@ -1546,7 +1548,7 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER { } else if (ret == FALSE) { - int error = GetLastError(); +// int error = GetLastError(); return true; } @@ -1616,7 +1618,7 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER { void gather_copy(file::iovec_t const* bufs, int num_bufs, char* dst) { - int offset = 0; + std::size_t offset = 0; for (int i = 0; i < num_bufs; ++i) { memcpy(dst + offset, bufs[i].iov_base, bufs[i].iov_len); @@ -1626,7 +1628,7 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER { void scatter_copy(file::iovec_t const* bufs, int num_bufs, char const* src) { - int offset = 0; + std::size_t offset = 0; for (int i = 0; i < num_bufs; ++i) { memcpy(bufs[i].iov_base, src + offset, bufs[i].iov_len); diff --git a/src/magnet_uri.cpp b/src/magnet_uri.cpp index 959ce69e8..1d01ec546 100644 --- a/src/magnet_uri.cpp +++ b/src/magnet_uri.cpp @@ -56,14 +56,14 @@ namespace libtorrent if (!st.name.empty()) { ret += "&dn="; - ret += escape_string(st.name.c_str(), st.name.length()); + ret += escape_string(st.name.c_str(), int(st.name.length())); } std::vector const& tr = handle.trackers(); for (std::vector::const_iterator i = tr.begin(), end(tr.end()); i != end; ++i) { ret += "&tr="; - ret += escape_string(i->url.c_str(), i->url.length()); + ret += escape_string(i->url.c_str(), int(i->url.length())); } std::set seeds = handle.url_seeds(); @@ -71,7 +71,7 @@ namespace libtorrent , end(seeds.end()); i != end; ++i) { ret += "&ws="; - ret += escape_string(i->c_str(), i->length()); + ret += escape_string(i->c_str(), int(i->length())); } return ret; From c9c5496f1c12631f551c6114afa1cc9f945d3b27 Mon Sep 17 00:00:00 2001 From: arvidn Date: Thu, 19 Nov 2015 22:50:40 -0500 Subject: [PATCH 2/3] lower alignment requirement of socket_type to silence msvc warning (it was probably not warranted in the first place anyway) --- include/libtorrent/socket_type.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/libtorrent/socket_type.hpp b/include/libtorrent/socket_type.hpp index 8283add41..a1ad28dc4 100644 --- a/include/libtorrent/socket_type.hpp +++ b/include/libtorrent/socket_type.hpp @@ -327,7 +327,7 @@ namespace libtorrent >::value }; - boost::aligned_storage::type m_data; + boost::aligned_storage::type m_data; }; // returns true if this socket is an SSL socket From 4aaa8ca4a9539b1c5b4c1cb722881b102e753df6 Mon Sep 17 00:00:00 2001 From: arvidn Date: Thu, 19 Nov 2015 23:37:45 -0500 Subject: [PATCH 3/3] silence msvc performance warnings. introduce more override and finals --- bindings/python/src/session.cpp | 4 +++ bindings/python/src/torrent_info.cpp | 5 +++ src/create_torrent.cpp | 3 +- src/metadata_transfer.cpp | 33 ++++++++++-------- src/smart_ban.cpp | 14 +++++--- src/torrent.cpp | 50 ++++++++++++++-------------- src/torrent_info.cpp | 17 ++++++---- src/ut_metadata.cpp | 32 +++++++++++------- src/ut_pex.cpp | 36 ++++++++++++-------- 9 files changed, 117 insertions(+), 77 deletions(-) diff --git a/bindings/python/src/session.cpp b/bindings/python/src/session.cpp index fe1e47f9b..0c80e0657 100644 --- a/bindings/python/src/session.cpp +++ b/bindings/python/src/session.cpp @@ -26,8 +26,12 @@ #include "gil.hpp" #include "bytes.hpp" +#include "libtorrent/aux_/disable_warnings_push.hpp" + #include +#include "libtorrent/aux_/disable_warnings_pop.hpp" + using namespace boost::python; using namespace libtorrent; namespace lt = libtorrent; diff --git a/bindings/python/src/torrent_info.cpp b/bindings/python/src/torrent_info.cpp index b454c5ccc..0fd3cf7fd 100644 --- a/bindings/python/src/torrent_info.cpp +++ b/bindings/python/src/torrent_info.cpp @@ -2,8 +2,13 @@ // 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 "libtorrent/aux_/disable_warnings_push.hpp" + #include #include + +#include "libtorrent/aux_/disable_warnings_pop.hpp" + #include "libtorrent/torrent_info.hpp" #include "libtorrent/session_settings.hpp" #include "libtorrent/time.hpp" diff --git a/src/create_torrent.cpp b/src/create_torrent.cpp index c99eb601d..0fada5114 100644 --- a/src/create_torrent.cpp +++ b/src/create_torrent.cpp @@ -105,6 +105,7 @@ namespace libtorrent std::string get_symlink_path(std::string const& p) { #if defined TORRENT_WINDOWS + TORRENT_UNUSED(p); return ""; #else std::string path = convert_to_native(p); @@ -361,7 +362,7 @@ namespace libtorrent #endif m_files.set_piece_length(piece_size); if (flags & (optimize_alignment | mutable_torrent_support)) - m_files.optimize(pad_file_limit, alignment, flags & mutable_torrent_support); + m_files.optimize(pad_file_limit, alignment, (flags & mutable_torrent_support) != 0); m_files.set_num_pieces(static_cast( (m_files.total_size() + m_files.piece_length() - 1) / m_files.piece_length())); diff --git a/src/metadata_transfer.cpp b/src/metadata_transfer.cpp index 2d23c792d..9de18f527 100644 --- a/src/metadata_transfer.cpp +++ b/src/metadata_transfer.cpp @@ -97,7 +97,8 @@ namespace libtorrent { namespace return ret; } - struct metadata_plugin : torrent_plugin + struct metadata_plugin TORRENT_FINAL + : torrent_plugin { metadata_plugin(torrent& t) : m_torrent(t) @@ -111,19 +112,19 @@ namespace libtorrent { namespace bool need_loaded() { return m_torrent.need_loaded(); } */ - virtual void on_unload() + virtual void on_unload() TORRENT_OVERRIDE { m_metadata.reset(); } - virtual void on_load() + virtual void on_load() TORRENT_OVERRIDE { // initialize m_metadata_size TORRENT_ASSERT(m_torrent.is_loaded()); metadata(); } - virtual void on_files_checked() + virtual void on_files_checked() TORRENT_OVERRIDE { // if the torrent is a seed, make a reference to // the metadata from the torrent before it is deallocated @@ -131,7 +132,7 @@ namespace libtorrent { namespace } virtual boost::shared_ptr new_connection( - peer_connection_handle const& pc); + peer_connection_handle const& pc) TORRENT_OVERRIDE; buffer::const_interval metadata() const { @@ -251,10 +252,13 @@ namespace libtorrent { namespace // this vector keeps track of how many times each meatdata // block has been requested std::vector m_requested_metadata; + + // explicitly disallow assignment, to silence msvc warning + metadata_plugin& operator=(metadata_plugin const&); }; - - struct metadata_peer_plugin : peer_plugin + struct metadata_peer_plugin TORRENT_FINAL + : peer_plugin { metadata_peer_plugin(torrent& t, peer_connection& pc , metadata_plugin& tp) @@ -268,17 +272,17 @@ namespace libtorrent { namespace , m_tp(tp) {} - virtual char const* type() const { return "LT_metadata"; } + virtual char const* type() const TORRENT_OVERRIDE { return "LT_metadata"; } // can add entries to the extension handshake - virtual void add_handshake(entry& h) + virtual void add_handshake(entry& h) TORRENT_OVERRIDE { entry& messages = h["m"]; messages["LT_metadata"] = 14; } // called when the extension handshake from the other end is received - virtual bool on_extension_handshake(bdecode_node const& h) + virtual bool on_extension_handshake(bdecode_node const& h) TORRENT_OVERRIDE { m_message_index = 0; if (h.type() != bdecode_node::dict_t) return false; @@ -385,7 +389,7 @@ namespace libtorrent { namespace } virtual bool on_extended(int length - , int msg, buffer::const_interval body) + , int msg, buffer::const_interval body) TORRENT_OVERRIDE { if (msg != 14) return false; if (m_message_index == 0) return false; @@ -487,7 +491,7 @@ namespace libtorrent { namespace return true; } - virtual void tick() + virtual void tick() TORRENT_OVERRIDE { if (m_pc.is_disconnecting()) return; @@ -518,7 +522,7 @@ namespace libtorrent { namespace // request to this peer, and reset to false when // we receive a reply to our request. bool m_waiting_metadata_request; - + // this is the message index the remote peer uses // for metadata extension messages. int m_message_index; @@ -545,6 +549,9 @@ namespace libtorrent { namespace torrent& m_torrent; peer_connection& m_pc; metadata_plugin& m_tp; + + // explicitly disallow assignment, to silence msvc warning + metadata_peer_plugin& operator=(metadata_peer_plugin const&); }; boost::shared_ptr metadata_plugin::new_connection( diff --git a/src/smart_ban.cpp b/src/smart_ban.cpp index ab4f52d57..ae3abc54d 100644 --- a/src/smart_ban.cpp +++ b/src/smart_ban.cpp @@ -118,7 +118,9 @@ namespace libtorrent { namespace { - struct smart_ban_plugin : torrent_plugin, boost::enable_shared_from_this + struct smart_ban_plugin TORRENT_FINAL + : torrent_plugin + , boost::enable_shared_from_this { smart_ban_plugin(torrent& t) : m_torrent(t) @@ -134,7 +136,7 @@ namespace { fclose(m_log_file); } #endif - void on_piece_pass(int p) + virtual void on_piece_pass(int p) TORRENT_OVERRIDE { #ifndef TORRENT_DISABLE_LOGGING m_torrent.debug_log(" PIECE PASS [ p: %d | block_hash_size: %d ]" @@ -186,7 +188,7 @@ namespace } } - void on_piece_failed(int p) + virtual void on_piece_failed(int p) TORRENT_OVERRIDE { // The piece failed the hash check. Record // the CRC and origin peer of every block @@ -315,7 +317,7 @@ namespace , print_address(p->ip().address()).c_str()); #endif } - + void on_read_ok_block(std::pair b, address a, disk_io_job const* j) { TORRENT_ASSERT(m_torrent.session().is_single_thread()); @@ -368,7 +370,7 @@ namespace if (p->connection) p->connection->disconnect( errors::peer_banned, op_bittorrent); } - + torrent& m_torrent; // This table maps a piece_block (piece and block index @@ -385,6 +387,8 @@ namespace #ifdef TORRENT_LOG_HASH_FAILURES FILE* m_log_file; #endif + // explicitly disallow assignment, to silence msvc warning + smart_ban_plugin& operator=(smart_ban_plugin const&); }; } } diff --git a/src/torrent.cpp b/src/torrent.cpp index 84622821b..0b6a53ed7 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -170,14 +170,14 @@ namespace libtorrent , add_torrent_params const& p, int block_size) : m_ses(ses) , m_complete(0xffffff) - , m_upload_mode(p.flags & add_torrent_params::flag_upload_mode) + , m_upload_mode((p.flags & add_torrent_params::flag_upload_mode) != 0) , m_connections_initialized(false) , m_abort(false) , m_allow_peers((p.flags & add_torrent_params::flag_paused) == 0) - , m_share_mode(p.flags & add_torrent_params::flag_share_mode) + , m_share_mode((p.flags & add_torrent_params::flag_share_mode) != 0) , m_have_all(false) , m_graceful_pause_mode(false) - , m_state_subscription(p.flags & add_torrent_params::flag_update_subscribe) + , m_state_subscription((p.flags & add_torrent_params::flag_update_subscribe) != 0) , m_max_connections(0xffffff) , m_block_size_shift(root2(block_size)) , m_state(torrent_status::checking_resume_data) @@ -237,7 +237,7 @@ namespace libtorrent , m_got_tracker_response(false) , m_seed_mode(false) , m_super_seeding(false) - , m_override_resume_data(p.flags & add_torrent_params::flag_override_resume_data) + , m_override_resume_data((p.flags & add_torrent_params::flag_override_resume_data) != 0) #ifndef TORRENT_DISABLE_RESOLVE_COUNTRIES , m_resolving_country(false) , m_resolve_countries(false) @@ -251,8 +251,8 @@ namespace libtorrent , m_need_connect_boost(true) , m_lsd_seq(0) , m_magnet_link(false) - , m_apply_ip_filter(p.flags & add_torrent_params::flag_apply_ip_filter) - , m_merge_resume_trackers(p.flags & add_torrent_params::flag_merge_resume_trackers) + , m_apply_ip_filter((p.flags & add_torrent_params::flag_apply_ip_filter) != 0) + , m_merge_resume_trackers((p.flags & add_torrent_params::flag_merge_resume_trackers) != 0) , m_padding(0) , m_priority(0) , m_incomplete(0xffffff) @@ -262,7 +262,7 @@ namespace libtorrent , m_is_active_finished(false) , m_ssl_torrent(false) , m_deleted(false) - , m_pinned(p.flags & add_torrent_params::flag_pinned) + , m_pinned((p.flags & add_torrent_params::flag_pinned) != 0) , m_should_be_loaded(true) , m_last_download((std::numeric_limits::min)()) , m_num_seeds(0) @@ -277,9 +277,9 @@ namespace libtorrent , m_last_scrape((std::numeric_limits::min)()) , m_progress_ppm(0) , m_pending_active_change(false) - , m_use_resume_save_path(p.flags & add_torrent_params::flag_use_resume_save_path) - , m_merge_resume_http_seeds(p.flags & add_torrent_params::flag_merge_resume_http_seeds) - , m_stop_when_ready(p.flags & add_torrent_params::flag_stop_when_ready) + , m_use_resume_save_path((p.flags & add_torrent_params::flag_use_resume_save_path) != 0) + , m_merge_resume_http_seeds((p.flags & add_torrent_params::flag_merge_resume_http_seeds) != 0) + , m_stop_when_ready((p.flags & add_torrent_params::flag_stop_when_ready) != 0) { // we cannot log in the constructor, because it relies on shared_from_this // being initialized, which happens after the constructor returns. @@ -331,7 +331,7 @@ namespace libtorrent m_trackers = m_torrent_file->trackers(); if (m_torrent_file->is_valid()) { - m_seed_mode = p.flags & add_torrent_params::flag_seed_mode; + m_seed_mode = (p.flags & add_torrent_params::flag_seed_mode) != 0; m_connections_initialized = true; m_block_size_shift = root2((std::min)(block_size, m_torrent_file->piece_length())); } @@ -3506,7 +3506,7 @@ namespace libtorrent i != resp.peers4.end(); ++i) { tcp::endpoint a(address_v4(i->ip), i->port); - need_update |= bool(add_peer(a, peer_info::tracker)); + need_update |= bool(add_peer(a, peer_info::tracker) != NULL); } #if TORRENT_USE_IPV6 @@ -3514,7 +3514,7 @@ namespace libtorrent i != resp.peers6.end(); ++i) { tcp::endpoint a(address_v6(i->ip), i->port); - need_update |= bool(add_peer(a, peer_info::tracker)); + need_update |= bool(add_peer(a, peer_info::tracker) != NULL); } #endif if (need_update) state_updated(); @@ -6774,27 +6774,27 @@ namespace libtorrent if (seed_mode_ != -1) m_seed_mode = seed_mode_ && m_torrent_file->is_valid(); int super_seeding_ = rd.dict_find_int_value("super_seeding", -1); - if (super_seeding_ != -1) super_seeding(super_seeding_); + if (super_seeding_ != -1) super_seeding(super_seeding_ != 0); int auto_managed_ = rd.dict_find_int_value("auto_managed", -1); if (auto_managed_ != -1) { - m_auto_managed = auto_managed_; + m_auto_managed = auto_managed_ != 0; update_want_scrape(); update_state_list(); } int sequential_ = rd.dict_find_int_value("sequential_download", -1); - if (sequential_ != -1) set_sequential_download(sequential_); + if (sequential_ != -1) set_sequential_download(sequential_ != 0); int paused_ = rd.dict_find_int_value("paused", -1); if (paused_ != -1) { - set_allow_peers(!paused_); - m_announce_to_dht = !paused_; - m_announce_to_trackers = !paused_; - m_announce_to_lsd = !paused_; + set_allow_peers(paused_ == 0); + m_announce_to_dht = (paused_ == 0); + m_announce_to_trackers = (paused_ == 0); + m_announce_to_lsd = (paused_ == 0); update_gauge(); update_want_peers(); @@ -6802,11 +6802,11 @@ namespace libtorrent update_state_list(); } int dht_ = rd.dict_find_int_value("announce_to_dht", -1); - if (dht_ != -1) m_announce_to_dht = dht_; + if (dht_ != -1) m_announce_to_dht = (dht_ != 0); int lsd_ = rd.dict_find_int_value("announce_to_lsd", -1); - if (lsd_ != -1) m_announce_to_lsd = lsd_; + if (lsd_ != -1) m_announce_to_lsd = (lsd_ != 0); int track_ = rd.dict_find_int_value("announce_to_trackers", -1); - if (track_ != -1) m_announce_to_trackers = track_; + if (track_ != -1) m_announce_to_trackers = (track_ != 0); #ifndef TORRENT_DISABLE_LOGGING debug_log("loaded resume data: max-uploads: %d max-connections: %d " @@ -7707,7 +7707,7 @@ namespace libtorrent if (m_share_mode) recalc_share_mode(); - return peerinfo->connection; + return peerinfo->connection != NULL; } bool torrent::set_metadata(char const* metadata_buf, int metadata_size) @@ -11853,7 +11853,7 @@ namespace libtorrent st->is_finished = is_finished(); st->super_seeding = m_super_seeding; st->has_metadata = valid_metadata(); - bytes_done(*st, flags & torrent_handle::query_accurate_download_counters); + bytes_done(*st, (flags & torrent_handle::query_accurate_download_counters) != 0); TORRENT_ASSERT(st->total_wanted_done >= 0); TORRENT_ASSERT(st->total_done >= st->total_wanted_done); diff --git a/src/torrent_info.cpp b/src/torrent_info.cpp index c0e07054a..15ada61c5 100644 --- a/src/torrent_info.cpp +++ b/src/torrent_info.cpp @@ -1090,7 +1090,7 @@ namespace libtorrent m_orig_files.reset(new file_storage(m_files)); } -#define SWAP(a, b) \ +#define SWAP(tmp, a, b) \ tmp = a; \ a = b; \ b = tmp; @@ -1109,16 +1109,19 @@ namespace libtorrent swap(m_creation_date, ti.m_creation_date); m_comment.swap(ti.m_comment); m_created_by.swap(ti.m_created_by); - boost::uint32_t tmp; - SWAP(m_multifile, ti.m_multifile); - SWAP(m_private, ti.m_private); - SWAP(m_i2p, ti.m_i2p); swap(m_info_section, ti.m_info_section); - SWAP(m_info_section_size, ti.m_info_section_size); swap(m_piece_hashes, ti.m_piece_hashes); m_info_dict.swap(ti.m_info_dict); swap(m_merkle_tree, ti.m_merkle_tree); - SWAP(m_merkle_first_leaf, ti.m_merkle_first_leaf); + std::swap(m_info_section_size, ti.m_info_section_size); + + boost::uint32_t tmp; + SWAP(tmp, m_merkle_first_leaf, ti.m_merkle_first_leaf); + + bool tmp2; + SWAP(tmp2, m_private, ti.m_private); + SWAP(tmp2, m_i2p, ti.m_i2p); + SWAP(tmp2, m_multifile, ti.m_multifile); } #undef SWAP diff --git a/src/ut_metadata.cpp b/src/ut_metadata.cpp index cbed5578f..06b77ade2 100644 --- a/src/ut_metadata.cpp +++ b/src/ut_metadata.cpp @@ -90,7 +90,8 @@ namespace libtorrent { namespace struct ut_metadata_peer_plugin; - struct ut_metadata_plugin : torrent_plugin + struct ut_metadata_plugin TORRENT_FINAL + : torrent_plugin { ut_metadata_plugin(torrent& t) : m_torrent(t) @@ -105,19 +106,19 @@ namespace libtorrent { namespace bool need_loaded() { return m_torrent.need_loaded(); } - virtual void on_unload() + virtual void on_unload() TORRENT_OVERRIDE { m_metadata.reset(); } - virtual void on_load() + virtual void on_load() TORRENT_OVERRIDE { // initialize m_metadata_size TORRENT_ASSERT(m_torrent.is_loaded()); metadata(); } - virtual void on_files_checked() + virtual void on_files_checked() TORRENT_OVERRIDE { // TODO: 2 if we were to initialize m_metadata_size lazily instead, // we would probably be more efficient @@ -126,7 +127,7 @@ namespace libtorrent { namespace } virtual boost::shared_ptr new_connection( - peer_connection_handle const& pc); + peer_connection_handle const& pc) TORRENT_OVERRIDE; int get_metadata_size() const { @@ -208,10 +209,14 @@ namespace libtorrent { namespace // block has been requested and who we ended up getting it from // std::numeric_limits::max() means we have the piece std::vector m_requested_metadata; + + // explicitly disallow assignment, to silence msvc warning + ut_metadata_plugin& operator=(ut_metadata_plugin const&); }; - struct ut_metadata_peer_plugin : peer_plugin, boost::enable_shared_from_this + struct ut_metadata_peer_plugin TORRENT_FINAL + : peer_plugin, boost::enable_shared_from_this { friend struct ut_metadata_plugin; @@ -224,10 +229,10 @@ namespace libtorrent { namespace , m_tp(tp) {} - virtual char const* type() const { return "ut_metadata"; } + virtual char const* type() const TORRENT_OVERRIDE { return "ut_metadata"; } // can add entries to the extension handshake - virtual void add_handshake(entry& h) + virtual void add_handshake(entry& h) TORRENT_OVERRIDE { entry& messages = h["m"]; messages["ut_metadata"] = 2; @@ -236,7 +241,7 @@ namespace libtorrent { namespace } // called when the extension handshake from the other end is received - virtual bool on_extension_handshake(bdecode_node const& h) + virtual bool on_extension_handshake(bdecode_node const& h) TORRENT_OVERRIDE { m_message_index = 0; if (h.type() != bdecode_node::dict_t) return false; @@ -322,7 +327,7 @@ namespace libtorrent { namespace } virtual bool on_extended(int length - , int extended_msg, buffer::const_interval body) + , int extended_msg, buffer::const_interval body) TORRENT_OVERRIDE { if (extended_msg != 2) return false; if (m_message_index == 0) return false; @@ -438,7 +443,7 @@ namespace libtorrent { namespace return true; } - virtual void tick() + virtual void tick() TORRENT_OVERRIDE { maybe_send_request(); while (!m_incoming_requests.empty() @@ -500,6 +505,9 @@ namespace libtorrent { namespace torrent& m_torrent; bt_peer_connection& m_pc; ut_metadata_plugin& m_tp; + + // explicitly disallow assignment, to silence msvc warning + ut_metadata_peer_plugin& operator=(ut_metadata_peer_plugin const&); }; boost::shared_ptr ut_metadata_plugin::new_connection( @@ -547,7 +555,7 @@ namespace libtorrent { namespace return piece; } - inline bool ut_metadata_plugin::received_metadata( + bool ut_metadata_plugin::received_metadata( ut_metadata_peer_plugin& source , char const* buf, int size, int piece, int total_size) { diff --git a/src/ut_pex.cpp b/src/ut_pex.cpp index 74b4b60b3..3a0216f27 100644 --- a/src/ut_pex.cpp +++ b/src/ut_pex.cpp @@ -81,7 +81,8 @@ namespace libtorrent { namespace return true; } - struct ut_pex_plugin: torrent_plugin + struct ut_pex_plugin TORRENT_FINAL + : torrent_plugin { // randomize when we rebuild the pex message // to evenly spread it out across all torrents @@ -91,8 +92,9 @@ namespace libtorrent { namespace : m_torrent(t) , m_last_msg(min_time()) , m_peers_in_message(0) {} - - virtual boost::shared_ptr new_connection(peer_connection_handle const& pc); + + virtual boost::shared_ptr new_connection( + peer_connection_handle const& pc) TORRENT_OVERRIDE; std::vector& get_ut_pex_msg() { @@ -109,7 +111,7 @@ namespace libtorrent { namespace // are calculated here and the pex message is created // each peer connection will use this message // max_peer_entries limits the packet size - virtual void tick() + virtual void tick() TORRENT_OVERRIDE { time_point now = aux::time_now(); if (now - seconds(60) < m_last_msg) return; @@ -231,11 +233,14 @@ namespace libtorrent { namespace time_point m_last_msg; std::vector m_ut_pex_msg; int m_peers_in_message; + + // explicitly disallow assignment, to silence msvc warning + ut_pex_plugin& operator=(ut_pex_plugin const&); }; - - struct ut_pex_peer_plugin : peer_plugin - { + struct ut_pex_peer_plugin TORRENT_FINAL + : peer_plugin + { ut_pex_peer_plugin(torrent& t, peer_connection& pc, ut_pex_plugin& tp) : m_torrent(t) , m_pc(pc) @@ -251,15 +256,15 @@ namespace libtorrent { namespace } } - virtual char const* type() const { return "ut_pex"; } + virtual char const* type() const TORRENT_OVERRIDE { return "ut_pex"; } - virtual void add_handshake(entry& h) + virtual void add_handshake(entry& h) TORRENT_OVERRIDE { entry& messages = h["m"]; messages[extension_name] = extension_index; } - virtual bool on_extension_handshake(bdecode_node const& h) + virtual bool on_extension_handshake(bdecode_node const& h) TORRENT_OVERRIDE { m_message_index = 0; if (h.type() != bdecode_node::dict_t) return false; @@ -272,7 +277,7 @@ namespace libtorrent { namespace return true; } - virtual bool on_extended(int length, int msg, buffer::const_interval body) + virtual bool on_extended(int length, int msg, buffer::const_interval body) TORRENT_OVERRIDE { if (msg != extension_index) return false; if (m_message_index == 0) return false; @@ -282,7 +287,7 @@ namespace libtorrent { namespace m_pc.disconnect(errors::pex_message_too_large, op_bittorrent, 2); return true; } - + if (body.left() < length) return true; time_point now = aux::time_now(); @@ -378,7 +383,7 @@ namespace libtorrent { namespace peers6_t::value_type v(adr.address().to_v6().to_bytes(), adr.port()); peers6_t::iterator j = std::lower_bound(m_peers6.begin(), m_peers6.end(), v); if (j != m_peers6.end() && *j == v) m_peers6.erase(j); - } + } } p6 = pex_msg.dict_find("added6"); @@ -425,7 +430,7 @@ namespace libtorrent { namespace // the peers second tick // every minute we send a pex message - virtual void tick() + virtual void tick() TORRENT_OVERRIDE { // no handshake yet if (!m_message_index) return; @@ -646,6 +651,9 @@ namespace libtorrent { namespace // it is used to know if a diff message or a) ful // message should be sent. bool m_first_time; + + // explicitly disallow assignment, to silence msvc warning + ut_pex_peer_plugin& operator=(ut_pex_peer_plugin const&); }; boost::shared_ptr ut_pex_plugin::new_connection(peer_connection_handle const& pc)