fix warnings

This commit is contained in:
Arvid Norberg 2015-05-19 03:13:49 +00:00
parent d18495eb39
commit 607e708bc4
19 changed files with 97 additions and 81 deletions

View File

@ -188,10 +188,6 @@ namespace libtorrent
void set_load_function(user_load_function_t fun)
{ m_user_load_torrent = fun; }
void queue_async_resume_data(boost::shared_ptr<torrent> const& t);
void done_async_resume();
void async_resume_dispatched(int num_popped_resume);
void init_peer_class_filter(bool unlimited_local);
#ifndef TORRENT_DISABLE_EXTENSIONS
@ -373,7 +369,7 @@ namespace libtorrent
int copy_pertinent_channels(peer_class_set const& set
, int channel, bandwidth_channel** dst, int max);
int use_quota_overhead(peer_class_set& set, int amount_down, int amount_up);
bool use_quota_overhead(bandwidth_channel* ch, int channel, int amount);
bool use_quota_overhead(bandwidth_channel* ch, int amount);
int create_peer_class(char const* name);
void delete_peer_class(int cid);
@ -1131,6 +1127,12 @@ namespace libtorrent
private:
// TODO: 2 the throttling of saving resume data could probably be
// factored out into a separate class
void queue_async_resume_data(boost::shared_ptr<torrent> const& t);
void done_async_resume();
void async_resume_dispatched();
// state for keeping track of external IPs
external_ip m_external_ip;

View File

@ -133,9 +133,8 @@ namespace libtorrent {
TORRENT_ASSERT(m_size > 1);
uintptr_t* ptr = m_storage;
header_t* hdr = reinterpret_cast<header_t*>(ptr);
TORRENT_ASSERT(reinterpret_cast<header_t*>(ptr)->len <= m_size);
ptr += header_size;
TORRENT_ASSERT(hdr->len <= m_size);
return reinterpret_cast<T*>(ptr);
}

View File

@ -59,6 +59,7 @@ namespace libtorrent
list_node* m_current;
};
// TOOD: 3 move the code into a .cpp file and add a unit test for linked_list
struct linked_list
{
linked_list(): m_first(0), m_last(0), m_size(0) {}
@ -68,7 +69,7 @@ namespace libtorrent
void erase(list_node* e)
{
#ifdef TORRENT_DEBUG
#if TORRENT_USE_ASSERTS
list_node* tmp = m_first;
bool found = false;
while (tmp)

View File

@ -1240,6 +1240,7 @@ void block_cache::insert_blocks(cached_piece_entry* pe, int block, file::iovec_t
if (flags & blocks_inc_refcount)
{
bool ret = inc_block_refcount(pe, block, ref_reading);
TORRENT_UNUSED(ret); // suppress warning
TORRENT_ASSERT(ret);
}
else
@ -1710,7 +1711,7 @@ int block_cache::copy_from_piece(cached_piece_entry* pe, disk_io_job* j
TORRENT_PIECE_ASSERT(size <= block_size(), pe);
const int start_block = block;
#ifdef TORRENT_DEBUG
#if TORRENT_USE_ASSERTS
int piece_size = j->storage->files()->piece_size(j->piece);
int blocks_in_piece = (piece_size + block_size() - 1) / block_size();
TORRENT_PIECE_ASSERT(start_block < blocks_in_piece, pe);
@ -1810,6 +1811,7 @@ bool block_cache::maybe_free_piece(cached_piece_entry* pe)
tailqueue jobs;
bool removed = evict_piece(pe, jobs);
TORRENT_UNUSED(removed); // suppress warning
TORRENT_PIECE_ASSERT(removed, pe);
TORRENT_PIECE_ASSERT(jobs.empty(), pe);

View File

@ -590,6 +590,9 @@ namespace libtorrent
, int crypto_field, int pad_size)
{
INVARIANT_CHECK;
#if !TORRENT_USE_ASSERTS
TORRENT_UNUSED(len);
#endif
TORRENT_ASSERT(crypto_field <= 0x03 && crypto_field > 0);
// vc,crypto_field,len(pad),pad, (len(ia))
@ -1953,14 +1956,15 @@ namespace libtorrent
TORRENT_ASSERT(m_message_handler[packet_type] != 0);
#ifdef TORRENT_DEBUG
#if TORRENT_USE_ASSERTS
boost::int64_t cur_payload_dl = statistics().last_payload_downloaded();
boost::int64_t cur_protocol_dl = statistics().last_protocol_downloaded();
#endif
// call the correct handler for this packet type
(this->*m_message_handler[packet_type])(received);
#ifdef TORRENT_DEBUG
#if TORRENT_USE_ASSERTS
TORRENT_ASSERT(statistics().last_payload_downloaded() - cur_payload_dl >= 0);
TORRENT_ASSERT(statistics().last_protocol_downloaded() - cur_protocol_dl >= 0);
boost::int64_t stats_diff = statistics().last_payload_downloaded() - cur_payload_dl +
@ -3521,7 +3525,7 @@ namespace libtorrent
disconnect(errors::torrent_removed, op_bittorrent, 1);
return;
}
#ifdef TORRENT_DEBUG
#if TORRENT_USE_ASSERTS
boost::int64_t cur_payload_dl = statistics().last_payload_downloaded();
boost::int64_t cur_protocol_dl = statistics().last_protocol_downloaded();
#endif
@ -3530,14 +3534,15 @@ namespace libtorrent
m_state = read_packet_size;
m_recv_buffer.reset(5);
}
#ifdef TORRENT_DEBUG
#if TORRENT_USE_ASSERTS
TORRENT_ASSERT(statistics().last_payload_downloaded() - cur_payload_dl >= 0);
TORRENT_ASSERT(statistics().last_protocol_downloaded() - cur_protocol_dl >= 0);
boost::int64_t stats_diff = statistics().last_payload_downloaded() - cur_payload_dl +
statistics().last_protocol_downloaded() - cur_protocol_dl;
TORRENT_ASSERT(stats_diff == boost::int64_t(bytes_transferred));
#endif
TORRENT_ASSERT(!m_recv_buffer.packet_finished());
#endif
return;
}

View File

@ -580,6 +580,8 @@ namespace libtorrent
// it should always suceed, since it's a dirty block, and
// should never have been marked as volatile
TORRENT_ASSERT(locked);
TORRENT_ASSERT(pe->cache_state != cached_piece_entry::volatile_read_lru);
TORRENT_UNUSED(locked);
flushing[num_flushing++] = i + block_base_index;
iov[iov_len].iov_base = pe->blocks[i].buf;
@ -1315,7 +1317,11 @@ namespace libtorrent
TORRENT_ASSERT(pe->blocks[block].buf);
int tmp = m_disk_cache.try_read(j, true);
// This should always succeed because we just checked to see there is a
// buffer for this block
TORRENT_ASSERT(tmp >= 0);
TORRENT_UNUSED(tmp);
maybe_issue_queued_read_jobs(pe, completed_jobs);
@ -1679,9 +1685,7 @@ namespace libtorrent
if (m_settings.get_int(settings_pack::cache_size) > 0
&& m_settings.get_bool(settings_pack::use_write_cache))
{
int block_size = m_disk_cache.block_size();
TORRENT_ASSERT((r.start % block_size) == 0);
TORRENT_ASSERT((r.start % m_disk_cache.block_size()) == 0);
if (storage->is_blocked(j))
{
@ -2103,6 +2107,7 @@ namespace libtorrent
tailqueue jobs;
bool ok = m_disk_cache.evict_piece(pe, jobs);
TORRENT_PIECE_ASSERT(ok, pe);
TORRENT_UNUSED(ok);
fail_jobs(storage_error(boost::asio::error::operation_aborted), jobs);
}

View File

@ -46,6 +46,10 @@ namespace libtorrent
, utp_socket_manager* sm
, bool peer_connection)
{
#ifndef TORRENT_USE_OPENSSL
TORRENT_UNUSED(ssl_context);
#endif
if (sm)
{
utp_stream* str;

View File

@ -88,7 +88,7 @@ namespace libtorrent { namespace
TORRENT_ASSERT(start + size <= 256);
// assert the identity of this function
#ifndef NDEBUG
#if TORRENT_USE_ASSERTS
std::pair<int, int> identity = req_to_offset(ret, total_size);
TORRENT_ASSERT(offset == identity);
#endif

View File

@ -5789,6 +5789,10 @@ namespace libtorrent
if (free_space > 0)
{
char* dst = m_send_buffer.append(buf, free_space);
// this should always succeed, because we checked how much space
// there was up-front
TORRENT_UNUSED(dst);
TORRENT_ASSERT(dst != 0);
size -= free_space;
buf += free_space;

View File

@ -834,7 +834,7 @@ namespace libtorrent
erase_peer(i, state);
}
}
#ifdef TORRENT_DEBUG
#if TORRENT_USE_ASSERTS
else
{
#if TORRENT_USE_I2P

View File

@ -2354,7 +2354,7 @@ get_out:
= TORRENT_ALLOCA(downloading_piece const*, partials_size);
int c = 0;
#if defined TORRENT_DEBUG && !defined TORRENT_DISABLE_INVARIANT_CHECKS
#if TORRENT_USE_ASSERTS && !defined TORRENT_DISABLE_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<downloading_piece>::const_iterator i
@ -2895,7 +2895,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 defined TORRENT_DEBUG && !defined TORRENT_DISABLE_INVARIANT_CHECKS
#if TORRENT_USE_ASSERTS && !defined TORRENT_DISABLE_INVARIANT_CHECKS
block_info const* info = blocks_for_piece(*i);
for (int k = 0; k < max_blocks; ++k)
{

View File

@ -622,7 +622,7 @@ namespace aux {
// this is called when one or all save resume alerts are
// popped off the alert queue
void session_impl::async_resume_dispatched(int num_popped_resume)
void session_impl::async_resume_dispatched()
{
INVARIANT_CHECK;
@ -1495,7 +1495,7 @@ namespace aux {
return num_copied;
}
bool session_impl::use_quota_overhead(bandwidth_channel* ch, int channel, int amount)
bool session_impl::use_quota_overhead(bandwidth_channel* ch, int amount)
{
ch->use_quota(amount);
return (ch->throttle() > 0 && ch->throttle() < amount);
@ -1509,11 +1509,12 @@ namespace aux {
{
peer_class* p = m_classes.at(set.class_at(i));
if (p == 0) continue;
bandwidth_channel* ch = &p->channel[peer_connection::download_channel];
if (use_quota_overhead(ch, peer_connection::download_channel, amount_down))
if (use_quota_overhead(ch, amount_down))
ret |= 1 << peer_connection::download_channel;
ch = &p->channel[peer_connection::upload_channel];
if (use_quota_overhead(ch, peer_connection::upload_channel, amount_up))
if (use_quota_overhead(ch, amount_up))
ret |= 1 << peer_connection::upload_channel;
}
return ret;
@ -6177,7 +6178,7 @@ retry:
// we can only issue more resume data jobs from
// the network thread
m_io_service.post(boost::bind(&session_impl::async_resume_dispatched
, this, num_resume));
, this));
}
}

View File

@ -7311,6 +7311,7 @@ namespace libtorrent
{
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
TORRENT_UNUSED(ignore_limit);
TORRENT_ASSERT(peerinfo);
TORRENT_ASSERT(peerinfo->connection == 0);
@ -7318,7 +7319,7 @@ namespace libtorrent
if (m_abort) return false;
peerinfo->last_connected = m_ses.session_time();
#ifdef TORRENT_DEBUG
#if TORRENT_USE_ASSERTS
if (!settings().get_bool(settings_pack::allow_multiple_connections_per_ip))
{
// this asserts that we don't have duplicates in the peer_list's peer list
@ -7333,7 +7334,7 @@ namespace libtorrent
|| (*i_)->type() != peer_connection::bittorrent_connection);
#endif
}
#endif
#endif // TORRENT_USE_ASSERTS
TORRENT_ASSERT(want_peers() || ignore_limit);
TORRENT_ASSERT(m_ses.num_connections()

View File

@ -501,6 +501,7 @@ namespace libtorrent { namespace
int ret = bdecode(&pex_msg[0], &pex_msg[0] + pex_msg.size(), m, ec);
TORRENT_ASSERT(ret == 0);
TORRENT_ASSERT(!ec);
TORRENT_UNUSED(ret);
int num_dropped = 0;
int num_added = 0;
bdecode_node e = m.dict_find_string("added");

View File

@ -511,7 +511,7 @@ void web_peer_connection::on_receive(error_code const& error
{
INVARIANT_CHECK;
#ifdef TORRENT_DEBUG
#if TORRENT_USE_ASSERTS
TORRENT_ASSERT(statistics().last_payload_downloaded()
+ statistics().last_protocol_downloaded() + bytes_transferred < size_t(INT_MAX));
int dl_target = statistics().last_payload_downloaded()
@ -525,11 +525,9 @@ void web_peer_connection::on_receive(error_code const& error
peer_log(peer_log_alert::info, "ERROR"
, "web_peer_connection error: %s", error.message().c_str());
#endif
#ifdef TORRENT_DEBUG
TORRENT_ASSERT(statistics().last_payload_downloaded()
+ statistics().last_protocol_downloaded()
== dl_target);
#endif
return;
}
@ -538,11 +536,9 @@ void web_peer_connection::on_receive(error_code const& error
for (;;)
{
#ifdef TORRENT_DEBUG
TORRENT_ASSERT(statistics().last_payload_downloaded()
+ statistics().last_protocol_downloaded() + int(bytes_transferred)
== dl_target);
#endif
buffer::const_interval recv_buffer = m_recv_buffer.get();
@ -565,11 +561,9 @@ void web_peer_connection::on_receive(error_code const& error
, "%s", std::string(recv_buffer.begin, recv_buffer.end).c_str());
#endif
disconnect(errors::http_parse_error, op_bittorrent, 2);
#ifdef TORRENT_DEBUG
TORRENT_ASSERT(statistics().last_payload_downloaded()
+ statistics().last_protocol_downloaded()
== dl_target);
#endif
return;
}
@ -582,11 +576,9 @@ void web_peer_connection::on_receive(error_code const& error
{
TORRENT_ASSERT(payload == 0);
TORRENT_ASSERT(bytes_transferred == 0);
#ifdef TORRENT_DEBUG
TORRENT_ASSERT(statistics().last_payload_downloaded()
+ statistics().last_protocol_downloaded() + int(bytes_transferred)
== dl_target);
#endif
break;
}
@ -594,11 +586,9 @@ void web_peer_connection::on_receive(error_code const& error
{
TORRENT_ASSERT(payload == 0);
TORRENT_ASSERT(bytes_transferred == 0);
#ifdef TORRENT_DEBUG
TORRENT_ASSERT(statistics().last_payload_downloaded()
+ statistics().last_protocol_downloaded() + int(bytes_transferred)
== dl_target);
#endif
break;
}

View File

@ -314,6 +314,7 @@ int test_main()
// test identify_client
// TODO: 3 move testing of identify_client out to its own test
TEST_EQUAL(identify_client(peer_id("-AZ123B-............")), "Azureus 1.2.3.11");
TEST_EQUAL(identify_client(peer_id("-AZ1230-............")), "Azureus 1.2.3");
TEST_EQUAL(identify_client(peer_id("S123--..............")), "Shadow 1.2.3");