fix some macro expansions of 'max' in headers, to improve compatibility with windows.h

This commit is contained in:
arvidn 2017-11-12 13:24:27 +01:00 committed by Arvid Norberg
parent b6a73eeaaa
commit 0378ae47f4
14 changed files with 21 additions and 20 deletions

View File

@ -46,7 +46,7 @@ namespace libtorrent { namespace aux {
using base = std::array<T, Size>;
using underlying_index = typename underlying_index_t<IndexType>::type;
static_assert(Size <= std::size_t(std::numeric_limits<underlying_index>::max())
static_assert(Size <= std::size_t((std::numeric_limits<underlying_index>::max)())
, "size is to big for index type");
array() = default;

View File

@ -76,7 +76,7 @@ namespace libtorrent { namespace aux {
IndexType end_index() const
{
TORRENT_ASSERT(this->size() <= std::size_t(std::numeric_limits<underlying_index>::max()));
TORRENT_ASSERT(this->size() <= std::size_t((std::numeric_limits<underlying_index>::max)()));
return IndexType(static_cast<underlying_index>(this->size()));
}

View File

@ -457,7 +457,7 @@ namespace aux {
peer_class_pool& peer_classes() override { return m_classes; }
bool ignore_unchoke_slots_set(peer_class_set const& set) const override;
int copy_pertinent_channels(peer_class_set const& set
, int channel, bandwidth_channel** dst, int max) override;
, int channel, bandwidth_channel** dst, int m) override;
int use_quota_overhead(peer_class_set& set, int amount_down, int amount_up) override;
bool use_quota_overhead(bandwidth_channel* ch, int amount);

View File

@ -249,7 +249,7 @@ namespace libtorrent { namespace aux {
virtual peer_class_pool& peer_classes() = 0;
virtual bool ignore_unchoke_slots_set(peer_class_set const& set) const = 0;
virtual int copy_pertinent_channels(peer_class_set const& set
, int channel, bandwidth_channel** dst, int max) = 0;
, int channel, bandwidth_channel** dst, int m) = 0;
virtual int use_quota_overhead(peer_class_set& set, int amount_down, int amount_up) = 0;
virtual bandwidth_manager* get_bandwidth_manager(int channel) = 0;

View File

@ -91,7 +91,7 @@ namespace libtorrent { namespace aux {
IndexType end_index() const
{
TORRENT_ASSERT(this->size() <= std::size_t(std::numeric_limits<underlying_index>::max()));
TORRENT_ASSERT(this->size() <= std::size_t((std::numeric_limits<underlying_index>::max)()));
return IndexType(static_cast<underlying_index>(this->size()));
}

View File

@ -85,7 +85,7 @@ namespace libtorrent { namespace aux {
IndexType end_index() const
{
TORRENT_ASSERT(this->size() <= std::size_t(std::numeric_limits<underlying_index>::max()));
TORRENT_ASSERT(this->size() <= std::size_t((std::numeric_limits<underlying_index>::max)()));
return IndexType(static_cast<underlying_index>(this->size()));
}

View File

@ -43,7 +43,7 @@ namespace libtorrent {
// member of peer_connection
struct TORRENT_EXTRA_EXPORT bandwidth_channel
{
static constexpr int inf = std::numeric_limits<std::int32_t>::max();
static constexpr int inf = (std::numeric_limits<std::int32_t>::max)();
bandwidth_channel();

View File

@ -199,7 +199,7 @@ namespace libtorrent {
new (&b.holder) Holder(std::move(buf));
m_bytes += used_size;
TORRENT_ASSERT(m_capacity < std::numeric_limits<int>::max() - b.size);
TORRENT_ASSERT(m_capacity < (std::numeric_limits<int>::max)() - b.size);
m_capacity += b.size;
TORRENT_ASSERT(m_bytes <= m_capacity);
}

View File

@ -267,7 +267,7 @@ namespace libtorrent {
// If multiple plugins implement this function the lowest return value
// (i.e. the highest priority) is used.
virtual uint64_t get_unchoke_priority(peer_connection_handle const& /* peer */)
{ return std::numeric_limits<uint64_t>::max(); }
{ return (std::numeric_limits<uint64_t>::max)(); }
// called when saving settings state
virtual void save_state(entry&) {}

View File

@ -164,7 +164,7 @@ namespace libtorrent {
{
TORRENT_ASSERT(is_single_thread());
TORRENT_ASSERT(allocate >= 0);
TORRENT_ASSERT(allocate <= std::numeric_limits<std::uint16_t>::max());
TORRENT_ASSERT(allocate <= (std::numeric_limits<std::uint16_t>::max)());
return alloc(allocate);
}

View File

@ -138,13 +138,13 @@ namespace libtorrent {
bool operator<(downloading_piece const& rhs) const { return index < rhs.index; }
// the index of the piece
piece_index_t index{std::numeric_limits<std::int32_t>::max()};
piece_index_t index{(std::numeric_limits<std::int32_t>::max)()};
// info about each block in this piece. this is an index into the
// m_block_info array, when multiplied by m_blocks_per_piece.
// The m_blocks_per_piece following entries contain information about
// all blocks in this piece.
std::uint16_t info_idx{std::numeric_limits<std::uint16_t>::max()};
std::uint16_t info_idx{(std::numeric_limits<std::uint16_t>::max)()};
// the number of blocks in the finished state
std::uint16_t finished:15;
@ -462,7 +462,7 @@ namespace libtorrent {
, index(index_)
{
TORRENT_ASSERT(peer_count_ >= 0);
TORRENT_ASSERT(peer_count_ < std::numeric_limits<std::uint16_t>::max());
TORRENT_ASSERT(peer_count_ < (std::numeric_limits<std::uint16_t>::max)());
TORRENT_ASSERT(index_ >= 0);
}

View File

@ -57,5 +57,5 @@ namespace libtorrent { namespace aux {
TORRENT_EXTRA_EXPORT void random_bytes(span<char> buffer);
}
TORRENT_EXTRA_EXPORT std::uint32_t random(std::uint32_t max);
TORRENT_EXTRA_EXPORT std::uint32_t random(std::uint32_t m);
}

View File

@ -177,14 +177,15 @@ struct crypto_receive_buffer
bool crypto_packet_finished() const
{
return m_recv_pos == INT_MAX || m_connection_buffer.packet_finished();
return m_recv_pos == (std::numeric_limits<int>::max)()
|| m_connection_buffer.packet_finished();
}
int packet_size() const;
int crypto_packet_size() const
{
TORRENT_ASSERT(m_recv_pos != INT_MAX);
TORRENT_ASSERT(m_recv_pos != (std::numeric_limits<int>::max)());
return m_connection_buffer.packet_size() - m_recv_pos;
}
@ -194,7 +195,7 @@ struct crypto_receive_buffer
void crypto_cut(int size, int packet_size)
{
TORRENT_ASSERT(m_recv_pos != INT_MAX);
TORRENT_ASSERT(m_recv_pos != (std::numeric_limits<int>::max)());
m_connection_buffer.cut(size, m_recv_pos + packet_size, m_recv_pos);
}
@ -211,7 +212,7 @@ private:
// explicitly disallow assignment, to silence msvc warning
crypto_receive_buffer& operator=(crypto_receive_buffer const&);
int m_recv_pos = std::numeric_limits<int>::max();
int m_recv_pos = (std::numeric_limits<int>::max)();
int m_packet_size = 0;
receive_buffer& m_connection_buffer;
};

View File

@ -82,7 +82,7 @@ namespace aux {
// returns an all-F digest. i.e. the maximum value
// representable by an N bit number (N/8 bytes). This is
// a static member function.
static digest32 max()
static digest32 (max)()
{
digest32 ret;
std::memset(ret.m_number, 0xff, size());
@ -92,7 +92,7 @@ namespace aux {
// returns an all-zero digest. i.e. the minimum value
// representable by an N bit number (N/8 bytes). This is
// a static member function.
static digest32 min()
static digest32 (min)()
{
digest32 ret;
// all bits are already 0