support release asserts

This commit is contained in:
Arvid Norberg 2011-05-08 09:04:59 +00:00
parent aeb90205c7
commit a73960aa5a
21 changed files with 59 additions and 53 deletions

View File

@ -190,7 +190,7 @@ namespace libtorrent
void incoming_connection(boost::shared_ptr<socket_type> const& s);
#ifdef TORRENT_DEBUG
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
bool is_network_thread() const
{
#if defined BOOST_HAS_PTHREADS
@ -1008,7 +1008,7 @@ namespace libtorrent
// the main working thread
boost::scoped_ptr<thread> m_thread;
#if defined TORRENT_DEBUG && defined BOOST_HAS_PTHREADS
#if (defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS) && defined BOOST_HAS_PTHREADS
pthread_t m_network_thread;
#endif
};

View File

@ -64,7 +64,7 @@ struct TORRENT_EXPORT bandwidth_manager
void close();
#ifdef TORRENT_DEBUG
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
bool is_queued(bandwidth_socket const* peer) const;
#endif

View File

@ -302,7 +302,7 @@ public:
{
TORRENT_ASSERT(send_buffer_size() == m_encrypted_bytes);
m_RC4_handler->encrypt(buffer, size);
#ifdef TORRENT_DEBUG
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
m_encrypted_bytes += size;
TORRENT_ASSERT(m_encrypted_bytes == send_buffer_size() + size);
#endif
@ -445,7 +445,7 @@ private:
boost::scoped_ptr<sha1_hash> m_sync_hash;
#endif // #ifndef TORRENT_DISABLE_ENCRYPTION
#ifdef TORRENT_DEBUG
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
// this is set to true when the client's
// bitfield is sent to this peer
bool m_sent_bitfield;

View File

@ -232,11 +232,11 @@ namespace libtorrent
struct TORRENT_EXPORT disk_buffer_pool : boost::noncopyable
{
disk_buffer_pool(int block_size);
#ifdef TORRENT_DEBUG
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
~disk_buffer_pool();
#endif
#if defined TORRENT_DEBUG || defined TORRENT_DISK_STATS
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS || defined TORRENT_DISK_STATS
bool is_disk_buffer(char* buffer
, mutex::scoped_lock& l) const;
bool is_disk_buffer(char* buffer) const;
@ -296,7 +296,7 @@ namespace libtorrent
std::ofstream m_log;
private:
#endif
#ifdef TORRENT_DEBUG
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
int m_magic;
#endif
};

View File

@ -78,7 +78,7 @@ struct observer : boost::noncopyable
, flags(0)
{
TORRENT_ASSERT(a);
#ifdef TORRENT_DEBUG
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
m_in_constructor = true;
m_was_sent = false;
#endif
@ -162,7 +162,7 @@ protected:
public:
unsigned char flags;
#ifdef TORRENT_DEBUG
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
bool m_in_constructor:1;
bool m_was_sent:1;
#endif

View File

@ -88,8 +88,10 @@ public:
void add_our_id(entry& e);
#ifdef TORRENT_DEBUG
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
size_t allocation_size() const;
#endif
#ifdef TORRENT_DEBUG
void check_invariant() const;
#endif

View File

@ -1215,7 +1215,7 @@ namespace libtorrent
);
}
#ifdef TORRENT_DEBUG
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
public:
bool m_in_constructor:1;
bool m_disconnect_started:1;

View File

@ -144,9 +144,10 @@ namespace libtorrent
void set_seed(policy::peer* p, bool s);
#ifdef TORRENT_DEBUG
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
bool has_connection(const peer_connection* p);
#endif
#ifdef TORRENT_DEBUG
void check_invariant() const;
#endif

View File

@ -164,7 +164,7 @@ namespace libtorrent
void maybe_realloc_buffers(int which = 3);
bool maybe_clear_callback();
#ifdef TORRENT_DEBUG
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
#if defined BOOST_HAS_PTHREADS
mutable pthread_t m_thread;
#endif
@ -226,7 +226,7 @@ namespace libtorrent
// operations hanging on this socket
int m_outstanding_ops;
#ifdef TORRENT_DEBUG
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
bool m_started;
int m_magic;
int m_outstanding_when_aborted;

View File

@ -223,12 +223,12 @@ private:
, supports_specific_external(true)
, disabled(false)
{
#ifdef TORRENT_DEBUG
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
magic = 1337;
#endif
}
#ifdef TORRENT_DEBUG
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
~rootdevice()
{
TORRENT_ASSERT(magic == 1337);
@ -264,7 +264,7 @@ private:
mutable boost::shared_ptr<http_connection> upnp_connection;
#ifdef TORRENT_DEBUG
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
int magic;
#endif
void close() const

View File

@ -313,7 +313,7 @@ public:
ec = asio::error::would_block;
return 0;
}
#ifdef TORRENT_DEBUG
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
size_t buf_size = 0;
#endif
@ -323,7 +323,7 @@ public:
using asio::buffer_cast;
using asio::buffer_size;
add_read_buffer(buffer_cast<void*>(*i), buffer_size(*i));
#ifdef TORRENT_DEBUG
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
buf_size += buffer_size(*i);
#endif
}

View File

@ -59,7 +59,7 @@ namespace libtorrent
m_queued_bytes = 0;
}
#ifdef TORRENT_DEBUG
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
bool bandwidth_manager::is_queued(bandwidth_socket const* peer) const
{
for (queue_t::const_iterator i = m_queue.begin()

View File

@ -122,7 +122,7 @@ namespace libtorrent
peer_log("*** bt_peer_connection");
#endif
#ifdef TORRENT_DEBUG
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
m_in_constructor = false;
m_encrypted_bytes = 0;
#endif
@ -174,7 +174,7 @@ namespace libtorrent
m_quota[upload_channel] = 80;
#endif
#ifdef TORRENT_DEBUG
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
m_in_constructor = false;
m_encrypted_bytes = 0;
#endif
@ -446,7 +446,7 @@ namespace libtorrent
send_buf.begin);
std::generate(send_buf.begin + dh_key_len, send_buf.end, std::rand);
#ifdef TORRENT_DEBUG
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
m_encrypted_bytes += send_buf.left();
TORRENT_ASSERT(m_encrypted_bytes <= send_buffer_size());
#endif
@ -532,7 +532,7 @@ namespace libtorrent
write_pe_vc_cryptofield(send_buf, crypto_provide, pad_size);
m_RC4_handler->encrypt(send_buf.end - encrypt_size, encrypt_size);
#ifdef TORRENT_DEBUG
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
m_encrypted_bytes = send_buffer_size();
#endif
@ -561,7 +561,7 @@ namespace libtorrent
m_RC4_handler->encrypt(send_buf.end - buf_size, buf_size);
TORRENT_ASSERT(send_buffer_size() - buf_size == m_encrypted_bytes);
#ifdef TORRENT_DEBUG
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
m_encrypted_bytes += buf_size;
TORRENT_ASSERT(m_encrypted_bytes <= send_buffer_size());
#endif
@ -683,7 +683,7 @@ namespace libtorrent
{
TORRENT_ASSERT(!m_rc4_encrypted || send_buffer_size() == m_encrypted_bytes);
m_RC4_handler->encrypt(const_cast<char*>(buf), size);
#ifdef TORRENT_DEBUG
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
m_encrypted_bytes += size;
#endif
}
@ -719,7 +719,7 @@ namespace libtorrent
TORRENT_ASSERT(m_enc_send_buffer.end);
TORRENT_ASSERT(m_RC4_handler);
TORRENT_ASSERT(send_buffer_size() - m_enc_send_buffer.left() == m_encrypted_bytes);
#ifdef TORRENT_DEBUG
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
m_encrypted_bytes += m_enc_send_buffer.left();
TORRENT_ASSERT(m_encrypted_bytes <= send_buffer_size());
#endif
@ -2791,7 +2791,7 @@ namespace libtorrent
return;
}
m_rc4_encrypted = true;
#ifdef TORRENT_DEBUG
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
m_encrypted_bytes = send_buffer_size();
#endif
}
@ -3364,7 +3364,7 @@ namespace libtorrent
std::remove_if(m_payloads.begin(), m_payloads.end(), range_below_zero)
, m_payloads.end());
#if defined TORRENT_DEBUG && !defined TORRENT_DISABLE_ENCRYPTION
#if (defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS) && !defined TORRENT_DISABLE_ENCRYPTION
if (m_encrypted_bytes > 0)
{
if (m_rc4_encrypted)

View File

@ -86,12 +86,12 @@ namespace libtorrent
m_disk_access_log.open("disk_access.log", std::ios::trunc);
#endif
#ifdef TORRENT_DEBUG
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
m_magic = 0x1337;
#endif
}
#ifdef TORRENT_DEBUG
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
disk_buffer_pool::~disk_buffer_pool()
{
TORRENT_ASSERT(m_magic == 0x1337);
@ -99,7 +99,7 @@ namespace libtorrent
}
#endif
#if defined TORRENT_DEBUG || defined TORRENT_DISK_STATS
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS || defined TORRENT_DISK_STATS
bool disk_buffer_pool::is_disk_buffer(char* buffer
, mutex::scoped_lock& l) const
{

View File

@ -230,12 +230,13 @@ void rpc_manager::free_observer(void* ptr)
m_pool_allocator.free(ptr);
}
#ifdef TORRENT_DEBUG
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
size_t rpc_manager::allocation_size() const
{
return observer_size;
}
#endif
#ifdef TORRENT_DEBUG
void rpc_manager::check_invariant() const
{
for (transactions_t::const_iterator i = m_transactions.begin()
@ -470,7 +471,7 @@ bool rpc_manager::invoke(entry& e, udp::endpoint target_addr
if (m_send(m_userdata, e, target_addr, 1))
{
m_transactions.push_back(o);
#ifdef TORRENT_DEBUG
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
o->m_was_sent = true;
#endif
}

View File

@ -2287,7 +2287,7 @@ namespace libtorrent
return;
}
#ifdef TORRENT_DEBUG
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
pending_block pending_b = *b;
#endif

View File

@ -78,7 +78,7 @@ namespace
tcp::endpoint const& m_ep;
};
#ifdef TORRENT_DEBUG
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
struct match_peer_connection
{
match_peer_connection(peer_connection const& c) : m_conn(c) {}
@ -1444,7 +1444,7 @@ namespace libtorrent
}
}
#ifdef TORRENT_DEBUG
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
bool policy::has_connection(const peer_connection* c)
{
INVARIANT_CHECK;
@ -1464,7 +1464,9 @@ namespace libtorrent
, m_peers.end()
, match_peer_connection_or_endpoint(*c)) != m_peers.end();
}
#endif
#ifdef TORRENT_DEBUG
void policy::check_invariant() const
{
TORRENT_ASSERT(m_num_connect_candidates >= 0);

View File

@ -1476,7 +1476,7 @@ namespace aux {
// abort all connections
while (!m_connections.empty())
{
#ifdef TORRENT_DEBUG
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
int conn = m_connections.size();
#endif
(*m_connections.begin())->disconnect(errors::stopping_torrent);
@ -4238,7 +4238,7 @@ namespace aux {
if (options & session::delete_files)
t.delete_files();
#ifdef TORRENT_DEBUG
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
sha1_hash i_hash = t.torrent_file().info_hash();
#endif
#ifndef TORRENT_DISABLE_DHT

View File

@ -326,7 +326,7 @@ namespace libtorrent
std::memset(i->iov_base, 0, i->iov_len);
}
#ifdef TORRENT_DEBUG
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
int count_bufs(file::iovec_t const* bufs, int bytes)
{
int size = 0;
@ -1112,7 +1112,7 @@ ret:
int size = bufs_size(bufs, num_bufs);
TORRENT_ASSERT(size > 0);
#ifdef TORRENT_DEBUG
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
std::vector<file_slice> slices
= files().map_block(slot, offset, size);
TORRENT_ASSERT(!slices.empty());
@ -1148,7 +1148,7 @@ ret:
TORRENT_ASSERT(bytes_left >= 0);
#ifdef TORRENT_DEBUG
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
int counter = 0;
#endif
@ -1169,7 +1169,7 @@ ret:
if (file_bytes_left == 0) continue;
#ifdef TORRENT_DEBUG
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
TORRENT_ASSERT(int(slices.size()) > counter);
size_type slice_size = slices[counter].size;
TORRENT_ASSERT(slice_size == file_bytes_left);

View File

@ -610,7 +610,7 @@ namespace libtorrent
// update our torrent_info object and move the
// torrent from the old info-hash to the new one
// as we replace the torrent_info object
#ifdef TORRENT_DEBUG
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
int num_torrents = m_ses.m_torrents.size();
#endif
// we're about to erase the session's reference to this
@ -718,7 +718,7 @@ namespace libtorrent
// update our torrent_info object and move the
// torrent from the old info-hash to the new one
// as we replace the torrent_info object
#ifdef TORRENT_DEBUG
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
int num_torrents = m_ses.m_torrents.size();
#endif
m_ses.m_torrents.erase(m_torrent_file->info_hash());
@ -5237,7 +5237,7 @@ namespace libtorrent
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING
(*p->m_logger) << "*** CLOSING CONNECTION: " << ec.message() << "\n";
#endif
#ifdef TORRENT_DEBUG
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
std::size_t size = m_connections.size();
#endif
if (p->is_disconnecting())
@ -5308,7 +5308,7 @@ namespace libtorrent
peer_connection* p = *i;
++ret;
TORRENT_ASSERT(p->associated_torrent().lock().get() == this);
#ifdef TORRENT_DEBUG
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
int num_conns = m_connections.size();
#endif
p->disconnect(ec);

View File

@ -82,7 +82,7 @@ udp_socket::udp_socket(asio::io_service& ios
, m_abort(false)
, m_outstanding_ops(0)
{
#ifdef TORRENT_DEBUG
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
m_magic = 0x1337;
m_started = false;
m_outstanding_when_aborted = -1;
@ -109,13 +109,13 @@ udp_socket::~udp_socket()
TORRENT_ASSERT_VAL(m_v4_outstanding == 0, m_v4_outstanding);
TORRENT_ASSERT(m_magic == 0x1337);
TORRENT_ASSERT(!m_callback || !m_started);
#ifdef TORRENT_DEBUG
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
m_magic = 0;
#endif
TORRENT_ASSERT(m_outstanding_ops == 0);
}
#ifdef TORRENT_DEBUG
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
#define CHECK_MAGIC check_magic_ cm_(m_magic)
struct check_magic_
{