diff --git a/include/libtorrent/alert_types.hpp b/include/libtorrent/alert_types.hpp index c810dd3f6..36c13c5ab 100755 --- a/include/libtorrent/alert_types.hpp +++ b/include/libtorrent/alert_types.hpp @@ -38,6 +38,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/socket.hpp" #include "libtorrent/peer_connection.hpp" #include "libtorrent/config.hpp" +#include "libtorrent/assert.hpp" namespace libtorrent { diff --git a/include/libtorrent/assert.hpp b/include/libtorrent/assert.hpp index 8ab605080..62425809e 100644 --- a/include/libtorrent/assert.hpp +++ b/include/libtorrent/assert.hpp @@ -30,9 +30,6 @@ POSSIBILITY OF SUCH DAMAGE. */ -#ifndef TORRENT_ASSERT_HPP_INCLUDED -#define TORRENT_ASSERT_HPP_INCLUDED - #include #ifndef NDEBUG @@ -43,7 +40,7 @@ POSSIBILITY OF SUCH DAMAGE. void assert_fail(const char* expr, int line, char const* file, char const* function); -#define assert(x) if (!(x)) assert_fail(#x, __LINE__, __FILE__, __PRETTY_FUNCTION__) +#define assert(x) if (x) {} else assert_fail(#x, __LINE__, __FILE__, __PRETTY_FUNCTION__) #endif @@ -53,5 +50,3 @@ void assert_fail(const char* expr, int line, char const* file, char const* funct #endif #endif -#endif - diff --git a/include/libtorrent/aux_/session_impl.hpp b/include/libtorrent/aux_/session_impl.hpp index 54a451892..0389bf3dc 100644 --- a/include/libtorrent/aux_/session_impl.hpp +++ b/include/libtorrent/aux_/session_impl.hpp @@ -83,6 +83,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/socket_type.hpp" #include "libtorrent/connection_queue.hpp" #include "libtorrent/disk_io_thread.hpp" +#include "libtorrent/assert.hpp" namespace libtorrent { diff --git a/include/libtorrent/bandwidth_manager.hpp b/include/libtorrent/bandwidth_manager.hpp index c46772bd8..03d4f65ae 100644 --- a/include/libtorrent/bandwidth_manager.hpp +++ b/include/libtorrent/bandwidth_manager.hpp @@ -33,9 +33,6 @@ POSSIBILITY OF SUCH DAMAGE. #ifndef TORRENT_BANDWIDTH_MANAGER_HPP_INCLUDED #define TORRENT_BANDWIDTH_MANAGER_HPP_INCLUDED -#include "libtorrent/socket.hpp" -#include "libtorrent/invariant_check.hpp" - #include #include #include @@ -44,6 +41,10 @@ POSSIBILITY OF SUCH DAMAGE. #include #include +#include "libtorrent/socket.hpp" +#include "libtorrent/invariant_check.hpp" +#include "libtorrent/assert.hpp" + using boost::weak_ptr; using boost::shared_ptr; using boost::intrusive_ptr; diff --git a/include/libtorrent/bencode.hpp b/include/libtorrent/bencode.hpp index a142b5864..9e670c10b 100755 --- a/include/libtorrent/bencode.hpp +++ b/include/libtorrent/bencode.hpp @@ -79,6 +79,8 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/entry.hpp" #include "libtorrent/config.hpp" +#include "libtorrent/assert.hpp" + #if defined(_MSC_VER) namespace std { diff --git a/include/libtorrent/buffer.hpp b/include/libtorrent/buffer.hpp index 0cb44225a..0f37edcbd 100644 --- a/include/libtorrent/buffer.hpp +++ b/include/libtorrent/buffer.hpp @@ -34,8 +34,9 @@ POSSIBILITY OF SUCH DAMAGE. //#define TORRENT_BUFFER_DEBUG -#include "libtorrent/invariant_check.hpp" #include +#include "libtorrent/invariant_check.hpp" +#include "libtorrent/assert.hpp" namespace libtorrent { diff --git a/include/libtorrent/fingerprint.hpp b/include/libtorrent/fingerprint.hpp index d7e5a5fc6..712be6979 100755 --- a/include/libtorrent/fingerprint.hpp +++ b/include/libtorrent/fingerprint.hpp @@ -37,6 +37,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include "libtorrent/peer_id.hpp" +#include "libtorrent/assert.hpp" namespace libtorrent { @@ -91,3 +92,4 @@ namespace libtorrent } #endif // TORRENT_FINGERPRINT_HPP_INCLUDED + diff --git a/include/libtorrent/http_connection.hpp b/include/libtorrent/http_connection.hpp index ed639b678..ccc145413 100644 --- a/include/libtorrent/http_connection.hpp +++ b/include/libtorrent/http_connection.hpp @@ -44,6 +44,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/socket.hpp" #include "libtorrent/http_tracker_connection.hpp" #include "libtorrent/time.hpp" +#include "libtorrent/assert.hpp" namespace libtorrent { diff --git a/include/libtorrent/ip_filter.hpp b/include/libtorrent/ip_filter.hpp index 8b1793c3a..7b8cc0e17 100644 --- a/include/libtorrent/ip_filter.hpp +++ b/include/libtorrent/ip_filter.hpp @@ -33,6 +33,9 @@ POSSIBILITY OF SUCH DAMAGE. #ifndef TORRENT_IP_FILTER_HPP #define TORRENT_IP_FILTER_HPP +#include +#include + #ifdef _MSC_VER #pragma warning(push, 1) #endif @@ -48,8 +51,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/config.hpp" #include "libtorrent/socket.hpp" -#include -#include +#include "libtorrent/assert.hpp" namespace libtorrent { diff --git a/include/libtorrent/kademlia/routing_table.hpp b/include/libtorrent/kademlia/routing_table.hpp index 45a7dd762..9e10a3483 100644 --- a/include/libtorrent/kademlia/routing_table.hpp +++ b/include/libtorrent/kademlia/routing_table.hpp @@ -50,6 +50,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include namespace libtorrent { namespace dht { diff --git a/include/libtorrent/peer_connection.hpp b/include/libtorrent/peer_connection.hpp index 2296c5ad5..5e65f767a 100755 --- a/include/libtorrent/peer_connection.hpp +++ b/include/libtorrent/peer_connection.hpp @@ -72,6 +72,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/policy.hpp" #include "libtorrent/socket_type.hpp" #include "libtorrent/intrusive_ptr_base.hpp" +#include "libtorrent/assert.hpp" namespace libtorrent { diff --git a/include/libtorrent/stat.hpp b/include/libtorrent/stat.hpp index 2424d5d6c..24e477a37 100755 --- a/include/libtorrent/stat.hpp +++ b/include/libtorrent/stat.hpp @@ -40,6 +40,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/size_type.hpp" #include "libtorrent/invariant_check.hpp" #include "libtorrent/config.hpp" +#include "libtorrent/assert.hpp" namespace libtorrent { diff --git a/include/libtorrent/time.hpp b/include/libtorrent/time.hpp index 2227fc932..27d61af9d 100644 --- a/include/libtorrent/time.hpp +++ b/include/libtorrent/time.hpp @@ -55,6 +55,7 @@ namespace libtorrent || _POSIX_MONOTONIC_CLOCK < 0)) || defined (TORRENT_USE_BOOST_DATE_TIME) #include +#include "libtorrent/assert.hpp" namespace libtorrent { @@ -85,6 +86,7 @@ namespace libtorrent #include #include +#include "libtorrent/assert.hpp" namespace libtorrent { @@ -170,6 +172,7 @@ namespace asio #include #include +#include "libtorrent/assert.hpp" // high precision timer for darwin intel and ppc @@ -249,6 +252,7 @@ namespace libtorrent #define WIN32_LEAN_AND_MEAN #endif #include +#include "libtorrent/assert.hpp" namespace libtorrent { @@ -335,6 +339,7 @@ namespace libtorrent #elif defined(_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 #include +#include "libtorrent/assert.hpp" namespace libtorrent { @@ -385,4 +390,4 @@ namespace libtorrent #endif #endif - + diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index b8f8d7ae4..bcc54899f 100755 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -68,6 +68,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/bandwidth_manager.hpp" #include "libtorrent/storage.hpp" #include "libtorrent/hasher.hpp" +#include "libtorrent/assert.hpp" namespace libtorrent { diff --git a/include/libtorrent/torrent_info.hpp b/include/libtorrent/torrent_info.hpp index 093d33781..492fda48d 100755 --- a/include/libtorrent/torrent_info.hpp +++ b/include/libtorrent/torrent_info.hpp @@ -58,6 +58,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/config.hpp" #include "libtorrent/time.hpp" #include "libtorrent/intrusive_ptr_base.hpp" +#include "libtorrent/assert.hpp" namespace libtorrent { @@ -321,8 +322,10 @@ namespace libtorrent entry m_extra_info; #ifndef NDEBUG + public: // this is set to true when seed_free() is called bool m_half_metadata; + private: #endif }; diff --git a/src/broadcast_socket.cpp b/src/broadcast_socket.cpp index b7e491283..a937fc11b 100644 --- a/src/broadcast_socket.cpp +++ b/src/broadcast_socket.cpp @@ -30,13 +30,15 @@ POSSIBILITY OF SUCH DAMAGE. */ -#include "libtorrent/socket.hpp" -#include "libtorrent/enum_net.hpp" -#include "libtorrent/broadcast_socket.hpp" #include #include #include +#include "libtorrent/socket.hpp" +#include "libtorrent/enum_net.hpp" +#include "libtorrent/broadcast_socket.hpp" +#include "libtorrent/assert.hpp" + namespace libtorrent { bool is_local(address const& a) diff --git a/src/escape_string.cpp b/src/escape_string.cpp index 673d56288..faff3de95 100755 --- a/src/escape_string.cpp +++ b/src/escape_string.cpp @@ -31,7 +31,6 @@ POSSIBILITY OF SUCH DAMAGE. */ #include "libtorrent/pch.hpp" -#include "libtorrent/assert.hpp" #include #include @@ -40,6 +39,8 @@ POSSIBILITY OF SUCH DAMAGE. #include #include +#include "libtorrent/assert.hpp" + namespace libtorrent { std::string unescape_string(std::string const& s) diff --git a/src/kademlia/closest_nodes.cpp b/src/kademlia/closest_nodes.cpp index 0c7d9d276..a3849ed69 100644 --- a/src/kademlia/closest_nodes.cpp +++ b/src/kademlia/closest_nodes.cpp @@ -35,6 +35,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include "libtorrent/assert.hpp" namespace libtorrent { namespace dht { diff --git a/src/natpmp.cpp b/src/natpmp.cpp index 0a5932a56..bdcabce9a 100644 --- a/src/natpmp.cpp +++ b/src/natpmp.cpp @@ -32,11 +32,13 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/pch.hpp" -#include -#include #include #include +#include "libtorrent/natpmp.hpp" +#include "libtorrent/io.hpp" +#include "libtorrent/assert.hpp" + using boost::bind; using namespace libtorrent; diff --git a/src/session.cpp b/src/session.cpp index dde39f4c7..1d7a070c2 100755 --- a/src/session.cpp +++ b/src/session.cpp @@ -182,6 +182,7 @@ namespace libtorrent , bool paused , storage_constructor_type sc) { + assert(!ti.m_half_metadata); boost::intrusive_ptr tip(new torrent_info(ti)); return m_impl->add_torrent(tip, save_path, resume_data , compact_mode, sc, paused); @@ -195,6 +196,7 @@ namespace libtorrent , bool paused , storage_constructor_type sc) { + assert(!ti->m_half_metadata); return m_impl->add_torrent(ti, save_path, resume_data , compact_mode, sc, paused); } diff --git a/src/socks5_stream.cpp b/src/socks5_stream.cpp index b1679c4ac..a6b5544e4 100644 --- a/src/socks5_stream.cpp +++ b/src/socks5_stream.cpp @@ -33,6 +33,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/pch.hpp" #include "libtorrent/socks5_stream.hpp" +#include "libtorrent/assert.hpp" namespace libtorrent { diff --git a/src/torrent.cpp b/src/torrent.cpp index 1a3083b7d..ddf8a9164 100755 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -72,6 +72,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/extensions.hpp" #include "libtorrent/aux_/session_impl.hpp" #include "libtorrent/instantiate_connection.hpp" +#include "libtorrent/assert.hpp" using namespace libtorrent; using boost::tuples::tuple; @@ -203,9 +204,6 @@ namespace libtorrent , m_num_uploads(0) , m_max_connections((std::numeric_limits::max)()) { -#ifndef NDEBUG - m_initial_done = 0; -#endif m_policy.reset(new policy(this)); } @@ -266,10 +264,6 @@ namespace libtorrent , m_num_uploads(0) , m_max_connections((std::numeric_limits::max)()) { -#ifndef NDEBUG - m_initial_done = 0; -#endif - INVARIANT_CHECK; if (name) m_name.reset(new std::string(name)); @@ -2215,14 +2209,12 @@ namespace libtorrent } pause(); } -#ifndef NDEBUG - m_initial_done = boost::get<0>(bytes_done()); -#endif return done; } std::pair torrent::check_files() { + assert(m_torrent_file->is_valid()); INVARIANT_CHECK; assert(m_owning_storage.get()); @@ -2250,9 +2242,6 @@ namespace libtorrent pause(); } -#ifndef NDEBUG - m_initial_done = boost::get<0>(bytes_done()); -#endif return progress; } @@ -2261,6 +2250,7 @@ namespace libtorrent { session_impl::mutex_t::scoped_lock l(m_ses.m_mutex); + assert(m_torrent_file->is_valid()); INVARIANT_CHECK; if (!is_seed()) @@ -2320,9 +2310,6 @@ namespace libtorrent } } } -#ifndef NDEBUG - m_initial_done = boost::get<0>(bytes_done()); -#endif } alert_manager& torrent::alerts() const @@ -2385,9 +2372,6 @@ namespace libtorrent #ifndef NDEBUG void torrent::check_invariant() const { -// size_type download = m_stat.total_payload_download(); -// size_type done = boost::get<0>(bytes_done()); -// assert(download >= done - m_initial_done); int num_uploads = 0; std::map num_requests; for (const_peer_iterator i = begin(); i != end(); ++i) diff --git a/test/setup_transfer.cpp b/test/setup_transfer.cpp index 6d7ca423f..a0b79580b 100644 --- a/test/setup_transfer.cpp +++ b/test/setup_transfer.cpp @@ -1,12 +1,15 @@ +#include + #include "libtorrent/session.hpp" #include "libtorrent/hasher.hpp" -#include + #include #include #include #include #include "test.hpp" +#include "libtorrent/assert.hpp" using boost::filesystem::remove_all; using boost::filesystem::create_directory; @@ -86,7 +89,7 @@ setup_transfer(session* ses1, session* ses2, session* ses3 // file pool will complain if two torrents are trying to // use the same files sha1_hash info_hash = t->info_hash(); - torrent_handle tor1 = ses1->add_torrent(t, "./tmp1"); + torrent_handle tor1 = ses1->add_torrent(clone_ptr(t), "./tmp1"); torrent_handle tor2; torrent_handle tor3; if (ses3) tor3 = ses3->add_torrent(clone_ptr(t), "./tmp3");