fix examples build. fix print formatting bugs. fix some gcc warnings

This commit is contained in:
Arvid Norberg 2015-04-25 04:22:51 +00:00
parent f7e4f83469
commit 821e34c795
17 changed files with 58 additions and 42 deletions

View File

@ -251,6 +251,9 @@ rule warnings ( properties * )
{
result += <cflags>-Wall ;
result += <cflags>-Wextra ;
# enable these warnings again, once the other ones are dealt with
result += <cflags>-Wno-sign-compare ;
}
if <toolset>msvc in $(properties)

View File

@ -1,7 +1,8 @@
#ifndef SESSION_VIEW_HPP_
#define SESSION_VIEW_HPP_
#include "libtorrent/session.hpp"
#include "libtorrent/session_stats.hpp"
#include <boost/cstdint.hpp>
namespace lt = libtorrent;

View File

@ -31,7 +31,7 @@ POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <libtorrent/session.hpp>
#include "libtorrent/session_stats.hpp"
using namespace libtorrent;

View File

@ -198,7 +198,7 @@ namespace libtorrent
// represents a window of a file in a torrent.
//
// The ``file_index`` refers to the index of the file (in the torrent_info).
// To get the path and filename, use ``file_at()`` and give the ``file_index``
// To get the path and filename, use ``file_path()`` and give the ``file_index``
// as argument. The ``offset`` is the byte offset in the file where the range
// starts, and ``size`` is the number of bytes this range is. The size + offset
// will never be greater than the file size.
@ -378,6 +378,7 @@ namespace libtorrent
reverse_iterator rbegin_deprecated() const { return m_files.rbegin(); }
reverse_iterator rend_deprecated() const { return m_files.rend(); }
iterator file_at_offset_deprecated(boost::int64_t offset) const;
file_entry at_deprecated(int index) const;
#endif // TORRENT_NO_DEPRECATE
// returns the number of files in the file_storage

View File

@ -37,6 +37,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <vector>
#include <assert.h>
#include <cstring>
#include <limits>
#include <boost/cstdint.hpp>
#include "libtorrent/invariant_check.hpp"
@ -57,20 +58,20 @@ namespace libtorrent
void operator+=(stat_channel const& s)
{
TORRENT_ASSERT(m_total_counter >= 0);
TORRENT_ASSERT(m_counter < (std::numeric_limits<boost::uint32_t>::max)() - s.m_counter);
m_counter += s.m_counter;
TORRENT_ASSERT(m_total_counter < (std::numeric_limits<boost::uint64_t>::max)() - s.m_counter);
m_total_counter += s.m_counter;
TORRENT_ASSERT(m_counter >= m_counter - s.m_counter);
}
void add(int count)
{
TORRENT_ASSERT(count >= 0);
TORRENT_ASSERT(m_counter < (std::numeric_limits<boost::uint32_t>::max)() - count);
m_counter += count;
TORRENT_ASSERT(m_counter >= m_counter - count);
TORRENT_ASSERT(m_total_counter < (std::numeric_limits<boost::uint64_t>::max)() - count);
m_total_counter += count;
TORRENT_ASSERT(m_total_counter >= m_total_counter - count);
}
// should be called once every second
@ -82,10 +83,8 @@ namespace libtorrent
void offset(boost::int64_t c)
{
TORRENT_ASSERT(c >= 0);
TORRENT_ASSERT(m_total_counter >= 0);
TORRENT_ASSERT(m_total_counter < (std::numeric_limits<boost::uint64_t>::max)() - c);
m_total_counter += c;
TORRENT_ASSERT(m_total_counter >= 0);
}
int counter() const { return m_counter; }

View File

@ -485,23 +485,23 @@ namespace libtorrent
// (``file_entry``) using the ``file_storage::at`` function, which takes
// an index and an iterator.
TORRENT_DEPRECATED
file_iterator begin_files() const TORRENT_DEPRECATED { return m_files.begin_deprecated(); }
file_iterator begin_files() const { return m_files.begin_deprecated(); }
TORRENT_DEPRECATED
file_iterator end_files() const TORRENT_DEPRECATED { return m_files.end_deprecated(); }
reverse_file_iterator rbegin_files() const TORRENT_DEPRECATED { return m_files.rbegin_deprecated(); }
file_iterator end_files() const { return m_files.end_deprecated(); }
reverse_file_iterator rbegin_files() const { return m_files.rbegin_deprecated(); }
TORRENT_DEPRECATED
reverse_file_iterator rend_files() const TORRENT_DEPRECATED { return m_files.rend_deprecated(); }
reverse_file_iterator rend_files() const { return m_files.rend_deprecated(); }
TORRENT_DEPRECATED
file_iterator file_at_offset(boost::int64_t offset) const TORRENT_DEPRECATED
file_iterator file_at_offset(boost::int64_t offset) const
{ return m_files.file_at_offset_deprecated(offset); }
TORRENT_DEPRECATED
file_entry file_at(int index) const TORRENT_DEPRECATED{ return m_files.at(index); }
file_entry file_at(int index) const { return m_files.at_deprecated(index); }
#endif // TORRENT_NO_DEPRECATE
// If you need index-access to files you can use the ``num_files()`` and
// ``file_at()`` to access files using indices.
// ``file_path()`` et.al. to access files using indices.
int num_files() const { return m_files.num_files(); }
// This function will map a piece index, a byte offset within that piece

View File

@ -262,7 +262,7 @@ const char* const job_action_name[] =
"hashing_done: %d\nmarked_for_deletion: %d\nneed_readback: %d\n"
"hash_passed: %d\nread_jobs: %d\njobs: %d\n"
"piece_log:\n"
, int(pe->piece), pe->refcount, pe->piece_refcount, pe->num_blocks
, int(pe->piece), pe->refcount, pe->piece_refcount, int(pe->num_blocks)
, int(pe->hashing), pe->hash, pe->hash ? pe->hash->offset : -1
, int(pe->cache_state), pe->cache_state >= 0 && pe->cache_state
< cached_piece_entry::num_lrus ? cache_state[pe->cache_state] : ""

View File

@ -2550,7 +2550,7 @@ namespace libtorrent
int consumed = m_enc_handler.decrypt(m_recv_buffer, bytes_transferred);
#ifndef TORRENT_DISABLE_LOGGING
if (consumed + bytes_transferred > 0)
peer_log("<== decrypted block [ s = %d ]", consumed + bytes_transferred);
peer_log("<== decrypted block [ s = %d ]", int(consumed + bytes_transferred));
#endif
if (bytes_transferred == SIZE_MAX)
{
@ -2721,7 +2721,7 @@ namespace libtorrent
std::size_t bytes_processed = syncoffset + 20;
#ifndef TORRENT_DISABLE_LOGGING
peer_log("*** sync point (hash) found at offset %d"
, m_sync_bytes_read + bytes_processed - 20);
, int(m_sync_bytes_read + bytes_processed - 20));
#endif
m_state = read_pe_skey_vc;
// skey,vc - 28 bytes
@ -2857,7 +2857,7 @@ namespace libtorrent
std::size_t bytes_processed = syncoffset + 8;
#ifndef TORRENT_DISABLE_LOGGING
peer_log("*** sync point (verification constant) found at offset %d"
, m_sync_bytes_read + bytes_processed - 8);
, int(m_sync_bytes_read + bytes_processed - 8));
#endif
int transferred_used = bytes_processed - recv_buffer.left() + bytes_transferred;
TORRENT_ASSERT(transferred_used <= int(bytes_transferred));

View File

@ -460,6 +460,11 @@ namespace libtorrent
#ifndef TORRENT_NO_DEPRECATE
file_entry file_storage::at(int index) const
{
return at_deprecated(index);
}
file_entry file_storage::at_deprecated(int index) const
{
TORRENT_ASSERT_PRECOND(index >= 0 && index < int(m_files.size()));
file_entry ret;
@ -890,7 +895,7 @@ namespace libtorrent
}
file_entry file_storage::at(file_storage::iterator i) const
{ return at(i - m_files.begin()); }
{ return at_deprecated(i - m_files.begin()); }
#endif // TORRENT_NO_DEPRECATE
void file_storage::reorder_file(int index, int dst)

View File

@ -377,7 +377,8 @@ namespace libtorrent
else
{
#ifndef TORRENT_DISABLE_LOGGING
peer_log("*** parsed chunk: %d header_size: %d", chunk_size, header_size);
peer_log("*** parsed chunk: %" PRId64 " header_size: %d"
, chunk_size, header_size);
#endif
TORRENT_ASSERT(bytes_transferred >= size_t(header_size - m_partial_chunk_header));
bytes_transferred -= header_size - m_partial_chunk_header;

View File

@ -1829,7 +1829,8 @@ namespace libtorrent
if (index >= int(m_have_piece.size()) || index < 0)
{
#ifndef TORRENT_DISABLE_LOGGING
peer_log("*** ERROR: [ have-metadata have_piece.size: %d ]", index, int(m_have_piece.size()));
peer_log("*** ERROR: [ have-metadata have_piece: %d size: %d ]"
, index, int(m_have_piece.size()));
#endif
disconnect(errors::invalid_have, op_bittorrent, 2);
return;
@ -4719,7 +4720,7 @@ namespace libtorrent
{
#ifndef TORRENT_DISABLE_LOGGING
peer_log("*** MUTUAL NO INTEREST [ t1: %d t2: %d ]"
, total_seconds(d1), total_seconds(d2));
, int(total_seconds(d1)), int(total_seconds(d2)));
#endif
disconnect(errors::timed_out_no_interest, op_bittorrent);
return;
@ -4771,7 +4772,7 @@ namespace libtorrent
// re-request the blocks.
#ifndef TORRENT_DISABLE_LOGGING
peer_log("*** PIECE_REQUEST TIMED OUT [ %d time: %d to: %d ]"
, (int)m_download_queue.size(), total_seconds(now - m_last_piece)
, int(m_download_queue.size()), int(total_seconds(now - m_last_piece))
, piece_timeout);
#endif
@ -5665,7 +5666,8 @@ namespace libtorrent
if (ret == 0 && !ec) ec = asio::error::eof;
#ifndef TORRENT_DISABLE_LOGGING
peer_log("<<< SYNC_READ [ max: %d ret: %d e: %s ]", max_receive, ret, ec ? ec.message().c_str() : "");
peer_log("<<< SYNC_READ [ max: %d ret: %d e: %s ]"
, max_receive, int(ret), ec ? ec.message().c_str() : "");
#endif
return ret;
}
@ -5783,7 +5785,7 @@ namespace libtorrent
}
#ifndef TORRENT_DISABLE_LOGGING
peer_log("<<< READ_AVAILABLE [ bytes: %d ]", buffer_size);
peer_log("<<< READ_AVAILABLE [ bytes: %d ]", int(buffer_size));
#endif
// at this point the ioctl told us the socket doesn't have any
@ -5891,7 +5893,7 @@ namespace libtorrent
TORRENT_ASSERT(is_single_thread());
#ifndef TORRENT_DISABLE_LOGGING
peer_log("<<< ON_RECEIVE_DATA [ bytes: %d error: %s ]"
, bytes_transferred, error.message().c_str());
, int(bytes_transferred), error.message().c_str());
#endif
// submit all disk jobs later
@ -5929,7 +5931,7 @@ namespace libtorrent
#ifndef TORRENT_DISABLE_LOGGING
peer_log("<<< ON_RECEIVE_DATA [ bytes: %d error: %s ]"
, bytes_transferred, error.message().c_str());
, int(bytes_transferred), error.message().c_str());
#endif
if (m_extension_outstanding_bytes > 0)

View File

@ -137,7 +137,7 @@ void receive_buffer::cut(int size, int packet_size, int offset)
TORRENT_ASSERT(int(m_recv_buffer.size()) >= m_recv_pos);
TORRENT_ASSERT(m_recv_pos >= size + offset);
TORRENT_ASSERT(offset >= 0);
TORRENT_ASSERT(m_recv_buffer.size() >= m_recv_end);
TORRENT_ASSERT(int(m_recv_buffer.size()) >= m_recv_end);
TORRENT_ASSERT(m_recv_start <= m_recv_end);
TORRENT_ASSERT(size >= 0);

View File

@ -532,7 +532,7 @@ namespace aux {
if (getrlimit(RLIMIT_NOFILE, &rl) == 0)
{
#ifndef TORRENT_DISABLE_LOGGING
session_log(" max number of open files: %d", rl.rlim_cur);
session_log(" max number of open files: %d", int(rl.rlim_cur));
#endif
// deduct some margin for epoll/kqueue, log files,
// futexes, shared objects etc.
@ -1035,7 +1035,7 @@ namespace aux {
#endif
#ifndef TORRENT_DISABLE_LOGGING
session_log(" aborting all torrents (%d)", m_torrents.size());
session_log(" aborting all torrents (%d)", int(m_torrents.size()));
#endif
// abort all torrents
for (torrent_map::iterator i = m_torrents.begin()
@ -1051,7 +1051,7 @@ namespace aux {
m_tracker_manager.abort_all_requests();
#ifndef TORRENT_DISABLE_LOGGING
session_log(" aborting all connections (%d)", m_connections.size());
session_log(" aborting all connections (%d)", int(m_connections.size()));
#endif
// abort all connections
while (!m_connections.empty())
@ -2389,7 +2389,7 @@ retry:
{
#ifndef TORRENT_DISABLE_LOGGING
session_log("%s <== INCOMING CONNECTION FAILED, could "
"not retrieve remote endpoint "
"not retrieve remote endpoint %s: %s"
, print_endpoint(endp).c_str(), ec.message().c_str());
#endif
return;

View File

@ -3488,7 +3488,7 @@ namespace libtorrent
, print_endpoint(p->ip()).c_str()
, p->rank(external, m_ses.listen_port())
, print_address(external.external_address(p->address())).c_str()
, m_ses.session_time() - p->last_connected);
, int(m_ses.session_time() - p->last_connected));
#endif
if (!connect_to_peer(p))

View File

@ -434,7 +434,7 @@ namespace libtorrent { namespace
{
#ifndef TORRENT_DISABLE_LOGGING
m_pc.peer_log("*** PEX [ waiting: %d seconds to next msg ]"
, total_seconds(seconds(60) - (now - m_last_msg)));
, int(total_seconds(seconds(60) - (now - m_last_msg))));
#endif
return;
}
@ -451,7 +451,8 @@ namespace libtorrent { namespace
if (now - milliseconds(delay) < global_last)
{
#ifndef TORRENT_DISABLE_LOGGING
m_pc.peer_log("*** PEX [ global-wait: %d ]", total_seconds(milliseconds(delay) - (now - global_last)));
m_pc.peer_log("*** PEX [ global-wait: %d ]"
, int(total_seconds(milliseconds(delay) - (now - global_last))));
#endif
return;
}

View File

@ -290,7 +290,7 @@ void web_peer_connection::write_request(peer_request const& r)
TORRENT_ASSERT(front.length > int(m_piece.size()));
#ifndef TORRENT_DISABLE_LOGGING
peer_log("*** RESTART-DATA: [ data: %d req: (%d, %d) ]"
peer_log("*** RESTART-DATA: [ data: %d req: (%d, %d) size: %d ]"
, int(m_piece.size()), int(front.piece), int(front.start)
, int (front.start + front.length - 1));
#endif
@ -430,7 +430,7 @@ bool web_peer_connection::maybe_harvest_block()
peer_request const& front_request = m_requests.front();
if (int(m_piece.size()) < front_request.length) return false;
TORRENT_ASSERT(int(m_piece.size() == front_request.length));
TORRENT_ASSERT(int(m_piece.size()) == front_request.length);
// each call to incoming_piece() may result in us becoming
// a seed. If we become a seed, all seeds we're connected to
@ -823,7 +823,8 @@ void web_peer_connection::on_receive(error_code const& error
else
{
#ifndef TORRENT_DISABLE_LOGGING
peer_log("*** parsed chunk: %d header_size: %d", chunk_size, header_size);
peer_log("*** parsed chunk: %" PRId64 " header_size: %d"
, chunk_size, header_size);
#endif
TORRENT_ASSERT(int(bytes_transferred) >= header_size - m_partial_chunk_header);
bytes_transferred -= header_size - m_partial_chunk_header;
@ -921,7 +922,8 @@ void web_peer_connection::on_receive(error_code const& error
std::vector<file_slice> sl = info.orig_files().map_block(
front_request.piece, front_request.start, front_request.start
+ front_request.length);
peer_log("INVALID HTTP RESPONSE [ in=(%d, %d-%d) expected=(%d, %d-%d) piece: %d ]"
peer_log("INVALID HTTP RESPONSE [ in=(%d, %" PRId64 "-%" PRId64 ") "
"expected=(%d, %" PRId64 "-%" PRId64 ") piece: %d ]"
, file_index, range_start, range_end, sl[0].file_index
, sl[0].offset, sl[0].offset + sl[0].size, front_request.piece);
#endif

View File

@ -104,5 +104,6 @@ int test_main()
TEST_EQUAL(merkle_num_nodes(8), 15);
TEST_EQUAL(merkle_num_nodes(16), 31);
return 0;
}