From 89c3db477d70360b90adbc4dca9abb4b5c0322e7 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Wed, 25 Sep 2013 19:44:29 +0000 Subject: [PATCH] merge build fix with C++11 from RC_0_16 --- ChangeLog | 1 + examples/client_test.cpp | 8 ++++---- examples/dump_torrent.cpp | 2 +- examples/fragmentation_test.cpp | 4 ++-- examples/rss_reader.cpp | 2 +- include/libtorrent/aux_/session_impl.hpp | 2 +- include/libtorrent/error_code.hpp | 16 ++++++++++------ include/libtorrent/i2p_stream.hpp | 6 +++--- include/libtorrent/socks5_stream.hpp | 6 +++--- include/libtorrent/upnp.hpp | 6 +++--- src/disk_io_thread.cpp | 8 ++++---- src/error_code.cpp | 8 ++++---- src/file.cpp | 2 +- src/http_tracker_connection.cpp | 8 ++++---- src/i2p_stream.cpp | 4 ++-- src/lazy_bdecode.cpp | 2 +- src/socks5_stream.cpp | 4 ++-- src/time.cpp | 2 +- src/upnp.cpp | 4 ++-- test/test_bencoding.cpp | 4 ++-- test/test_rss.cpp | 2 +- test/test_torrent_parse.cpp | 2 +- test/test_web_seed.cpp | 2 +- tools/parse_request_log.cpp | 2 +- 24 files changed, 56 insertions(+), 51 deletions(-) diff --git a/ChangeLog b/ChangeLog index a8f2a3121..077b80cd9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -24,6 +24,7 @@ * fix uTP edge case where udp socket buffer fills up * fix nagle implementation in uTP + * fix building with C++11 * fix IPv6 support in UDP socket (uTP) * fix mingw build issues * increase max allowed outstanding piece requests from peers diff --git a/examples/client_test.cpp b/examples/client_test.cpp index d3115c5a7..d37c6077e 100644 --- a/examples/client_test.cpp +++ b/examples/client_test.cpp @@ -2134,7 +2134,7 @@ int main(int argc, char* argv[]) progress_bar_color = "32"; // green } - snprintf(str, sizeof(str), " %-10s: %s%-11"PRId64"%s Bytes %6.2f%% %s\n" + snprintf(str, sizeof(str), " %-10s: %s%-11" PRId64 "%s Bytes %6.2f%% %s\n" , s.sequential_download?"sequential":"progress" , esc("32"), s.total_done, esc("0") , s.progress_ppm / 10000.f @@ -2197,8 +2197,8 @@ int main(int argc, char* argv[]) out += str; snprintf(str, sizeof(str), "==== waste: %s fail: %s unchoked: %d / %d " - "bw queues: %8d (%d) | %8d (%d) disk queues: %d | %d cache: w: %"PRId64"%% r: %"PRId64"%% " - "size: %s (%s) / %s dq: %"PRId64" ===\n" + "bw queues: %8d (%d) | %8d (%d) disk queues: %d | %d cache: w: %" PRId64 "%% r: %" PRId64 "%% " + "size: %s (%s) / %s dq: %" PRId64 " ===\n" , add_suffix(sess_stat.total_redundant_bytes).c_str() , add_suffix(sess_stat.total_failed_bytes).c_str() , sess_stat.num_unchoked, sess_stat.allowed_upload_slots @@ -2224,7 +2224,7 @@ int main(int argc, char* argv[]) if (show_dht_status) { snprintf(str, sizeof(str), "DHT nodes: %d DHT cached nodes: %d " - "total DHT size: %"PRId64" total observers: %d\n" + "total DHT size: %" PRId64 " total observers: %d\n" , sess_stat.dht_nodes, sess_stat.dht_node_cache, sess_stat.dht_global_nodes , sess_stat.dht_total_allocations); out += str; diff --git a/examples/dump_torrent.cpp b/examples/dump_torrent.cpp index 6c50eeba7..af60264c8 100644 --- a/examples/dump_torrent.cpp +++ b/examples/dump_torrent.cpp @@ -166,7 +166,7 @@ std::string print_entry(libtorrent::lazy_entry const& e, bool single_line = fals case lazy_entry::int_t: { char str[100]; - snprintf(str, sizeof(str), "%"PRId64, e.int_value()); + snprintf(str, sizeof(str), "%" PRId64, e.int_value()); return str; } case lazy_entry::string_t: diff --git a/examples/fragmentation_test.cpp b/examples/fragmentation_test.cpp index 9c9a9d3b5..12abad848 100644 --- a/examples/fragmentation_test.cpp +++ b/examples/fragmentation_test.cpp @@ -83,7 +83,7 @@ int main(int argc, char* argv[]) for (int i = 0; i < ti->num_files(); ++i) { if (ti->file_at(i).size == files[i].first) continue; - fprintf(stderr, "Files for this torrent are missing or incomplete: %s was %"PRId64" bytes, expected %"PRId64" bytes\n" + fprintf(stderr, "Files for this torrent are missing or incomplete: %s was %" PRId64 " bytes, expected %" PRId64 " bytes\n" , ti->files().file_path(ti->file_at(i)).c_str(), files[i].first, ti->file_at(i).size); return 1; } @@ -120,7 +120,7 @@ int main(int argc, char* argv[]) for (int i = 0; i < pieces.size(); ++i) { - fprintf(f, "%d %"PRId64"\n", pieces[i].first, pieces[i].second); + fprintf(f, "%d %" PRId64 "\n", pieces[i].first, pieces[i].second); } fclose(f); diff --git a/examples/rss_reader.cpp b/examples/rss_reader.cpp index ffe3aa3f9..26db6b7d6 100644 --- a/examples/rss_reader.cpp +++ b/examples/rss_reader.cpp @@ -113,7 +113,7 @@ void print_feed(feed_status const& f) , end(f.items.end()); i != end; ++i) { printf("\033[32m%s\033[0m\n------------------------------------------------------\n" - " url: %s\n size: %"PRId64"\n info-hash: %s\n uuid: %s\n description: %s\n" + " url: %s\n size: %" PRId64 "\n info-hash: %s\n uuid: %s\n description: %s\n" " comment: %s\n category: %s\n" , i->title.c_str(), i->url.c_str(), i->size , i->info_hash.is_all_zeros() ? "" : to_hex(i->info_hash.to_string()).c_str() diff --git a/include/libtorrent/aux_/session_impl.hpp b/include/libtorrent/aux_/session_impl.hpp index 6896fb23f..e471ea0cf 100644 --- a/include/libtorrent/aux_/session_impl.hpp +++ b/include/libtorrent/aux_/session_impl.hpp @@ -437,7 +437,7 @@ namespace libtorrent #endif // TORRENT_NO_DEPRECATE #ifndef TORRENT_DISABLE_DHT - bool is_dht_running() const { return m_dht; } + bool is_dht_running() const { return m_dht.get(); } #endif #if TORRENT_USE_I2P diff --git a/include/libtorrent/error_code.hpp b/include/libtorrent/error_code.hpp index 5a4459a30..dd5f14aa9 100644 --- a/include/libtorrent/error_code.hpp +++ b/include/libtorrent/error_code.hpp @@ -50,6 +50,10 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/string_util.hpp" // for allocate_string_copy #include // free +#ifndef BOOST_SYSTEM_NOEXCEPT +#define BOOST_SYSTEM_NOEXCEPT throw() +#endif + namespace libtorrent { @@ -496,17 +500,17 @@ namespace libtorrent struct TORRENT_EXPORT libtorrent_error_category : boost::system::error_category { - virtual const char* name() const throw(); - virtual std::string message(int ev) const throw(); - virtual boost::system::error_condition default_error_condition(int ev) const throw() + virtual const char* name() const BOOST_SYSTEM_NOEXCEPT; + virtual std::string message(int ev) const BOOST_SYSTEM_NOEXCEPT; + virtual boost::system::error_condition default_error_condition(int ev) const BOOST_SYSTEM_NOEXCEPT { return boost::system::error_condition(ev, *this); } }; struct TORRENT_EXPORT http_error_category : boost::system::error_category { - virtual const char* name() const throw(); - virtual std::string message(int ev) const throw(); - virtual boost::system::error_condition default_error_condition(int ev) const throw() + virtual const char* name() const BOOST_SYSTEM_NOEXCEPT; + virtual std::string message(int ev) const BOOST_SYSTEM_NOEXCEPT; + virtual boost::system::error_condition default_error_condition(int ev) const BOOST_SYSTEM_NOEXCEPT { return boost::system::error_condition(ev, *this); } }; diff --git a/include/libtorrent/i2p_stream.hpp b/include/libtorrent/i2p_stream.hpp index 1f87fa626..a749c9d03 100644 --- a/include/libtorrent/i2p_stream.hpp +++ b/include/libtorrent/i2p_stream.hpp @@ -67,9 +67,9 @@ namespace libtorrent { struct TORRENT_EXPORT i2p_error_category : boost::system::error_category { - virtual const char* name() const; - virtual std::string message(int ev) const; - virtual boost::system::error_condition default_error_condition(int ev) const + virtual const char* name() const BOOST_SYSTEM_NOEXCEPT; + virtual std::string message(int ev) const BOOST_SYSTEM_NOEXCEPT; + virtual boost::system::error_condition default_error_condition(int ev) const BOOST_SYSTEM_NOEXCEPT { return boost::system::error_condition(ev, *this); } }; diff --git a/include/libtorrent/socks5_stream.hpp b/include/libtorrent/socks5_stream.hpp index f5c109f79..d374aeab4 100644 --- a/include/libtorrent/socks5_stream.hpp +++ b/include/libtorrent/socks5_stream.hpp @@ -68,9 +68,9 @@ typedef asio::error::error_category socks_error_category; struct TORRENT_EXTRA_EXPORT socks_error_category : boost::system::error_category { - virtual const char* name() const; - virtual std::string message(int ev) const; - virtual boost::system::error_condition default_error_condition(int ev) const + virtual const char* name() const BOOST_SYSTEM_NOEXCEPT; + virtual std::string message(int ev) const BOOST_SYSTEM_NOEXCEPT; + virtual boost::system::error_condition default_error_condition(int ev) const BOOST_SYSTEM_NOEXCEPT { return boost::system::error_condition(ev, *this); } }; diff --git a/include/libtorrent/upnp.hpp b/include/libtorrent/upnp.hpp index 9e6eedef0..b8a733060 100644 --- a/include/libtorrent/upnp.hpp +++ b/include/libtorrent/upnp.hpp @@ -99,9 +99,9 @@ namespace libtorrent struct TORRENT_EXPORT upnp_error_category : boost::system::error_category { - virtual const char* name() const; - virtual std::string message(int ev) const; - virtual boost::system::error_condition default_error_condition(int ev) const + virtual const char* name() const BOOST_SYSTEM_NOEXCEPT; + virtual std::string message(int ev) const BOOST_SYSTEM_NOEXCEPT; + virtual boost::system::error_condition default_error_condition(int ev) const BOOST_SYSTEM_NOEXCEPT { return boost::system::error_condition(ev, *this); } }; diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index 330a5e7e2..a04c7bb7d 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -611,7 +611,7 @@ namespace libtorrent else { TORRENT_ASSERT(buf); - file::iovec_t b = { buf.get(), buffer_size }; + file::iovec_t b = { buf.get(), size_t(buffer_size) }; int ret = p.storage->write_impl(&b, p.piece, (std::min)( i * m_block_size, piece_size) - buffer_size, 1); if (ret > 0) ++num_write_calls; @@ -811,7 +811,7 @@ namespace libtorrent if (buf) { l.unlock(); - file::iovec_t b = { buf.get(), buffer_size }; + file::iovec_t b = { buf.get(), size_t(buffer_size) }; ret = p.storage->read_impl(&b, p.piece, start_block * m_block_size, 1); l.lock(); ++m_cache_stats.reads; @@ -2025,7 +2025,7 @@ namespace libtorrent } else if (ret == -2) { - file::iovec_t b = { j.buffer, j.buffer_size }; + file::iovec_t b = { j.buffer, size_t(j.buffer_size) }; ret = j.storage->read_impl(&b, j.piece, j.offset, 1); if (ret < 0) { @@ -2138,7 +2138,7 @@ namespace libtorrent { l.unlock(); ptime start = time_now_hires(); - file::iovec_t iov = {j.buffer, j.buffer_size}; + file::iovec_t iov = {j.buffer, size_t(j.buffer_size) }; ret = j.storage->write_impl(&iov, j.piece, j.offset, 1); l.lock(); if (ret < 0) diff --git a/src/error_code.cpp b/src/error_code.cpp index c0950583b..f6dba63f0 100644 --- a/src/error_code.cpp +++ b/src/error_code.cpp @@ -40,12 +40,12 @@ namespace libtorrent { #if BOOST_VERSION >= 103500 - const char* libtorrent_error_category::name() const throw() + const char* libtorrent_error_category::name() const BOOST_SYSTEM_NOEXCEPT { return "libtorrent error"; } - std::string libtorrent_error_category::message(int ev) const throw() + std::string libtorrent_error_category::message(int ev) const BOOST_SYSTEM_NOEXCEPT { static char const* msgs[] = { @@ -275,12 +275,12 @@ namespace libtorrent return http_category; } - const char* http_error_category::name() const throw() + const char* http_error_category::name() const BOOST_SYSTEM_NOEXCEPT { return "http error"; } - std::string http_error_category::message(int ev) const throw() + std::string http_error_category::message(int ev) const BOOST_SYSTEM_NOEXCEPT { std::string ret; ret += to_string(ev).elems; diff --git a/src/file.cpp b/src/file.cpp index 953e84352..2c4228992 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -1084,7 +1084,7 @@ namespace libtorrent 0, // start offset 0, // length (0 = until EOF) getpid(), // owner - (mode & write_only) ? F_WRLCK : F_RDLCK, // lock type + short((mode & write_only) ? F_WRLCK : F_RDLCK), // lock type SEEK_SET // whence }; if (fcntl(m_fd, F_SETLK, &l) != 0) diff --git a/src/http_tracker_connection.cpp b/src/http_tracker_connection.cpp index 378ce5914..5001edc55 100644 --- a/src/http_tracker_connection.cpp +++ b/src/http_tracker_connection.cpp @@ -141,10 +141,10 @@ namespace libtorrent , "info_hash=%s" "&peer_id=%s" "&port=%d" - "&uploaded=%"PRId64 - "&downloaded=%"PRId64 - "&left=%"PRId64 - "&corrupt=%"PRId64 + "&uploaded=%" PRId64 + "&downloaded=%" PRId64 + "&left=%" PRId64 + "&corrupt=%" PRId64 "&key=%X" "%s%s" // event "&numwant=%d" diff --git a/src/i2p_stream.cpp b/src/i2p_stream.cpp index 68fa565fa..19620ee17 100644 --- a/src/i2p_stream.cpp +++ b/src/i2p_stream.cpp @@ -48,12 +48,12 @@ namespace libtorrent i2p_error_category i2p_category; - const char* i2p_error_category::name() const + const char* i2p_error_category::name() const BOOST_SYSTEM_NOEXCEPT { return "i2p error"; } - std::string i2p_error_category::message(int ev) const + std::string i2p_error_category::message(int ev) const BOOST_SYSTEM_NOEXCEPT { static char const* messages[] = { diff --git a/src/lazy_bdecode.cpp b/src/lazy_bdecode.cpp index 9b1d9950c..c166fd186 100644 --- a/src/lazy_bdecode.cpp +++ b/src/lazy_bdecode.cpp @@ -491,7 +491,7 @@ namespace libtorrent case lazy_entry::int_t: { char str[100]; - snprintf(str, sizeof(str), "%"PRId64, e.int_value()); + snprintf(str, sizeof(str), "%" PRId64, e.int_value()); return str; } case lazy_entry::string_t: diff --git a/src/socks5_stream.cpp b/src/socks5_stream.cpp index d49bff876..205eec45e 100644 --- a/src/socks5_stream.cpp +++ b/src/socks5_stream.cpp @@ -42,12 +42,12 @@ namespace libtorrent socks_error_category socks_category; #if BOOST_VERSION >= 103500 - const char* socks_error_category::name() const + const char* socks_error_category::name() const BOOST_SYSTEM_NOEXCEPT { return "socks error"; } - std::string socks_error_category::message(int ev) const + std::string socks_error_category::message(int ev) const BOOST_SYSTEM_NOEXCEPT { static char const* messages[] = { diff --git a/src/time.cpp b/src/time.cpp index 84b1855d9..c3f04dcb5 100644 --- a/src/time.cpp +++ b/src/time.cpp @@ -82,7 +82,7 @@ namespace libtorrent { static const ptime start = time_now_hires(); char ret[200]; - snprintf(ret, sizeof(ret), "%"PRId64, total_microseconds(time_now_hires() - start)); + snprintf(ret, sizeof(ret), "%" PRId64, total_microseconds(time_now_hires() - start)); return ret; } } diff --git a/src/upnp.cpp b/src/upnp.cpp index c2139583b..d560cfc09 100644 --- a/src/upnp.cpp +++ b/src/upnp.cpp @@ -1099,12 +1099,12 @@ namespace #if BOOST_VERSION >= 103500 -const char* upnp_error_category::name() const +const char* upnp_error_category::name() const BOOST_SYSTEM_NOEXCEPT { return "UPnP error"; } -std::string upnp_error_category::message(int ev) const +std::string upnp_error_category::message(int ev) const BOOST_SYSTEM_NOEXCEPT { int num_errors = sizeof(error_codes) / sizeof(error_codes[0]); error_code_t* end = error_codes + num_errors; diff --git a/test/test_bencoding.cpp b/test/test_bencoding.cpp index bf484090b..912827e34 100644 --- a/test/test_bencoding.cpp +++ b/test/test_bencoding.cpp @@ -180,7 +180,7 @@ int test_main() // test invalid encoding { - char buf[] = + unsigned char buf[] = { 0x64 , 0x31 , 0x3a , 0x61 , 0x64 , 0x32 , 0x3a , 0x69 , 0x64 , 0x32 , 0x30 , 0x3a , 0x2a , 0x21 , 0x19 , 0x89 , 0x9f , 0xcd , 0x5f , 0xc9 , 0xbc , 0x80 , 0xc1 , 0x76 @@ -198,7 +198,7 @@ int test_main() printf("%s\n", buf); lazy_entry e; error_code ec; - int ret = lazy_bdecode(buf, buf + sizeof(buf), e, ec); + int ret = lazy_bdecode((char*)buf, (char*)buf + sizeof(buf), e, ec); TEST_CHECK(ret == -1); } return 0; diff --git a/test/test_rss.cpp b/test/test_rss.cpp index 9f4b07333..43eb1ecf5 100644 --- a/test/test_rss.cpp +++ b/test/test_rss.cpp @@ -55,7 +55,7 @@ void print_feed(feed_status const& f) , end(f.items.end()); i != end; ++i) { fprintf(stderr, "\033[32m%s\033[0m\n------------------------------------------------------\n" - " url: %s\n size: %"PRId64"\n info-hash: %s\n uuid: %s\n description: %s\n" + " url: %s\n size: %" PRId64 "\n info-hash: %s\n uuid: %s\n description: %s\n" " comment: %s\n category: %s\n" , i->title.c_str(), i->url.c_str(), i->size , i->info_hash.is_all_zeros() ? "" : to_hex(i->info_hash.to_string()).c_str() diff --git a/test/test_torrent_parse.cpp b/test/test_torrent_parse.cpp index cfc542700..7ae65b834 100644 --- a/test/test_torrent_parse.cpp +++ b/test/test_torrent_parse.cpp @@ -429,7 +429,7 @@ int test_main() int first = ti->map_file(i, 0, 0).piece; int last = ti->map_file(i, (std::max)(fs.file_size(i)-1, size_type(0)), 0).piece; int flags = fs.file_flags(i); - fprintf(stderr, " %11"PRId64" %c%c%c%c [ %4d, %4d ] %7u %s %s %s%s\n" + fprintf(stderr, " %11" PRId64 " %c%c%c%c [ %4d, %4d ] %7u %s %s %s%s\n" , fs.file_size(i) , (flags & file_storage::flag_pad_file)?'p':'-' , (flags & file_storage::flag_executable)?'x':'-' diff --git a/test/test_web_seed.cpp b/test/test_web_seed.cpp index b607f0934..31aee3f9b 100644 --- a/test/test_web_seed.cpp +++ b/test/test_web_seed.cpp @@ -197,7 +197,7 @@ void save_file(char const* filename, char const* data, int size) fprintf(stderr, "ERROR opening file '%s': %s\n", filename, ec.message().c_str()); return; } - file::iovec_t b = { (void*)data, size }; + file::iovec_t b = { (void*)data, size_t(size) }; out.writev(0, &b, 1, ec); TEST_CHECK(!ec); if (ec) diff --git a/tools/parse_request_log.cpp b/tools/parse_request_log.cpp index 6e802acd9..c719f652e 100644 --- a/tools/parse_request_log.cpp +++ b/tools/parse_request_log.cpp @@ -210,7 +210,7 @@ int main(int argc, char* argv[]) if (first_timestamp == 0) first_timestamp = r.timestamp; - fprintf(expand_file, "%"PRIu64"\t%"PRIu64"\t%"PRIu32"\t%"PRIu32"\t%"PRIu32"\t%"PRIu32"\n" + fprintf(expand_file, "%" PRIu64 "\t%" PRIu64 "\t%" PRIu32 "\t%" PRIu32 "\t%" PRIu32 "\t%" PRIu32 "\n" , r.timestamp, r.infohash, r.peer, r.piece, r.start, r.length); bool hit = disk_cache->incoming_request(r);