general modernization (#836)

general modernization. use nullptr instead of NULL, use std::tuple instead of boost::tuple, transition some unordered set/map from boost to std. some clean-up of includes
This commit is contained in:
Arvid Norberg 2016-06-20 11:32:06 -04:00 committed by GitHub
parent a9dbbdea37
commit 6aabe3762b
155 changed files with 804 additions and 961 deletions

View File

@ -199,7 +199,7 @@ int load_file(std::string const& filename, std::vector<char>& v
{
ec.clear();
FILE* f = std::fopen(filename.c_str(), "rb");
if (f == NULL)
if (f == nullptr)
{
ec.assign(errno, boost::system::system_category());
return -1;
@ -616,7 +616,7 @@ std::string path_to_url(std::string f)
if (f[i] == '\\') ret.push_back('/');
else
#endif
if (std::strchr(unreserved, f[i]) != NULL) ret.push_back(f[i]);
if (std::strchr(unreserved, f[i]) != nullptr) ret.push_back(f[i]);
else
{
ret.push_back('%');
@ -837,7 +837,7 @@ void print_alert(libtorrent::alert const* a, std::string& str)
int save_file(std::string const& filename, std::vector<char>& v)
{
FILE* f = std::fopen(filename.c_str(), "wb");
if (f == NULL)
if (f == nullptr)
return -1;
int w = int(std::fwrite(&v[0], 1, v.size(), f));
@ -996,7 +996,7 @@ bool handle_alert(libtorrent::session& ses, libtorrent::alert* a
if (!peer.empty())
{
char* port = (char*) strrchr((char*)peer.c_str(), ':');
if (port != NULL)
if (port != nullptr)
{
*port++ = 0;
char const* ip = peer.c_str();
@ -1258,7 +1258,7 @@ int main(int argc, char* argv[])
}
// maybe this is an assignment of a libtorrent setting
if (argv[i][1] == '-' && strchr(argv[i], '=') != NULL)
if (argv[i][1] == '-' && strchr(argv[i], '=') != nullptr)
{
char const* equal = strchr(argv[i], '=');
char const* start = argv[i]+2;
@ -1301,7 +1301,7 @@ int main(int argc, char* argv[])
// if there's a flag but no argument following, ignore it
if (argc == i) continue;
char const* arg = argv[i+1];
if (arg == NULL) arg = "";
if (arg == nullptr) arg = "";
switch (argv[i][1])
{

View File

@ -825,7 +825,7 @@ void generate_data(char const* path, torrent_info const& ti)
storage_params params;
params.files = &const_cast<file_storage&>(fs);
params.mapped_files = NULL;
params.mapped_files = nullptr;
params.path = path;
params.pool = &fp;
params.mode = storage_mode_sparse;

View File

@ -45,7 +45,7 @@ int load_file(std::string const& filename, std::vector<char>& v
{
ec.clear();
FILE* f = std::fopen(filename.c_str(), "rb");
if (f == NULL)
if (f == nullptr)
{
ec.assign(errno, boost::system::system_category());
return -1;

View File

@ -55,7 +55,7 @@ int load_file(std::string const& filename, std::vector<char>& v, libtorrent::err
{
ec.clear();
FILE* f = std::fopen(filename.c_str(), "rb");
if (f == NULL)
if (f == nullptr)
{
ec.assign(errno, boost::system::system_category());
return -1;
@ -145,12 +145,12 @@ bool file_filter(std::string const& f)
char const* sep = strrchr(first, '/');
#if defined(TORRENT_WINDOWS) || defined(TORRENT_OS2)
char const* altsep = strrchr(first, '\\');
if (sep == NULL || altsep > sep) sep = altsep;
if (sep == nullptr || altsep > sep) sep = altsep;
#endif
// if there is no parent path, just set 'sep'
// to point to the filename.
// if there is a parent path, skip the '/' character
if (sep == NULL) sep = first;
if (sep == nullptr) sep = first;
else ++sep;
// return false if the first character of the filename is a .
@ -405,7 +405,7 @@ int main(int argc, char* argv[])
FILE* output = stdout;
if (!outfile.empty())
output = std::fopen(outfile.c_str(), "wb+");
if (output == NULL)
if (output == nullptr)
{
std::fprintf(stderr, "failed to open file \"%s\": (%d) %s\n"
, outfile.c_str(), errno, std::strerror(errno));
@ -419,7 +419,7 @@ int main(int argc, char* argv[])
if (!merklefile.empty())
{
output = std::fopen(merklefile.c_str(), "wb+");
if (output == NULL)
if (output == nullptr)
{
std::fprintf(stderr, "failed to open file \"%s\": (%d) %s\n"
, merklefile.c_str(), errno, std::strerror(errno));

View File

@ -466,7 +466,7 @@ void print(char const* buf)
{
if (*buf == '\033' && buf[1] == '[')
{
WriteFile(out, start, DWORD(buf - start), &written, NULL);
WriteFile(out, start, DWORD(buf - start), &written, nullptr);
buf += 2; // skip escape and '['
start = buf;
if (*buf == 0) break;
@ -535,7 +535,7 @@ one_more:
++buf;
}
}
WriteFile(out, start, DWORD(buf - start), &written, NULL);
WriteFile(out, start, DWORD(buf - start), &written, nullptr);
#else
fputs(buf, stdout);

View File

@ -142,7 +142,7 @@ namespace libtorrent
virtual int category() const override { return static_category; }
virtual std::string message() const override;
// returns a null-terminated string of the tracker's URL
// returns a 0-terminated string of the tracker's URL
char const* tracker_url() const;
#ifndef TORRENT_NO_DEPRECATE
@ -668,7 +668,7 @@ namespace libtorrent
static const int static_category = alert::peer_notification;
virtual std::string message() const override;
// a NULL-terminated string of the low-level operation that failed, or NULL if
// a 0-terminated string of the low-level operation that failed, or nullptr if
// there was no low level disk operation.
int operation;
@ -933,8 +933,8 @@ namespace libtorrent
// If the error happened for a specific file, this returns its path.
char const* file_path() const;
// If the error happened in a specific disk operation this is a NULL
// terminated string naming which one, otherwise it's NULL.
// If the error happened in a specific disk operation this is a nullptr
// terminated string naming which one, otherwise it's nullptr.
char const* operation;
private:
int m_file_idx;
@ -1507,8 +1507,8 @@ namespace libtorrent
// If the error happened to a specific file, this returns the path to it.
char const* file_path() const;
// If the error happened in a disk operation. a NULL-terminated string of
// the name of that operation. ``operation`` is NULL otherwise.
// If the error happened in a disk operation. a 0-terminated string of
// the name of that operation. ``operation`` is nullptr otherwise.
char const* operation;
#ifndef TORRENT_NO_DEPRECATE

View File

@ -37,13 +37,9 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/time.hpp" // for time_point
#include "libtorrent/error_code.hpp"
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <string>
#include <cstdint>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
namespace libtorrent
{
namespace aux {

View File

@ -42,7 +42,7 @@ namespace libtorrent { namespace aux {
template <typename T>
struct array_view
{
array_view() : m_ptr(NULL), m_len(0) {}
array_view() : m_ptr(nullptr), m_len(0) {}
// T -> const T conversion constructor
template <typename U, typename

View File

@ -38,10 +38,10 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/config.hpp"
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <cstdint>
#include "libtorrent/aux_/disable_warnings_push.hpp"
#ifdef TORRENT_WINDOWS
#include <winsock2.h>
#else

View File

@ -64,7 +64,7 @@ namespace libtorrent
// convert a file://-URL to a proper path
TORRENT_EXTRA_EXPORT std::string resolve_file_url(std::string const& url);
// returns true if the given string (not null terminated) contains
// returns true if the given string (not 0-terminated) contains
// characters that would need to be escaped if used in a URL
TORRENT_EXTRA_EXPORT bool need_encoding(char const* str, int len);

View File

@ -33,10 +33,7 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef TORRENT_AUX_IO_HPP_INCLUDED
#define TORRENT_AUX_IO_HPP_INCLUDED
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <cstdint>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#include <string>
#include <algorithm> // for copy
#include "libtorrent/aux_/array_view.hpp"

View File

@ -160,7 +160,7 @@ namespace libtorrent
// the actual sockets (TCP listen socket and UDP socket)
// An entry does not necessarily have a UDP or TCP socket. One of these
// pointers may be null!
// pointers may be nullptr!
// These must be shared_ptr to avoid a dangling reference if an
// incoming packet is in the event queue when the socket is erased
boost::shared_ptr<tcp::acceptor> sock;
@ -518,7 +518,7 @@ namespace libtorrent
proxy_settings proxy() const override;
#ifndef TORRENT_DISABLE_DHT
bool is_dht_running() const { return (m_dht.get() != NULL); }
bool is_dht_running() const { return (m_dht.get() != nullptr); }
int external_udp_port() const override
{
for (std::list<listen_socket_t>::const_iterator i = m_listen_sockets.begin()
@ -633,7 +633,7 @@ namespace libtorrent
virtual bool verify_bound_address(address const& addr, bool utp
, error_code& ec) override;
bool has_lsd() const override { return m_lsd.get() != NULL; }
bool has_lsd() const override { return m_lsd.get() != nullptr; }
std::vector<block_info>& block_info_storage() override { return m_block_info_storage; }

View File

@ -33,12 +33,8 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef TORRENT_BANDWIDTH_CHANNEL_HPP_INCLUDED
#define TORRENT_BANDWIDTH_CHANNEL_HPP_INCLUDED
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <boost/integer_traits.hpp>
#include <cstdint>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#include <limits>
#include "libtorrent/assert.hpp"
@ -47,7 +43,7 @@ namespace libtorrent {
// member of peer_connection
struct TORRENT_EXTRA_EXPORT bandwidth_channel
{
static const int inf = boost::integer_traits<int>::const_max;
static constexpr int inf = std::numeric_limits<int>::max();
bandwidth_channel();
@ -55,7 +51,7 @@ struct TORRENT_EXTRA_EXPORT bandwidth_channel
void throttle(int limit);
int throttle() const
{
TORRENT_ASSERT_VAL(m_limit < INT_MAX, m_limit);
TORRENT_ASSERT_VAL(m_limit < inf, m_limit);
return int(m_limit);
}

View File

@ -34,9 +34,7 @@ POSSIBILITY OF SUCH DAMAGE.
#define TORRENT_BANDWIDTH_QUEUE_ENTRY_HPP_INCLUDED
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <boost/shared_ptr.hpp>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#include "libtorrent/bandwidth_limit.hpp"

View File

@ -30,20 +30,19 @@ POSSIBILITY OF SUCH DAMAGE.
*/
#include "libtorrent/aux_/disable_warnings_push.hpp"
#ifndef TORRENT_BDECODE_HPP
#define TORRENT_BDECODE_HPP
#include <boost/system/error_code.hpp>
#include <vector>
#include <string>
#include <cstdint>
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <boost/system/error_code.hpp>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#include "libtorrent/assert.hpp"
#ifndef TORRENT_BDECODE_HPP
#define TORRENT_BDECODE_HPP
/*
This is an efficient bdecoder. It decodes into a flat memory buffer of tokens.
@ -296,7 +295,7 @@ struct TORRENT_EXPORT bdecode_node
// Functions with the ``dict_`` prefix operates on dictionaries. They are
// only valid if ``type()`` == ``dict_t``. In case a key you're looking up
// contains a 0 byte, you cannot use the null-terminated string overloads,
// contains a 0 byte, you cannot use the 0-terminated string overloads,
// but have to use ``std::string`` instead. ``dict_find_list`` will return a
// valid ``bdecode_node`` if the key is found _and_ it is a list. Otherwise
// it will return a default-constructed bdecode_node.
@ -323,7 +322,7 @@ struct TORRENT_EXPORT bdecode_node
std::int64_t int_value() const;
// these functions are only valid if ``type()`` == ``string_t``. They return
// the string values. Note that ``string_ptr()`` is *not* null-terminated.
// the string values. Note that ``string_ptr()`` is *not* 0-terminated.
// ``string_length()`` returns the number of bytes in the string.
std::string string_value() const;
char const* string_ptr() const;
@ -390,7 +389,7 @@ TORRENT_EXPORT std::string print_entry(bdecode_node const& e
// is specified by the ``start`` of the buffer as well as the ``end``, i.e. one
// byte past the end. If the buffer fails to parse, the function returns a
// non-zero value and fills in ``ec`` with the error code. The optional
// argument ``error_pos``, if set to non-null, will be set to the byte offset
// argument ``error_pos``, if set to non-nullptr, will be set to the byte offset
// into the buffer where the parse failure occurred.
//
// ``depth_limit`` specifies the max number of nested lists or dictionaries are
@ -411,7 +410,7 @@ TORRENT_EXPORT std::string print_entry(bdecode_node const& e
// produced by this function does not copy any data out of the buffer, but
// simply produces references back into it.
TORRENT_EXPORT int bdecode(char const* start, char const* end, bdecode_node& ret
, error_code& ec, int* error_pos = NULL, int depth_limit = 100
, error_code& ec, int* error_pos = nullptr, int depth_limit = 100
, int token_limit = 1000000);
}

View File

@ -56,18 +56,18 @@ namespace libtorrent
// The constructor taking a pointer ``b`` and ``bits`` copies a bitfield
// from the specified buffer, and ``bits`` number of bits (rounded up to
// the nearest byte boundary).
bitfield(): m_buf(NULL) {}
bitfield(int bits): m_buf(NULL)
bitfield(): m_buf(nullptr) {}
bitfield(int bits): m_buf(nullptr)
{ resize(bits); }
bitfield(int bits, bool val): m_buf(NULL)
bitfield(int bits, bool val): m_buf(nullptr)
{ resize(bits, val); }
bitfield(char const* b, int bits): m_buf(NULL)
bitfield(char const* b, int bits): m_buf(nullptr)
{ assign(b, bits); }
bitfield(bitfield const& rhs): m_buf(NULL)
bitfield(bitfield const& rhs): m_buf(nullptr)
{ assign(rhs.data(), rhs.size()); }
#if __cplusplus > 199711L
bitfield(bitfield&& rhs): m_buf(rhs.m_buf)
{ rhs.m_buf = NULL; }
{ rhs.m_buf = nullptr; }
#endif
// hidden
@ -126,7 +126,7 @@ namespace libtorrent
// returns the size of the bitfield in bits.
int size() const
{
return m_buf == NULL ? 0 : int(m_buf[-1]);
return m_buf == nullptr ? 0 : int(m_buf[-1]);
}
int num_words() const
@ -135,7 +135,7 @@ namespace libtorrent
}
// returns true if the bitfield has zero size.
bool empty() const { return m_buf == NULL ? true : m_buf[-1] == 0; }
bool empty() const { return m_buf == nullptr ? true : m_buf[-1] == 0; }
// returns a pointer to the internal buffer of the bitfield.
char const* data() const { return reinterpret_cast<char const*>(m_buf); }
@ -255,7 +255,7 @@ namespace libtorrent
void dealloc()
{
if (m_buf) std::free(m_buf-1);
m_buf = NULL;
m_buf = nullptr;
}
// the first element is not part of the bitfield, it's the

View File

@ -37,13 +37,8 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/config.hpp" // for sha1_hash
#include <cmath> // for log()
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <cstdint>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
namespace libtorrent
{
TORRENT_EXTRA_EXPORT void set_bits(std::uint8_t const* b, std::uint8_t* bits, int len);

View File

@ -38,6 +38,8 @@ POSSIBILITY OF SUCH DAMAGE.
#include <algorithm>
#include <vector>
#include <string>
#include <array>
#include <cstdint>
#include "libtorrent/debug.hpp"
@ -45,9 +47,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <boost/smart_ptr.hpp>
#include <boost/noncopyable.hpp>
#include <array>
#include <boost/optional.hpp>
#include <cstdint>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
@ -296,7 +296,7 @@ public:
// peer_connection functions of the same names
virtual void append_const_send_buffer(char const* buffer, int size
, chained_buffer::free_buffer_fun destructor = &nop
, void* userdata = NULL, block_cache_reference ref
, void* userdata = nullptr, block_cache_reference ref
= block_cache_reference()) override;
private:

View File

@ -29,19 +29,17 @@ POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef LIBTORRENT_BUFFER_HPP
#define LIBTORRENT_BUFFER_HPP
#ifndef TORRENT_BUFFER_HPP_INCLUDED
#define TORRENT_BUFFER_HPP_INCLUDED
#include <cstring>
#include <limits> // for numeric_limits
#include "libtorrent/invariant_check.hpp"
#include "libtorrent/assert.hpp"
#include <cstdlib> // malloc/free/realloc
#include <algorithm> // for std::swap
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <cstdint>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#include "libtorrent/invariant_check.hpp"
#include "libtorrent/assert.hpp"
namespace libtorrent {
@ -135,7 +133,7 @@ public:
, m_size(b.m_size)
, m_capacity(b.m_capacity)
{
b.m_begin = NULL;
b.m_begin = nullptr;
b.m_size = b.m_capacity = 0;
}
@ -146,7 +144,7 @@ public:
m_begin = b.m_begin;
m_size = b.m_size;
m_capacity = b.m_capacity;
b.m_begin = NULL;
b.m_begin = nullptr;
b.m_size = b.m_capacity = 0;
return *this;
}
@ -220,7 +218,7 @@ public:
char* tmp = static_cast<char*>(std::realloc(m_begin, n));
#ifndef BOOST_NO_EXCEPTIONS
if (tmp == NULL) throw std::bad_alloc();
if (tmp == nullptr) throw std::bad_alloc();
#endif
m_begin = tmp;
m_capacity = std::uint32_t(n);
@ -251,5 +249,5 @@ private:
}
#endif // LIBTORRENT_BUFFER_HPP
#endif // BTORRENT_BUFFER_HPP_INCLUDED

View File

@ -103,7 +103,7 @@ namespace libtorrent
// skip the stack frame of 'add_outstanding_async'
char* ptr = strchr(stack_text, '\n');
if (ptr != NULL) ++ptr;
if (ptr != nullptr) ++ptr;
else ptr = stack_text;
a.stack = ptr;
}

View File

@ -95,7 +95,7 @@ namespace libtorrent
char* get() const { return m_buf; }
// set the holder object to hold the specified buffer
// (or NULL by default). If it's already holding a
// (or nullptr by default). If it's already holding a
// disk buffer, it will first be freed.
void reset(char* buf = 0);
void reset(disk_io_job const& j);

View File

@ -60,20 +60,15 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/config.hpp"
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <map>
#include <list>
#include <string>
#include <stdexcept>
#include <cstdint>
#include <boost/config.hpp>
#if TORRENT_USE_IOSTREAM
#include <iosfwd>
#endif
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#include "libtorrent/assert.hpp"
#include "libtorrent/error_code.hpp"
@ -231,10 +226,8 @@ namespace libtorrent
// throw ``system_error``.
entry& operator[](char const* key);
entry& operator[](std::string const& key);
#ifndef BOOST_NO_EXCEPTIONS
const entry& operator[](char const* key) const;
const entry& operator[](std::string const& key) const;
#endif
// These functions requires the entry to be a dictionary, if it isn't
// they will throw ``system_error``.

View File

@ -98,7 +98,7 @@ POSSIBILITY OF SUCH DAMAGE.
// ``torrent_handle::add_extension()``.
//
// The function should return a ``boost::shared_ptr<torrent_plugin>`` which
// may or may not be 0. If it is a null pointer, the extension is simply ignored
// may or may not be 0. If it is a nullptr, the extension is simply ignored
// for this torrent. If it is a valid pointer (to a class inheriting
// ``torrent_plugin``), it will be associated with this torrent and callbacks
// will be made on torrent events.

View File

@ -199,7 +199,7 @@ namespace libtorrent
// array at the end, it will end up referring
// to the m_name field
struct dirent m_dirent;
char m_name[TORRENT_MAX_PATH + 1]; // +1 to make room for null
char m_name[TORRENT_MAX_PATH + 1]; // +1 to make room for terminating 0
#endif
bool m_done;
};
@ -220,7 +220,7 @@ namespace libtorrent
file* get();
file const* get() const;
operator bool() const;
file_handle& reset(file* f = NULL);
file_handle& reset(file* f = nullptr);
char stack[2048];
private:

View File

@ -95,7 +95,7 @@ namespace libtorrent
// release all files belonging to the specified storage_interface (``st``)
// the overload that takes ``file_index`` releases only the file with
// that index in storage ``st``.
void release(void* st = NULL);
void release(void* st = nullptr);
void release(void* st, int file_index);
// update the allowed number of open file handles to ``size``.

View File

@ -33,17 +33,12 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef TORRENT_FILE_STORAGE_HPP_INCLUDED
#define TORRENT_FILE_STORAGE_HPP_INCLUDED
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <string>
#include <vector>
#include <unordered_set>
#include <ctime>
#include <cstdint>
#include <boost/unordered_set.hpp>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#include "libtorrent/assert.hpp"
#include "libtorrent/peer_request.hpp"
@ -136,7 +131,7 @@ namespace libtorrent
, hidden_attribute(false)
, executable_attribute(false)
, symlink_attribute(false)
, name(NULL)
, name(nullptr)
, path_index(-1)
{}
@ -171,10 +166,10 @@ namespace libtorrent
std::uint64_t size:48;
// the number of characters in the name. If this is
// name_is_owned, name is null terminated and owned by this object
// name_is_owned, name is 0-terminated and owned by this object
// (i.e. it should be freed in the destructor). If
// the len is not name_is_owned, the name pointer doesn not belong
// to this object, and it's not null terminated
// to this object, and it's not 0-terminated
std::uint64_t name_len:12;
std::uint64_t pad_file:1;
std::uint64_t hidden_attribute:1;
@ -183,7 +178,7 @@ namespace libtorrent
// make it available for logging
private:
// This string is not necessarily null terminated!
// This string is not necessarily 0-terminated!
// that's why it's private, to keep people away from it
char const* name;
public:
@ -273,7 +268,7 @@ namespace libtorrent
// to ``filehash``, which is an optional pointer to a 20 byte binary
// SHA-1 hash of the file.
//
// if ``filename`` is NULL, the filename from ``path`` is used and not
// if ``filename`` is nullptr, the filename from ``path`` is used and not
// borrowed. In this case ``filename_len`` is ignored.
//
// The ``path`` argument is the full path (in the torrent file) to
@ -314,7 +309,7 @@ namespace libtorrent
#ifndef TORRENT_NO_DEPRECATE
TORRENT_DEPRECATED
void add_file(file_entry const& fe, char const* filehash = NULL);
void add_file(file_entry const& fe, char const* filehash = nullptr);
#if TORRENT_USE_WSTRING
// all wstring APIs are deprecated since 0.16.11
@ -540,7 +535,7 @@ namespace libtorrent
int file_index_at_offset(std::int64_t offset) const;
// low-level function. returns a pointer to the internal storage for
// the filename. This string may not be null terminated!
// the filename. This string may not be 0-terminated!
// the ``file_name_len()`` function returns the length of the filename.
char const* file_name_ptr(int index) const;
int file_name_len(int index) const;

View File

@ -37,12 +37,8 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/config.hpp"
#include "libtorrent/assert.hpp"
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <cstdint>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#ifdef TORRENT_USE_GCRYPT
#include <gcrypt.h>

View File

@ -34,14 +34,8 @@ POSSIBILITY OF SUCH DAMAGE.
#define TORRENT_HETEROGENEOUS_QUEUE_HPP_INCLUDED
#include <vector>
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <cstdint>
#include <boost/utility/enable_if.hpp>
#include <boost/type_traits/is_base_of.hpp>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#include <type_traits>
#include "libtorrent/assert.hpp"
@ -51,14 +45,14 @@ namespace libtorrent {
struct heterogeneous_queue
{
heterogeneous_queue()
: m_storage(NULL)
: m_storage(nullptr)
, m_capacity(0)
, m_size(0)
, m_num_items(0)
{}
template <class U, typename... Args>
typename boost::enable_if<boost::is_base_of<T, U>, U&>::type
typename std::enable_if<std::is_base_of<T, U>::value, U&>::type
emplace_back(Args&&... args)
{
// the size of the type rounded up to pointer alignment
@ -133,7 +127,7 @@ namespace libtorrent {
T* front()
{
if (m_size == 0) return NULL;
if (m_size == 0) return nullptr;
TORRENT_ASSERT(m_size > 1);
uintptr_t* ptr = m_storage;

View File

@ -146,7 +146,7 @@ private:
, error_code const& e);
void on_assign_bandwidth(error_code const& e);
void callback(error_code e, char* data = NULL, int size = 0);
void callback(error_code e, char* data = nullptr, int size = 0);
std::vector<char> m_recvbuffer;

View File

@ -37,20 +37,14 @@ POSSIBILITY OF SUCH DAMAGE.
#include <string>
#include <utility>
#include <vector>
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <cstdint>
#include <boost/tuple/tuple.hpp>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#include <tuple>
#include "libtorrent/config.hpp"
#include "libtorrent/buffer.hpp"
namespace libtorrent
{
// return true if the status code is 200, 206, or in the 300-400 range
TORRENT_EXTRA_EXPORT bool is_ok_status(int http_status);
@ -83,7 +77,7 @@ namespace libtorrent
buffer::const_interval get_body() const;
bool header_finished() const { return m_state == read_body; }
bool finished() const { return m_finished; }
boost::tuple<int, int> incoming(buffer::const_interval recv_buffer
std::tuple<int, int> incoming(buffer::const_interval recv_buffer
, bool& error);
int body_start() const { return m_body_start_pos; }
std::int64_t content_length() const { return m_content_length; }

View File

@ -37,18 +37,13 @@ POSSIBILITY OF SUCH DAMAGE.
#include <algorithm>
#include <deque>
#include <string>
#include <array>
#include <cstdint>
#include "libtorrent/debug.hpp"
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <boost/smart_ptr.hpp>
#include <boost/weak_ptr.hpp>
#include <boost/noncopyable.hpp>
#include <array>
#include <boost/optional.hpp>
#include <cstdint>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#include "libtorrent/config.hpp"

View File

@ -33,10 +33,7 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef TORRENT_IO_HPP_INCLUDED
#define TORRENT_IO_HPP_INCLUDED
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <cstdint>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#include <string>
#include <algorithm> // for copy
#include <cstring> // for memcpy

View File

@ -35,17 +35,12 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/config.hpp"
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <set>
#include <vector>
#include <boost/limits.hpp>
#include <boost/utility.hpp>
#include <cstdint>
#include <boost/tuple/tuple.hpp>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#include <tuple>
#include <iterator> // for next
#include <limits>
#include "libtorrent/address.hpp"
#include "libtorrent/assert.hpp"
@ -159,13 +154,13 @@ namespace detail
TORRENT_ASSERT(j != i);
std::uint32_t first_access = i->access;
std::uint32_t last_access = boost::prior(j)->access;
std::uint32_t last_access = std::prev(j)->access;
if (i->start != first && first_access != flags)
{
i = m_access_list.insert(i, range(first, flags));
}
else if (i != m_access_list.begin() && boost::prior(i)->access == flags)
else if (i != m_access_list.begin() && std::prev(i)->access == flags)
{
--i;
first_access = i->access;
@ -173,7 +168,7 @@ namespace detail
TORRENT_ASSERT(!m_access_list.empty());
TORRENT_ASSERT(i != m_access_list.end());
if (i != j) m_access_list.erase(boost::next(i), j);
if (i != j) m_access_list.erase(std::next(i), j);
if (i->start == first)
{
// we can do this const-cast because we know that the new
@ -206,8 +201,8 @@ namespace detail
typename range_t::const_iterator i = m_access_list.upper_bound(addr);
if (i != m_access_list.begin()) --i;
TORRENT_ASSERT(i != m_access_list.end());
TORRENT_ASSERT(i->start <= addr && (boost::next(i) == m_access_list.end()
|| addr < boost::next(i)->start));
TORRENT_ASSERT(i->start <= addr && (std::next(i) == m_access_list.end()
|| addr < std::next(i)->start));
return i->access;
}
@ -296,10 +291,10 @@ struct TORRENT_EXPORT ip_filter
int access(address const& addr) const;
#if TORRENT_USE_IPV6
typedef boost::tuple<std::vector<ip_range<address_v4> >
, std::vector<ip_range<address_v6> > > filter_tuple_t;
using filter_tuple_t = std::tuple<std::vector<ip_range<address_v4> >
, std::vector<ip_range<address_v6> > >;
#else
typedef std::vector<ip_range<address_v4> > filter_tuple_t;
using filter_tuple_t = std::vector<ip_range<address_v4> >;
#endif
// This function will return the current state of the filter in the minimum number of

View File

@ -95,15 +95,15 @@ public:
void assign(entry const& v)
{
assign(v, std::pair<char const*, int>(static_cast<char const*>(NULL)
, 0), 0, NULL, NULL);
assign(v, std::pair<char const*, int>(static_cast<char const*>(nullptr)
, 0), 0, nullptr, nullptr);
}
void assign(entry const& v, std::pair<char const*, int> salt
, std::uint64_t seq, char const* pk, char const* sk);
void assign(bdecode_node const& v)
{
assign(v, std::pair<char const*, int>(static_cast<char const*>(NULL)
, 0), 0, NULL, NULL);
assign(v, std::pair<char const*, int>(static_cast<char const*>(nullptr)
, 0), 0, nullptr, nullptr);
}
bool assign(bdecode_node const& v, std::pair<char const*, int> salt
, std::uint64_t seq, char const* pk, char const* sig);

View File

@ -37,6 +37,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <map>
#include <set>
#include <mutex>
#include <cstdint>
#include <libtorrent/config.hpp>
#include <libtorrent/kademlia/dht_storage.hpp>
@ -54,9 +55,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include <libtorrent/assert.hpp>
#include <libtorrent/bloom_filter.hpp>
#include <cstdint>
#include <boost/ref.hpp>
#include "libtorrent/socket.hpp"
namespace libtorrent {
@ -126,7 +124,7 @@ public:
node_id const& nid() const { return m_id; }
boost::tuple<int, int, int> size() const { return m_table.size(); }
std::tuple<int, int, int> size() const { return m_table.size(); }
std::int64_t num_global_nodes() const
{ return m_table.num_global_nodes(); }
@ -195,7 +193,7 @@ public:
void status(std::vector<dht_routing_bucket>& table
, std::vector<dht_lookup>& requests);
boost::tuple<int, int, int> get_stats_counters() const;
std::tuple<int, int, int> get_stats_counters() const;
#ifndef TORRENT_NO_DEPRECATE
void status(libtorrent::session_status& s);

View File

@ -34,10 +34,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <algorithm>
#include <vector>
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <cstdint>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#include "libtorrent/config.hpp"
#include "libtorrent/peer_id.hpp"

View File

@ -33,15 +33,15 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef OBSERVER_HPP
#define OBSERVER_HPP
#include <cstdint>
#include <libtorrent/time.hpp>
#include <libtorrent/address.hpp>
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <boost/pool/pool.hpp>
#include <boost/detail/atomic_count.hpp>
#include <boost/intrusive_ptr.hpp>
#include <cstdint>
#include "libtorrent/aux_/disable_warnings_pop.hpp"

View File

@ -33,18 +33,15 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef ROUTING_TABLE_HPP
#define ROUTING_TABLE_HPP
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <vector>
#include <set>
#include <unordered_set>
#include <cstdint>
#include <boost/utility.hpp>
#include <boost/tuple/tuple.hpp>
#include <tuple>
#include <array>
#include <boost/noncopyable.hpp>
#include <boost/unordered_set.hpp>
#include "libtorrent/aux_/disable_warnings_push.hpp"
//#include <boost/utility.hpp>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#include <libtorrent/kademlia/node_id.hpp>
@ -73,6 +70,28 @@ struct routing_table_node
bucket_t live_nodes;
};
struct ipv4_hash
{
using argument_type = address_v4::bytes_type;
using result_type = std::size_t;
result_type operator()(argument_type const& ip) const
{
return std::hash<std::uint32_t>()(*reinterpret_cast<std::uint32_t const*>(&ip[0]));
}
};
#if TORRENT_USE_IPV6
struct ipv6_hash
{
using argument_type = address_v6::bytes_type;
using result_type = std::size_t;
result_type operator()(argument_type const& ip) const
{
return std::hash<std::uint64_t>()(*reinterpret_cast<std::uint64_t const*>(&ip[0]));
}
};
#endif
struct ip_set
{
void insert(address addr);
@ -98,9 +117,9 @@ struct ip_set
// these must be multisets because there can be multiple routing table
// entries for a single IP when restrict_routing_ips is set to false
boost::unordered_multiset<address_v4::bytes_type> m_ip4s;
std::unordered_multiset<address_v4::bytes_type, ipv4_hash> m_ip4s;
#if TORRENT_USE_IPV6
boost::unordered_multiset<address_v6::bytes_type> m_ip6s;
std::unordered_multiset<address_v6::bytes_type, ipv6_hash> m_ip6s;
#endif
};
@ -126,19 +145,22 @@ namespace impl
TORRENT_EXTRA_EXPORT bool compare_ip_cidr(address const& lhs, address const& rhs);
class TORRENT_EXTRA_EXPORT routing_table : boost::noncopyable
class TORRENT_EXTRA_EXPORT routing_table
{
public:
// TODO: 3 to improve memory locality and scanning performance, turn the
// routing table into a single vector with boundaries for the nodes instead.
// Perhaps replacement nodes should be in a separate vector.
typedef std::vector<routing_table_node> table_t;
using table_t = std::vector<routing_table_node>;
routing_table(node_id const& id, udp proto
, int bucket_size
, dht_settings const& settings
, dht_logger* log);
routing_table(routing_table const&) = delete;
routing_table& operator=(routing_table const&) = delete;
#ifndef TORRENT_NO_DEPRECATE
void status(session_status& s) const;
#endif
@ -219,7 +241,7 @@ public:
// returns the number of nodes in the main buckets, number of nodes in the
// replacement buckets and the number of nodes in the main buckets that have
// been pinged and confirmed up
boost::tuple<int, int, int> size() const;
std::tuple<int, int, int> size() const;
std::int64_t num_global_nodes() const;

View File

@ -33,14 +33,12 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef RPC_MANAGER_HPP
#define RPC_MANAGER_HPP
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <unordered_map>
#include <cstdint>
#include <boost/pool/pool.hpp>
#include <boost/function/function3.hpp>
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <boost/pool/pool.hpp>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#include <libtorrent/socket.hpp>

View File

@ -95,24 +95,24 @@ namespace libtorrent
, lazy_entry& ret, int depth_limit = 1000, int item_limit = 1000000);
#endif
// this is a string that is not NULL-terminated. Instead it
// this is a string that is not 0-terminated. Instead it
// comes with a length, specified in bytes. This is particularly
// useful when parsing bencoded structures, because strings are
// not NULL-terminated internally, and requiring NULL termination
// not 0-terminated internally, and requiring 0-termination
// would require copying the string.
//
// see lazy_entry::string_pstr().
struct TORRENT_EXPORT pascal_string
{
// construct a string pointing to the characters at ``p``
// of length ``l`` characters. No NULL termination is required.
// of length ``l`` characters. No 0-termination is required.
pascal_string(char const* p, int l): len(l), ptr(p) {}
// the number of characters in the string.
int len;
// the pointer to the first character in the string. This is
// not NULL terminated, but instead consult the ``len`` field
// not 0-terminated, but instead consult the ``len`` field
// to know how many characters follow.
char const* ptr;
@ -147,7 +147,7 @@ namespace libtorrent
// internal
lazy_entry() : m_begin(0), m_len(0), m_size(0), m_type(none_t)
{ m_data.start = NULL; }
{ m_data.start = nullptr; }
// tells you which specific type this lazy entry has.
// See entry_type_t. The type determines which subset of
@ -172,7 +172,7 @@ namespace libtorrent
// internal
void construct_string(char const* start, int length);
// the string is not null-terminated!
// the string is not 0-terminated!
// use string_length() to determine how many bytes
// are part of the string.
char const* string_ptr() const
@ -181,7 +181,7 @@ namespace libtorrent
return m_data.start;
}
// this will return a null terminated string
// this will return a 0-terminated string
// it will write to the source buffer!
char const* string_cstr() const
{
@ -226,7 +226,7 @@ namespace libtorrent
void pop();
// if this is a dictionary, look for a key ``name``, and return
// a pointer to its value, or NULL if there is none.
// a pointer to its value, or nullptr if there is none.
lazy_entry* dict_find(char const* name);
lazy_entry const* dict_find(char const* name) const
{ return const_cast<lazy_entry*>(this)->dict_find(name); }
@ -237,13 +237,13 @@ namespace libtorrent
// if this is a dictionary, look for a key ``name`` whose value
// is a string. If such key exist, return a pointer to
// its value, otherwise NULL.
// its value, otherwise nullptr.
std::string dict_find_string_value(char const* name) const;
pascal_string dict_find_pstr(char const* name) const;
// if this is a dictionary, look for a key ``name`` whose value
// is an int. If such key exist, return a pointer to its value,
// otherwise NULL.
// otherwise nullptr.
std::int64_t dict_find_int_value(char const* name
, std::int64_t default_val = 0) const;
lazy_entry const* dict_find_int(char const* name) const;
@ -253,7 +253,7 @@ namespace libtorrent
// specified name in the dictionary. ``dict_find_dict`` only
// finds dictionaries and ``dict_find_list`` only finds lists.
// if no key with the corresponding value of the right type is
// found, NULL is returned.
// found, nullptr is returned.
lazy_entry const* dict_find_dict(char const* name) const;
lazy_entry const* dict_find_dict(std::string const& name) const;
lazy_entry const* dict_find_list(char const* name) const;
@ -330,7 +330,7 @@ namespace libtorrent
// internal: releases ownership of any memory allocated
void release()
{
m_data.start = NULL;
m_data.start = nullptr;
m_size = 0;
m_type = none_t;
}

View File

@ -68,7 +68,7 @@ namespace libtorrent
template <typename T>
struct linked_list
{
linked_list(): m_first(NULL), m_last(NULL), m_size(0) {}
linked_list(): m_first(nullptr), m_last(nullptr), m_size(0) {}
list_iterator<T> iterate() const
{ return list_iterator<T>(m_first); }

View File

@ -33,21 +33,18 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef TORRENT_PARSE_URL_HPP_INCLUDED
#define TORRENT_PARSE_URL_HPP_INCLUDED
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <boost/tuple/tuple.hpp>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#include <string>
#include "libtorrent/config.hpp"
#include <tuple>
#include <string>
#include "libtorrent/error_code.hpp"
namespace libtorrent
{
// returns protocol, auth, hostname, port, path
TORRENT_EXTRA_EXPORT boost::tuple<std::string, std::string
TORRENT_EXTRA_EXPORT std::tuple<std::string, std::string
, std::string, int, std::string>
parse_url_components(std::string url, error_code& ec);

View File

@ -30,16 +30,12 @@ POSSIBILITY OF SUCH DAMAGE.
*/
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <string>
#include <vector>
#include <mutex>
#include <boost/unordered_map.hpp>
#include <unordered_map>
#include <cstdint>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#include "libtorrent/config.hpp"
#include "libtorrent/file.hpp"
#include "libtorrent/error_code.hpp"
@ -109,7 +105,7 @@ namespace libtorrent
bool m_dirty_metadata;
// maps a piece index to the part-file slot it is stored in
boost::unordered_map<int, int> m_piece_map;
std::unordered_map<int, int> m_piece_map;
// this is the file handle to the part file
file m_file;

View File

@ -118,7 +118,7 @@ namespace libtorrent
bool is_recv_plaintext() const
{
return m_dec_handler.get() == NULL;
return m_dec_handler.get() == nullptr;
}
private:

View File

@ -36,13 +36,12 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/bandwidth_limit.hpp"
#include "libtorrent/assert.hpp"
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <vector>
#include <string>
#include <boost/smart_ptr.hpp>
#include <cstdint>
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <boost/smart_ptr.hpp>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
namespace libtorrent

View File

@ -70,6 +70,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <utility> // for std::forward
#include <tuple> // for make_tuple
#include <array>
#include <cstdint>
#include "libtorrent/aux_/disable_warnings_push.hpp"
@ -77,7 +78,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include <boost/weak_ptr.hpp>
#include <boost/noncopyable.hpp>
#include <boost/optional.hpp>
#include <cstdint>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
@ -309,7 +309,7 @@ namespace libtorrent
void set_peer_info(torrent_peer* pi)
{
TORRENT_ASSERT(m_peer_info == 0 || pi == 0 );
TORRENT_ASSERT(pi != NULL || m_disconnect_started);
TORRENT_ASSERT(pi != nullptr || m_disconnect_started);
m_peer_info = pi;
}
@ -659,12 +659,12 @@ namespace libtorrent
void append_send_buffer(char* buffer, int size
, chained_buffer::free_buffer_fun destructor = &nop
, void* userdata = NULL, block_cache_reference ref
, void* userdata = nullptr, block_cache_reference ref
= block_cache_reference());
virtual void append_const_send_buffer(char const* buffer, int size
, chained_buffer::free_buffer_fun destructor = &nop
, void* userdata = NULL, block_cache_reference ref
, void* userdata = nullptr, block_cache_reference ref
= block_cache_reference());
int outstanding_bytes() const { return m_outstanding_bytes; }

View File

@ -68,9 +68,9 @@ namespace libtorrent
, max_peerlist_size(1000)
, min_reconnect_time(60)
, loop_counter(0)
, ip(NULL), port(0)
, ip(nullptr), port(0)
, max_failcount(3)
, peer_allocator(NULL)
, peer_allocator(nullptr)
{}
bool is_paused;
bool is_finished;
@ -236,7 +236,7 @@ namespace libtorrent
peers_t m_peers;
// this should be NULL for the most part. It's set
// this should be nullptr for the most part. It's set
// to point to a valid torrent_peer object if that
// object needs to be kept alive. If we ever feel
// like removing a torrent_peer from m_peers, we

View File

@ -35,15 +35,11 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/config.hpp"
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <cstdint>
#include <atomic>
#include <mutex>
#include <array>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
namespace libtorrent
{
struct TORRENT_EXTRA_EXPORT counters

View File

@ -41,13 +41,8 @@ POSSIBILITY OF SUCH DAMAGE.
#include <vector>
#include <bitset>
#include <utility>
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <cstdint>
#include <boost/tuple/tuple.hpp>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#include <tuple>
#ifdef TORRENT_DEBUG_REFCOUNTS
#include <set>
@ -477,7 +472,7 @@ namespace libtorrent
friend struct piece_pos;
boost::tuple<bool, bool, int, int> requested_from(
std::tuple<bool, bool, int, int> requested_from(
piece_picker::downloading_piece const& p
, int num_blocks_in_piece, torrent_peer* peer) const;

View File

@ -166,10 +166,10 @@ namespace libtorrent
// pass 0 as the flags parameter.
session(settings_pack const& pack = settings_pack()
, int flags = start_default_features | add_default_plugins)
: session_handle(NULL)
: session_handle(nullptr)
{
TORRENT_CFG();
start(flags, pack, NULL);
start(flags, pack, nullptr);
}
// overload of the constructor that takes an external io_service to run
@ -188,7 +188,7 @@ namespace libtorrent
session(settings_pack const& pack
, io_service& ios
, int flags = start_default_features | add_default_plugins)
: session_handle(NULL)
: session_handle(nullptr)
{
TORRENT_CFG();
start(flags, pack, &ios);
@ -199,7 +199,7 @@ namespace libtorrent
session(fingerprint const& print
, int flags = start_default_features | add_default_plugins
, std::uint32_t alert_mask = alert::error_notification)
: session_handle(NULL)
: session_handle(nullptr)
{
TORRENT_CFG();
settings_pack pack;
@ -213,7 +213,7 @@ namespace libtorrent
pack.set_bool(settings_pack::enable_dht, false);
}
start(flags, pack, NULL);
start(flags, pack, nullptr);
}
TORRENT_DEPRECATED
@ -222,7 +222,7 @@ namespace libtorrent
, char const* listen_interface = "0.0.0.0"
, int flags = start_default_features | add_default_plugins
, int alert_mask = alert::error_notification)
: session_handle(NULL)
: session_handle(nullptr)
{
TORRENT_CFG();
TORRENT_ASSERT(listen_port_range.first > 0);
@ -234,7 +234,7 @@ namespace libtorrent
pack.set_str(settings_pack::peer_fingerprint, print.to_string());
char if_string[100];
if (listen_interface == NULL) listen_interface = "0.0.0.0";
if (listen_interface == nullptr) listen_interface = "0.0.0.0";
std::snprintf(if_string, sizeof(if_string), "%s:%d", listen_interface, listen_port_range.first);
pack.set_str(settings_pack::listen_interfaces, if_string);
@ -245,7 +245,7 @@ namespace libtorrent
pack.set_bool(settings_pack::enable_lsd, false);
pack.set_bool(settings_pack::enable_dht, false);
}
start(flags, pack, NULL);
start(flags, pack, nullptr);
}
#endif // TORRENT_NO_DEPRECATE

View File

@ -63,13 +63,13 @@ namespace libtorrent
struct TORRENT_EXPORT session_handle
{
session_handle() : m_impl(NULL) {}
session_handle() : m_impl(nullptr) {}
session_handle(aux::session_impl* impl)
: m_impl(impl)
{}
bool is_valid() const { return m_impl != NULL; }
bool is_valid() const { return m_impl != nullptr; }
// TODO: 2 the ip filter should probably be saved here too
@ -909,7 +909,7 @@ namespace libtorrent
// will pop it and the second will free it.
//
// If there is no alert in the queue and no alert arrives within the
// specified timeout, ``wait_for_alert`` returns NULL.
// specified timeout, ``wait_for_alert`` returns nullptr.
//
// In the python binding, ``wait_for_alert`` takes the number of
// milliseconds to wait as an integer.

View File

@ -95,7 +95,7 @@ namespace libtorrent
}
// copies 20 bytes from the pointer provided, into the sha1-hash.
// The passed in string MUST be at least 20 bytes. NULL terminators
// The passed in string MUST be at least 20 bytes. 0-terminators
// are ignored, ``s`` is treated like a raw memory buffer.
explicit sha1_hash(char const* s)
{

View File

@ -33,14 +33,10 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef TORRENT_STAT_CACHE_HPP
#define TORRENT_STAT_CACHE_HPP
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <vector>
#include <string>
#include <cstdint>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#include "libtorrent/config.hpp"
#include "libtorrent/error_code.hpp"
#include "libtorrent/file_storage.hpp"

View File

@ -294,7 +294,7 @@ namespace libtorrent
// on disk. If the resume data seems to be up-to-date, return true. If
// not, set ``error`` to a description of what mismatched and return false.
//
// If the ``links`` pointer is non-null, it has the same number
// If the ``links`` pointer is non-nullptr, it has the same number
// of elements as there are files. Each element is either empty or contains
// the absolute path to a file identical to the corresponding file in this
// torrent. The storage must create hard links (or copy) those files. If
@ -383,7 +383,7 @@ namespace libtorrent
friend struct read_fileop;
public:
// constructs the default_storage based on the give file_storage (fs).
// ``mapped`` is an optional argument (it may be NULL). If non-NULL it
// ``mapped`` is an optional argument (it may be nullptr). If non-nullptr it
// represents the file mapping that have been made to the torrent before
// adding it. That's where files are supposed to be saved and looked for
// on disk. ``save_path`` is the root save folder for this torrent.

View File

@ -61,8 +61,8 @@ namespace libtorrent
// see default_storage::default_storage()
struct TORRENT_EXPORT storage_params
{
storage_params(): files(NULL), mapped_files(NULL), pool(NULL)
, mode(storage_mode_sparse), priorities(NULL), info(NULL) {}
storage_params(): files(nullptr), mapped_files(nullptr), pool(nullptr)
, mode(storage_mode_sparse), priorities(nullptr), info(nullptr) {}
file_storage const* files;
file_storage const* mapped_files; // optional
std::string path;

View File

@ -35,16 +35,12 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/config.hpp"
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <vector>
#include <string>
#include <cstdint>
#include <boost/limits.hpp>
#include <limits>
#include <array> // for std::array
#include "libtorrent/aux_/disable_warnings_pop.hpp"
namespace libtorrent
{
TORRENT_EXTRA_EXPORT bool is_alpha(char c);
@ -100,11 +96,11 @@ namespace libtorrent
// searches for separator in the string 'last'. the pointer last points to
// is set to point to the first character following the separator.
// returns a pointer to a null terminated string starting at last, ending
// returns a pointer to a 0-terminated string starting at last, ending
// at the separator (the string is mutated to replace the separator with
// a '\0' character). If there is no separator, but the end of the string,
// the pointer next points to is set to the last null terminator, which will
// make the following invocation return NULL, to indicate the end of the
// the pointer next points to is set to the last 0-terminator, which will
// make the following invocation return nullptr, to indicate the end of the
// string.
TORRENT_EXTRA_EXPORT char* string_tokenize(char* last, char sep, char** next);

View File

@ -71,7 +71,7 @@ namespace libtorrent
//#error boost::enable_if< is_base<T, tailqueue_node<T> > >
struct TORRENT_EXTRA_EXPORT tailqueue
{
tailqueue(): m_first(NULL), m_last(NULL), m_size(0) {}
tailqueue(): m_first(nullptr), m_last(nullptr), m_size(0) {}
tailqueue_iterator<const T> iterate() const
{ return tailqueue_iterator<const T>(m_first); }

View File

@ -35,18 +35,13 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/config.hpp"
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <cstdint>
#include <chrono>
#if defined TORRENT_BUILD_SIMULATOR
#include "simulator/simulator.hpp"
#endif
#include "libtorrent/aux_/disable_warnings_pop.hpp"
namespace libtorrent {
#if defined TORRENT_BUILD_SIMULATOR

View File

@ -33,9 +33,7 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef TIMESTAMP_HISTORY_HPP
#define TIMESTAMP_HISTORY_HPP
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <cstdint>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#include "libtorrent/config.hpp"
#include "libtorrent/assert.hpp"

View File

@ -936,7 +936,7 @@ namespace libtorrent
int num_connect_candidates() const { return m_peer_list ? m_peer_list->num_connect_candidates() : 0; }
piece_manager& storage();
bool has_storage() const { return m_storage.get() != NULL; }
bool has_storage() const { return m_storage.get() != nullptr; }
torrent_info const& torrent_file() const
{ return *m_torrent_file; }
@ -1004,7 +1004,7 @@ namespace libtorrent
bool are_files_checked() const
{ return m_files_checked; }
bool valid_storage() const
{ return m_storage.get() != NULL; }
{ return m_storage.get() != nullptr; }
// parses the info section from the given
// bencoded tree and moves the torrent

View File

@ -35,11 +35,10 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/config.hpp"
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <vector>
#include <set>
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <boost/shared_ptr.hpp>
#include <boost/function.hpp>
#include <boost/weak_ptr.hpp>
@ -48,7 +47,6 @@ POSSIBILITY OF SUCH DAMAGE.
// for deprecated force_reannounce
#include <boost/date_time/posix_time/posix_time_duration.hpp>
#endif
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#include "libtorrent/address.hpp"
@ -878,7 +876,7 @@ namespace libtorrent
// Returns a pointer to the torrent_info object associated with this
// torrent. The torrent_info object may be a copy of the internal object.
// If the torrent doesn't have metadata, the pointer will not be
// initialized (i.e. a NULL pointer). The torrent may be in a state
// initialized (i.e. a nullptr). The torrent may be in a state
// without metadata only if it was started without a .torrent file, e.g.
// by using the libtorrent extension of just supplying a tracker and
// info-hash.

View File

@ -415,7 +415,7 @@ namespace libtorrent
// sha1-hash for that piece and ``info_hash()`` returns the 20-bytes
// sha1-hash for the info-section of the torrent file.
// ``hash_for_piece_ptr()`` returns a pointer to the 20 byte sha1 digest
// for the piece. Note that the string is not null-terminated.
// for the piece. Note that the string is not 0-terminated.
int piece_size(int index) const { return m_files.piece_size(index); }
sha1_hash hash_for_piece(int index) const;
char const* hash_for_piece_ptr(int index) const
@ -498,7 +498,7 @@ namespace libtorrent
// This function looks up keys from the info-dictionary of the loaded
// torrent file. It can be used to access extension values put in the
// .torrent file. If the specified key cannot be found, it returns NULL.
// .torrent file. If the specified key cannot be found, it returns nullptr.
bdecode_node info(char const* key) const;
// swap the content of this and ``ti```.
@ -566,7 +566,7 @@ namespace libtorrent
// these or strings of the "collections" key from the torrent file. The
// pointers point directly into the info_section buffer and when copied,
// these pointers must be corrected to point into the new buffer. The
// int is the length of the string. Strings are not NULL-terminated.
// int is the length of the string. Strings are not 0-terminated.
std::vector<std::pair<char const*, int> > m_collections;
// these are the collections from outside of the info-dict. These are

View File

@ -41,10 +41,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/storage_defs.hpp" // for storage_mode_t
#include "libtorrent/error_code.hpp" // for storage_mode_t
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <cstdint>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#include <string>
namespace libtorrent
@ -249,7 +246,7 @@ namespace libtorrent
std::int64_t all_time_upload;
std::int64_t all_time_download;
// the posix-time when this torrent was added. i.e. what ``time(NULL)``
// the posix-time when this torrent was added. i.e. what ``time(nullptr)``
// returned at the time.
time_t added_time;

View File

@ -39,14 +39,14 @@ POSSIBILITY OF SUCH DAMAGE.
#include <string>
#include <list>
#include <utility>
#include <cstdint>
#include <tuple>
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <cstdint>
#include <boost/weak_ptr.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/unordered_map.hpp>
#include <boost/function.hpp>

View File

@ -33,17 +33,15 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef TORRENT_UDP_TRACKER_CONNECTION_HPP_INCLUDED
#define TORRENT_UDP_TRACKER_CONNECTION_HPP_INCLUDED
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <vector>
#include <string>
#include <utility>
#include <ctime>
#include <mutex>
#include <boost/shared_ptr.hpp>
#include <cstdint>
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <boost/shared_ptr.hpp>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#include "libtorrent/udp_socket.hpp"

View File

@ -185,7 +185,7 @@ namespace libtorrent
int m_mtu_idx;
// this is passed on to the instantiate connection
// if this is non-null it will create SSL connections over uTP
// if this is non-nullptr it will create SSL connections over uTP
void* m_ssl_context;
};
}

View File

@ -35,21 +35,19 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/debug.hpp"
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <ctime>
#include <algorithm>
#include <vector>
#include <deque>
#include <string>
#include <array>
#include <cstdint>
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <boost/smart_ptr.hpp>
#include <boost/weak_ptr.hpp>
#include <boost/noncopyable.hpp>
#include <array>
#include <boost/optional.hpp>
#include <cstdint>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#include "libtorrent/buffer.hpp"

View File

@ -33,20 +33,20 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef TORRENT_WEB_PEER_CONNECTION_HPP_INCLUDED
#define TORRENT_WEB_PEER_CONNECTION_HPP_INCLUDED
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <ctime>
#include <algorithm>
#include <vector>
#include <deque>
#include <string>
#include <array>
#include <cstdint>
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <boost/smart_ptr.hpp>
#include <boost/weak_ptr.hpp>
#include <boost/noncopyable.hpp>
#include <array>
#include <boost/optional.hpp>
#include <cstdint>
#include "libtorrent/aux_/disable_warnings_pop.hpp"

View File

@ -66,7 +66,7 @@ namespace libtorrent
// , char const* val, int val_len)
// name is element or attribute name
// val is attribute value
// neither string is null terminated, but their lengths are specified via
// neither string is 0-terminated, but their lengths are specified via
// name_len and val_len respectively
TORRENT_EXTRA_EXPORT void xml_parse(char const* p, char const* end
, boost::function<void(int,char const*,int,char const*,int)> callback);

View File

@ -632,7 +632,7 @@ TORRENT_TEST(stop_when_ready)
}
// there should not have been any announces. the torrent should have
// been stopped *before* announcing.
TEST_CHECK(alert_cast<tracker_announce_alert>(a) == NULL);
TEST_CHECK(alert_cast<tracker_announce_alert>(a) == nullptr);
}
for (torrent_handle const& h : ses.get_torrents())

View File

@ -1909,7 +1909,7 @@ namespace libtorrent {
// ignore errors here. This is best-effort. It may be a broken encoding
// but at least we'll print the valid parts
bdecode(pkt_buf(), pkt_buf() + pkt_size(), print, ec, NULL, 100, 100);
bdecode(pkt_buf(), pkt_buf() + pkt_size(), print, ec, nullptr, 100, 100);
std::string msg = print_entry(print, true);

View File

@ -61,7 +61,7 @@ namespace libtorrent
if (!m_alerts[m_generation].empty())
return m_alerts[m_generation].front();
return NULL;
return nullptr;
}
void alert_manager::maybe_notify(alert* a, std::unique_lock<std::mutex>& lock)

View File

@ -115,7 +115,7 @@ namespace libtorrent
void* ret;
#if TORRENT_USE_POSIX_MEMALIGN
if (posix_memalign(&ret, page_size(), bytes)
!= 0) ret = NULL;
!= 0) ret = nullptr;
#elif TORRENT_USE_MEMALIGN
ret = memalign(page_size(), bytes);
#elif defined TORRENT_WINDOWS
@ -123,11 +123,11 @@ namespace libtorrent
#elif defined TORRENT_BEOS
area_id id = create_area("", &ret, B_ANY_ADDRESS
, (bytes + page_size() - 1) & (page_size()-1), B_NO_LOCK, B_READ_AREA | B_WRITE_AREA);
if (id < B_OK) return NULL;
if (id < B_OK) return nullptr;
#else
ret = valloc(size_t(bytes));
#endif
if (ret == NULL) return NULL;
if (ret == nullptr) return nullptr;
#ifdef TORRENT_DEBUG_BUFFERS
// make the two surrounding pages non-readable and -writable
@ -137,7 +137,7 @@ namespace libtorrent
print_backtrace(h->stack, sizeof(h->stack));
#ifdef TORRENT_WINDOWS
#define mprotect(buf, size, prot) VirtualProtect(buf, size, prot, NULL)
#define mprotect(buf, size, prot) VirtualProtect(buf, size, prot, nullptr)
#define PROT_READ PAGE_READONLY
#endif
mprotect(ret, page, PROT_READ);
@ -162,7 +162,7 @@ namespace libtorrent
#ifdef TORRENT_DEBUG_BUFFERS
#ifdef TORRENT_WINDOWS
#define mprotect(buf, size, prot) VirtualProtect(buf, size, prot, NULL)
#define mprotect(buf, size, prot) VirtualProtect(buf, size, prot, nullptr)
#define PROT_READ PAGE_READONLY
#define PROT_WRITE PAGE_READWRITE
#endif

View File

@ -207,7 +207,7 @@ TORRENT_EXPORT void print_backtrace(char* out, int len, int max_depth
if (!sym_initialized)
{
sym_initialized = true;
SymInitialize(p, NULL, true);
SymInitialize(p, nullptr, true);
}
SymRefreshModuleList(p);
for (int i = 0; i < size && len > 0; ++i)

View File

@ -47,7 +47,7 @@ namespace libtorrent
{
TORRENT_ASSERT(limit >= 0);
// if the throttle is more than this, we might overflow
TORRENT_ASSERT(limit < INT_MAX);
TORRENT_ASSERT(limit < inf);
m_limit = limit;
}

View File

@ -30,16 +30,12 @@ POSSIBILITY OF SUCH DAMAGE.
*/
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <cstdint>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#include "libtorrent/bandwidth_queue_entry.hpp"
#include <cstring>
#include <algorithm>
#include "libtorrent/bandwidth_queue_entry.hpp"
namespace libtorrent
{
bw_request::bw_request(boost::shared_ptr<bandwidth_socket> const& pe

View File

@ -110,7 +110,7 @@ namespace libtorrent
std::uint32_t state:1;
};
// str1 is null-terminated
// str1 is 0-terminated
// str2 is not, str2 is len2 chars
bool string_equal(char const* str1, char const* str2, int len2)
{
@ -212,7 +212,7 @@ namespace libtorrent
bdecode_node::bdecode_node()
: m_root_tokens(0)
, m_buffer(NULL)
, m_buffer(nullptr)
, m_buffer_size(0)
, m_token_idx(-1)
, m_last_index(-1)
@ -262,7 +262,7 @@ namespace libtorrent
, m_last_token(-1)
, m_size(-1)
{
TORRENT_ASSERT(tokens != NULL);
TORRENT_ASSERT(tokens != nullptr);
TORRENT_ASSERT(idx >= 0);
}
@ -279,7 +279,7 @@ namespace libtorrent
void bdecode_node::clear()
{
m_tokens.clear();
m_root_tokens = NULL;
m_root_tokens = nullptr;
m_token_idx = -1;
m_size = -1;
m_last_index = -1;
@ -780,7 +780,7 @@ namespace libtorrent
// in order to gracefully terminate the tree,
// make sure the end of the previous token is set correctly
if (error_pos) *error_pos = start - orig_start;
error_pos = NULL;
error_pos = nullptr;
start = int_start;
TORRENT_FAIL_BDECODE(e);
}

View File

@ -131,10 +131,10 @@ namespace libtorrent
const int b = (bits + 31) / 32;
if (bits == 0)
{
if (m_buf != NULL)
if (m_buf != nullptr)
{
std::free(m_buf-1);
m_buf = NULL;
m_buf = nullptr;
}
return;
}
@ -143,7 +143,7 @@ namespace libtorrent
{
std::uint32_t* tmp = static_cast<std::uint32_t*>(std::realloc(m_buf-1, (b+1) * 4));
#ifndef BOOST_NO_EXCEPTIONS
if (tmp == NULL) throw std::bad_alloc();
if (tmp == nullptr) throw std::bad_alloc();
#endif
m_buf = tmp + 1;
m_buf[-1] = bits;
@ -153,7 +153,7 @@ namespace libtorrent
// +1 because the first word is the size (in bits)
std::uint32_t* tmp = static_cast<std::uint32_t*>(std::malloc((b+1) * 4));
#ifndef BOOST_NO_EXCEPTIONS
if (tmp == NULL) throw std::bad_alloc();
if (tmp == nullptr) throw std::bad_alloc();
#endif
m_buf = tmp + 1;
m_buf[-1] = bits;

View File

@ -268,9 +268,9 @@ static_assert(sizeof(job_action_name)/sizeof(job_action_name[0])
"write", "volatile-read", "read-lru", "read-lru-ghost", "read-lfu", "read-lfu-ghost"
};
if (pe == NULL)
if (pe == nullptr)
{
assert_print("piece: NULL\n");
assert_print("piece: nullptr\n");
}
else
{
@ -309,7 +309,7 @@ static_assert(sizeof(job_action_name)/sizeof(job_action_name[0])
cached_piece_entry::cached_piece_entry()
: storage()
, hash(0)
, last_requester(NULL)
, last_requester(nullptr)
, blocks()
, expire(min_time())
, piece(0)
@ -390,7 +390,7 @@ int block_cache::try_read(disk_io_job* j, bool expect_no_fail)
// if the piece cannot be found in the cache,
// it's a cache miss
TORRENT_ASSERT(!expect_no_fail || p != NULL);
TORRENT_ASSERT(!expect_no_fail || p != nullptr);
if (p == 0) return -1;
#if TORRENT_USE_ASSERTS
@ -435,7 +435,7 @@ void block_cache::cache_hit(cached_piece_entry* p, void* requester, bool volatil
// frequently requested, when in fact it's only a single peer
int target_queue = cached_piece_entry::read_lru2;
if (p->last_requester == requester || requester == NULL)
if (p->last_requester == requester || requester == nullptr)
{
// if it's the same requester and the piece isn't in
// any of the ghost lists, ignore it
@ -459,7 +459,7 @@ void block_cache::cache_hit(cached_piece_entry* p, void* requester, bool volatil
target_queue = cached_piece_entry::read_lru1;
}
if (requester != NULL)
if (requester != nullptr)
p->last_requester = requester;
// if we have this piece anywhere in L1 or L2, it's a "hit"
@ -594,7 +594,7 @@ void block_cache::try_evict_one_volatile()
if (b.buf == 0 || b.refcount > 0 || b.dirty || b.pending) continue;
to_delete[num_to_delete++] = b.buf;
b.buf = NULL;
b.buf = nullptr;
TORRENT_PIECE_ASSERT(pe->num_blocks > 0, pe);
--pe->num_blocks;
TORRENT_PIECE_ASSERT(m_read_cache_size > 0, pe);
@ -650,7 +650,7 @@ cached_piece_entry* block_cache::allocate_piece(disk_io_job const* j, int cache_
pe.cache_state = cache_state;
pe.last_requester = j->requester;
TORRENT_PIECE_ASSERT(pe.blocks, &pe);
if (!pe.blocks) return 0;
if (!pe.blocks) return nullptr;
p = const_cast<cached_piece_entry*>(&*m_pieces.insert(pe).first);
j->storage->add_piece(p);
@ -815,7 +815,7 @@ cached_piece_entry* block_cache::add_dirty_block(disk_io_job* j)
TORRENT_PIECE_ASSERT(j->piece == pe->piece, pe);
pe->jobs.push_back(j);
if (block == 0 && pe->hash == NULL && pe->hashing_done == false)
if (block == 0 && pe->hash == nullptr && pe->hashing_done == false)
pe->hash = new partial_hash;
update_cache_state(pe);
@ -896,7 +896,7 @@ void block_cache::free_block(cached_piece_entry* pe, int block)
TORRENT_PIECE_ASSERT(pe->num_blocks > 0, pe);
--pe->num_blocks;
free_buffer(b.buf);
b.buf = NULL;
b.buf = nullptr;
}
bool block_cache::evict_piece(cached_piece_entry* pe, tailqueue<disk_io_job>& jobs)
@ -914,7 +914,7 @@ bool block_cache::evict_piece(cached_piece_entry* pe, tailqueue<disk_io_job>& jo
TORRENT_PIECE_ASSERT(pe->blocks[i].buf != 0, pe);
TORRENT_PIECE_ASSERT(num_to_delete < pe->blocks_in_piece, pe);
to_delete[num_to_delete++] = pe->blocks[i].buf;
pe->blocks[i].buf = NULL;
pe->blocks[i].buf = nullptr;
TORRENT_PIECE_ASSERT(pe->num_blocks > 0, pe);
--pe->num_blocks;
if (!pe->blocks[i].dirty)
@ -943,7 +943,7 @@ bool block_cache::evict_piece(cached_piece_entry* pe, tailqueue<disk_io_job>& jo
if (pe->ok_to_evict(true))
{
delete pe->hash;
pe->hash = NULL;
pe->hash = nullptr;
// append will move the items from pe->jobs onto the end of jobs
jobs.append(pe->jobs);
@ -991,7 +991,7 @@ void block_cache::erase_piece(cached_piece_entry* pe)
{
TORRENT_PIECE_ASSERT(pe->hash->offset == 0, pe);
delete pe->hash;
pe->hash = NULL;
pe->hash = nullptr;
}
if (pe->cache_state != cached_piece_entry::read_lru1_ghost
&& pe->cache_state != cached_piece_entry::read_lru2_ghost)
@ -1103,7 +1103,7 @@ int block_cache::try_evict_blocks(int num, cached_piece_entry* ignore)
if (b.buf == 0 || b.refcount > 0 || b.dirty || b.pending) continue;
to_delete[num_to_delete++] = b.buf;
b.buf = NULL;
b.buf = nullptr;
TORRENT_PIECE_ASSERT(pe->num_blocks > 0, pe);
--pe->num_blocks;
++removed;
@ -1182,7 +1182,7 @@ int block_cache::try_evict_blocks(int num, cached_piece_entry* ignore)
if (b.buf == 0 || b.refcount > 0 || b.dirty || b.pending) continue;
to_delete[num_to_delete++] = b.buf;
b.buf = NULL;
b.buf = nullptr;
TORRENT_PIECE_ASSERT(pe->num_blocks > 0, pe);
--pe->num_blocks;
++removed;
@ -1336,7 +1336,7 @@ void block_cache::insert_blocks(cached_piece_entry* pe, int block, file::iovec_t
TORRENT_PIECE_ASSERT(iov[i].iov_len == (std::min)(block_size()
, pe->storage->files()->piece_size(pe->piece) - block * block_size()), pe);
// no NULL pointers allowed
// no nullptrs allowed
TORRENT_ASSERT(iov[i].iov_base);
#ifdef TORRENT_DEBUG_BUFFERS
@ -1357,7 +1357,7 @@ void block_cache::insert_blocks(cached_piece_entry* pe, int block, file::iovec_t
{
pe->blocks[block].buf = static_cast<char*>(iov[i].iov_base);
TORRENT_PIECE_ASSERT(iov[i].iov_base != NULL, pe);
TORRENT_PIECE_ASSERT(iov[i].iov_base != nullptr, pe);
TORRENT_PIECE_ASSERT(pe->blocks[block].dirty == false, pe);
++pe->num_blocks;
++m_read_cache_size;
@ -1371,7 +1371,7 @@ void block_cache::insert_blocks(cached_piece_entry* pe, int block, file::iovec_t
}
}
TORRENT_ASSERT(pe->blocks[block].buf != NULL);
TORRENT_ASSERT(pe->blocks[block].buf != nullptr);
}
TORRENT_PIECE_ASSERT(pe->cache_state != cached_piece_entry::read_lru1_ghost, pe);
@ -1384,7 +1384,7 @@ bool block_cache::inc_block_refcount(cached_piece_entry* pe, int block, int reas
TORRENT_PIECE_ASSERT(pe->in_use, pe);
TORRENT_PIECE_ASSERT(block < pe->blocks_in_piece, pe);
TORRENT_PIECE_ASSERT(block >= 0, pe);
if (pe->blocks[block].buf == NULL) return false;
if (pe->blocks[block].buf == nullptr) return false;
TORRENT_PIECE_ASSERT(pe->blocks[block].refcount < cached_block_entry::max_refcount, pe);
if (pe->blocks[block].refcount == 0)
{
@ -1414,7 +1414,7 @@ void block_cache::dec_block_refcount(cached_piece_entry* pe, int block, int reas
TORRENT_PIECE_ASSERT(block < pe->blocks_in_piece, pe);
TORRENT_PIECE_ASSERT(block >= 0, pe);
TORRENT_PIECE_ASSERT(pe->blocks[block].buf != NULL, pe);
TORRENT_PIECE_ASSERT(pe->blocks[block].buf != nullptr, pe);
TORRENT_PIECE_ASSERT(pe->blocks[block].refcount > 0, pe);
--pe->blocks[block].refcount;
TORRENT_PIECE_ASSERT(pe->refcount > 0, pe);
@ -1452,12 +1452,12 @@ void block_cache::abort_dirty(cached_piece_entry* pe)
{
if (!pe->blocks[i].dirty
|| pe->blocks[i].refcount > 0
|| pe->blocks[i].buf == NULL) continue;
|| pe->blocks[i].buf == nullptr) continue;
TORRENT_PIECE_ASSERT(!pe->blocks[i].pending, pe);
TORRENT_PIECE_ASSERT(pe->blocks[i].dirty, pe);
to_delete[num_to_delete++] = pe->blocks[i].buf;
pe->blocks[i].buf = NULL;
pe->blocks[i].buf = nullptr;
pe->blocks[i].dirty = false;
TORRENT_PIECE_ASSERT(pe->num_blocks > 0, pe);
--pe->num_blocks;
@ -1495,7 +1495,7 @@ void block_cache::free_piece(cached_piece_entry* pe)
TORRENT_PIECE_ASSERT(pe->blocks[i].refcount == 0, pe);
TORRENT_PIECE_ASSERT(num_to_delete < pe->blocks_in_piece, pe);
to_delete[num_to_delete++] = pe->blocks[i].buf;
pe->blocks[i].buf = NULL;
pe->blocks[i].buf = nullptr;
TORRENT_PIECE_ASSERT(pe->num_blocks > 0, pe);
--pe->num_blocks;
if (pe->blocks[i].dirty)
@ -1536,7 +1536,7 @@ int block_cache::drain_piece_bufs(cached_piece_entry& p, std::vector<char*>& buf
TORRENT_PIECE_ASSERT(p.blocks[i].refcount == 0, &p);
buf.push_back(p.blocks[i].buf);
++ret;
p.blocks[i].buf = NULL;
p.blocks[i].buf = nullptr;
TORRENT_PIECE_ASSERT(p.num_blocks > 0, &p);
--p.num_blocks;
@ -1842,7 +1842,7 @@ void block_cache::reclaim_block(block_cache_reference const& ref)
{
cached_piece_entry* pe = find_piece(ref);
TORRENT_ASSERT(pe);
if (pe == NULL) return;
if (pe == nullptr) return;
TORRENT_PIECE_ASSERT(pe->in_use, pe);
@ -1893,7 +1893,7 @@ cached_piece_entry* block_cache::find_piece(piece_manager* st, int piece)
model.piece = piece;
iterator i = m_pieces.find(model);
TORRENT_ASSERT(i == m_pieces.end() || (i->storage.get() == st && i->piece == piece));
if (i == m_pieces.end()) return 0;
if (i == m_pieces.end()) return nullptr;
TORRENT_PIECE_ASSERT(i->in_use, &*i);
#if TORRENT_USE_ASSERTS

View File

@ -734,7 +734,7 @@ namespace libtorrent
// since we'll mutate it
char* buf = static_cast<char*>(malloc(size));
memcpy(buf, buffer, size);
append_send_buffer(buf, size, &regular_c_free, NULL);
append_send_buffer(buf, size, &regular_c_free, nullptr);
destructor(const_cast<char*>(buffer), userdata, ref);
}
else

View File

@ -185,7 +185,7 @@ namespace libtorrent
iothread->async_hash(storage.get(), *piece_counter
, disk_io_job::sequential_access
, std::bind(&on_hash, _1, t, storage, iothread
, piece_counter, completed_piece, f, ec), NULL);
, piece_counter, completed_piece, f, ec), nullptr);
++(*piece_counter);
}
else
@ -280,7 +280,7 @@ namespace libtorrent
storage_params params;
params.files = &t.files();
params.mapped_files = NULL;
params.mapped_files = nullptr;
params.path = path;
params.pool = &disk_thread.files();
params.mode = storage_mode_sparse;
@ -307,7 +307,7 @@ namespace libtorrent
{
disk_thread.async_hash(storage.get(), i, disk_io_job::sequential_access
, std::bind(&on_hash, _1, &t, storage, &disk_thread
, &piece_counter, &completed_piece, &f, &ec), NULL);
, &piece_counter, &completed_piece, &f, &ec), nullptr);
++piece_counter;
if (piece_counter >= t.num_pieces()) break;
}

View File

@ -232,7 +232,7 @@ namespace libtorrent
{
iov[i].iov_base = allocate_buffer_impl(l, "pending read");
iov[i].iov_len = block_size();
if (iov[i].iov_base == NULL)
if (iov[i].iov_base == nullptr)
{
// uh oh. We failed to allocate the buffer!
// we need to roll back and free all the buffers
@ -302,7 +302,7 @@ namespace libtorrent
ret = page_aligned_allocator::malloc(m_block_size);
}
#endif
if (ret == NULL)
if (ret == nullptr)
{
m_exceeded_max_size = true;
m_trigger_cache_trim();

View File

@ -43,7 +43,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/platform_util.hpp"
#include <boost/scoped_array.hpp>
#include <functional>
#include <boost/tuple/tuple.hpp>
#include <tuple>
#include <set>
#include <vector>
@ -345,7 +345,7 @@ namespace libtorrent
// otherwise, hold off
bool range_full = true;
cached_piece_entry* first_piece = NULL;
cached_piece_entry* first_piece = nullptr;
DLOG("try_flush_hashed: multi-piece: ");
for (int i = range_start; i < range_end; ++i)
{
@ -356,9 +356,9 @@ namespace libtorrent
continue;
}
cached_piece_entry* pe = m_disk_cache.find_piece(p->storage.get(), i);
if (pe == NULL)
if (pe == nullptr)
{
DLOG("[%d NULL] ", i);
DLOG("[%d nullptr] ", i);
range_full = false;
break;
}
@ -434,7 +434,7 @@ namespace libtorrent
cached_piece_entry* pe;
if (i == p->piece) pe = p;
else pe = m_disk_cache.find_piece(p->storage.get(), range_start + i);
if (pe == NULL
if (pe == nullptr
|| pe->cache_state != cached_piece_entry::write_lru)
{
refcount_pieces[i] = 0;
@ -461,7 +461,7 @@ namespace libtorrent
// ok, now we have one (or more, but hopefully one) contiguous
// iovec array. Now, flush it to disk
TORRENT_ASSERT(first_piece != NULL);
TORRENT_ASSERT(first_piece != nullptr);
if (iov_len == 0)
{
@ -485,7 +485,7 @@ namespace libtorrent
cached_piece_entry* pe;
if (i == p->piece) pe = p;
else pe = m_disk_cache.find_piece(p->storage.get(), range_start + i);
if (pe == NULL)
if (pe == nullptr)
{
DLOG("iovec_flushed: piece %d gone!\n", range_start + i);
TORRENT_PIECE_ASSERT(refcount_pieces[i] == 0, pe);
@ -553,7 +553,7 @@ namespace libtorrent
TORRENT_PIECE_ASSERT(size_left > 0, pe);
// don't flush blocks that are empty (buf == 0), not dirty
// (read cache blocks), or pending (already being written)
if (pe->blocks[i].buf == NULL
if (pe->blocks[i].buf == nullptr
|| pe->blocks[i].pending
|| !pe->blocks[i].dirty)
{
@ -684,7 +684,7 @@ namespace libtorrent
while (j)
{
disk_io_job* next = j->next;
j->next = NULL;
j->next = nullptr;
TORRENT_PIECE_ASSERT((j->flags & disk_io_job::in_progress) || !j->storage, pe);
TORRENT_PIECE_ASSERT(j->piece == pe->piece, pe);
if (j->completed(pe, block_size))
@ -817,7 +817,7 @@ namespace libtorrent
, end(piece_index.end()); i != end; ++i)
{
cached_piece_entry* pe = m_disk_cache.find_piece(storage, *i);
if (pe == NULL) continue;
if (pe == nullptr) continue;
TORRENT_PIECE_ASSERT(pe->storage.get() == storage, pe);
flush_piece(pe, flags, completed_jobs, l);
}
@ -890,7 +890,7 @@ namespace libtorrent
// TODO: instead of doing a lookup each time through the loop, save
// cached_piece_entry pointers with piece_refcount incremented to pin them
cached_piece_entry* pe = m_disk_cache.find_piece(i->first, i->second);
if (pe == NULL) continue;
if (pe == nullptr) continue;
// another thread may flush this piece while we're looping and
// evict it into a read piece and then also evict it to ghost
@ -920,7 +920,7 @@ namespace libtorrent
, end(pieces.end()); i != end; ++i)
{
cached_piece_entry* pe = m_disk_cache.find_piece(i->first, i->second);
if (pe == NULL) continue;
if (pe == nullptr) continue;
if (pe->num_dirty == 0) continue;
// another thread may flush this piece while we're looping and
@ -1195,7 +1195,7 @@ namespace libtorrent
if (evict > 0) m_disk_cache.try_evict_blocks(evict);
cached_piece_entry* pe = m_disk_cache.find_piece(j);
if (pe == NULL)
if (pe == nullptr)
{
l.unlock();
return do_uncached_read(j);
@ -1257,7 +1257,7 @@ namespace libtorrent
m_disk_cache.free_iovec(iov, iov_len);
pe = m_disk_cache.find_piece(j);
if (pe == NULL)
if (pe == nullptr)
{
// the piece is supposed to be allocated when the
// disk job is allocated
@ -1331,7 +1331,7 @@ namespace libtorrent
pe->read_jobs.swap(stalled_jobs);
// the next job to issue (i.e. this is a cache-miss)
disk_io_job* next_job = NULL;
disk_io_job* next_job = nullptr;
while (stalled_jobs.size() > 0)
{
@ -1358,7 +1358,7 @@ namespace libtorrent
{
// cache-miss, issue the first one
// put back the rest
if (next_job == NULL)
if (next_job == nullptr)
{
next_job = j;
}
@ -1413,7 +1413,7 @@ namespace libtorrent
}
m_disk_cache.free_buffer(j->buffer.disk_block);
j->buffer.disk_block = NULL;
j->buffer.disk_block = nullptr;
return ret;
}
@ -1432,7 +1432,7 @@ namespace libtorrent
print_piece_log(pe->piece_log);
#endif
TORRENT_ASSERT(pe->blocks[j->d.io.offset / 16 / 1024].buf != j->buffer.disk_block);
TORRENT_ASSERT(pe->blocks[j->d.io.offset / 16 / 1024].buf != NULL);
TORRENT_ASSERT(pe->blocks[j->d.io.offset / 16 / 1024].buf != nullptr);
j->error.ec = error::operation_aborted;
j->error.operation = storage_error::write;
return -1;
@ -1569,13 +1569,13 @@ namespace libtorrent
// but only if there is no existing piece entry. Otherwise there may be a
// partial hit on one-or-more dirty buffers so we must use the cache
// to avoid reading bogus data from storage
if (m_disk_cache.find_piece(j) == NULL)
if (m_disk_cache.find_piece(j) == nullptr)
return 1;
}
cached_piece_entry* pe = m_disk_cache.allocate_piece(j, cached_piece_entry::read_lru1);
if (pe == NULL)
if (pe == nullptr)
{
j->ret = -1;
j->error.ec = error::no_memory;
@ -1632,7 +1632,7 @@ namespace libtorrent
// to be cleared first, (async_clear_piece).
TORRENT_ASSERT(pe->hashing_done == 0);
TORRENT_ASSERT(pe->blocks[r.start / 0x4000].refcount == 0 || pe->blocks[r.start / 0x4000].buf == NULL);
TORRENT_ASSERT(pe->blocks[r.start / 0x4000].refcount == 0 || pe->blocks[r.start / 0x4000].buf == nullptr);
}
l3_.unlock();
#endif
@ -1735,7 +1735,7 @@ namespace libtorrent
memcpy(j->d.piece_hash, &result[0], 20);
delete pe->hash;
pe->hash = NULL;
pe->hash = nullptr;
if (pe->cache_state != cached_piece_entry::volatile_read_lru)
pe->hashing_done = 1;
@ -1806,7 +1806,7 @@ namespace libtorrent
{
disk_io_job* next = qj->next;
#if TORRENT_USE_ASSERTS
qj->next = NULL;
qj->next = nullptr;
#endif
if (qj->storage.get() == storage)
to_abort.push_back(qj);
@ -1887,7 +1887,7 @@ namespace libtorrent
{
disk_io_job* next = qj->next;
#if TORRENT_USE_ASSERTS
qj->next = NULL;
qj->next = nullptr;
#endif
if (qj->storage.get() == storage)
to_abort.push_back(qj);
@ -2059,7 +2059,7 @@ namespace libtorrent
TORRENT_PIECE_ASSERT(pe->hashing == false, pe);
pe->hashing_done = 0;
delete pe->hash;
pe->hash = NULL;
pe->hash = nullptr;
// evict_piece returns true if the piece was in fact
// evicted. A piece may fail to be evicted if there
@ -2152,7 +2152,7 @@ namespace libtorrent
{
TORRENT_PIECE_ASSERT((j->flags & disk_io_job::in_progress) || !j->storage, pe);
disk_io_job* next = j->next;
j->next = NULL;
j->next = nullptr;
TORRENT_PIECE_ASSERT(j->piece == pe->piece, pe);
if (j->action == disk_io_job::hash) hash_jobs.push_back(j);
else pe->jobs.push_back(j);
@ -2170,7 +2170,7 @@ namespace libtorrent
}
delete pe->hash;
pe->hash = NULL;
pe->hash = nullptr;
if (pe->cache_state != cached_piece_entry::volatile_read_lru)
pe->hashing_done = 1;
#if TORRENT_USE_ASSERTS
@ -2264,7 +2264,7 @@ namespace libtorrent
sha1_hash piece_hash = pe->hash->h.final();
memcpy(j->d.piece_hash, &piece_hash[0], 20);
delete pe->hash;
pe->hash = NULL;
pe->hash = nullptr;
if (pe->cache_state != cached_piece_entry::volatile_read_lru)
pe->hashing_done = 1;
#if TORRENT_USE_ASSERTS
@ -2280,14 +2280,14 @@ namespace libtorrent
return do_uncached_hash(j);
}
if (pe == NULL)
if (pe == nullptr)
{
int cache_state = (j->flags & disk_io_job::volatile_read)
? cached_piece_entry::volatile_read_lru
: cached_piece_entry::read_lru1;
pe = m_disk_cache.allocate_piece(j, cache_state);
}
if (pe == NULL)
if (pe == nullptr)
{
j->error.ec = error::no_memory;
j->error.operation = storage_error::alloc_cache_piece;
@ -2310,7 +2310,7 @@ namespace libtorrent
|| pe->cache_state == cached_piece_entry::read_lru2, pe);
++pe->piece_refcount;
if (pe->hash == NULL)
if (pe->hash == nullptr)
{
pe->hashing_done = 0;
pe->hash = new partial_hash;
@ -2333,7 +2333,7 @@ namespace libtorrent
for (int i = ph->offset / block_size; i < blocks_in_piece; ++i)
{
// is the block not in the cache?
if (pe->blocks[i].buf == NULL) continue;
if (pe->blocks[i].buf == nullptr) continue;
// if we fail to lock the block, it' no longer in the cache
if (m_disk_cache.inc_block_refcount(pe, i, block_cache::ref_hashing) == false)
@ -2367,7 +2367,7 @@ namespace libtorrent
{
iov.iov_base = m_disk_cache.allocate_buffer("hashing");
if (iov.iov_base == NULL)
if (iov.iov_base == nullptr)
{
l.lock();
// TODO: introduce a holder class that automatically increments
@ -2380,7 +2380,7 @@ namespace libtorrent
--pe->piece_refcount;
pe->hashing = false;
delete pe->hash;
pe->hash = NULL;
pe->hash = nullptr;
m_disk_cache.maybe_free_piece(pe);
@ -2455,7 +2455,7 @@ namespace libtorrent
memcpy(j->d.piece_hash, &piece_hash[0], 20);
delete pe->hash;
pe->hash = NULL;
pe->hash = nullptr;
if (pe->cache_state != cached_piece_entry::volatile_read_lru)
pe->hashing_done = 1;
#if TORRENT_USE_ASSERTS
@ -2524,7 +2524,7 @@ namespace libtorrent
add_torrent_params const* rd = j->buffer.check_resume_data;
add_torrent_params tmp;
if (rd == NULL) rd = &tmp;
if (rd == nullptr) rd = &tmp;
std::unique_ptr<std::vector<std::string> > links(j->d.links);
return j->storage->check_fastresume(*rd, links.get(), j->error);
@ -2575,14 +2575,14 @@ namespace libtorrent
std::unique_lock<std::mutex> l(m_cache_mutex);
cached_piece_entry* pe = m_disk_cache.find_piece(j);
if (pe == NULL)
if (pe == nullptr)
{
int cache_state = (j->flags & disk_io_job::volatile_read)
? cached_piece_entry::volatile_read_lru
: cached_piece_entry::read_lru1;
pe = m_disk_cache.allocate_piece(j, cache_state);
}
if (pe == NULL)
if (pe == nullptr)
{
j->error.ec = error::no_memory;
j->error.operation = storage_error::alloc_cache_piece;
@ -2616,7 +2616,7 @@ namespace libtorrent
iov.iov_base = m_disk_cache.allocate_buffer("read cache");
if (iov.iov_base == NULL)
if (iov.iov_base == nullptr)
{
//#error introduce a holder class that automatically increments and decrements the piece_refcount
--pe->piece_refcount;
@ -2815,7 +2815,7 @@ namespace libtorrent
std::unique_lock<std::mutex> l(m_cache_mutex);
cached_piece_entry* pe = m_disk_cache.find_piece(j);
if (pe == NULL) return 0;
if (pe == nullptr) return 0;
#if TORRENT_USE_ASSERTS
pe->piece_log.push_back(piece_log_t(j->action));
@ -2835,7 +2835,7 @@ namespace libtorrent
cached_piece_entry* pe = m_disk_cache.find_piece(j);
if (pe == NULL) return 0;
if (pe == nullptr) return 0;
pe->outstanding_flush = 0;
@ -2911,7 +2911,7 @@ namespace libtorrent
torrent_info* t = new torrent_info(filename, j->error.ec);
if (j->error.ec)
{
j->buffer.torrent_file = NULL;
j->buffer.torrent_file = nullptr;
delete t;
}
else
@ -2938,7 +2938,7 @@ namespace libtorrent
TORRENT_PIECE_ASSERT(pe->hashing == false, pe);
pe->hashing_done = 0;
delete pe->hash;
pe->hash = NULL;
pe->hash = nullptr;
pe->hashing_done = false;
#if TORRENT_USE_ASSERTS
@ -3039,7 +3039,7 @@ namespace libtorrent
TORRENT_ASSERT(m_magic == 0x1337);
TORRENT_ASSERT(!j->storage || j->storage->files()->is_valid());
TORRENT_ASSERT(j->next == NULL);
TORRENT_ASSERT(j->next == nullptr);
// if this happens, it means we started to shut down
// the disk threads too early. We have to post all jobs
// before the disk threads are shut down
@ -3436,7 +3436,7 @@ namespace libtorrent
if (pe)
{
TORRENT_ASSERT(pe->blocks[j->d.io.offset / 16 / 1024].buf != j->buffer.disk_block);
TORRENT_ASSERT(pe->blocks[j->d.io.offset / 16 / 1024].buf == NULL);
TORRENT_ASSERT(pe->blocks[j->d.io.offset / 16 / 1024].buf == nullptr);
TORRENT_ASSERT(!pe->hashing_done);
}
}
@ -3473,7 +3473,7 @@ namespace libtorrent
cached_piece_entry* pe = m_disk_cache.add_dirty_block(j);
if (pe == NULL)
if (pe == nullptr)
{
// this isn't correct, since jobs in the jobs
// queue aren't ordered

View File

@ -46,12 +46,6 @@ POSSIBILITY OF SUCH DAMAGE.
namespace
{
template <class T>
void call_destructor(T* o)
{
TORRENT_ASSERT(o);
o->~T();
}
}
namespace libtorrent
@ -81,14 +75,22 @@ namespace libtorrent
namespace
{
#ifndef BOOST_NO_EXCEPTIONS
TORRENT_NO_RETURN inline void throw_error()
{
#ifndef BOOST_NO_EXCEPTIONS
throw system_error(error_code(errors::invalid_entry_type
, get_libtorrent_category()));
}
#else
std::terminate();
#endif
}
template <class T>
void call_destructor(T* o)
{
TORRENT_ASSERT(o);
o->~T();
}
}
entry& entry::operator[](char const* key)
@ -137,7 +139,6 @@ namespace libtorrent
return &i->second;
}
#ifndef BOOST_NO_EXCEPTIONS
const entry& entry::operator[](char const* key) const
{
return (*this)[std::string(key)];
@ -149,11 +150,10 @@ namespace libtorrent
if (i == dict().end()) throw_error();
return i->second;
}
#endif
entry::data_type entry::type() const
{
#ifdef TORRENT_DEBUG
#if TORRENT_USE_ASSERTS
m_type_queried = true;
#endif
return entry::data_type(m_type);
@ -178,20 +178,18 @@ namespace libtorrent
entry::integer_type& entry::integer()
{
if (m_type == undefined_t) construct(int_t);
#ifndef BOOST_NO_EXCEPTIONS
if (m_type != int_t) throw_error();
#elif defined TORRENT_DEBUG
#ifdef BOOST_NO_EXCEPTIONS
TORRENT_ASSERT(m_type_queried);
#endif
if (m_type != int_t) throw_error();
TORRENT_ASSERT(m_type == int_t);
return *reinterpret_cast<integer_type*>(&data);
}
entry::integer_type const& entry::integer() const
{
#ifndef BOOST_NO_EXCEPTIONS
if (m_type != int_t) throw_error();
#elif defined TORRENT_DEBUG
#ifdef BOOST_NO_EXCEPTIONS
TORRENT_ASSERT(m_type_queried);
#endif
TORRENT_ASSERT(m_type == int_t);
@ -201,20 +199,18 @@ namespace libtorrent
entry::string_type& entry::string()
{
if (m_type == undefined_t) construct(string_t);
#ifndef BOOST_NO_EXCEPTIONS
if (m_type != string_t) throw_error();
#elif defined TORRENT_DEBUG
#ifdef BOOST_NO_EXCEPTIONS
TORRENT_ASSERT(m_type_queried);
#endif
if (m_type != string_t) throw_error();
TORRENT_ASSERT(m_type == string_t);
return *reinterpret_cast<string_type*>(&data);
}
entry::string_type const& entry::string() const
{
#ifndef BOOST_NO_EXCEPTIONS
if (m_type != string_t) throw_error();
#elif defined TORRENT_DEBUG
#ifdef BOOST_NO_EXCEPTIONS
TORRENT_ASSERT(m_type_queried);
#endif
TORRENT_ASSERT(m_type == string_t);
@ -224,20 +220,18 @@ namespace libtorrent
entry::list_type& entry::list()
{
if (m_type == undefined_t) construct(list_t);
#ifndef BOOST_NO_EXCEPTIONS
if (m_type != list_t) throw_error();
#elif defined TORRENT_DEBUG
#ifdef BOOST_NO_EXCEPTIONS
TORRENT_ASSERT(m_type_queried);
#endif
if (m_type != list_t) throw_error();
TORRENT_ASSERT(m_type == list_t);
return *reinterpret_cast<list_type*>(&data);
}
entry::list_type const& entry::list() const
{
#ifndef BOOST_NO_EXCEPTIONS
if (m_type != list_t) throw_error();
#elif defined TORRENT_DEBUG
#ifdef BOOST_NO_EXCEPTIONS
TORRENT_ASSERT(m_type_queried);
#endif
TORRENT_ASSERT(m_type == list_t);
@ -247,20 +241,18 @@ namespace libtorrent
entry::dictionary_type& entry::dict()
{
if (m_type == undefined_t) construct(dictionary_t);
#ifndef BOOST_NO_EXCEPTIONS
if (m_type != dictionary_t) throw_error();
#elif defined TORRENT_DEBUG
#ifdef BOOST_NO_EXCEPTIONS
TORRENT_ASSERT(m_type_queried);
#endif
if (m_type != dictionary_t) throw_error();
TORRENT_ASSERT(m_type == dictionary_t);
return *reinterpret_cast<dictionary_type*>(&data);
}
entry::dictionary_type const& entry::dict() const
{
#ifndef BOOST_NO_EXCEPTIONS
if (m_type != dictionary_t) throw_error();
#elif defined TORRENT_DEBUG
#ifdef BOOST_NO_EXCEPTIONS
TORRENT_ASSERT(m_type_queried);
#endif
TORRENT_ASSERT(m_type == dictionary_t);
@ -270,20 +262,18 @@ namespace libtorrent
entry::preformatted_type& entry::preformatted()
{
if (m_type == undefined_t) construct(preformatted_t);
#ifndef BOOST_NO_EXCEPTIONS
if (m_type != preformatted_t) throw_error();
#elif defined TORRENT_DEBUG
#ifdef BOOST_NO_EXCEPTIONS
TORRENT_ASSERT(m_type_queried);
#endif
if (m_type != preformatted_t) throw_error();
TORRENT_ASSERT(m_type == preformatted_t);
return *reinterpret_cast<preformatted_type*>(&data);
}
entry::preformatted_type const& entry::preformatted() const
{
#ifndef BOOST_NO_EXCEPTIONS
if (m_type != preformatted_t) throw_error();
#elif defined TORRENT_DEBUG
#ifdef BOOST_NO_EXCEPTIONS
TORRENT_ASSERT(m_type_queried);
#endif
TORRENT_ASSERT(m_type == preformatted_t);
@ -293,7 +283,7 @@ namespace libtorrent
entry::entry()
: m_type(undefined_t)
{
#ifdef TORRENT_DEBUG
#if TORRENT_USE_ASSERTS
m_type_queried = true;
#endif
}
@ -302,7 +292,7 @@ namespace libtorrent
: m_type(undefined_t)
{
construct(t);
#ifdef TORRENT_DEBUG
#if TORRENT_USE_ASSERTS
m_type_queried = true;
#endif
}
@ -311,7 +301,7 @@ namespace libtorrent
: m_type(undefined_t)
{
copy(e);
#ifdef TORRENT_DEBUG
#if TORRENT_USE_ASSERTS
m_type_queried = e.m_type_queried;
#endif
}
@ -319,11 +309,11 @@ namespace libtorrent
entry::entry(entry&& e)
: m_type(undefined_t)
{
#ifdef TORRENT_DEBUG
#if TORRENT_USE_ASSERTS
uint8_t type_queried = e.m_type_queried;
#endif
swap(e);
#ifdef TORRENT_DEBUG
#if TORRENT_USE_ASSERTS
m_type_queried = type_queried;
#endif
}
@ -331,7 +321,7 @@ namespace libtorrent
entry::entry(dictionary_type const& v)
: m_type(undefined_t)
{
#ifdef TORRENT_DEBUG
#if TORRENT_USE_ASSERTS
m_type_queried = true;
#endif
new(&data) dictionary_type(v);
@ -341,7 +331,7 @@ namespace libtorrent
entry::entry(string_type const& v)
: m_type(undefined_t)
{
#ifdef TORRENT_DEBUG
#if TORRENT_USE_ASSERTS
m_type_queried = true;
#endif
new(&data) string_type(v);
@ -351,7 +341,7 @@ namespace libtorrent
entry::entry(list_type const& v)
: m_type(undefined_t)
{
#ifdef TORRENT_DEBUG
#if TORRENT_USE_ASSERTS
m_type_queried = true;
#endif
new(&data) list_type(v);
@ -361,7 +351,7 @@ namespace libtorrent
entry::entry(integer_type const& v)
: m_type(undefined_t)
{
#ifdef TORRENT_DEBUG
#if TORRENT_USE_ASSERTS
m_type_queried = true;
#endif
new(&data) integer_type(v);
@ -371,7 +361,7 @@ namespace libtorrent
entry::entry(preformatted_type const& v)
: m_type(undefined_t)
{
#ifdef TORRENT_DEBUG
#if TORRENT_USE_ASSERTS
m_type_queried = true;
#endif
new(&data) preformatted_type(v);
@ -461,7 +451,7 @@ namespace libtorrent
destruct();
new(&data) preformatted_type(v);
m_type = preformatted_t;
#ifdef TORRENT_DEBUG
#if TORRENT_USE_ASSERTS
m_type_queried = true;
#endif
return *this;
@ -472,7 +462,7 @@ namespace libtorrent
destruct();
new(&data) dictionary_type(v);
m_type = dictionary_t;
#ifdef TORRENT_DEBUG
#if TORRENT_USE_ASSERTS
m_type_queried = true;
#endif
return *this;
@ -483,7 +473,7 @@ namespace libtorrent
destruct();
new(&data) string_type(v);
m_type = string_t;
#ifdef TORRENT_DEBUG
#if TORRENT_USE_ASSERTS
m_type_queried = true;
#endif
return *this;
@ -494,7 +484,7 @@ namespace libtorrent
destruct();
new(&data) list_type(v);
m_type = list_t;
#ifdef TORRENT_DEBUG
#if TORRENT_USE_ASSERTS
m_type_queried = true;
#endif
return *this;
@ -505,7 +495,7 @@ namespace libtorrent
destruct();
new(&data) integer_type(v);
m_type = int_t;
#ifdef TORRENT_DEBUG
#if TORRENT_USE_ASSERTS
m_type_queried = true;
#endif
return *this;
@ -513,7 +503,7 @@ namespace libtorrent
bool entry::operator==(entry const& e) const
{
if (m_type != e.m_type) return false;
if (type() != e.type()) return false;
switch (m_type)
{
@ -556,7 +546,7 @@ namespace libtorrent
break;
}
m_type = t;
#ifdef TORRENT_DEBUG
#if TORRENT_USE_ASSERTS
m_type_queried = true;
#endif
}
@ -585,7 +575,7 @@ namespace libtorrent
break;
}
m_type = e.type();
#ifdef TORRENT_DEBUG
#if TORRENT_USE_ASSERTS
m_type_queried = true;
#endif
}
@ -614,7 +604,7 @@ namespace libtorrent
break;
}
m_type = undefined_t;
#ifdef TORRENT_DEBUG
#if TORRENT_USE_ASSERTS
m_type_queried = false;
#endif
}
@ -692,7 +682,7 @@ namespace libtorrent
{
TORRENT_ASSERT(indent >= 0);
for (int i = 0; i < indent; ++i) out += " ";
switch (m_type)
switch (type())
{
case int_t:
out += libtorrent::to_string(integer()).data();
@ -759,7 +749,6 @@ namespace libtorrent
out += "<preformatted>\n";
break;
case undefined_t:
default:
out += "<uninitialized>\n";
}
}

View File

@ -310,7 +310,7 @@ int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldl
// determine address
rv.interface_address = sockaddr_to_address(ifa->ifa_addr);
// determine netmask
if (ifa->ifa_netmask != NULL)
if (ifa->ifa_netmask != nullptr)
{
rv.netmask = sockaddr_to_address(ifa->ifa_netmask);
}
@ -468,7 +468,7 @@ namespace libtorrent
{
ifreq req;
memset(&req, 0, sizeof(req));
// -1 to leave a null terminator
// -1 to leave a 0-terminator
strncpy(req.ifr_name, iface.name, IF_NAMESIZE - 1);
// ignore errors here. This is best-effort
@ -529,7 +529,7 @@ namespace libtorrent
ifreq req;
memset(&req, 0, sizeof(req));
// -1 to leave a null terminator
// -1 to leave a 0-terminator
strncpy(req.ifr_name, item.ifr_name, IF_NAMESIZE - 1);
if (ioctl(s, siocgifmtu, &req) < 0)
{
@ -585,7 +585,7 @@ namespace libtorrent
GetAdaptersAddresses_t GetAdaptersAddresses = (GetAdaptersAddresses_t)GetProcAddress(
iphlp, "GetAdaptersAddresses");
if (GetAdaptersAddresses == NULL)
if (GetAdaptersAddresses == nullptr)
{
FreeLibrary(iphlp);
ec = error_code(boost::system::errc::not_supported, generic_category());
@ -598,13 +598,13 @@ namespace libtorrent
= reinterpret_cast<IP_ADAPTER_ADDRESSES*>(&buffer[0]);
DWORD res = GetAdaptersAddresses(AF_UNSPEC, GAA_FLAG_SKIP_MULTICAST | GAA_FLAG_SKIP_DNS_SERVER
| GAA_FLAG_SKIP_ANYCAST, NULL, adapter_addresses, &buf_size);
| GAA_FLAG_SKIP_ANYCAST, nullptr, adapter_addresses, &buf_size);
if (res == ERROR_BUFFER_OVERFLOW)
{
buffer.resize(buf_size);
adapter_addresses = reinterpret_cast<IP_ADAPTER_ADDRESSES*>(&buffer[0]);
res = GetAdaptersAddresses(AF_UNSPEC, GAA_FLAG_SKIP_MULTICAST | GAA_FLAG_SKIP_DNS_SERVER
| GAA_FLAG_SKIP_ANYCAST, NULL, adapter_addresses, &buf_size);
| GAA_FLAG_SKIP_ANYCAST, nullptr, adapter_addresses, &buf_size);
}
if (res != NO_ERROR)
{
@ -986,7 +986,7 @@ namespace libtorrent
iphlp, "FreeMibTable");
if (GetIpForwardTable2 && FreeMibTable)
{
MIB_IPFORWARD_TABLE2* routes = NULL;
MIB_IPFORWARD_TABLE2* routes = nullptr;
int res = GetIpForwardTable2(AF_UNSPEC, &routes);
if (res == NO_ERROR)
{
@ -1026,7 +1026,7 @@ namespace libtorrent
return std::vector<ip_route>();
}
MIB_IPFORWARDTABLE* routes = NULL;
MIB_IPFORWARDTABLE* routes = nullptr;
ULONG out_buf_size = 0;
if (GetIpForwardTable(routes, &out_buf_size, FALSE) != ERROR_INSUFFICIENT_BUFFER)
{

View File

@ -38,6 +38,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <mutex>
#include <cstring>
#include <array>
#include <tuple>
#ifdef TORRENT_WINDOWS
#ifndef WIN32_LEAN_AND_MEAN
@ -225,7 +226,7 @@ namespace libtorrent
std::string protocol, host, auth, path;
int port;
error_code ec;
boost::tie(protocol, auth, host, port, path) = parse_url_components(url, ec);
std::tie(protocol, auth, host, port, path) = parse_url_components(url, ec);
if (ec) return url;
// first figure out if this url contains unencoded characters
@ -335,13 +336,13 @@ namespace libtorrent
'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
'y', 'z', '2', '3', '4', '5', '6', '7'
};
const char *base32_table = 0 != (flags & string::lowercase) ? base32_table_lowercase : base32_table_canonical;
char const *base32_table = 0 != (flags & string::lowercase) ? base32_table_lowercase : base32_table_canonical;
static int const input_output_mapping[] = {0, 2, 4, 5, 7, 8};
std::uint8_t inbuf[5];
std::uint8_t outbuf[8];
int input_output_mapping[] = {0, 2, 4, 5, 7, 8};
unsigned char inbuf[5];
unsigned char outbuf[8];
std::string ret;
for (std::string::const_iterator i = s.begin(); i != s.end();)
{
@ -568,7 +569,7 @@ namespace libtorrent
libtorrent::utf8_wchar(s, ws);
std::string ret;
ret.resize(ws.size() * 4 + 1);
std::size_t size = WideCharToMultiByte(CP_ACP, 0, ws.c_str(), -1, &ret[0], int(ret.size()), NULL, NULL);
std::size_t size = WideCharToMultiByte(CP_ACP, 0, ws.c_str(), -1, &ret[0], int(ret.size()), nullptr, nullptr);
if (size == std::size_t(-1)) return s;
if (size != 0 && ret[size - 1] == '\0') --size;
ret.resize(size);

View File

@ -183,9 +183,9 @@ namespace
{
ol[i].OffsetHigh = file_offset >> 32;
ol[i].Offset = file_offset & 0xffffffff;
ol[i].hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
ol[i].hEvent = CreateEvent(nullptr, TRUE, FALSE, nullptr);
h[i] = ol[i].hEvent;
if (h[i] == NULL)
if (h[i] == nullptr)
{
// we failed to create the event, roll-back and return an error
for (int j = 0; j < i; ++j) CloseHandle(h[i]);
@ -253,9 +253,9 @@ done:
{
ol[i].OffsetHigh = file_offset >> 32;
ol[i].Offset = file_offset & 0xffffffff;
ol[i].hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
ol[i].hEvent = CreateEvent(nullptr, TRUE, FALSE, nullptr);
h[i] = ol[i].hEvent;
if (h[i] == NULL)
if (h[i] == nullptr)
{
// we failed to create the event, roll-back and return an error
for (int j = 0; j < i; ++j) CloseHandle(h[i]);
@ -393,7 +393,7 @@ namespace libtorrent
// in order to open a directory, we need the FILE_FLAG_BACKUP_SEMANTICS
HANDLE h = CreateFile_(f.c_str(), 0, FILE_SHARE_DELETE | FILE_SHARE_READ
| FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
| FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, nullptr);
if (h == INVALID_HANDLE_VALUE)
{
@ -528,7 +528,7 @@ namespace libtorrent
std::string n_exist = convert_to_native(file);
std::string n_link = convert_to_native(link);
#endif
BOOL ret = CreateHardLink_(n_link.c_str(), n_exist.c_str(), NULL);
BOOL ret = CreateHardLink_(n_link.c_str(), n_exist.c_str(), nullptr);
if (ret)
{
ec.clear();
@ -779,7 +779,7 @@ namespace libtorrent
#endif
char const* ext = strrchr(f.c_str(), '.');
// if we don't have an extension, just return f
if (ext == 0 || ext == &f[0] || (slash != NULL && ext < slash)) return f;
if (ext == 0 || ext == &f[0] || (slash != nullptr && ext < slash)) return f;
return f.substr(0, ext - &f[0]);
}
@ -1591,7 +1591,7 @@ namespace libtorrent
return false;
overlapped_t ol;
if (ol.ol.hEvent == NULL) return false;
if (ol.ol.hEvent == nullptr) return false;
#ifndef FSCTL_QUERY_ALLOCATED_RANGES
typedef struct _FILE_ALLOCATED_RANGE_BUFFER {
@ -1990,15 +1990,15 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER {
PTOKEN_PRIVILEGES PreviousState,
PDWORD ReturnLength);
static OpenProcessToken_t pOpenProcessToken = NULL;
static LookupPrivilegeValue_t pLookupPrivilegeValue = NULL;
static AdjustTokenPrivileges_t pAdjustTokenPrivileges = NULL;
static OpenProcessToken_t pOpenProcessToken = nullptr;
static LookupPrivilegeValue_t pLookupPrivilegeValue = nullptr;
static AdjustTokenPrivileges_t pAdjustTokenPrivileges = nullptr;
static bool failed_advapi = false;
if (pOpenProcessToken == NULL && !failed_advapi)
if (pOpenProcessToken == nullptr && !failed_advapi)
{
HMODULE advapi = LoadLibraryA("advapi32");
if (advapi == NULL)
if (advapi == nullptr)
{
failed_advapi = true;
return false;
@ -2006,9 +2006,9 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER {
pOpenProcessToken = (OpenProcessToken_t)GetProcAddress(advapi, "OpenProcessToken");
pLookupPrivilegeValue = (LookupPrivilegeValue_t)GetProcAddress(advapi, "LookupPrivilegeValueA");
pAdjustTokenPrivileges = (AdjustTokenPrivileges_t)GetProcAddress(advapi, "AdjustTokenPrivileges");
if (pOpenProcessToken == NULL
|| pLookupPrivilegeValue == NULL
|| pAdjustTokenPrivileges == NULL)
if (pOpenProcessToken == nullptr
|| pLookupPrivilegeValue == nullptr
|| pAdjustTokenPrivileges == nullptr)
{
failed_advapi = true;
return false;
@ -2021,7 +2021,7 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER {
return false;
TOKEN_PRIVILEGES privs;
if (!pLookupPrivilegeValue(NULL, "SeManageVolumePrivilege"
if (!pLookupPrivilegeValue(nullptr, "SeManageVolumePrivilege"
, &privs.Privileges[0].Luid))
{
CloseHandle(token);
@ -2031,7 +2031,7 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER {
privs.PrivilegeCount = 1;
privs.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
bool ret = pAdjustTokenPrivileges(token, FALSE, &privs, 0, NULL, NULL)
bool ret = pAdjustTokenPrivileges(token, FALSE, &privs, 0, nullptr, nullptr)
&& GetLastError() == ERROR_SUCCESS;
CloseHandle(token);
@ -2042,19 +2042,19 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER {
void set_file_valid_data(HANDLE f, std::int64_t size)
{
typedef BOOL (WINAPI *SetFileValidData_t)(HANDLE, LONGLONG);
static SetFileValidData_t pSetFileValidData = NULL;
static SetFileValidData_t pSetFileValidData = nullptr;
static bool failed_kernel32 = false;
if (pSetFileValidData == NULL && !failed_kernel32)
if (pSetFileValidData == nullptr && !failed_kernel32)
{
HMODULE k32 = LoadLibraryA("kernel32");
if (k32 == NULL)
if (k32 == nullptr)
{
failed_kernel32 = true;
return;
}
pSetFileValidData = (SetFileValidData_t)GetProcAddress(k32, "SetFileValidData");
if (pSetFileValidData == NULL)
if (pSetFileValidData == nullptr)
{
failed_kernel32 = true;
return;
@ -2109,11 +2109,11 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER {
, LPVOID lpFileInformation
, DWORD dwBufferSize);
static GetFileInformationByHandleEx_t GetFileInformationByHandleEx_ = NULL;
static GetFileInformationByHandleEx_t GetFileInformationByHandleEx_ = nullptr;
static bool failed_kernel32 = false;
if ((GetFileInformationByHandleEx_ == NULL) && !failed_kernel32)
if ((GetFileInformationByHandleEx_ == nullptr) && !failed_kernel32)
{
HMODULE kernel32 = LoadLibraryA("kernel32.dll");
if (kernel32)
@ -2357,7 +2357,7 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER {
for (std::set<file_handle*>::iterator i = global_file_handles.begin()
, end(global_file_handles.end()); i != end; ++i)
{
TORRENT_ASSERT(*i != NULL);
TORRENT_ASSERT(*i != nullptr);
if (!*i) continue;
file_handle const& h = **i;
if (!h) continue;

View File

@ -91,23 +91,23 @@ namespace libtorrent
} FILE_IO_PRIORITY_HINT_INFO_LOCAL;
typedef BOOL (WINAPI *SetFileInformationByHandle_t)(HANDLE hFile, FILE_INFO_BY_HANDLE_CLASS_LOCAL FileInformationClass, LPVOID lpFileInformation, DWORD dwBufferSize);
static SetFileInformationByHandle_t SetFileInformationByHandle = NULL;
static SetFileInformationByHandle_t SetFileInformationByHandle = nullptr;
static bool failed_kernel_load = false;
if (failed_kernel_load) return;
if (SetFileInformationByHandle == NULL)
if (SetFileInformationByHandle == nullptr)
{
HMODULE kernel32 = LoadLibraryA("kernel32.dll");
if (kernel32 == NULL)
if (kernel32 == nullptr)
{
failed_kernel_load = true;
return;
}
SetFileInformationByHandle = (SetFileInformationByHandle_t)GetProcAddress(kernel32, "SetFileInformationByHandle");
if (SetFileInformationByHandle == NULL)
if (SetFileInformationByHandle == nullptr)
{
failed_kernel_load = true;
return;

View File

@ -271,7 +271,7 @@ namespace libtorrent
// if borrow_chars >= 0, don't take ownership over n, just
// point to it. It points to borrow_chars number of characters.
// if borrow_chars == -1, n is a null terminated string that
// if borrow_chars == -1, n is a 0-terminated string that
// should be copied
void internal_file_entry::set_name(char const* n, bool borrow_string, int string_len)
{
@ -283,10 +283,10 @@ namespace libtorrent
// free the current string, before assigning the new one
if (name_len == name_is_owned) free(const_cast<char*>(name));
if (n == NULL)
if (n == nullptr)
{
TORRENT_ASSERT(borrow_string == false);
name = NULL;
name = nullptr;
}
else if (borrow_string)
{
@ -316,7 +316,7 @@ namespace libtorrent
for (int i = 0; i < m_file_hashes.size(); ++i)
{
if (m_file_hashes[i] == NULL) continue;
if (m_file_hashes[i] == nullptr) continue;
m_file_hashes[i] += off;
}
}
@ -331,7 +331,7 @@ namespace libtorrent
if (fe.executable_attribute) flags |= file_storage::flag_executable;
if (fe.symlink_attribute) flags |= file_storage::flag_symlink;
add_file_borrow(NULL, 0, fe.path, fe.size, flags, filehash, fe.mtime
add_file_borrow(nullptr, 0, fe.path, fe.size, flags, filehash, fe.mtime
, fe.symlink_path);
}
@ -536,7 +536,7 @@ namespace libtorrent
void file_storage::add_file(std::string const& path, std::int64_t file_size
, int file_flags, std::time_t mtime, std::string const& symlink_path)
{
add_file_borrow(NULL, 0, path, file_size, file_flags, NULL, mtime
add_file_borrow(nullptr, 0, path, file_size, file_flags, nullptr, mtime
, symlink_path);
}
@ -567,12 +567,12 @@ namespace libtorrent
// the last argument specified whether the function should also set
// the filename. If it does, it will copy the leaf filename from path.
// if filename is NULL, we should copy it. If it isn't, we're borrowing
// if filename is nullptr, we should copy it. If it isn't, we're borrowing
// it and we can save the copy by setting it after this call to
// update_path_index().
update_path_index(e, path, filename == NULL);
update_path_index(e, path, filename == nullptr);
// filename is allowed to be NULL, in which case we just use path
// filename is allowed to be nullptr, in which case we just use path
if (filename)
e.set_name(filename, true, filename_len);
@ -933,7 +933,7 @@ namespace libtorrent
if (!m_file_hashes.empty())
{
TORRENT_ASSERT(m_file_hashes.size() == m_files.size());
if (int(m_file_hashes.size()) < index) m_file_hashes.resize(index + 1, NULL);
if (int(m_file_hashes.size()) < index) m_file_hashes.resize(index + 1, nullptr);
std::iter_swap(m_file_hashes.begin() + dst, m_file_hashes.begin() + index);
}
#ifndef TORRENT_NO_DEPRECATE
@ -1075,7 +1075,7 @@ namespace libtorrent
++pad_file_counter;
if (!m_mtime.empty()) m_mtime.resize(index + 1, 0);
if (!m_file_hashes.empty()) m_file_hashes.resize(index + 1, NULL);
if (!m_file_hashes.empty()) m_file_hashes.resize(index + 1, nullptr);
#ifndef TORRENT_NO_DEPRECATE
if (!m_file_base.empty()) m_file_base.resize(index + 1, 0);
#endif

View File

@ -125,7 +125,7 @@ void http_connection::get(std::string const& url, time_duration timeout, int pri
error_code ec;
int port;
boost::tie(protocol, auth, hostname, port, path)
std::tie(protocol, auth, hostname, port, path)
= parse_url_components(url, ec);
if (auth.empty()) auth = auth_;
@ -142,7 +142,7 @@ void http_connection::get(std::string const& url, time_duration timeout, int pri
if (ec)
{
m_timer.get_io_service().post(std::bind(&http_connection::callback
, me, ec, static_cast<char*>(NULL), 0));
, me, ec, static_cast<char*>(nullptr), 0));
return;
}
@ -154,7 +154,7 @@ void http_connection::get(std::string const& url, time_duration timeout, int pri
{
error_code err(errors::unsupported_url_protocol);
m_timer.get_io_service().post(std::bind(&http_connection::callback
, me, err, static_cast<char*>(NULL), 0));
, me, err, static_cast<char*>(nullptr), 0));
return;
}
@ -260,7 +260,7 @@ void http_connection::start(std::string const& hostname, int port
if (ec)
{
m_timer.get_io_service().post(std::bind(&http_connection::callback
, me, ec, static_cast<char*>(NULL), 0));
, me, ec, static_cast<char*>(nullptr), 0));
return;
}
@ -298,7 +298,7 @@ void http_connection::start(std::string const& hostname, int port
if (is_i2p && i2p_conn->proxy().type != settings_pack::i2p_proxy)
{
m_timer.get_io_service().post(std::bind(&http_connection::callback
, me, error_code(errors::no_i2p_router, get_libtorrent_category()), static_cast<char*>(NULL), 0));
, me, error_code(errors::no_i2p_router, get_libtorrent_category()), static_cast<char*>(nullptr), 0));
return;
}
#endif
@ -339,7 +339,7 @@ void http_connection::start(std::string const& hostname, int port
if (ec)
{
m_timer.get_io_service().post(std::bind(&http_connection::callback
, me, ec, static_cast<char*>(NULL), 0));
, me, ec, static_cast<char*>(nullptr), 0));
return;
}
}
@ -348,10 +348,10 @@ void http_connection::start(std::string const& hostname, int port
}
#endif
// assume this is not a tracker connection. Tracker connections that
// shouldn't be subject to the proxy should pass in NULL as the proxy
// shouldn't be subject to the proxy should pass in nullptr as the proxy
// pointer.
instantiate_connection(m_timer.get_io_service()
, proxy ? *proxy : null_proxy, m_sock, userdata, NULL, false, false);
, proxy ? *proxy : null_proxy, m_sock, userdata, nullptr, false, false);
if (m_bind_addr != address_v4::any())
{
@ -360,7 +360,7 @@ void http_connection::start(std::string const& hostname, int port
if (ec)
{
m_timer.get_io_service().post(std::bind(&http_connection::callback
, me, ec, static_cast<char*>(NULL), 0));
, me, ec, static_cast<char*>(nullptr), 0));
return;
}
}
@ -369,7 +369,7 @@ void http_connection::start(std::string const& hostname, int port
if (ec)
{
m_timer.get_io_service().post(std::bind(&http_connection::callback
, me, ec, static_cast<char*>(NULL), 0));
, me, ec, static_cast<char*>(nullptr), 0));
return;
}

View File

@ -32,7 +32,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <cctype>
#include <algorithm>
#include <stdlib.h>
#include <cstdlib>
#include "libtorrent/config.hpp"
#include "libtorrent/http_parser.hpp"
@ -65,20 +65,20 @@ namespace libtorrent
if (location.empty()) return referrer;
error_code ec;
using boost::tuples::ignore;
boost::tie(ignore, ignore, ignore, ignore, ignore)
using std::ignore;
std::tie(ignore, ignore, ignore, ignore, ignore)
= parse_url_components(location, ec);
// if location is a full URL, just return it
if (!ec) return location;
// otherwise it's likely to be just the path, or a relative path
std::string url = referrer;
if (location[0] == '/')
{
// it's an absolute path. replace the path component of
// referrer with location.
// referrer with location.
// first skip the url scheme of the referer
std::size_t i = url.find("://");
@ -150,11 +150,11 @@ namespace libtorrent
, m_finished(false)
{}
boost::tuple<int, int> http_parser::incoming(
std::tuple<int, int> http_parser::incoming(
buffer::const_interval recv_buffer, bool& error)
{
TORRENT_ASSERT(recv_buffer.left() >= m_recv_buffer.left());
boost::tuple<int, int> ret(0, 0);
std::tuple<int, int> ret(0, 0);
int start_pos = m_recv_buffer.left();
// early exit if there's nothing new in the receive buffer
@ -179,7 +179,7 @@ restart_response:
// if we don't have a full line yet, wait.
if (newline == recv_buffer.end)
{
boost::get<1>(ret) += m_recv_buffer.left() - start_pos;
std::get<1>(ret) += m_recv_buffer.left() - start_pos;
return ret;
}
@ -198,7 +198,7 @@ restart_response:
TORRENT_ASSERT(newline >= pos);
int incoming = int(newline - pos);
m_recv_pos += incoming;
boost::get<1>(ret) += newline - (m_recv_buffer.begin + start_pos);
std::get<1>(ret) += newline - (m_recv_buffer.begin + start_pos);
pos = newline;
m_protocol = read_until(line, ' ', line_end);
@ -342,7 +342,7 @@ restart_response:
TORRENT_ASSERT(pos <= recv_buffer.end);
newline = std::find(pos, recv_buffer.end, '\n');
}
boost::get<1>(ret) += newline - (m_recv_buffer.begin + start_pos);
std::get<1>(ret) += newline - (m_recv_buffer.begin + start_pos);
}
if (m_state == read_body)
@ -361,7 +361,7 @@ restart_response:
{
TORRENT_ASSERT(payload < (std::numeric_limits<int>::max)());
m_recv_pos += payload;
boost::get<0>(ret) += int(payload);
std::get<0>(ret) += int(payload);
incoming -= int(payload);
}
buffer::const_interval buf(recv_buffer.begin + m_cur_chunk_end, recv_buffer.end);
@ -409,13 +409,13 @@ restart_response:
}
m_chunk_header_size += header_size;
m_recv_pos += header_size;
boost::get<1>(ret) += header_size;
std::get<1>(ret) += header_size;
incoming -= header_size;
}
if (incoming > 0)
{
m_recv_pos += incoming;
boost::get<0>(ret) += incoming;
std::get<0>(ret) += incoming;
// incoming = 0;
}
}
@ -432,7 +432,7 @@ restart_response:
TORRENT_ASSERT(incoming >= 0);
m_recv_pos += incoming;
boost::get<0>(ret) += incoming;
std::get<0>(ret) += incoming;
}
if (m_content_length >= 0

View File

@ -248,7 +248,7 @@ namespace libtorrent
bool parse_error = false;
int protocol = 0;
int payload = 0;
boost::tie(payload, protocol) = m_parser.incoming(recv_buffer, parse_error);
std::tie(payload, protocol) = m_parser.incoming(recv_buffer, parse_error);
received_bytes(0, protocol);
bytes_transferred -= protocol;
#if TORRENT_USE_ASSERTS

View File

@ -69,7 +69,7 @@ namespace libtorrent
: tracker_connection(man, req, ios, c)
, m_man(man)
#if TORRENT_USE_I2P
, m_i2p_conn(NULL)
, m_i2p_conn(nullptr)
#endif
{}
@ -218,7 +218,7 @@ namespace libtorrent
aux::proxy_settings ps(settings);
m_tracker_connection->get(url, seconds(timeout)
, tracker_req().event == tracker_request::stopped ? 2 : 1
, ps.proxy_tracker_connections ? &ps : NULL
, ps.proxy_tracker_connections ? &ps : nullptr
, 5, settings.get_bool(settings_pack::anonymous_mode)
? "" : settings.get_str(settings_pack::user_agent)
, bind_interface()

View File

@ -309,7 +309,7 @@ namespace libtorrent
error_code invalid_response(i2p_error::parse_failed
, get_i2p_category());
// null-terminate the string and parse it
// 0-terminate the string and parse it
m_buffer.push_back(0);
char* ptr = &m_buffer[0];
char* next = ptr;

View File

@ -69,7 +69,7 @@ namespace libtorrent
ip_filter::filter_tuple_t ip_filter::export_filter() const
{
#if TORRENT_USE_IPV6
return boost::make_tuple(m_filter4.export_filter<address_v4>()
return std::make_tuple(m_filter4.export_filter<address_v4>()
, m_filter6.export_filter<address_v6>());
#else
return m_filter4.export_filter<address_v4>();

View File

@ -32,12 +32,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/kademlia/dht_storage.hpp"
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <boost/tuple/tuple.hpp>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#include <tuple>
#include <algorithm>
#include <utility>
#include <map>
@ -382,7 +377,7 @@ namespace
to_add.size = size;
memcpy(to_add.value, buf, size);
boost::tie(i, boost::tuples::ignore) = m_immutable_table.insert(
std::tie(i, std::ignore) = m_immutable_table.insert(
std::make_pair(target, to_add));
m_counters.immutable_data += 1;
}
@ -449,7 +444,7 @@ namespace
to_add.value = static_cast<char*>(malloc(size));
to_add.size = size;
to_add.seq = seq;
to_add.salt = NULL;
to_add.salt = nullptr;
to_add.salt_size = 0;
if (salt_size > 0)
{
@ -461,7 +456,7 @@ namespace
memcpy(to_add.value, buf, size);
memcpy(&to_add.key, pk, sizeof(to_add.key));
boost::tie(i, boost::tuples::ignore) = m_mutable_table.insert(
std::tie(i, std::ignore) = m_mutable_table.insert(
std::make_pair(target, to_add));
m_counters.mutable_data += 1;
}

View File

@ -85,7 +85,7 @@ namespace libtorrent { namespace dht
{
if (e.type() != entry::dictionary_t) return (node_id::min)();
entry const* nid = e.find_key(key);
if (nid == NULL || nid->type() != entry::string_t || nid->string().length() != 20)
if (nid == nullptr || nid->type() != entry::string_t || nid->string().length() != 20)
return (node_id::min)();
return node_id(nid->string().c_str());
}
@ -93,7 +93,7 @@ namespace libtorrent { namespace dht
void add_dht_counters(node const& dht, counters& c)
{
int nodes, replacements, allocated_observers;
boost::tie(nodes, replacements, allocated_observers) = dht.get_stats_counters();
std::tie(nodes, replacements, allocated_observers) = dht.get_stats_counters();
c.inc_stats_counter(counters::dht_nodes, nodes);
c.inc_stats_counter(counters::dht_node_cache, replacements);
@ -345,9 +345,10 @@ namespace libtorrent { namespace dht
void dht_tracker::get_peers(sha1_hash const& ih
, boost::function<void(std::vector<tcp::endpoint> const&)> f)
{
m_dht.get_peers(ih, f, NULL, false);
boost::function<void(std::vector<std::pair<node_entry, std::string> > const&)> empty;
m_dht.get_peers(ih, f, empty, false);
#if TORRENT_USE_IPV6
m_dht6.get_peers(ih, f, NULL, false);
m_dht6.get_peers(ih, f, empty, false);
#endif
}

View File

@ -184,8 +184,8 @@ void get_item::done()
void get_item_observer::reply(msg const& m)
{
char const* pk = NULL;
char const* sig = NULL;
char const* pk = nullptr;
char const* sig = nullptr;
std::uint64_t seq = 0;
bdecode_node r = m.message.dict_find_dict("r");

View File

@ -38,7 +38,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <boost/tuple/tuple.hpp>
#include <tuple>
#include <boost/function/function1.hpp>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
@ -656,7 +656,7 @@ void node::tick()
}
node_entry const* ne = m_table.next_refresh();
if (ne == NULL) return;
if (ne == nullptr) return;
// this shouldn't happen
TORRENT_ASSERT(m_id != ne->id);
@ -743,11 +743,11 @@ void node::status(std::vector<dht_routing_bucket>& table
}
}
boost::tuple<int, int, int> node::get_stats_counters() const
std::tuple<int, int, int> node::get_stats_counters() const
{
int nodes, replacements;
boost::tie(nodes, replacements, boost::tuples::ignore) = size();
return boost::make_tuple(nodes, replacements, m_rpc.num_allocated_observers());
std::tie(nodes, replacements, std::ignore) = size();
return std::make_tuple(nodes, replacements, m_rpc.num_allocated_observers());
}
#ifndef TORRENT_NO_DEPRECATE
@ -993,11 +993,11 @@ void node::incoming_request(msg const& m, entry& e)
bool mutable_put = (msg_keys[2] && msg_keys[3] && msg_keys[4]);
// public key (only set if it's a mutable put)
char const* pk = NULL;
char const* pk = nullptr;
if (msg_keys[3]) pk = msg_keys[3].string_ptr();
// signature (only set if it's a mutable put)
char const* sig = NULL;
char const* sig = nullptr;
if (msg_keys[4]) sig = msg_keys[4].string_ptr();
// pointer and length to the whole entry
@ -1009,7 +1009,7 @@ void node::incoming_request(msg const& m, entry& e)
return;
}
std::pair<char const*, int> salt(static_cast<char const*>(NULL), 0);
std::pair<char const*, int> salt(static_cast<char const*>(nullptr), 0);
if (msg_keys[6])
salt = std::pair<char const*, int>(
msg_keys[6].string_ptr(), msg_keys[6].string_length());

View File

@ -37,6 +37,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <numeric>
#include <cstdio> // for snprintf
#include <cinttypes> // for PRId64 et.al.
#include <cstdint>
#include "libtorrent/config.hpp"
@ -52,29 +53,9 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/invariant_check.hpp"
#include "libtorrent/address.hpp"
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <cstdint>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
using std::uint8_t;
using namespace std::placeholders;
#if BOOST_VERSION <= 104700
namespace boost {
size_t hash_value(libtorrent::address_v4::bytes_type ip)
{
return boost::hash_value(*reinterpret_cast<std::uint32_t*>(&ip[0]));
}
size_t hash_value(libtorrent::address_v6::bytes_type ip)
{
return boost::hash_value(*reinterpret_cast<std::uint64_t*>(&ip[0]));
}
}
#endif
namespace libtorrent { namespace dht
{
namespace
@ -174,7 +155,7 @@ void routing_table::status(session_status& s) const
int dht_nodes;
int dht_node_cache;
int ignore;
boost::tie(dht_nodes, dht_node_cache, ignore) = size();
std::tie(dht_nodes, dht_node_cache, ignore) = size();
s.dht_nodes += dht_nodes;
s.dht_node_cache += dht_node_cache;
// TODO: arvidn note
@ -198,7 +179,7 @@ void routing_table::status(session_status& s) const
}
#endif
boost::tuple<int, int, int> routing_table::size() const
std::tuple<int, int, int> routing_table::size() const
{
int nodes = 0;
int replacements = 0;
@ -215,7 +196,7 @@ boost::tuple<int, int, int> routing_table::size() const
replacements += int(i->replacements.size());
}
return boost::make_tuple(nodes, replacements, confirmed);
return std::make_tuple(nodes, replacements, confirmed);
}
std::int64_t routing_table::num_global_nodes() const
@ -443,7 +424,7 @@ node_entry const* routing_table::next_refresh()
// recent, return false. Otherwise return a random target ID that's close to
// a missing prefix for that bucket
node_entry* candidate = NULL;
node_entry* candidate = nullptr;
// this will have a bias towards pinging nodes close to us first.
int idx = int(m_buckets.size()) - 1;
@ -463,7 +444,7 @@ node_entry const* routing_table::next_refresh()
goto out;
}
if (candidate == NULL || j->last_queried < candidate->last_queried)
if (candidate == nullptr || j->last_queried < candidate->last_queried)
{
candidate = &*j;
}
@ -790,10 +771,10 @@ ip_ok:
// can we split the bucket?
// only nodes that haven't failed can split the bucket, and we can only
// split the last bucket
bool const can_split = (boost::next(i) == m_buckets.end()
bool const can_split = (std::next(i) == m_buckets.end()
&& m_buckets.size() < 159)
&& e.fail_count() == 0
&& (i == m_buckets.begin() || boost::prior(i)->live_nodes.size() > 1);
&& (i == m_buckets.begin() || std::prev(i)->live_nodes.size() > 1);
// if there's room in the main bucket, just insert it
// if we can split the bucket (i.e. it's the last bucket) use the next

Some files were not shown because too many files have changed in this diff Show More