diff --git a/examples/client_test.cpp b/examples/client_test.cpp index cdb5a4a1b..6bf5c0741 100644 --- a/examples/client_test.cpp +++ b/examples/client_test.cpp @@ -552,7 +552,7 @@ void add_torrent(libtorrent::session& ses p.auto_managed = true; torrent_handle h = ses.add_torrent(p, ec); - handles.insert(std::make_pair( + handles.insert(std::pair( monitored_dir?std::string(torrent):std::string(), h)); h.set_max_connections(50); @@ -846,7 +846,7 @@ int main(int argc, char* argv[]) continue; } - handles.insert(std::make_pair(std::string(), h)); + handles.insert(std::pair(std::string(), h)); h.set_max_connections(50); h.set_max_uploads(-1); @@ -881,7 +881,7 @@ int main(int argc, char* argv[]) continue; } - handles.insert(std::make_pair(std::string(), h)); + handles.insert(std::pair(std::string(), h)); h.set_max_connections(50); h.set_max_uploads(-1); diff --git a/include/libtorrent/bitfield.hpp b/include/libtorrent/bitfield.hpp index 40bb3d329..3434738e7 100644 --- a/include/libtorrent/bitfield.hpp +++ b/include/libtorrent/bitfield.hpp @@ -232,7 +232,7 @@ namespace libtorrent else if (bits > m_size) { unsigned char* tmp = (unsigned char*)std::malloc(bytes); - std::memcpy(tmp, m_bytes, (std::min)((m_size + 7)/ 8, bytes)); + std::memcpy(tmp, m_bytes, (std::min)(int(m_size + 7)/ 8, bytes)); m_bytes = tmp; m_own = true; } diff --git a/include/libtorrent/config.hpp b/include/libtorrent/config.hpp index 214394254..e657f94c0 100644 --- a/include/libtorrent/config.hpp +++ b/include/libtorrent/config.hpp @@ -50,21 +50,43 @@ POSSIBILITY OF SUCH DAMAGE. #endif #endif -#if defined(__GNUC__) && __GNUC__ >= 4 -#define TORRENT_DEPRECATED __attribute__ ((deprecated)) +// ======= GCC ========= -# if defined(TORRENT_BUILDING_SHARED) || defined(TORRENT_LINKING_SHARED) -# define TORRENT_EXPORT __attribute__ ((visibility("default"))) +#if defined __GNUC__ + +# define TORRENT_DEPRECATED __attribute__ ((deprecated)) + +// GCC pre 4.0 did not have support for the visibility attribute +# if __GNUC__ >= 4 +# if defined(TORRENT_BUILDING_SHARED) || defined(TORRENT_LINKING_SHARED) +# define TORRENT_EXPORT __attribute__ ((visibility("default"))) +# else +# define TORRENT_EXPORT +# endif # else # define TORRENT_EXPORT # endif -#elif defined(__GNUC__) -# define TORRENT_EXPORT +// ======= SUNPRO ========= -#elif defined(BOOST_MSVC) +#elif defined __SUNPRO_CC + +# if __SUNPRO_CC >= 0x550 +# if defined(TORRENT_BUILDING_SHARED) || defined(TORRENT_LINKING_SHARED) +# define TORRENT_EXPORT __global +# else +# define TORRENT_EXPORT +# endif +# else +# define TORRENT_EXPORT +# endif + + +// ======= MSVC ========= + +#elif defined BOOST_MSVC #pragma warning(disable: 4258) #pragma warning(disable: 4251) @@ -79,10 +101,16 @@ POSSIBILITY OF SUCH DAMAGE. #define TORRENT_DEPRECATED_PREFIX __declspec(deprecated("function is deprecated")) + + +// ======= GENERIC COMPILER ========= + #else # define TORRENT_EXPORT #endif + + #ifndef TORRENT_DEPRECATED_PREFIX #define TORRENT_DEPRECATED_PREFIX #endif @@ -129,14 +157,22 @@ POSSIBILITY OF SUCH DAMAGE. // (disables some float-dependent APIs) #define TORRENT_NO_FPU 0 +// make sure NAME_MAX is defined +#ifndef NAME_MAX +#ifdef MAXPATH +#define NAME_MAX MAXPATH +#else +// this is the maximum number of characters in a +// path element / filename on windows +#define NAME_MAX 255 +#endif // MAXPATH +#endif // NAME_MAX + #ifdef TORRENT_WINDOWS #pragma warning(disable:4251) // class X needs to have dll-interface to be used by clients of class Y #include -// this is the maximum number of characters in a -// path element / filename on windows -#define NAME_MAX 255 inline int snprintf(char* buf, int len, char const* fmt, ...) { diff --git a/include/libtorrent/error_code.hpp b/include/libtorrent/error_code.hpp index 11f9758d8..d9d2d2c8f 100644 --- a/include/libtorrent/error_code.hpp +++ b/include/libtorrent/error_code.hpp @@ -191,6 +191,8 @@ namespace libtorrent reserved8, no_i2p_router, + + error_code_max }; } diff --git a/include/libtorrent/file.hpp b/include/libtorrent/file.hpp index bfe894466..00f3001d9 100644 --- a/include/libtorrent/file.hpp +++ b/include/libtorrent/file.hpp @@ -115,6 +115,14 @@ namespace libtorrent typedef iovec iovec_t; #endif + // use a typedef for the type of iovec_t::iov_base + // since it may differ +#ifdef TORRENT_SOLARIS + typedef char* iovec_base_t; +#else + typedef void* iovec_base_t; +#endif + file(); file(fs::path const& p, int m, error_code& ec); ~file(); diff --git a/include/libtorrent/i2p_stream.hpp b/include/libtorrent/i2p_stream.hpp index c910cb1ce..094b28c43 100644 --- a/include/libtorrent/i2p_stream.hpp +++ b/include/libtorrent/i2p_stream.hpp @@ -148,7 +148,7 @@ private: read_connect_response, read_accept_response, read_session_create_response, - read_name_lookup_response, + read_name_lookup_response }; int m_state; diff --git a/include/libtorrent/io.hpp b/include/libtorrent/io.hpp index f73c3e290..06c7563ec 100644 --- a/include/libtorrent/io.hpp +++ b/include/libtorrent/io.hpp @@ -35,6 +35,8 @@ POSSIBILITY OF SUCH DAMAGE. #include #include +#include // for copy +#include // for memcpy namespace libtorrent { @@ -137,7 +139,7 @@ namespace libtorrent inline void write_string(std::string const& str, char*& start) { - std::copy(str.begin(), str.end(), start); + std::memcpy((void*)start, &str[0], str.size()); start += str.size(); } diff --git a/include/libtorrent/ip_filter.hpp b/include/libtorrent/ip_filter.hpp index 39a99d25d..e58873618 100644 --- a/include/libtorrent/ip_filter.hpp +++ b/include/libtorrent/ip_filter.hpp @@ -87,16 +87,14 @@ namespace detail Addr plus_one(Addr const& a) { Addr tmp(a); - typedef typename Addr::reverse_iterator iter; - for (iter i = tmp.rbegin() - , end(tmp.rend()); i != end; ++i) + for (int i = tmp.size() - 1; i >= 0; --i) { - if (*i < (std::numeric_limits::max)()) + if (tmp[i] < (std::numeric_limits::max)()) { - *i += 1; + tmp[i] += 1; break; } - *i = 0; + tmp[i] = 0; } return tmp; } @@ -107,16 +105,14 @@ namespace detail Addr minus_one(Addr const& a) { Addr tmp(a); - typedef typename Addr::reverse_iterator iter; - for (iter i = tmp.rbegin() - , end(tmp.rend()); i != end; ++i) + for (int i = tmp.size() - 1; i >= 0; --i) { - if (*i > 0) + if (tmp[i] > 0) { - *i -= 1; + tmp[i] -= 1; break; } - *i = (std::numeric_limits::max)(); + tmp[i] = (std::numeric_limits::max)(); } return tmp; } diff --git a/include/libtorrent/kademlia/refresh.hpp b/include/libtorrent/kademlia/refresh.hpp index 318e26644..36dd5964f 100644 --- a/include/libtorrent/kademlia/refresh.hpp +++ b/include/libtorrent/kademlia/refresh.hpp @@ -55,12 +55,12 @@ class rpc_manager; class refresh : public traversal_algorithm { public: + typedef std::vector::iterator InIt; typedef boost::function done_callback; void ping_reply(node_id id); void ping_timeout(node_id id, bool prevent_request = false); - template refresh(node_impl& node, node_id target, InIt first, InIt last , done_callback const& callback); @@ -131,12 +131,11 @@ private: boost::intrusive_ptr m_algorithm; }; -template inline refresh::refresh( node_impl& node , node_id target - , InIt first - , InIt last + , refresh::InIt first + , refresh::InIt last , done_callback const& callback) : traversal_algorithm(node, target, first, last) , m_max_active_pings(10) diff --git a/include/libtorrent/peer_id.hpp b/include/libtorrent/peer_id.hpp index a0395d089..f770f2d71 100644 --- a/include/libtorrent/peer_id.hpp +++ b/include/libtorrent/peer_id.hpp @@ -86,12 +86,14 @@ namespace libtorrent void clear() { - std::fill(m_number,m_number+number_size,0); + std::fill(m_number,m_number+number_size,(const unsigned char)(0)); } bool is_all_zeros() const { - return std::count(m_number,m_number+number_size,0) == number_size; + for (const unsigned char* i = m_number; i < m_number+number_size; ++i) + if (*i != 0) return false; + return true; } bool operator==(big_number const& n) const diff --git a/include/libtorrent/policy.hpp b/include/libtorrent/policy.hpp index 96e3d9ff8..093090b80 100644 --- a/include/libtorrent/policy.hpp +++ b/include/libtorrent/policy.hpp @@ -148,8 +148,13 @@ namespace libtorrent // we'll have to add thes figures with the // statistics from the peer_connection. // 48 bits can fit 256 Terabytes +#ifdef __SUNPRO_CC + unsigned prev_amount_upload:48; + unsigned prev_amount_download:48; +#else boost::uint64_t prev_amount_upload:48; boost::uint64_t prev_amount_download:48; +#endif // if the peer is connected now, this // will refer to a valid peer_connection diff --git a/include/libtorrent/torrent_handle.hpp b/include/libtorrent/torrent_handle.hpp index bf2ebe722..98e2722af 100644 --- a/include/libtorrent/torrent_handle.hpp +++ b/include/libtorrent/torrent_handle.hpp @@ -301,7 +301,12 @@ namespace libtorrent { none, requested, writing, finished }; private: +#ifdef __SUNPRO_CC + // sunpro is strict about POD types in unions + struct +#else union +#endif { address_v4::bytes_type v4; address_v6::bytes_type v6; diff --git a/include/libtorrent/upnp.hpp b/include/libtorrent/upnp.hpp index a088172e9..cc55fafc5 100644 --- a/include/libtorrent/upnp.hpp +++ b/include/libtorrent/upnp.hpp @@ -68,7 +68,7 @@ namespace libtorrent internal_port_must_match_external = 724, only_permanent_leases_supported = 725, remote_host_must_be_wildcard = 726, - external_port_must_be_wildcard = 727, + external_port_must_be_wildcard = 727 }; } diff --git a/src/bt_peer_connection.cpp b/src/bt_peer_connection.cpp index b9350e99b..89245fe1f 100644 --- a/src/bt_peer_connection.cpp +++ b/src/bt_peer_connection.cpp @@ -1233,7 +1233,7 @@ namespace libtorrent (*m_logger) << " " << e->list_int_value_at(0) << ": " << sha1_hash(e->list_at(1)->string_ptr()); #endif - nodes.insert(nodes.begin(), std::make_pair(int(e->list_int_value_at(0)) + nodes.insert(std::make_pair(int(e->list_int_value_at(0)) , sha1_hash(e->list_at(1)->string_ptr()))); } #ifdef TORRENT_VERBOSE_LOGGING diff --git a/src/entry.cpp b/src/entry.cpp index e331139a2..7d3a65712 100644 --- a/src/entry.cpp +++ b/src/entry.cpp @@ -85,8 +85,7 @@ namespace libtorrent dictionary_type::iterator i = dict().find(key); if (i != dict().end()) return i->second; dictionary_type::iterator ret = dict().insert( - dict().begin() - , std::make_pair(key, entry())); + std::pair(key, entry())).first; return ret->second; } @@ -95,8 +94,7 @@ namespace libtorrent dictionary_type::iterator i = dict().find(key); if (i != dict().end()) return i->second; dictionary_type::iterator ret = dict().insert( - dict().begin() - , std::make_pair(std::string(key), entry())); + std::make_pair(key, entry())).first; return ret->second; } diff --git a/src/escape_string.cpp b/src/escape_string.cpp index dfb701c39..f8c117ff3 100644 --- a/src/escape_string.cpp +++ b/src/escape_string.cpp @@ -196,10 +196,7 @@ namespace libtorrent std::string ret; for (int i = 0; i < len; ++i) { - if (std::count( - unreserved_chars+offset - , unreserved_chars+sizeof(unreserved_chars)-1 - , *str)) + if (std::strchr(unreserved_chars+offset, *str)) { ret += *str; } @@ -228,13 +225,8 @@ namespace libtorrent { for (int i = 0; i < len; ++i) { - if (std::count( - unreserved_chars - , unreserved_chars+sizeof(unreserved_chars)-1 - , *str) == 0) - { + if (std::strchr(unreserved_chars, *str) == 0) return true; - } ++str; } return false; @@ -296,7 +288,7 @@ namespace libtorrent { // available input is 1,2 or 3 bytes // since we read 3 bytes at a time at most - int available_input = (std::min)(3, (int)std::distance(i, s.end())); + int available_input = (std::min)(3, int(s.end()-i)); // clear input buffer std::fill(inbuf, inbuf+3, 0); @@ -344,7 +336,7 @@ namespace libtorrent std::string ret; for (std::string::const_iterator i = s.begin(); i != s.end();) { - int available_input = (std::min)(5, (int)std::distance(i, s.end())); + int available_input = (std::min)(5, int(s.end()-i)); // clear input buffer std::fill(inbuf, inbuf+5, 0); @@ -387,7 +379,7 @@ namespace libtorrent std::string ret; for (std::string::const_iterator i = s.begin(); i != s.end();) { - int available_input = (std::min)(8, (int)std::distance(i, s.end())); + int available_input = (std::min)(8, int(s.end()-i)); int pad_start = 0; if (available_input < 8) pad_start = available_input; diff --git a/src/http_parser.cpp b/src/http_parser.cpp index 9851e68c7..cd8e10e12 100644 --- a/src/http_parser.cpp +++ b/src/http_parser.cpp @@ -98,7 +98,7 @@ namespace libtorrent char const* line = pos; ++newline; - int incoming = (int)std::distance(pos, newline); + int incoming = int(newline - pos); m_recv_pos += incoming; boost::get<1>(ret) += newline - (m_recv_buffer.begin + start_pos); pos = newline; diff --git a/src/http_tracker_connection.cpp b/src/http_tracker_connection.cpp index eafba8cf8..945654a13 100644 --- a/src/http_tracker_connection.cpp +++ b/src/http_tracker_connection.cpp @@ -429,7 +429,7 @@ namespace libtorrent for (std::string::const_iterator i = peers.begin(); i != peers.end();) { - if (std::distance(i, peers.end()) < 6) break; + if (peers.end() - i < 6) break; peer_entry p; p.pid.clear(); @@ -463,7 +463,7 @@ namespace libtorrent for (std::string::const_iterator i = peers.begin(); i != peers.end();) { - if (std::distance(i, peers.end()) < 18) break; + if (peers.end() - i < 18) break; peer_entry p; p.pid.clear(); diff --git a/src/identify_client.cpp b/src/identify_client.cpp index 9bae799c4..d35a939ca 100644 --- a/src/identify_client.cpp +++ b/src/identify_client.cpp @@ -349,12 +349,12 @@ namespace libtorrent } if (find_string(PID, "-BOW") && PID[7] == '-') - return "Bits on Wheels " + std::string(PID + 4, PID + 7); + return "Bits on Wheels " + std::string((char const*)PID + 4, (char const*)PID + 7); if (find_string(PID, "eX")) { - std::string user(PID + 2, PID + 14); + std::string user((char const*)PID + 2, (char const*)PID + 14); return std::string("eXeem ('") + user.c_str() + "')"; } diff --git a/src/kademlia/dht_tracker.cpp b/src/kademlia/dht_tracker.cpp index e4c6ab20c..65c1d536b 100644 --- a/src/kademlia/dht_tracker.cpp +++ b/src/kademlia/dht_tracker.cpp @@ -80,8 +80,7 @@ namespace void operator()(std::pair const& t) { - count += std::distance(t.second.peers.begin() - , t.second.peers.end()); + count += t.second.peers.size(); } }; @@ -1024,7 +1023,7 @@ namespace libtorrent { namespace dht e["y"] = "r"; e["r"] = entry(entry::dictionary_t); entry& r = e["r"]; - r["id"] = std::string(m.id.begin(), m.id.end()); + r["id"] = std::string((char*)m.id.begin(), (char*)m.id.end()); if (!m.write_token.empty()) { r["token"] = m.write_token; @@ -1085,7 +1084,7 @@ namespace libtorrent { namespace dht e["y"] = "q"; e["a"] = entry(entry::dictionary_t); entry& a = e["a"]; - a["id"] = std::string(m.id.begin(), m.id.end()); + a["id"] = std::string((char*)m.id.begin(), (char*)m.id.end()); TORRENT_ASSERT(m.message_id <= messages::error); e["q"] = messages::ids[m.message_id]; @@ -1100,7 +1099,7 @@ namespace libtorrent { namespace dht case messages::find_node: { send_flags = 1; - a["target"] = std::string(m.info_hash.begin(), m.info_hash.end()); + a["target"] = std::string((char*)m.info_hash.begin(), (char*)m.info_hash.end()); #ifdef TORRENT_DHT_VERBOSE_LOGGING log_line << " target: " << boost::lexical_cast(m.info_hash); #endif @@ -1109,7 +1108,7 @@ namespace libtorrent { namespace dht case messages::get_peers: { send_flags = 1; - a["info_hash"] = std::string(m.info_hash.begin(), m.info_hash.end()); + a["info_hash"] = std::string((char*)m.info_hash.begin(), (char*)m.info_hash.end()); #ifdef TORRENT_DHT_VERBOSE_LOGGING log_line << " ih: " << boost::lexical_cast(m.info_hash); #endif @@ -1118,7 +1117,7 @@ namespace libtorrent { namespace dht case messages::announce_peer: send_flags = 1; a["port"] = m.port; - a["info_hash"] = std::string(m.info_hash.begin(), m.info_hash.end()); + a["info_hash"] = std::string((char*)m.info_hash.begin(), (char*)m.info_hash.end()); a["token"] = m.write_token; #ifdef TORRENT_DHT_VERBOSE_LOGGING log_line << " port: " << m.port diff --git a/src/piece_picker.cpp b/src/piece_picker.cpp index 11c2cf01b..9117af94e 100644 --- a/src/piece_picker.cpp +++ b/src/piece_picker.cpp @@ -106,10 +106,10 @@ namespace libtorrent i->index = 0; } - for (std::vector::const_iterator i = m_piece_map.begin() + m_cursor + for (std::vector::iterator i = m_piece_map.begin() + m_cursor , end(m_piece_map.end()); i != end && (i->have() || i->filtered()); ++i, ++m_cursor); - for (std::vector::const_reverse_iterator i = m_piece_map.rend() + for (std::vector::reverse_iterator i = m_piece_map.rend() - m_reverse_cursor; m_reverse_cursor > 0 && (i->have() || i->filtered()); ++i, --m_reverse_cursor); @@ -345,7 +345,7 @@ namespace libtorrent index = num_pieces; if (num_pieces > 0) { - for (std::vector::const_reverse_iterator i = m_piece_map.rend() + for (std::vector::reverse_iterator i = m_piece_map.rend() - index; index > 0 && (i->have() || i->filtered()); ++i, --index); TORRENT_ASSERT(index == num_pieces || m_piece_map[index].have() diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 39ce50c04..fdc024e08 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -2992,9 +2992,12 @@ namespace aux { #ifdef TORRENT_DEBUG void session_impl::check_invariant() const { - int num_checking = std::count_if(m_queued_for_checking.begin() - , m_queued_for_checking.end(), boost::bind(&torrent::state, _1) - == torrent_status::checking_files); + int num_checking = 0; + for (check_queue_t::const_iterator i = m_queued_for_checking.begin() + , end(m_queued_for_checking.end()); i != end; ++i) + { + if ((*i)->state() == torrent_status::checking_files) ++num_checking; + } // the queue is either empty, or it has exactly one checking torrent in it TORRENT_ASSERT(m_queued_for_checking.empty() || num_checking == 1); diff --git a/src/smart_ban.cpp b/src/smart_ban.cpp index 1f6e6ae01..5c7e5130e 100644 --- a/src/smart_ban.cpp +++ b/src/smart_ban.cpp @@ -226,7 +226,7 @@ namespace libtorrent { namespace return; } - m_block_crc.insert(i, std::make_pair(b, e)); + m_block_crc.insert(i, std::pair(b, e)); #ifdef TORRENT_LOGGING char const* client = "-"; diff --git a/src/storage.cpp b/src/storage.cpp index 2d1fb8cff..634b6a8bd 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -1427,7 +1427,7 @@ ret: , int offset , int size) { - file::iovec_t b = { (void*)buf, size }; + file::iovec_t b = { (file::iovec_base_t)buf, size }; return writev(&b, slot, offset, 1); } @@ -1437,7 +1437,7 @@ ret: , int offset , int size) { - file::iovec_t b = { (void*)buf, size }; + file::iovec_t b = { (file::iovec_base_t)buf, size }; return readv(&b, slot, offset, 1); } @@ -2526,7 +2526,7 @@ ret: if (m_hash_to_piece.empty()) { for (int i = 0; i < m_files.num_pieces(); ++i) - m_hash_to_piece.insert(std::make_pair(m_info->hash_for_piece(i), i)); + m_hash_to_piece.insert(std::pair(m_info->hash_for_piece(i), i)); } partial_hash ph; diff --git a/src/torrent.cpp b/src/torrent.cpp index 74ebfadf3..21b341bce 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -185,7 +185,7 @@ namespace if (p->pid() != pid) return false; // have a special case for all zeros. We can have any number // of peers with that pid, since it's used to indicate no pid. - if (std::count(pid.begin(), pid.end(), 0) == 20) return false; + if (pid.is_all_zeros()) return false; return true; } @@ -5708,7 +5708,7 @@ namespace libtorrent std::vector pieces; m_picker->piece_priorities(pieces); // make sure all pieces have priority 0 - TORRENT_ASSERT(std::count(pieces.begin(), pieces.end(), 0) == int(pieces.size())); + TORRENT_ASSERT(std::accumulate(pieces.begin(), pieces.end(), 0) == 0); } } if (s == torrent_status::seeding) @@ -5906,8 +5906,11 @@ namespace libtorrent { INVARIANT_CHECK; - return (int)std::count_if(m_connections.begin(), m_connections.end() - , boost::bind(&peer_connection::is_seed, _1)); + int ret = 0; + for (std::set::iterator i = m_connections.begin() + , end(m_connections.end()); i != end; ++i) + if ((*i)->is_seed()) ++ret; + return ret; } void torrent::tracker_request_timed_out( diff --git a/src/torrent_info.cpp b/src/torrent_info.cpp index 736bb72cc..ec25c94ad 100644 --- a/src/torrent_info.cpp +++ b/src/torrent_info.cpp @@ -93,7 +93,7 @@ namespace libtorrent continue; } - if (std::distance(i, end) < 2) + if (end - i < 2) { convert_to_utf8(tmp_path, *i); valid_encoding = false; @@ -110,7 +110,7 @@ namespace libtorrent continue; } - if (std::distance(i, end) < 3) + if (end - i < 3) { convert_to_utf8(tmp_path, *i); valid_encoding = false; @@ -129,7 +129,7 @@ namespace libtorrent continue; } - if (std::distance(i, end) < 4) + if (end - i < 4) { convert_to_utf8(tmp_path, *i); valid_encoding = false;