From ead11737b4e810e495f28ddc01dbb754de66139a Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sat, 18 Jun 2016 08:31:07 -0400 Subject: [PATCH] fix uses of defines for whether or not asserts are active (#832) --- include/libtorrent/assert.hpp | 3 +-- include/libtorrent/bt_peer_connection.hpp | 2 +- include/libtorrent/disk_buffer_pool.hpp | 2 +- include/libtorrent/disk_io_job.hpp | 2 +- include/libtorrent/kademlia/observer.hpp | 4 ++-- src/assert.cpp | 3 +-- src/bt_peer_connection.cpp | 2 +- src/disk_io_job.cpp | 2 +- src/disk_job_pool.cpp | 4 ++-- src/http_seed_connection.cpp | 2 +- src/kademlia/find_data.cpp | 2 +- src/kademlia/node.cpp | 6 +++--- src/kademlia/put_data.cpp | 2 +- src/kademlia/refresh.cpp | 2 +- src/pe_crypto.cpp | 4 ++-- src/peer_list.cpp | 2 +- src/session_handle.cpp | 4 ++-- src/torrent.cpp | 6 +++--- src/udp_tracker_connection.cpp | 2 +- test/main.cpp | 6 ++---- test/test_block_cache.cpp | 2 +- test/test_dht.cpp | 2 +- 22 files changed, 31 insertions(+), 35 deletions(-) diff --git a/include/libtorrent/assert.hpp b/include/libtorrent/assert.hpp index 43cca6305..7a8b9038f 100644 --- a/include/libtorrent/assert.hpp +++ b/include/libtorrent/assert.hpp @@ -34,10 +34,9 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/config.hpp" -#if (defined TORRENT_DEBUG && TORRENT_USE_ASSERTS) \ +#if TORRENT_USE_ASSERTS \ || defined TORRENT_ASIO_DEBUGGING \ || defined TORRENT_PROFILE_CALLS \ - || defined TORRENT_RELEASE_ASSERTS \ || defined TORRENT_DEBUG_BUFFERS #include diff --git a/include/libtorrent/bt_peer_connection.hpp b/include/libtorrent/bt_peer_connection.hpp index 24aa2e331..cc1234c80 100644 --- a/include/libtorrent/bt_peer_connection.hpp +++ b/include/libtorrent/bt_peer_connection.hpp @@ -440,7 +440,7 @@ private: char m_reserved_bits[8]; #endif -#if defined TORRENT_DEBUG || defined TORRENT_RELEASE_ASSERTS +#if TORRENT_USE_ASSERTS bool m_in_constructor; #endif diff --git a/include/libtorrent/disk_buffer_pool.hpp b/include/libtorrent/disk_buffer_pool.hpp index c964ffd28..1a2c70af7 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 || TORRENT_RELEASE_ASSERTS +#if defined TORRENT_DEBUG #include #endif diff --git a/include/libtorrent/disk_io_job.hpp b/include/libtorrent/disk_io_job.hpp index f3f02a7f7..42a12737e 100644 --- a/include/libtorrent/disk_io_job.hpp +++ b/include/libtorrent/disk_io_job.hpp @@ -222,7 +222,7 @@ namespace libtorrent // flags controlling this job boost::uint8_t flags; -#if defined TORRENT_DEBUG || defined TORRENT_RELEASE_ASSERTS +#if TORRENT_USE_ASSERTS bool in_use:1; // set to true when the job is added to the completion queue. diff --git a/include/libtorrent/kademlia/observer.hpp b/include/libtorrent/kademlia/observer.hpp index 887e98237..8570291c1 100644 --- a/include/libtorrent/kademlia/observer.hpp +++ b/include/libtorrent/kademlia/observer.hpp @@ -73,7 +73,7 @@ struct TORRENT_EXTRA_EXPORT observer : boost::noncopyable , flags(0) { TORRENT_ASSERT(a); -#if defined TORRENT_DEBUG || defined TORRENT_RELEASE_ASSERTS +#if TORRENT_USE_ASSERTS m_in_constructor = true; m_was_sent = false; m_was_abandoned = false; @@ -164,7 +164,7 @@ private: public: unsigned char flags; -#if defined TORRENT_DEBUG || defined TORRENT_RELEASE_ASSERTS +#if TORRENT_USE_ASSERTS bool m_in_constructor:1; bool m_was_sent:1; bool m_was_abandoned:1; diff --git a/src/assert.cpp b/src/assert.cpp index 8994814f7..5ba0be60d 100644 --- a/src/assert.cpp +++ b/src/assert.cpp @@ -39,10 +39,9 @@ POSSIBILITY OF SUCH DAMAGE. #include #endif -#if (defined TORRENT_DEBUG && TORRENT_USE_ASSERTS) \ +#if TORRENT_USE_ASSERTS \ || defined TORRENT_ASIO_DEBUGGING \ || defined TORRENT_PROFILE_CALLS \ - || defined TORRENT_RELEASE_ASSERTS \ || defined TORRENT_DEBUG_BUFFERS #ifdef __APPLE__ diff --git a/src/bt_peer_connection.cpp b/src/bt_peer_connection.cpp index 61b739338..a583221c4 100644 --- a/src/bt_peer_connection.cpp +++ b/src/bt_peer_connection.cpp @@ -160,7 +160,7 @@ namespace libtorrent , m_dont_have_id(0) , m_share_mode_id(0) #endif -#if defined TORRENT_DEBUG || defined TORRENT_RELEASE_ASSERTS +#if TORRENT_USE_ASSERTS , m_in_constructor(true) #endif { diff --git a/src/disk_io_job.cpp b/src/disk_io_job.cpp index d1b737e77..f2230d2f2 100644 --- a/src/disk_io_job.cpp +++ b/src/disk_io_job.cpp @@ -43,7 +43,7 @@ namespace libtorrent , action(read) , ret(0) , flags(0) -#if defined TORRENT_DEBUG || defined TORRENT_RELEASE_ASSERTS +#if TORRENT_USE_ASSERTS , in_use(false) , job_posted(false) , callback_called(false) diff --git a/src/disk_job_pool.cpp b/src/disk_job_pool.cpp index e5b8c85c4..78a3d1a88 100644 --- a/src/disk_job_pool.cpp +++ b/src/disk_job_pool.cpp @@ -62,7 +62,7 @@ namespace libtorrent new (ptr) disk_io_job; ptr->action = static_cast(type); -#if defined TORRENT_DEBUG || defined TORRENT_RELEASE_ASSERTS +#if TORRENT_USE_ASSERTS ptr->in_use = true; #endif return ptr; @@ -72,7 +72,7 @@ namespace libtorrent { TORRENT_ASSERT(j); if (j == 0) return; -#if defined TORRENT_DEBUG || defined TORRENT_RELEASE_ASSERTS +#if TORRENT_USE_ASSERTS TORRENT_ASSERT(j->in_use); j->in_use = false; #endif diff --git a/src/http_seed_connection.cpp b/src/http_seed_connection.cpp index 33b6714d4..9c1ea7e28 100644 --- a/src/http_seed_connection.cpp +++ b/src/http_seed_connection.cpp @@ -251,7 +251,7 @@ namespace libtorrent boost::tie(payload, protocol) = m_parser.incoming(recv_buffer, parse_error); received_bytes(0, protocol); bytes_transferred -= protocol; -#if defined TORRENT_DEBUG || defined TORRENT_RELEASE_ASSERTS +#if TORRENT_USE_ASSERTS if (payload > front_request.length) payload = front_request.length; #endif diff --git a/src/kademlia/find_data.cpp b/src/kademlia/find_data.cpp index 005fcd6f5..8aae1fb1e 100644 --- a/src/kademlia/find_data.cpp +++ b/src/kademlia/find_data.cpp @@ -130,7 +130,7 @@ observer_ptr find_data::new_observer(void* ptr , udp::endpoint const& ep, node_id const& id) { observer_ptr o(new (ptr) find_data_observer(this, ep, id)); -#if defined TORRENT_DEBUG || defined TORRENT_RELEASE_ASSERTS +#if TORRENT_USE_ASSERTS o->m_in_constructor = false; #endif return o; diff --git a/src/kademlia/node.cpp b/src/kademlia/node.cpp index f14bea57f..dc606b3d2 100644 --- a/src/kademlia/node.cpp +++ b/src/kademlia/node.cpp @@ -383,7 +383,7 @@ namespace void* ptr = node.m_rpc.allocate_observer(); if (ptr == 0) return; observer_ptr o(new (ptr) announce_observer(algo, i->first.ep(), i->first.id)); -#if defined TORRENT_DEBUG || defined TORRENT_RELEASE_ASSERTS +#if TORRENT_USE_ASSERTS o->m_in_constructor = false; #endif entry e; @@ -470,7 +470,7 @@ void node::direct_request(udp::endpoint ep, entry& e void* ptr = m_rpc.allocate_observer(); if (ptr == 0) return; observer_ptr o(new (ptr) direct_observer(algo, ep, (node_id::min)())); -#if defined TORRENT_DEBUG || defined TORRENT_RELEASE_ASSERTS +#if TORRENT_USE_ASSERTS o->m_in_constructor = false; #endif m_rpc.invoke(e, ep, o); @@ -690,7 +690,7 @@ void node::send_single_refresh(udp::endpoint const& ep, int bucket boost::intrusive_ptr algo( new traversal_algorithm(*this, (node_id::min)())); observer_ptr o(new (ptr) ping_observer(algo, ep, id)); -#if defined TORRENT_DEBUG || defined TORRENT_RELEASE_ASSERTS +#if TORRENT_USE_ASSERTS o->m_in_constructor = false; #endif entry e; diff --git a/src/kademlia/put_data.cpp b/src/kademlia/put_data.cpp index 393e3406a..e55184bdd 100644 --- a/src/kademlia/put_data.cpp +++ b/src/kademlia/put_data.cpp @@ -66,7 +66,7 @@ void put_data::set_targets(std::vector > cons observer_ptr o(new (ptr) put_data_observer(this, i->first.ep() , i->first.id, i->second)); - #if defined TORRENT_DEBUG || defined TORRENT_RELEASE_ASSERTS + #if TORRENT_USE_ASSERTS o->m_in_constructor = false; #endif m_results.push_back(o); diff --git a/src/kademlia/refresh.cpp b/src/kademlia/refresh.cpp index 998e6efd1..7a04ffba3 100644 --- a/src/kademlia/refresh.cpp +++ b/src/kademlia/refresh.cpp @@ -45,7 +45,7 @@ observer_ptr bootstrap::new_observer(void* ptr , udp::endpoint const& ep, node_id const& id) { observer_ptr o(new (ptr) get_peers_observer(this, ep, id)); -#if defined TORRENT_DEBUG || defined TORRENT_RELEASE_ASSERTS +#if TORRENT_USE_ASSERTS o->m_in_constructor = false; #endif return o; diff --git a/src/pe_crypto.cpp b/src/pe_crypto.cpp index d42220dc6..08618eee9 100644 --- a/src/pe_crypto.cpp +++ b/src/pe_crypto.cpp @@ -130,7 +130,7 @@ namespace libtorrent TORRENT_ASSERT(to_process == 0); } -#if defined TORRENT_DEBUG || defined TORRENT_RELEASE_ASSERTS +#if TORRENT_USE_ASSERTS to_process = 0; for (std::vector::iterator i = iovec.begin(); i != iovec.end(); ++i) @@ -154,7 +154,7 @@ namespace libtorrent m_send_barriers.pop_front(); } -#if defined TORRENT_DEBUG || defined TORRENT_RELEASE_ASSERTS +#if TORRENT_USE_ASSERTS if (next_barrier != INT_MAX) { int overhead = 0; diff --git a/src/peer_list.cpp b/src/peer_list.cpp index 0d356f8f6..530ed8306 100644 --- a/src/peer_list.cpp +++ b/src/peer_list.cpp @@ -58,7 +58,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/bt_peer_connection.hpp" #endif -#if defined TORRENT_DEBUG || defined TORRENT_RELEASE_ASSERTS +#if TORRENT_USE_ASSERTS #include "libtorrent/socket_io.hpp" // for print_endpoint #endif diff --git a/src/session_handle.cpp b/src/session_handle.cpp index c0b200195..e0b6b692a 100644 --- a/src/session_handle.cpp +++ b/src/session_handle.cpp @@ -637,7 +637,7 @@ namespace libtorrent bencode(std::back_inserter(buf), ses_state); bdecode_node e; error_code ec; -#if defined TORRENT_DEBUG || defined TORRENT_RELEASE_ASSERTS || !defined BOOST_NO_EXCEPTIONS +#if TORRENT_USE_ASSERTS || !defined BOOST_NO_EXCEPTIONS int ret = #endif bdecode(&buf[0], &buf[0] + buf.size(), e, ec); @@ -664,7 +664,7 @@ namespace libtorrent std::pair buf = ses_state.data_section(); bdecode_node e; error_code ec; -#if defined TORRENT_DEBUG || defined TORRENT_RELEASE_ASSERTS || !defined BOOST_NO_EXCEPTIONS +#if TORRENT_USE_ASSERTS || !defined BOOST_NO_EXCEPTIONS int ret = #endif bdecode(buf.first, buf.first + buf.second, e, ec); diff --git a/src/torrent.cpp b/src/torrent.cpp index aae2a4c0c..1d3466483 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -851,7 +851,7 @@ namespace libtorrent TORRENT_ASSERT(m_abort); TORRENT_ASSERT(prev == NULL && next == NULL); -#if defined TORRENT_DEBUG || defined TORRENT_RELEASE_ASSERTS +#if TORRENT_USE_ASSERTS for (int i = 0; i < aux::session_interface::num_torrent_lists; ++i) { if (!m_links[i].in_list()) continue; @@ -8115,7 +8115,7 @@ namespace libtorrent TORRENT_ASSERT(m_info_hash == m_torrent_file->info_hash()); } -#if defined TORRENT_DEBUG || defined TORRENT_RELEASE_ASSERTS +#if TORRENT_USE_ASSERTS for (int i = 0; i < aux::session_interface::num_torrent_lists; ++i) { if (!m_links[i].in_list()) continue; @@ -11107,7 +11107,7 @@ namespace libtorrent st->state = static_cast(m_state); -#if defined TORRENT_DEBUG || defined TORRENT_RELEASE_ASSERTS +#if TORRENT_USE_ASSERTS if (st->state == torrent_status::finished || st->state == torrent_status::seeding) { diff --git a/src/udp_tracker_connection.cpp b/src/udp_tracker_connection.cpp index 38d37f34f..ff65da7bb 100644 --- a/src/udp_tracker_connection.cpp +++ b/src/udp_tracker_connection.cpp @@ -563,7 +563,7 @@ namespace libtorrent // info_hash std::copy(tracker_req().info_hash.begin(), tracker_req().info_hash.end() , view.data()); -#if defined TORRENT_DEBUG || defined TORRENT_RELEASE_ASSERTS +#if TORRENT_USE_ASSERTS TORRENT_ASSERT(view.size() == 20); #endif diff --git a/test/main.cpp b/test/main.cpp index 0cd3d477c..8f2f93076 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -102,10 +102,9 @@ LONG WINAPI seh_exception_handler(LPEXCEPTION_POINTERS p) { char stack_text[10000]; -#if (defined TORRENT_DEBUG && TORRENT_USE_ASSERTS) \ +#if TORRENT_USE_ASSERTS \ || defined TORRENT_ASIO_DEBUGGING \ || defined TORRENT_PROFILE_CALLS \ - || defined TORRENT_RELEASE_ASSERTS \ || defined TORRENT_DEBUG_BUFFERS print_backtrace(stack_text, sizeof(stack_text), 30 , p->ContextRecord); @@ -159,10 +158,9 @@ void sig_handler(int sig) { char stack_text[10000]; -#if (defined TORRENT_DEBUG && TORRENT_USE_ASSERTS) \ +#if TORRENT_USE_ASSERTS \ || defined TORRENT_ASIO_DEBUGGING \ || defined TORRENT_PROFILE_CALLS \ - || defined TORRENT_RELEASE_ASSERTS \ || defined TORRENT_DEBUG_BUFFERS print_backtrace(stack_text, sizeof(stack_text), 30); #elif defined __FUNCTION__ diff --git a/test/test_block_cache.cpp b/test/test_block_cache.cpp index fa4eb3796..4b23330eb 100644 --- a/test/test_block_cache.cpp +++ b/test/test_block_cache.cpp @@ -79,7 +79,7 @@ struct test_storage_impl : storage_interface static void nop() {} -#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS +#if TORRENT_USE_ASSERTS #define INITIALIZE_JOB(j) j.in_use = true; #else #define INITIALIZE_JOB(j) diff --git a/test/test_dht.cpp b/test/test_dht.cpp index ada236e6c..f00b166d0 100644 --- a/test/test_dht.cpp +++ b/test/test_dht.cpp @@ -2652,7 +2652,7 @@ TORRENT_TEST(rpc_invalid_error_msg) node, node_id())); observer_ptr o(new (rpc.allocate_observer()) null_observer(algo, source, node_id())); -#if defined TORRENT_DEBUG || defined TORRENT_RELEASE_ASSERTS +#if TORRENT_USE_ASSERTS o->m_in_constructor = false; #endif rpc.invoke(req, source, o);