improved sun studio support (it seems to lack a lot of stl)

This commit is contained in:
Arvid Norberg 2009-08-30 07:38:52 +00:00
parent f764227012
commit 1f5a722b01
26 changed files with 132 additions and 82 deletions

View File

@ -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<const std::string, torrent_handle>(
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<const std::string, torrent_handle>(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<const std::string, torrent_handle>(std::string(), h));
h.set_max_connections(50);
h.set_max_uploads(-1);

View File

@ -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;
}

View File

@ -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 <stdarg.h>
// 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, ...)
{

View File

@ -191,6 +191,8 @@ namespace libtorrent
reserved8,
no_i2p_router,
error_code_max
};
}

View File

@ -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();

View File

@ -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;

View File

@ -35,6 +35,8 @@ POSSIBILITY OF SUCH DAMAGE.
#include <boost/cstdint.hpp>
#include <string>
#include <algorithm> // for copy
#include <cstring> // 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();
}

View File

@ -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<typename iter::value_type>::max)())
if (tmp[i] < (std::numeric_limits<typename Addr::value_type>::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<typename iter::value_type>::max)();
tmp[i] = (std::numeric_limits<typename Addr::value_type>::max)();
}
return tmp;
}

View File

@ -55,12 +55,12 @@ class rpc_manager;
class refresh : public traversal_algorithm
{
public:
typedef std::vector<node_entry>::iterator InIt;
typedef boost::function<void()> done_callback;
void ping_reply(node_id id);
void ping_timeout(node_id id, bool prevent_request = false);
template<class InIt>
refresh(node_impl& node, node_id target, InIt first, InIt last
, done_callback const& callback);
@ -131,12 +131,11 @@ private:
boost::intrusive_ptr<refresh> m_algorithm;
};
template<class InIt>
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)

View File

@ -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

View File

@ -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

View File

@ -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;

View File

@ -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
};
}

View File

@ -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

View File

@ -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<const std::string, entry>(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;
}

View File

@ -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;

View File

@ -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;

View File

@ -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();

View File

@ -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() + "')";
}

View File

@ -80,8 +80,7 @@ namespace
void operator()(std::pair<libtorrent::dht::node_id
, libtorrent::dht::torrent_entry> 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<std::string>(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<std::string>(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

View File

@ -106,10 +106,10 @@ namespace libtorrent
i->index = 0;
}
for (std::vector<piece_pos>::const_iterator i = m_piece_map.begin() + m_cursor
for (std::vector<piece_pos>::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<piece_pos>::const_reverse_iterator i = m_piece_map.rend()
for (std::vector<piece_pos>::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<piece_pos>::const_reverse_iterator i = m_piece_map.rend()
for (std::vector<piece_pos>::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()

View File

@ -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);

View File

@ -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<const piece_block, block_entry>(b, e));
#ifdef TORRENT_LOGGING
char const* client = "-";

View File

@ -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<const sha1_hash, int>(m_info->hash_for_piece(i), i));
}
partial_hash ph;

View File

@ -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<int> 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<peer_connection*>::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(

View File

@ -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;