Fix compilation with GCC 8

This commit is contained in:
Eugene Shalygin 2018-05-05 23:10:01 +02:00 committed by Arvid Norberg
parent 4b368e1cfc
commit 81fd09775c
5 changed files with 30 additions and 11 deletions

View File

@ -354,6 +354,9 @@ namespace libtorrent {
swap(m_len, e.m_len);
}
lazy_entry(lazy_entry&&);
lazy_entry& operator=(lazy_entry&&);
private:
int capacity() const;
@ -382,13 +385,13 @@ namespace libtorrent {
std::uint32_t m_type:3;
// non-copyable
lazy_entry(lazy_entry const&);
lazy_entry const& operator=(lazy_entry const&);
lazy_entry(lazy_entry const&) = delete;
lazy_entry const& operator=(lazy_entry const&) = delete;
};
struct TORRENT_DEPRECATED lazy_dict_entry
{
char const* name;
char const* name = nullptr;
lazy_entry val;
};

View File

@ -88,7 +88,7 @@ namespace libtorrent {
data_type* data()
{
return &m_sockaddr;
return reinterpret_cast<data_type*>(&m_sockaddr);
}
const data_type* data() const

View File

@ -36,6 +36,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/lazy_entry.hpp"
#include "libtorrent/bdecode.hpp" // for error codes
#include "libtorrent/string_util.hpp" // for is_digit
#include <algorithm>
#include <cstring> // for memset
#include <limits> // for numeric_limits
#include <cstdio> // for snprintf
@ -266,8 +267,7 @@ namespace {
int const capacity = this->capacity() * lazy_entry_grow_factor / 100;
auto* tmp = new (std::nothrow) lazy_dict_entry[capacity + 1];
if (tmp == nullptr) return nullptr;
std::memcpy(tmp, m_data.dict, sizeof(lazy_dict_entry) * (m_size + 1));
for (int i = 0; i < int(m_size); ++i) m_data.dict[i + 1].val.release();
std::move(m_data.dict, m_data.dict + m_size + 1, tmp);
delete[] m_data.dict;
m_data.dict = tmp;
@ -437,8 +437,7 @@ namespace {
int const capacity = this->capacity() * lazy_entry_grow_factor / 100;
lazy_entry* tmp = new (std::nothrow) lazy_entry[capacity + 1];
if (tmp == nullptr) return nullptr;
std::memcpy(tmp, m_data.list, sizeof(lazy_entry) * (m_size + 1));
for (int i = 0; i < int(m_size); ++i) m_data.list[i + 1].release();
std::move(m_data.list, m_data.list + m_size + 1, tmp);
delete[] m_data.list;
m_data.list = tmp;
@ -492,6 +491,18 @@ namespace {
return {m_begin, m_len};
}
lazy_entry::lazy_entry(lazy_entry&& other)
: lazy_entry()
{
this->swap(other);
}
lazy_entry& lazy_entry::operator=(lazy_entry&& other)
{
this->swap(other);
return *this;
}
namespace {
int line_longer_than(lazy_entry const& e, int limit)

View File

@ -1094,7 +1094,6 @@ namespace {
int const num_nodes = merkle_num_nodes(num_leafs);
m_merkle_first_leaf = num_nodes - num_leafs;
m_merkle_tree.resize(num_nodes);
std::memset(m_merkle_tree.data(), 0, aux::numeric_cast<std::size_t>(num_nodes * 20));
m_merkle_tree[0].assign(root_hash.string_ptr());
}

View File

@ -34,6 +34,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <iostream>
#include <cstring>
#include <utility>
#ifndef TORRENT_NO_DEPRECATE
#include "libtorrent/lazy_entry.hpp"
@ -629,12 +630,17 @@ TORRENT_TEST(lazy_entry)
for (int i = 0; i < int(sizeof(b)/sizeof(b[0])); ++i)
{
lazy_entry e;
lazy_entry tmp;
error_code ec;
int ret = lazy_bdecode(b[i], b[i] + strlen(b[i]), e, ec, nullptr);
int ret = lazy_bdecode(b[i], b[i] + strlen(b[i]), tmp, ec, nullptr);
lazy_entry e;
e = std::move(tmp);
TEST_EQUAL(ret, -1);
TEST_CHECK(ec == error_code(bdecode_errors::unexpected_eof));
std::printf("%s\n", print_entry(e).c_str());
lazy_entry* moved = new lazy_entry(std::move(e));
delete moved;
}
}
}