From c28789260d3a2734fcc289e311223173fdde55d5 Mon Sep 17 00:00:00 2001 From: arvidn Date: Sun, 27 Dec 2015 23:02:04 -0500 Subject: [PATCH 1/2] enable _GLIBCXX_DEBUG_PEDANTIC along with debug iterators when running tests and simulations. update libsimulator submodule --- Jamfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Jamfile b/Jamfile index 2db64f262..1ee657652 100644 --- a/Jamfile +++ b/Jamfile @@ -482,7 +482,8 @@ feature.compose off : TORRENT_NO_DEPRECATE ; feature boost-link : default static shared : propagated composite ; feature debug-iterators : off on : composite propagated link-incompatible ; -feature.compose on : _SCL_SECURE=1 _GLIBCXX_DEBUG ; +feature.compose on : _SCL_SECURE=1 _GLIBCXX_DEBUG + _GLIBCXX_DEBUG_PEDANTIC ; feature fpic : off on : composite propagated link-incompatible ; feature.compose on : -fPIC ; From 3f3b366ed5dbf9ceeede1adcefbb080e6d17699b Mon Sep 17 00:00:00 2001 From: arvidn Date: Sat, 20 Feb 2016 23:40:45 -0500 Subject: [PATCH 2/2] be a bit more strict about when the STL containers need complete types (to make it build under GCC with concept checks enabled). add proper assignment operator to types used in STL containers --- include/libtorrent/config.hpp | 11 ++++++++++- include/libtorrent/entry.hpp | 16 ++++++++-------- include/libtorrent/torrent.hpp | 4 ++-- include/libtorrent/torrent_info.hpp | 4 ++++ include/libtorrent/torrent_peer.hpp | 11 ++--------- src/entry.cpp | 21 ++++++++++++++------- src/torrent.cpp | 16 ++++++++-------- src/torrent_handle.cpp | 8 ++++++-- src/torrent_peer.cpp | 13 +++++++++++++ 9 files changed, 67 insertions(+), 37 deletions(-) diff --git a/include/libtorrent/config.hpp b/include/libtorrent/config.hpp index 35853c16a..703da9e5f 100644 --- a/include/libtorrent/config.hpp +++ b/include/libtorrent/config.hpp @@ -96,6 +96,10 @@ POSSIBILITY OF SUCH DAMAGE. #if defined __GNUC__ +#ifdef _GLIBCXX_CONCEPT_CHECKS +#define TORRENT_COMPLETE_TYPES_REQUIRED 1 +#endif + // deprecation markup is only enabled when libtorrent // headers are included by clients, not while building // libtorrent itself @@ -112,6 +116,8 @@ POSSIBILITY OF SUCH DAMAGE. // seem to allow boost::array in unions #define TORRENT_BROKEN_UNIONS 1 +#define TORRENT_COMPLETE_TYPES_REQUIRED 1 + // ======= MSVC ========= #elif defined BOOST_MSVC @@ -124,6 +130,10 @@ POSSIBILITY OF SUCH DAMAGE. // '_vsnprintf': This function or variable may be unsafe #pragma warning(disable:4996) +#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 @@ -300,7 +310,6 @@ POSSIBILITY OF SUCH DAMAGE. // ==== SOLARIS === #elif defined sun || defined __sun #define TORRENT_SOLARIS -#define TORRENT_COMPLETE_TYPES_REQUIRED 1 #define TORRENT_USE_IFCONF 1 #define TORRENT_HAS_SALEN 0 #define TORRENT_HAS_SEM_RELTIMEDWAIT 1 diff --git a/include/libtorrent/entry.hpp b/include/libtorrent/entry.hpp index 5cbe4c269..49aaacfa1 100644 --- a/include/libtorrent/entry.hpp +++ b/include/libtorrent/entry.hpp @@ -150,14 +150,14 @@ namespace libtorrent // copies the structure of the right hand side into this // entry. #ifndef TORRENT_NO_DEPRECATE - void operator=(lazy_entry const&); + entry& operator=(lazy_entry const&); #endif - void operator=(bdecode_node const&); - void operator=(entry const&); - void operator=(dictionary_type const&); - void operator=(string_type const&); - void operator=(list_type const&); - void operator=(integer_type const&); + entry& operator=(bdecode_node const&); + entry& operator=(entry const&); + entry& operator=(dictionary_type const&); + entry& operator=(string_type const&); + entry& operator=(list_type const&); + entry& operator=(integer_type const&); // The ``integer()``, ``string()``, ``list()`` and ``dict()`` functions // are accessors that return the respective type. If the ``entry`` object @@ -261,7 +261,7 @@ namespace libtorrent void to_string_impl(std::string& out, int indent) const; -#if (defined(_MSC_VER) && _MSC_VER < 1310) || TORRENT_COMPLETE_TYPES_REQUIRED +#if TORRENT_COMPLETE_TYPES_REQUIRED // workaround for msvc-bug. // assumes sizeof(map) == sizeof(map) // and sizeof(list) == sizeof(list) diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 976483f80..7703fc309 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -659,8 +659,8 @@ namespace libtorrent peer_iterator begin() { return m_connections.begin(); } peer_iterator end() { return m_connections.end(); } - void get_full_peer_list(std::vector& v) const; - void get_peer_info(std::vector& v); + void get_full_peer_list(std::vector* v) const; + void get_peer_info(std::vector* v); void get_download_queue(std::vector* queue) const; void refresh_explicit_cache(int cache_size); diff --git a/include/libtorrent/torrent_info.hpp b/include/libtorrent/torrent_info.hpp index 0bcc80b71..957260620 100644 --- a/include/libtorrent/torrent_info.hpp +++ b/include/libtorrent/torrent_info.hpp @@ -52,6 +52,10 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/sha1_hash.hpp" #include "libtorrent/file_storage.hpp" +#if TORRENT_COMPLETE_TYPES_REQUIRED +#include "libtorrent/announce_entry.hpp" +#endif + namespace libtorrent { class peer_connection; diff --git a/include/libtorrent/torrent_peer.hpp b/include/libtorrent/torrent_peer.hpp index 853f9a0e0..d6edec89a 100644 --- a/include/libtorrent/torrent_peer.hpp +++ b/include/libtorrent/torrent_peer.hpp @@ -203,20 +203,17 @@ namespace libtorrent ipv4_peer(ipv4_peer const& p); address_v4 addr; - private: - ipv4_peer& operator=(ipv4_peer const&); }; #if TORRENT_USE_I2P struct TORRENT_EXTRA_EXPORT i2p_peer : torrent_peer { i2p_peer(char const* destination, bool connectable, int src); + i2p_peer(const i2p_peer&); ~i2p_peer(); + i2p_peer& operator=(i2p_peer const&); char* destination; - private: - i2p_peer(const i2p_peer&); - i2p_peer& operator=(i2p_peer const&); }; #endif @@ -226,10 +223,6 @@ namespace libtorrent ipv6_peer(tcp::endpoint const& ip, bool connectable, int src); const address_v6::bytes_type addr; - private: - // explicitly disallow assignment, to silence msvc warning - ipv6_peer& operator=(ipv6_peer const&); - ipv6_peer(ipv6_peer const&); }; #endif diff --git a/src/entry.cpp b/src/entry.cpp index 97f08d5a9..05aadb383 100644 --- a/src/entry.cpp +++ b/src/entry.cpp @@ -156,10 +156,11 @@ namespace libtorrent entry::~entry() { destruct(); } - void entry::operator=(const entry& e) + entry& entry::operator=(const entry& e) { destruct(); copy(e); + return *this; } entry::integer_type& entry::integer() @@ -321,7 +322,7 @@ namespace libtorrent } // convert a bdecode_node into an old skool entry - void entry::operator=(bdecode_node const& e) + entry& entry::operator=(bdecode_node const& e) { switch (e.type()) { @@ -355,11 +356,12 @@ namespace libtorrent destruct(); break; } + return *this; } #ifndef TORRENT_NO_DEPRECATE // convert a lazy_entry into an old skool entry - void entry::operator=(lazy_entry const& e) + entry& entry::operator=(lazy_entry const& e) { switch (e.type()) { @@ -393,10 +395,11 @@ namespace libtorrent destruct(); break; } + return *this; } #endif - void entry::operator=(dictionary_type const& v) + entry& entry::operator=(dictionary_type const& v) { destruct(); new(data) dictionary_type(v); @@ -404,9 +407,10 @@ namespace libtorrent #ifdef TORRENT_DEBUG m_type_queried = true; #endif + return *this; } - void entry::operator=(string_type const& v) + entry& entry::operator=(string_type const& v) { destruct(); new(data) string_type(v); @@ -414,9 +418,10 @@ namespace libtorrent #ifdef TORRENT_DEBUG m_type_queried = true; #endif + return *this; } - void entry::operator=(list_type const& v) + entry& entry::operator=(list_type const& v) { destruct(); new(data) list_type(v); @@ -424,9 +429,10 @@ namespace libtorrent #ifdef TORRENT_DEBUG m_type_queried = true; #endif + return *this; } - void entry::operator=(integer_type const& v) + entry& entry::operator=(integer_type const& v) { destruct(); new(data) integer_type(v); @@ -434,6 +440,7 @@ namespace libtorrent #ifdef TORRENT_DEBUG m_type_queried = true; #endif + return *this; } bool entry::operator==(entry const& e) const diff --git a/src/torrent.cpp b/src/torrent.cpp index ef7f8e28a..996140673 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -7079,12 +7079,12 @@ namespace libtorrent } } - void torrent::get_full_peer_list(std::vector& v) const + void torrent::get_full_peer_list(std::vector* v) const { - v.clear(); + v->clear(); if (!m_peer_list) return; - v.reserve(m_peer_list->num_peers()); + v->reserve(m_peer_list->num_peers()); for (peer_list::const_iterator i = m_peer_list->begin_peer(); i != m_peer_list->end_peer(); ++i) { @@ -7093,13 +7093,13 @@ namespace libtorrent e.flags = (*i)->banned ? peer_list_entry::banned : 0; e.failcount = (*i)->failcount; e.source = (*i)->source; - v.push_back(e); + v->push_back(e); } } - void torrent::get_peer_info(std::vector& v) + void torrent::get_peer_info(std::vector* v) { - v.clear(); + v->clear(); for (peer_iterator i = begin(); i != end(); ++i) { @@ -7110,8 +7110,8 @@ namespace libtorrent // not be included in this list if (peer->associated_torrent().expired()) continue; - v.push_back(peer_info()); - peer_info& p = v.back(); + v->push_back(peer_info()); + peer_info& p = v->back(); peer->get_peer_info(p); #ifndef TORRENT_NO_DEPRECATE diff --git a/src/torrent_handle.cpp b/src/torrent_handle.cpp index c33875f80..2e32cc41d 100644 --- a/src/torrent_handle.cpp +++ b/src/torrent_handle.cpp @@ -59,6 +59,10 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/thread.hpp" #include "libtorrent/announce_entry.hpp" +#if TORRENT_COMPLETE_TYPES_REQUIRED +#include "libtorrent/peer_info.hpp" // for peer_list_entry +#endif + #ifdef __GNUC__ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-macros" @@ -818,12 +822,12 @@ namespace libtorrent void torrent_handle::get_full_peer_list(std::vector& v) const { - TORRENT_SYNC_CALL1(get_full_peer_list, boost::ref(v)); + TORRENT_SYNC_CALL1(get_full_peer_list, &v); } void torrent_handle::get_peer_info(std::vector& v) const { - TORRENT_SYNC_CALL1(get_peer_info, boost::ref(v)); + TORRENT_SYNC_CALL1(get_peer_info, &v); } void torrent_handle::get_download_queue(std::vector& queue) const diff --git a/src/torrent_peer.cpp b/src/torrent_peer.cpp index 705541cf2..4c267e2dc 100644 --- a/src/torrent_peer.cpp +++ b/src/torrent_peer.cpp @@ -259,6 +259,19 @@ namespace libtorrent i2p_peer::~i2p_peer() { free(destination); } + + i2p_peer::i2p_peer(const i2p_peer& rhs) + : torrent_peer(rhs.port, rhs.connectable, rhs.source) + , destination(allocate_string_copy(rhs.destination)) + {} + + i2p_peer& i2p_peer::operator=(i2p_peer const& rhs) + { + char* tmp = allocate_string_copy(rhs.destination); + free(destination); + destination = tmp; + return *this; + } #endif // TORRENT_USE_I2P #if TORRENT_USE_IPV6