diff --git a/Jamfile b/Jamfile index 1da6930b9..4c40ba9ce 100644 --- a/Jamfile +++ b/Jamfile @@ -113,8 +113,7 @@ rule linking ( properties * ) } if windows in $(properties) - && ( TORRENT_DEBUG - || on in $(properties) + && ( on in $(properties) || production in $(properties) || debug in $(properties) || debug in $(properties) @@ -415,11 +414,10 @@ feature.compose off : TORRENT_USE_ICONV=0 ; feature memory-optimization : off on : composite propagated link-incompatible ; feature.compose on : TORRENT_OPTIMIZE_MEMORY_USAGE ; -feature asserts : auto on off production system : composite propagated ; +feature asserts : off on production system : composite propagated ; feature.compose on : TORRENT_USE_ASSERTS=1 ; feature.compose production : TORRENT_USE_ASSERTS=1 TORRENT_PRODUCTION_ASSERTS=1 ; feature.compose system : TORRENT_USE_ASSERTS=1 TORRENT_USE_SYSTEM_ASSERTS=1 ; -feature.compose off : TORRENT_USE_ASSERTS=0 ; feature windows-version : vista win7 xp : composite propagated link-incompatible ; feature.compose vista : _WIN32_WINNT=0x0600 ; @@ -451,9 +449,9 @@ feature piece-allocator : valloc memalign posix_memalign : composite propagated feature.compose memalign : TORRENT_USE_MEMALIGN=1 ; feature.compose posix_memalign : TORRENT_USE_POSIX_MEMALIGN=1 ; -feature invariant-checks : on off full : composite propagated link-incompatible ; -feature.compose off : TORRENT_DISABLE_INVARIANT_CHECKS ; -feature.compose full : TORRENT_EXPENSIVE_INVARIANT_CHECKS ; +feature invariant-checks : off on full : composite propagated link-incompatible ; +feature.compose on : TORRENT_USE_INVARIANT_CHECKS=1 ; +feature.compose full : TORRENT_USE_INVARIANT_CHECKS=1 TORRENT_EXPENSIVE_INVARIANT_CHECKS ; feature disk-stats : off on : composite propagated link-incompatible ; feature.compose on : TORRENT_DISK_STATS ; @@ -513,25 +511,25 @@ feature export-extra : off on : composite propagated ; # allowed memory usage on travis-ci variant test_release : release : production on - full shared off - on on multi - off + full shared off + on on multi + off ; variant test_debug : debug : openssl libcrypto on on - debug - full shared - on on multi on + debug + full shared + on on multi on ; variant test_barebones : debug : off off off off shared - off off - on on multi on + off off + on on multi on ; variant test_arm : debug : off off off off - off off - on on + off off + on on ; # required for openssl on windows @@ -726,7 +724,6 @@ local usage-requirements = # and iconv.h is installed there /usr/local/include release:NDEBUG - debug:TORRENT_DEBUG _FILE_OFFSET_BITS=64 BOOST_EXCEPTION_DISABLE # enable cancel support in asio @@ -767,6 +764,8 @@ lib torrent on:src/kademlia/$(KADEMLIA_SOURCES).cpp on:ed25519/src/$(ED25519_SOURCES).cpp + debug:on + debug:on @building @warnings diff --git a/configure.ac b/configure.ac index c0bf48edb..141ebbce7 100644 --- a/configure.ac +++ b/configure.ac @@ -312,7 +312,7 @@ AC_MSG_CHECKING([whether debug build should be enabled]) AS_CASE(["$ARG_ENABLE_DEBUG"], ["yes"], [ AC_MSG_RESULT([yes]) - AC_DEFINE([TORRENT_DEBUG],[1],[Define to enable debug code.]) + AC_DEFINE([TORRENT_USE_ASSERTS],[1],[Define to enable debug code.]) COMPILETIME_OPTIONS="$COMPILETIME_OPTIONS -DTORRENT_DEBUG " DEBUGFLAGS="-g" ], @@ -330,19 +330,16 @@ AC_MSG_CHECKING([whether invariant check should be enabled]) #depends: $ac_arg_e AS_CASE(["$ARG_ENABLE_INVARIANT"], ["yes"|"on"], [ AC_MSG_RESULT([yes]) - AS_IF([test "x$ac_arg_enable_debug" = "xno"], - [AC_MSG_ERROR([invariant-checks: this setting only affects debug build. Try using --enable-debug.])]) + [AC_DEFINE([TORRENT_USE_INVARIANT_CHECKS],[1],[Define to enable internal invariant checks.])]) ], ["no"|"off"], [ AC_MSG_RESULT([no]) - AS_IF([test "x$ac_arg_enable_debug" = "xyes"], - [AC_DEFINE([TORRENT_DISABLE_INVARIANT_CHECKS],[1],[Define to disable internal invariant checks. Asserts are still enabled while debug is on.])]) + [AC_DEFINE([TORRENT_USE_INVARIANT_CHECKS],[0],[Define to disable internal invariant checks. Asserts are still enabled while debug is on.])]) ], ["full"], [ AC_MSG_RESULT([full]) - AS_IF([test "x$ac_arg_enable_debug" = "xyes"], - [AC_DEFINE([TORRENT_EXPENSIVE_INVARIANT_CHECKS],[1],[Define to enable extra expensive invariant checks.])], - [AC_MSG_ERROR([invariant-checks: this setting only affects debug build. Try using --enable-debug.])]) + [AC_DEFINE([TORRENT_USE_INVARIANT_CHECKS],[1],[Define to enable internal invariant checks.])]) + [AC_DEFINE([TORRENT_EXPENSIVE_INVARIANT_CHECKS],[1],[Define to enable extra expensive invariant checks.])], ], [AC_MSG_RESULT([$ARG_ENABLE_INVARIANT]) AC_MSG_ERROR([Unknown option "$ARG_ENABLE_INVARIANT". Use either "yes", "no" or "full".])] diff --git a/docs/building.rst b/docs/building.rst index bdf327252..ee2797ccb 100644 --- a/docs/building.rst +++ b/docs/building.rst @@ -584,12 +584,11 @@ defines you can use to control the build. | | use wide character API, to properly support | | | non-ansi characters. | +----------------------------------------+-------------------------------------------------+ -| ``TORRENT_DISABLE_INVARIANT_CHECKS`` | This will disable internal invariant checks in | -| | libtorrent. The invariant checks can sometime | +| ``TORRENT_USE_INVARIANT_CHECKS`` | If defined to non-zero, this will enable | +| | internal invariant checks in libtorrent. | +| | The invariant checks can sometimes | | | be quite expensive, they typically don't scale | -| | very well. This option can be used to still | -| | build in debug mode, with asserts enabled, but | -| | make the resulting executable faster. | +| | very well. | +----------------------------------------+-------------------------------------------------+ | ``TORRENT_EXPENSIVE_INVARIANT_CHECKS`` | This will enable extra expensive invariant | | | checks. Useful for finding particular bugs | diff --git a/docs/gen_reference_doc.py b/docs/gen_reference_doc.py index 49beff6cc..8863ccf38 100644 --- a/docs/gen_reference_doc.py +++ b/docs/gen_reference_doc.py @@ -532,33 +532,26 @@ def consume_ifdef(lno, lines, warn_on_ifdefs = False): if verbose: print 'prep %s' % l - if warn_on_ifdefs and ('TORRENT_DEBUG' in l): + if warn_on_ifdefs and l.strip().startswith('#if'): while l.endswith('\\'): lno += 1 l += lines[lno].strip() if verbose: print 'prep %s' % lines[lno].trim() define = trim_define(l) - print '\x1b[31mWARNING: possible ABI breakage in public struct! "%s" \x1b[34m %s:%d\x1b[0m' % \ - (define, filename, lno) - # we've already warned once, no need to do it twice - warn_on_ifdefs = False - - if warn_on_ifdefs and '#if' in l: - while l.endswith('\\'): - lno += 1 - l += lines[lno].strip() - if verbose: print 'prep %s' % lines[lno].trim() - define = trim_define(l) - if define != '': + if 'TORRENT_' in define: + print '\x1b[31mWARNING: possible ABI breakage in public struct! "%s" \x1b[34m %s:%d\x1b[0m' % \ + (define, filename, lno) + # we've already warned once, no need to do it twice + warn_on_ifdefs = False + elif define != '': print '\x1b[33msensitive define in public struct: "%s"\x1b[34m %s:%d\x1b[0m' % (define, filename, lno) - if l == '#ifndef TORRENT_NO_DEPRECATE' or \ - l == '#ifdef TORRENT_DEBUG' or \ - (l.startswith('#if ') and ' TORRENT_USE_ASSERTS' in l) or \ - (l.startswith('#if ') and ' TORRENT_USE_INVARIANT_CHECKS' in l) or \ - l == '#ifdef TORRENT_ASIO_DEBUGGING' or \ - (l.startswith('#if') and 'defined TORRENT_DEBUG' in l) or \ - (l.startswith('#if') and 'defined TORRENT_ASIO_DEBUGGING' in l): + if (l.startswith('#if') and ( + ' TORRENT_USE_ASSERTS' in l or + ' TORRENT_USE_INVARIANT_CHECKS' in l or + ' TORRENT_ASIO_DEBUGGING' in l) or + l == '#ifndef TORRENT_NO_DEPRECATE' + ): while lno < len(lines): l = lines[lno].strip() lno += 1 diff --git a/include/libtorrent/aux_/file_progress.hpp b/include/libtorrent/aux_/file_progress.hpp index a4636c4f0..d4d0011dc 100644 --- a/include/libtorrent/aux_/file_progress.hpp +++ b/include/libtorrent/aux_/file_progress.hpp @@ -38,7 +38,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/export.hpp" -#if TORRENT_USE_INVARIANT_CHECKS && defined TORRENT_DEBUG +#if TORRENT_USE_INVARIANT_CHECKS #include "libtorrent/bitfield.hpp" #include "libtorrent/invariant_check.hpp" #endif @@ -75,7 +75,7 @@ namespace aux // is first queried by the client std::vector m_file_progress; -#if TORRENT_USE_INVARIANT_CHECKS && defined TORRENT_DEBUG +#if TORRENT_USE_INVARIANT_CHECKS friend class libtorrent::invariant_access; void check_invariant() const; diff --git a/include/libtorrent/config.hpp b/include/libtorrent/config.hpp index ed3918d2e..95979b542 100644 --- a/include/libtorrent/config.hpp +++ b/include/libtorrent/config.hpp @@ -473,17 +473,10 @@ POSSIBILITY OF SUCH DAMAGE. // builds have asserts if they are explicitly enabled by // the release_asserts macro. #ifndef TORRENT_USE_ASSERTS -#if defined TORRENT_DEBUG -#define TORRENT_USE_ASSERTS 1 -#else #define TORRENT_USE_ASSERTS 0 -#endif #endif // TORRENT_USE_ASSERTS -#if defined TORRENT_DEBUG && TORRENT_USE_ASSERTS \ - && !defined TORRENT_DISABLE_INVARIANT_CHECKS -#define TORRENT_USE_INVARIANT_CHECKS 1 -#else +#ifndef TORRENT_USE_INVARIANT_CHECKS #define TORRENT_USE_INVARIANT_CHECKS 0 #endif diff --git a/include/libtorrent/disk_buffer_pool.hpp b/include/libtorrent/disk_buffer_pool.hpp index b7e73622d..db2711b69 100644 --- a/include/libtorrent/disk_buffer_pool.hpp +++ b/include/libtorrent/disk_buffer_pool.hpp @@ -48,7 +48,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #endif -#if defined TORRENT_DEBUG +#if TORRENT_USE_INVARIANT_CHECKS #include #endif @@ -180,7 +180,7 @@ namespace libtorrent // this is specifically exempt from release_asserts // since it's a quite costly check. Only for debug // builds. -#if defined TORRENT_DEBUG +#if TORRENT_USE_INVARIANT_CHECKS std::set m_buffers_in_use; #endif #if TORRENT_USE_ASSERTS diff --git a/include/libtorrent/file_storage.hpp b/include/libtorrent/file_storage.hpp index 4f5a18425..0d6ed274b 100644 --- a/include/libtorrent/file_storage.hpp +++ b/include/libtorrent/file_storage.hpp @@ -116,7 +116,7 @@ namespace libtorrent struct TORRENT_DEPRECATED_EXPORT internal_file_entry { friend class file_storage; -#ifdef TORRENT_DEBUG +#if TORRENT_USE_INVARIANT_CHECKS // for torrent_info::invariant_check friend class torrent_info; #endif diff --git a/include/libtorrent/kademlia/node.hpp b/include/libtorrent/kademlia/node.hpp index 660f686ef..1c0d32609 100644 --- a/include/libtorrent/kademlia/node.hpp +++ b/include/libtorrent/kademlia/node.hpp @@ -132,7 +132,8 @@ public: int data_size() const { return int(m_storage.num_torrents()); } #endif -#if defined TORRENT_DEBUG +#ifndef TORRENT_DISABLE_LOGGING + // TODO: 3 make this print to the DHT logger instead void print_state(std::ostream& os) const { m_table.print_state(os); } #endif diff --git a/include/libtorrent/kademlia/observer.hpp b/include/libtorrent/kademlia/observer.hpp index 494640c7c..875128976 100644 --- a/include/libtorrent/kademlia/observer.hpp +++ b/include/libtorrent/kademlia/observer.hpp @@ -162,7 +162,7 @@ private: // the transaction ID for this call std::uint16_t m_transaction_id; public: - unsigned char flags; + std::uint8_t flags; #if TORRENT_USE_ASSERTS bool m_in_constructor:1; diff --git a/include/libtorrent/kademlia/routing_table.hpp b/include/libtorrent/kademlia/routing_table.hpp index 83def578a..e5668cd0e 100644 --- a/include/libtorrent/kademlia/routing_table.hpp +++ b/include/libtorrent/kademlia/routing_table.hpp @@ -254,7 +254,7 @@ public: void replacement_cache(bucket_t& nodes) const; -#if defined TORRENT_DEBUG +#ifndef TORRENT_DISABLE_LOGGING // used for debug and monitoring purposes. This will print out // the state of the routing table to the given stream void print_state(std::ostream& os) const; diff --git a/include/libtorrent/storage.hpp b/include/libtorrent/storage.hpp index 2f25d8f7e..56c259ef8 100644 --- a/include/libtorrent/storage.hpp +++ b/include/libtorrent/storage.hpp @@ -600,10 +600,6 @@ namespace libtorrent int check_no_fastresume(storage_error& error); int check_init_storage(storage_error& error); -#ifdef TORRENT_DEBUG - std::string name() const { return m_files.name(); } -#endif - #if TORRENT_USE_INVARIANT_CHECKS void check_invariant() const; #endif diff --git a/simulation/Jamfile b/simulation/Jamfile index 2e6e2c33a..ff5256f55 100644 --- a/simulation/Jamfile +++ b/simulation/Jamfile @@ -19,6 +19,7 @@ project multi full on + on on ; diff --git a/simulation/setup_dht.cpp b/simulation/setup_dht.cpp index e96dc6a7a..fa5b57a59 100644 --- a/simulation/setup_dht.cpp +++ b/simulation/setup_dht.cpp @@ -218,7 +218,7 @@ struct dht_node final : lt::dht::udp_socket_interface if (nodes_per_bucket[bucket] == 0) continue; --nodes_per_bucket[bucket]; bool const added = dht().m_table.node_seen(n.first, n.second, (lt::random() % 300) + 10); - TORRENT_ASSERT(added); + TEST_CHECK(added); if (m_add_dead_nodes) { // generate a random node ID that would fall in `bucket` diff --git a/src/block_cache.cpp b/src/block_cache.cpp index 6c9a3fb57..3c80f5bfe 100644 --- a/src/block_cache.cpp +++ b/src/block_cache.cpp @@ -558,7 +558,7 @@ void block_cache::try_evict_one_volatile() if (pe->ok_to_evict()) { -#ifndef TORRENT_DISABLE_INVARIANT_CHECKS +#if TORRENT_USE_INVARIANT_CHECKS for (int j = 0; j < pe->blocks_in_piece; ++j) TORRENT_PIECE_ASSERT(pe->blocks[j].buf == 0, pe); #endif @@ -601,7 +601,7 @@ void block_cache::try_evict_one_volatile() if (pe->ok_to_evict()) { -#ifndef TORRENT_DISABLE_INVARIANT_CHECKS +#if TORRENT_USE_INVARIANT_CHECKS for (int j = 0; j < pe->blocks_in_piece; ++j) TORRENT_PIECE_ASSERT(pe->blocks[j].buf == 0, pe); #endif @@ -1075,7 +1075,7 @@ int block_cache::try_evict_blocks(int num, cached_piece_entry* ignore) if (pe->ok_to_evict()) { -#ifndef TORRENT_DISABLE_INVARIANT_CHECKS +#if TORRENT_USE_INVARIANT_CHECKS for (int j = 0; j < pe->blocks_in_piece; ++j) TORRENT_PIECE_ASSERT(pe->blocks[j].buf == 0, pe); #endif @@ -1115,7 +1115,7 @@ int block_cache::try_evict_blocks(int num, cached_piece_entry* ignore) if (pe->ok_to_evict()) { -#ifndef TORRENT_DISABLE_INVARIANT_CHECKS +#if TORRENT_USE_INVARIANT_CHECKS for (int j = 0; j < pe->blocks_in_piece; ++j) TORRENT_PIECE_ASSERT(pe->blocks[j].buf == 0, pe); #endif @@ -1148,7 +1148,7 @@ int block_cache::try_evict_blocks(int num, cached_piece_entry* ignore) if (pe->ok_to_evict()) { -#ifndef TORRENT_DISABLE_INVARIANT_CHECKS +#if TORRENT_USE_INVARIANT_CHECKS for (int j = 0; j < pe->blocks_in_piece; ++j) TORRENT_PIECE_ASSERT(pe->blocks[j].buf == 0, pe); #endif @@ -1194,7 +1194,7 @@ int block_cache::try_evict_blocks(int num, cached_piece_entry* ignore) if (pe->ok_to_evict()) { -#ifndef TORRENT_DISABLE_INVARIANT_CHECKS +#if TORRENT_USE_INVARIANT_CHECKS for (int j = 0; j < pe->blocks_in_piece; ++j) TORRENT_PIECE_ASSERT(pe->blocks[j].buf == 0, pe); #endif diff --git a/src/broadcast_socket.cpp b/src/broadcast_socket.cpp index 944715523..226e64509 100644 --- a/src/broadcast_socket.cpp +++ b/src/broadcast_socket.cpp @@ -57,10 +57,6 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/assert.hpp" #include "libtorrent/debug.hpp" -#ifdef TORRENT_DEBUG -#include "libtorrent/socket_io.hpp" -#endif - using namespace std::placeholders; namespace libtorrent @@ -212,13 +208,6 @@ namespace libtorrent #endif open_multicast_socket(ios, i->interface_address, loopback, ec); -#ifdef TORRENT_DEBUG - std::fprintf(stderr, "broadcast socket [ if: %s group: %s mask: %s ] %s\n" - , i->interface_address.to_string().c_str() - , m_multicast_endpoint.address().to_string().c_str() - , i->netmask.to_string().c_str() - , ec.message().c_str()); -#endif open_unicast_socket(ios, i->interface_address , i->netmask.is_v4() ? i->netmask.to_v4() : address_v4()); } diff --git a/src/disk_buffer_pool.cpp b/src/disk_buffer_pool.cpp index 9803654e6..8090ae0a4 100644 --- a/src/disk_buffer_pool.cpp +++ b/src/disk_buffer_pool.cpp @@ -176,7 +176,7 @@ namespace libtorrent } #endif -#if defined TORRENT_DEBUG +#if TORRENT_USE_INVARIANT_CHECKS return m_buffers_in_use.count(buffer) == 1; #elif defined TORRENT_DEBUG_BUFFERS return page_aligned_allocator::in_use(buffer); @@ -310,7 +310,7 @@ namespace libtorrent } } -#if defined TORRENT_DEBUG +#if TORRENT_USE_INVARIANT_CHECKS TORRENT_ASSERT(m_buffers_in_use.count(ret) == 0); m_buffers_in_use.insert(ret); #endif @@ -553,7 +553,7 @@ namespace libtorrent #endif // TORRENT_DISABLE_POOL_ALLOCATOR } -#if defined TORRENT_DEBUG +#if TORRENT_USE_INVARIANT_CHECKS std::set::iterator i = m_buffers_in_use.find(buf); TORRENT_ASSERT(i != m_buffers_in_use.end()); m_buffers_in_use.erase(i); diff --git a/src/file.cpp b/src/file.cpp index 0f5be4b39..3de03a7b9 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -321,11 +321,9 @@ done: # endif #endif -#ifdef TORRENT_DEBUG static_assert((libtorrent::file::rw_mask & libtorrent::file::sparse) == 0, "internal flags error"); static_assert((libtorrent::file::rw_mask & libtorrent::file::attribute_mask) == 0, "internal flags error"); static_assert((libtorrent::file::sparse & libtorrent::file::attribute_mask) == 0, "internal flags error"); -#endif #if defined TORRENT_WINDOWS && defined UNICODE && !TORRENT_USE_WSTRING diff --git a/src/file_progress.cpp b/src/file_progress.cpp index c8c67cccc..d4a871156 100644 --- a/src/file_progress.cpp +++ b/src/file_progress.cpp @@ -53,7 +53,7 @@ namespace libtorrent { namespace aux int const num_pieces = fs.num_pieces(); int const num_files = fs.num_files(); -#if TORRENT_USE_INVARIANT_CHECKS && defined TORRENT_DEBUG +#if TORRENT_USE_INVARIANT_CHECKS m_have_pieces.clear(); m_have_pieces.resize(num_pieces, false); m_file_sizes.clear(); @@ -87,7 +87,7 @@ namespace libtorrent { namespace aux if (!picker.have_piece(piece)) continue; -#if TORRENT_USE_INVARIANT_CHECKS && defined TORRENT_DEBUG +#if TORRENT_USE_INVARIANT_CHECKS m_have_pieces.set_bit(piece); #endif @@ -127,7 +127,7 @@ namespace libtorrent { namespace aux { INVARIANT_CHECK; std::vector().swap(m_file_progress); -#if TORRENT_USE_INVARIANT_CHECKS && defined TORRENT_DEBUG +#if TORRENT_USE_INVARIANT_CHECKS m_have_pieces.clear(); #endif } @@ -140,7 +140,7 @@ namespace libtorrent { namespace aux INVARIANT_CHECK; if (m_file_progress.empty()) return; -#if TORRENT_USE_INVARIANT_CHECKS && defined TORRENT_DEBUG +#if TORRENT_USE_INVARIANT_CHECKS // if this assert fires, we've told the file_progress object that we have // a piece twice. That violates its precondition and will cause incorect // accounting diff --git a/src/ip_filter.cpp b/src/ip_filter.cpp index 01350899f..cc76fb807 100644 --- a/src/ip_filter.cpp +++ b/src/ip_filter.cpp @@ -31,8 +31,6 @@ POSSIBILITY OF SUCH DAMAGE. */ #include "libtorrent/ip_filter.hpp" -#include - namespace libtorrent { @@ -75,7 +73,7 @@ namespace libtorrent return m_filter4.export_filter(); #endif } - + void port_filter::add_rule(std::uint16_t first, std::uint16_t last, std::uint32_t flags) { m_filter.add_rule(first, last, flags); diff --git a/src/kademlia/dht_tracker.cpp b/src/kademlia/dht_tracker.cpp index 23ae15e3a..6cc061a75 100644 --- a/src/kademlia/dht_tracker.cpp +++ b/src/kademlia/dht_tracker.cpp @@ -330,18 +330,6 @@ namespace libtorrent { namespace dht m_storage.update_node_ids(ids); } -/* -#if defined TORRENT_DEBUG && TORRENT_USE_IOSTREAM - std::ofstream st("dht_routing_table_state.txt", std::ios_base::trunc); - m_dht.print_state(st); - - #if TORRENT_USE_IPV6 - std::ofstream st6("dht6_routing_table_state.txt", std::ios_base::trunc); - m_dht6.print_state(st6); - #endif -#endif -*/ - void dht_tracker::get_peers(sha1_hash const& ih , boost::function const&)> f) { diff --git a/src/kademlia/item.cpp b/src/kademlia/item.cpp index d97c0cb11..6244b0138 100644 --- a/src/kademlia/item.cpp +++ b/src/kademlia/item.cpp @@ -38,7 +38,7 @@ POSSIBILITY OF SUCH DAMAGE. #include // for snprintf #include // for PRId64 et.al. -#ifdef TORRENT_DEBUG +#if TORRENT_USE_ASSERTS #include "libtorrent/bdecode.hpp" #endif @@ -52,7 +52,7 @@ namespace , std::pair salt, char out[canonical_length]) { // v must be valid bencoding! -#ifdef TORRENT_DEBUG +#if TORRENT_USE_ASSERTS bdecode_node e; error_code ec; TORRENT_ASSERT(bdecode(v.first, v.first + v.second, e, ec) == 0); diff --git a/src/kademlia/routing_table.cpp b/src/kademlia/routing_table.cpp index 851cc49b2..74667cef9 100644 --- a/src/kademlia/routing_table.cpp +++ b/src/kademlia/routing_table.cpp @@ -242,8 +242,7 @@ int routing_table::depth() const return m_depth; } -#if defined TORRENT_DEBUG && TORRENT_USE_IOSTREAM - +#ifndef TORRENT_DISABLE_LOGGING void routing_table::print_state(std::ostream& os) const { std::vector buf(2048); diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index a5327b137..bc76a3936 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -4315,7 +4315,7 @@ namespace libtorrent TORRENT_ASSERT(m_request_queue.empty()); } -#if defined TORRENT_DEBUG && defined TORRENT_EXPENSIVE_INVARIANT_CHECKS +#if defined TORRENT_EXPENSIVE_INVARIANT_CHECKS // since this connection doesn't have a torrent reference // no torrent should have a reference to this connection either TORRENT_ASSERT(!m_ses.any_torrent_has_peer(this)); diff --git a/src/peer_list.cpp b/src/peer_list.cpp index 55f90f08f..e0a247807 100644 --- a/src/peer_list.cpp +++ b/src/peer_list.cpp @@ -54,10 +54,6 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/ip_filter.hpp" #include "libtorrent/torrent_peer_allocator.hpp" -#ifdef TORRENT_DEBUG -#include "libtorrent/bt_peer_connection.hpp" -#endif - #if TORRENT_USE_ASSERTS #include "libtorrent/socket_io.hpp" // for print_endpoint #endif @@ -88,7 +84,7 @@ namespace tcp::endpoint const& m_ep; }; -#ifndef TORRENT_DISABLE_INVARIANT_CHECKS +#if TORRENT_USE_INVARIANT_CHECKS struct match_peer_connection { match_peer_connection(peer_connection_interface const& c) : m_conn(c) {} @@ -1195,7 +1191,7 @@ namespace libtorrent TORRENT_ASSERT(p->in_use); -#ifndef TORRENT_DISABLE_INVARIANT_CHECKS +#if TORRENT_USE_INVARIANT_CHECKS // web seeds are special, they're not connected via the peer list // so they're not kept in m_peers TORRENT_ASSERT(p->web_seed @@ -1308,8 +1304,7 @@ namespace libtorrent int connect_candidates = 0; const_iterator prev = m_peers.end(); - for (const_iterator i = m_peers.begin(); - i != m_peers.end(); ++i) + for (const_iterator i = m_peers.begin(); i != m_peers.end(); ++i) { if (prev != m_peers.end()) ++prev; if (i == m_peers.begin() + 1) prev = m_peers.begin(); @@ -1339,7 +1334,7 @@ namespace libtorrent #endif // TORRENT_EXPENSIVE_INVARIANT_CHECKS } -#endif // TORRENT_DEBUG +#endif // this returns true if lhs is a better erase candidate than rhs bool peer_list::compare_peer_erase(torrent_peer const& lhs, torrent_peer const& rhs) const diff --git a/src/piece_picker.cpp b/src/piece_picker.cpp index 01c6c3c75..904293585 100644 --- a/src/piece_picker.cpp +++ b/src/piece_picker.cpp @@ -317,7 +317,6 @@ namespace libtorrent void piece_picker::check_piece_state() const { -#ifndef TORRENT_DISABLE_INVARIANT_CHECKS for (int k = 0; k < piece_pos::num_download_categories; ++k) { if (!m_downloads[k].empty()) @@ -327,7 +326,6 @@ namespace libtorrent { downloading_piece const& dp = *i; downloading_piece const& next = *(i + 1); -// TORRENT_ASSERT(dp.finished + dp.writing >= next.finished + next.writing); TORRENT_ASSERT(dp.index < next.index); TORRENT_ASSERT(int(dp.info_idx) * m_blocks_per_piece + m_blocks_per_piece <= int(m_block_info.size())); @@ -345,7 +343,6 @@ namespace libtorrent } } } -#endif } void piece_picker::verify_pick(std::vector const& picked @@ -2321,7 +2318,7 @@ get_out: = TORRENT_ALLOCA(downloading_piece const*, partials_size); int c = 0; -#if TORRENT_USE_ASSERTS && !defined TORRENT_DISABLE_INVARIANT_CHECKS +#if TORRENT_USE_INVARIANT_CHECKS // if we get here, we're about to pick a busy block. First, make sure // we really exhausted the available blocks for (std::vector::const_iterator i @@ -2424,7 +2421,7 @@ get_out: --partials_size; } -#if defined TORRENT_DEBUG && !defined TORRENT_DISABLE_INVARIANT_CHECKS +#if TORRENT_USE_INVARIANT_CHECKS // make sure that we at this point have added requests to all unrequested blocks // in all downloading pieces @@ -2491,7 +2488,7 @@ get_out: if (k == m_downloads[download_state].end()) continue; } } -#endif // TORRENT_DEBUG && !defined TORRENT_DISABLE_INVARIANT_CHECKS +#endif return ret; } @@ -2848,7 +2845,7 @@ get_out: if (int(i->finished) + int(i->writing) < max_blocks) return false; TORRENT_ASSERT(int(i->finished) + int(i->writing) == max_blocks); -#if TORRENT_USE_ASSERTS && !defined TORRENT_DISABLE_INVARIANT_CHECKS +#if TORRENT_USE_INVARIANT_CHECKS block_info const* info = blocks_for_piece(*i); for (int k = 0; k < max_blocks; ++k) { diff --git a/src/receive_buffer.cpp b/src/receive_buffer.cpp index 05395590d..0827bfafe 100644 --- a/src/receive_buffer.cpp +++ b/src/receive_buffer.cpp @@ -117,7 +117,7 @@ void receive_buffer::cut(int const size, int const packet_size, int const offset m_recv_pos -= size; m_recv_end -= size; -#ifdef TORRENT_DEBUG +#if TORRENT_USE_ASSERTS std::fill(m_recv_buffer.begin() + m_recv_end, m_recv_buffer.end(), 0xcc); #endif } @@ -213,7 +213,7 @@ void receive_buffer::normalize(int force_shrink) m_recv_end -= m_recv_start; m_recv_start = 0; -#ifdef TORRENT_DEBUG +#if TORRENT_USE_ASSERTS std::fill(m_recv_buffer.begin() + m_recv_end, m_recv_buffer.end(), 0xcc); #endif } diff --git a/src/request_blocks.cpp b/src/request_blocks.cpp index fedf57f31..c2edf8698 100644 --- a/src/request_blocks.cpp +++ b/src/request_blocks.cpp @@ -120,7 +120,7 @@ namespace libtorrent // the number of blocks we want, but it will try to make the picked // blocks be from whole pieces, possibly by returning more blocks // than we requested. -#ifdef TORRENT_DEBUG +#if TORRENT_USE_ASSERTS error_code ec; TORRENT_ASSERT(c.remote() == c.get_socket()->remote_endpoint(ec) || ec); #endif @@ -231,7 +231,7 @@ namespace libtorrent if (std::find_if(dq.begin(), dq.end(), has_block(*i)) != dq.end() || std::find_if(rq.begin(), rq.end(), has_block(*i)) != rq.end()) { -#ifdef TORRENT_DEBUG +#if TORRENT_USE_ASSERTS std::vector::const_iterator j = std::find_if(dq.begin(), dq.end(), has_block(*i)); if (j != dq.end()) TORRENT_ASSERT(j->timed_out || j->not_wanted); @@ -272,7 +272,7 @@ namespace libtorrent // and can't find any, that doesn't count as end-game if (!c.has_peer_choked()) c.set_endgame(true); - + // if we don't have any potential busy blocks to request // or if we already have outstanding requests, don't // pick a busy piece @@ -282,7 +282,7 @@ namespace libtorrent return true; } -#ifdef TORRENT_DEBUG +#if TORRENT_USE_ASSERTS piece_picker::downloading_piece st; p.piece_info(busy_block.piece_index, st); TORRENT_ASSERT(st.requested + st.finished + st.writing diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 7cf4752c6..c411f4ccf 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -40,9 +40,9 @@ POSSIBILITY OF SUCH DAMAGE. #include // for PRId64 et.al. #include -#if defined TORRENT_DEBUG && !defined TORRENT_DISABLE_INVARIANT_CHECKS +#if TORRENT_USE_INVARIANT_CHECKS #include -#endif // TORRENT_DEBUG && !TORRENT_DISABLE_INVARIANT_CHECKS +#endif #include "libtorrent/aux_/disable_warnings_push.hpp" @@ -1094,7 +1094,7 @@ namespace aux { TORRENT_ASSERT(pc); if (pc == 0) { -#ifdef TORRENT_DEBUG +#if TORRENT_USE_INVARIANT_CHECKS // make it obvious that the return value is undefined ret.upload_limit = 0xf0f0f0f; ret.download_limit = 0xf0f0f0f; @@ -1229,7 +1229,7 @@ namespace aux { // checking to see if it's the first item if (t->next != nullptr || t->prev != nullptr || m_torrent_lru.front() == t) { -#ifdef TORRENT_DEBUG +#if TORRENT_USE_ASSERTS torrent* i = m_torrent_lru.front(); while (i != nullptr && i != t) i = i->next; TORRENT_ASSERT(i == t); @@ -1269,7 +1269,7 @@ namespace aux { TORRENT_ASSERT(t->next != nullptr || t->prev != nullptr || m_torrent_lru.front() == t); -#if defined TORRENT_DEBUG && defined TORRENT_EXPENSIVE_INVARIANT_CHECKS +#if TORRENT_USE_ASSERTS torrent* i = m_torrent_lru.front(); while (i != nullptr && i != t) i = i->next; TORRENT_ASSERT(i == t); @@ -1308,7 +1308,7 @@ namespace aux { // one more torrent in the list. if (ignore->next != nullptr || ignore->prev != nullptr || m_torrent_lru.front() == ignore) { -#ifdef TORRENT_DEBUG +#if TORRENT_USE_ASSERTS torrent* i = m_torrent_lru.front(); while (i != nullptr && i != ignore) i = i->next; TORRENT_ASSERT(i == ignore); @@ -2866,15 +2866,6 @@ namespace aux { if (!sp.unique()) m_undead_peers.push_back(sp); -// too expensive -// INVARIANT_CHECK; - -#ifdef TORRENT_DEBUG -// for (aux::session_impl::torrent_map::const_iterator i = m_torrents.begin() -// , end(m_torrents.end()); i != end; ++i) -// TORRENT_ASSERT(!i->second->has_peer((peer_connection*)p)); -#endif - #ifndef TORRENT_DISABLE_LOGGING session_log(" CLOSING CONNECTION %s : %s" , print_endpoint(p->remote()).c_str(), ec.message().c_str()); @@ -4246,7 +4237,7 @@ namespace aux { TORRENT_ASSERT(is_single_thread()); torrent_map::const_iterator i = m_torrents.find(info_hash); -#if defined TORRENT_DEBUG && defined TORRENT_EXPENSIVE_INVARIANT_CHECKS +#if TORRENT_USE_INVARIANT_CHECKS for (torrent_map::const_iterator j = m_torrents.begin(); j != m_torrents.end(); ++j) { diff --git a/src/torrent.cpp b/src/torrent.cpp index 218a0c56c..b7025b6ec 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -3866,11 +3866,9 @@ namespace libtorrent { downloading_piece[block] = p->bytes_downloaded; } -#ifdef TORRENT_DEBUG TORRENT_ASSERT(p->bytes_downloaded <= p->full_block_bytes); TORRENT_ASSERT(p->full_block_bytes == to_req(piece_block( p->piece_index, p->block_index)).length); -#endif } for (std::map::iterator i = downloading_piece.begin(); i != downloading_piece.end(); ++i) @@ -3884,7 +3882,7 @@ namespace libtorrent TORRENT_ASSERT(st.total_done <= m_torrent_file->total_size() - m_padding); TORRENT_ASSERT(st.total_wanted_done <= m_torrent_file->total_size() - m_padding); -#ifdef TORRENT_DEBUG +#if TORRENT_USE_INVARIANT_CHECKS if (st.total_done >= m_torrent_file->total_size()) { @@ -4296,7 +4294,7 @@ namespace libtorrent std::set peers; std::copy(downloaders.begin(), downloaders.end(), std::inserter(peers, peers.begin())); -#ifdef TORRENT_DEBUG +#if TORRENT_USE_ASSERTS for (std::vector::iterator i = downloaders.begin() , end(downloaders.end()); i != end; ++i) { @@ -4414,7 +4412,7 @@ namespace libtorrent on_piece_sync(&j); } -#ifdef TORRENT_DEBUG +#if TORRENT_USE_ASSERTS for (std::vector::iterator i = downloaders.begin() , end(downloaders.end()); i != end; ++i) { @@ -4494,12 +4492,10 @@ namespace libtorrent torrent_peer* pp = peer->peer_info_struct(); m_picker->inc_refcount(index, pp); } -#ifdef TORRENT_DEBUG else { TORRENT_ASSERT(is_seed() || !m_have_all); } -#endif } // when we get a bitfield message, this is called for that piece @@ -4511,12 +4507,10 @@ namespace libtorrent torrent_peer* pp = peer->peer_info_struct(); m_picker->inc_refcount(bits, pp); } -#ifdef TORRENT_DEBUG else { TORRENT_ASSERT(is_seed() || !m_have_all); } -#endif } void torrent::peer_has_all(peer_connection const* peer) @@ -4526,12 +4520,10 @@ namespace libtorrent torrent_peer* pp = peer->peer_info_struct(); m_picker->inc_refcount_all(pp); } -#ifdef TORRENT_DEBUG else { TORRENT_ASSERT(is_seed() || !m_have_all); } -#endif } void torrent::peer_lost(bitfield const& bits, peer_connection const* peer) @@ -4542,12 +4534,10 @@ namespace libtorrent torrent_peer* pp = peer->peer_info_struct(); m_picker->dec_refcount(bits, pp); } -#ifdef TORRENT_DEBUG else { TORRENT_ASSERT(is_seed() || !m_have_all); } -#endif } void torrent::peer_lost(int index, peer_connection const* peer) @@ -4557,12 +4547,10 @@ namespace libtorrent torrent_peer* pp = peer->peer_info_struct(); m_picker->dec_refcount(index, pp); } -#ifdef TORRENT_DEBUG else { TORRENT_ASSERT(is_seed() || !m_have_all); } -#endif } void torrent::abort() @@ -7299,7 +7287,7 @@ namespace libtorrent debug_log("incoming peer (%d)", int(m_connections.size())); #endif -#ifdef TORRENT_DEBUG +#if TORRENT_USE_ASSERTS error_code ec; TORRENT_ASSERT(p->remote() == p->get_socket()->remote_endpoint(ec) || ec); #endif @@ -7603,7 +7591,7 @@ namespace libtorrent { INVARIANT_CHECK; -#ifdef TORRENT_DEBUG +#if TORRENT_USE_ASSERTS for (peer_iterator i = m_connections.begin() , end(m_connections.end()); i != end; ++i) { diff --git a/src/utp_stream.cpp b/src/utp_stream.cpp index 412e8d7eb..142e91009 100644 --- a/src/utp_stream.cpp +++ b/src/utp_stream.cpp @@ -202,7 +202,7 @@ struct packet // sent with the DF bit set (Don't Fragment) bool mtu_probe:1; -#ifdef TORRENT_DEBUG +#if TORRENT_USE_ASSERTS int num_fast_resend; #endif @@ -1018,7 +1018,7 @@ void utp_stream::add_write_buffer(void const* buf, size_t len) TORRENT_ASSERT(len > 0); TORRENT_ASSERT(buf); -#ifdef TORRENT_DEBUG +#if TORRENT_USE_ASSERTS int write_buffer_size = 0; for (std::vector::iterator i = m_impl->m_write_buffer.begin() , end(m_impl->m_write_buffer.end()); i != end; ++i) @@ -1032,7 +1032,7 @@ void utp_stream::add_write_buffer(void const* buf, size_t len) m_impl->m_write_buffer.push_back(utp_socket_impl::iovec_t(const_cast(buf), len)); m_impl->m_write_buffer_size += int(len); -#ifdef TORRENT_DEBUG +#if TORRENT_USE_ASSERTS write_buffer_size = 0; for (std::vector::iterator i = m_impl->m_write_buffer.begin() , end(m_impl->m_write_buffer.end()); i != end; ++i) @@ -1367,7 +1367,7 @@ void utp_socket_impl::send_syn() p->header_size = sizeof(utp_header); p->num_transmissions = 0; p->mtu_probe = false; -#ifdef TORRENT_DEBUG +#if TORRENT_USE_ASSERTS p->num_fast_resend = 0; #endif p->need_resend = false; @@ -1623,7 +1623,7 @@ void utp_socket_impl::write_payload(std::uint8_t* ptr, int size) { INVARIANT_CHECK; -#ifdef TORRENT_DEBUG +#if TORRENT_USE_ASSERTS int write_buffer_size = 0; for (std::vector::iterator i = m_write_buffer.begin() , end(m_write_buffer.end()); i != end; ++i) @@ -1662,7 +1662,7 @@ void utp_socket_impl::write_payload(std::uint8_t* ptr, int size) m_write_buffer.erase(m_write_buffer.begin() , m_write_buffer.begin() + buffers_to_clear); -#ifdef TORRENT_DEBUG +#if TORRENT_USE_ASSERTS write_buffer_size = 0; for (std::vector::iterator j = m_write_buffer.begin() , end(m_write_buffer.end()); j != end; ++j) @@ -1921,7 +1921,7 @@ bool utp_socket_impl::send_pkt(int const flags) p->size = packet_size; p->header_size = packet_size - payload_size; p->num_transmissions = 0; -#ifdef TORRENT_DEBUG +#if TORRENT_USE_ASSERTS p->num_fast_resend = 0; #endif p->need_resend = false; @@ -2241,7 +2241,7 @@ bool utp_socket_impl::resend_packet(packet* p, bool fast_resend) m_sm->inc_stats_counter(counters::utp_packet_resend); if (fast_resend) m_sm->inc_stats_counter(counters::utp_fast_retransmit); -#ifdef TORRENT_DEBUG +#if TORRENT_USE_ASSERTS if (fast_resend) ++p->num_fast_resend; #endif p->need_resend = false; @@ -2629,7 +2629,7 @@ bool utp_socket_impl::consume_incoming_data( p->size = payload_size; p->header_size = 0; p->num_transmissions = 0; -#ifdef TORRENT_DEBUG +#if TORRENT_USE_ASSERTS p->num_fast_resend = 0; #endif p->need_resend = false; diff --git a/src/web_peer_connection.cpp b/src/web_peer_connection.cpp index 2c37b931b..9e8e99217 100644 --- a/src/web_peer_connection.cpp +++ b/src/web_peer_connection.cpp @@ -858,10 +858,10 @@ void web_peer_connection::on_receive(error_code const& error { TORRENT_ASSERT_VAL(m_chunk_pos == 0, m_chunk_pos); -#ifdef TORRENT_DEBUG - chunk_start = recv_buffer; - chunk_start.begin += m_chunk_pos; - TORRENT_ASSERT(chunk_start.left() == 0 || chunk_start.begin[0] == 'H'); +#if TORRENT_USE_ASSERTS + buffer::const_interval chunk = recv_buffer; + chunk.begin += m_chunk_pos; + TORRENT_ASSERT(chunk.left() == 0 || chunk.begin[0] == 'H'); #endif m_chunk_pos = -1; diff --git a/test/Jamfile b/test/Jamfile index c470455e4..04f6e9423 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -98,6 +98,7 @@ project msvc:_SCL_SECURE_NO_WARNINGS : default-build multi + on full shared on diff --git a/test/dht_server.cpp b/test/dht_server.cpp index 9a87ebe1e..f74e873c0 100644 --- a/test/dht_server.cpp +++ b/test/dht_server.cpp @@ -44,7 +44,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include -#if defined TORRENT_DEBUG && TORRENT_USE_IOSTREAM +#if TORRENT_USE_IOSTREAM #include #endif @@ -145,7 +145,7 @@ struct dht_server { entry msg = bdecode(buffer, buffer + bytes_transferred); -#if defined TORRENT_DEBUG && TORRENT_USE_IOSTREAM +#if TORRENT_USE_IOSTREAM std::cerr << msg << std::endl; #endif ++m_dht_requests; diff --git a/test/test_dht.cpp b/test/test_dht.cpp index 342af7973..925e5b445 100644 --- a/test/test_dht.cpp +++ b/test/test_dht.cpp @@ -1299,7 +1299,7 @@ void do_test_dht(address(&rand_addr)()) //#error test num_global_nodes //#error test need_refresh -#if defined TORRENT_DEBUG +#ifndef TORRENT_DISABLE_LOGGING table.print_state(std::cerr); #endif @@ -2377,7 +2377,7 @@ TORRENT_TEST(routing_table_uniform) // i.e. no more than 5 levels TEST_EQUAL(tbl.num_active_buckets(), 5); -#if defined TORRENT_DHT_VERBOSE_LOGGING || defined TORRENT_DEBUG +#if defined TORRENT_DHT_VERBOSE_LOGGING tbl.print_state(std::cerr); #endif } @@ -2402,7 +2402,7 @@ TORRENT_TEST(routing_table_balance) std::printf("num_active_buckets: %d\n", tbl.num_active_buckets()); TEST_EQUAL(tbl.num_active_buckets(), 2); -#if defined TORRENT_DEBUG +#ifndef TORRENT_DISABLE_LOGGING tbl.print_state(std::cerr); #endif } @@ -2431,7 +2431,7 @@ TORRENT_TEST(routing_table_extended) } TEST_EQUAL(tbl.num_active_buckets(), 6); -#if defined TORRENT_DEBUG +#ifndef TORRENT_DISABLE_LOGGING tbl.print_state(std::cerr); #endif } @@ -2466,7 +2466,7 @@ TORRENT_TEST(routing_table_set_id) std::set original_nodes; tbl.for_each_node(std::bind(&inserter, &original_nodes, _1)); -#if defined TORRENT_DEBUG +#ifndef TORRENT_DISABLE_LOGGING tbl.print_state(std::cerr); #endif @@ -2486,7 +2486,7 @@ TORRENT_TEST(routing_table_set_id) // all remaining nodes also exist in the original nodes TEST_EQUAL(intersection.size(), remaining_nodes.size()); -#if defined TORRENT_DEBUG +#ifndef TORRENT_DISABLE_LOGGING tbl.print_state(std::cerr); #endif } diff --git a/test/test_settings_pack.cpp b/test/test_settings_pack.cpp index 78474ac83..97549f423 100644 --- a/test/test_settings_pack.cpp +++ b/test/test_settings_pack.cpp @@ -51,7 +51,7 @@ TORRENT_TEST(default_settings) // by save_settings TEST_EQUAL(e.dict().size(), 0); -#if defined TORRENT_DEBUG && TORRENT_USE_IOSTREAM +#if TORRENT_USE_IOSTREAM if (e.dict().size() > 0) std::cerr << e << std::endl; #endif