diff --git a/examples/client_test.cpp b/examples/client_test.cpp index 19b33adfc..3c51429d3 100644 --- a/examples/client_test.cpp +++ b/examples/client_test.cpp @@ -199,7 +199,7 @@ int load_file(std::string const& filename, std::vector& 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& 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]) { diff --git a/examples/connection_tester.cpp b/examples/connection_tester.cpp index 729880a51..8ad8849cc 100644 --- a/examples/connection_tester.cpp +++ b/examples/connection_tester.cpp @@ -825,7 +825,7 @@ void generate_data(char const* path, torrent_info const& ti) storage_params params; params.files = &const_cast(fs); - params.mapped_files = NULL; + params.mapped_files = nullptr; params.path = path; params.pool = &fp; params.mode = storage_mode_sparse; diff --git a/examples/dump_torrent.cpp b/examples/dump_torrent.cpp index d14c3b59c..b9aeb61b6 100644 --- a/examples/dump_torrent.cpp +++ b/examples/dump_torrent.cpp @@ -45,7 +45,7 @@ int load_file(std::string const& filename, std::vector& 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; diff --git a/examples/make_torrent.cpp b/examples/make_torrent.cpp index 608964ac8..095a6cd0e 100644 --- a/examples/make_torrent.cpp +++ b/examples/make_torrent.cpp @@ -55,7 +55,7 @@ int load_file(std::string const& filename, std::vector& 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)); diff --git a/examples/print.cpp b/examples/print.cpp index 1841968d0..6ba9b14b3 100644 --- a/examples/print.cpp +++ b/examples/print.cpp @@ -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); diff --git a/include/libtorrent/alert_types.hpp b/include/libtorrent/alert_types.hpp index fb5970840..77f6971ff 100644 --- a/include/libtorrent/alert_types.hpp +++ b/include/libtorrent/alert_types.hpp @@ -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 diff --git a/include/libtorrent/announce_entry.hpp b/include/libtorrent/announce_entry.hpp index 3ba0155e7..4aef87aa9 100644 --- a/include/libtorrent/announce_entry.hpp +++ b/include/libtorrent/announce_entry.hpp @@ -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 #include -#include "libtorrent/aux_/disable_warnings_pop.hpp" - namespace libtorrent { namespace aux { diff --git a/include/libtorrent/aux_/array_view.hpp b/include/libtorrent/aux_/array_view.hpp index 08ec5beb0..2c9b438dc 100644 --- a/include/libtorrent/aux_/array_view.hpp +++ b/include/libtorrent/aux_/array_view.hpp @@ -42,7 +42,7 @@ namespace libtorrent { namespace aux { template 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 +#include "libtorrent/aux_/disable_warnings_push.hpp" + #ifdef TORRENT_WINDOWS #include #else diff --git a/include/libtorrent/aux_/escape_string.hpp b/include/libtorrent/aux_/escape_string.hpp index c5d5f243f..98f762fe9 100644 --- a/include/libtorrent/aux_/escape_string.hpp +++ b/include/libtorrent/aux_/escape_string.hpp @@ -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); diff --git a/include/libtorrent/aux_/io.hpp b/include/libtorrent/aux_/io.hpp index b695f1c6d..a2c44ddb8 100644 --- a/include/libtorrent/aux_/io.hpp +++ b/include/libtorrent/aux_/io.hpp @@ -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 -#include "libtorrent/aux_/disable_warnings_pop.hpp" - #include #include // for copy #include "libtorrent/aux_/array_view.hpp" diff --git a/include/libtorrent/aux_/session_impl.hpp b/include/libtorrent/aux_/session_impl.hpp index 19db65ba3..c631f9fdd 100644 --- a/include/libtorrent/aux_/session_impl.hpp +++ b/include/libtorrent/aux_/session_impl.hpp @@ -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 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::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_storage() override { return m_block_info_storage; } diff --git a/include/libtorrent/bandwidth_limit.hpp b/include/libtorrent/bandwidth_limit.hpp index 23505b80b..2b408ef70 100644 --- a/include/libtorrent/bandwidth_limit.hpp +++ b/include/libtorrent/bandwidth_limit.hpp @@ -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 #include - -#include "libtorrent/aux_/disable_warnings_pop.hpp" +#include #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::const_max; + static constexpr int inf = std::numeric_limits::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); } diff --git a/include/libtorrent/bandwidth_queue_entry.hpp b/include/libtorrent/bandwidth_queue_entry.hpp index 61af5c2b8..0c6b7df62 100644 --- a/include/libtorrent/bandwidth_queue_entry.hpp +++ b/include/libtorrent/bandwidth_queue_entry.hpp @@ -34,9 +34,7 @@ POSSIBILITY OF SUCH DAMAGE. #define TORRENT_BANDWIDTH_QUEUE_ENTRY_HPP_INCLUDED #include "libtorrent/aux_/disable_warnings_push.hpp" - #include - #include "libtorrent/aux_/disable_warnings_pop.hpp" #include "libtorrent/bandwidth_limit.hpp" diff --git a/include/libtorrent/bdecode.hpp b/include/libtorrent/bdecode.hpp index 45fa4b22f..0a1700144 100644 --- a/include/libtorrent/bdecode.hpp +++ b/include/libtorrent/bdecode.hpp @@ -30,20 +30,19 @@ POSSIBILITY OF SUCH DAMAGE. */ -#include "libtorrent/aux_/disable_warnings_push.hpp" +#ifndef TORRENT_BDECODE_HPP +#define TORRENT_BDECODE_HPP -#include #include #include #include +#include "libtorrent/aux_/disable_warnings_push.hpp" +#include #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); } diff --git a/include/libtorrent/bitfield.hpp b/include/libtorrent/bitfield.hpp index cb81e8a9e..a87849fd3 100644 --- a/include/libtorrent/bitfield.hpp +++ b/include/libtorrent/bitfield.hpp @@ -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(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 diff --git a/include/libtorrent/bloom_filter.hpp b/include/libtorrent/bloom_filter.hpp index 64c81867b..3a71e2e24 100644 --- a/include/libtorrent/bloom_filter.hpp +++ b/include/libtorrent/bloom_filter.hpp @@ -37,13 +37,8 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/config.hpp" // for sha1_hash #include // for log() - -#include "libtorrent/aux_/disable_warnings_push.hpp" - #include -#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); diff --git a/include/libtorrent/bt_peer_connection.hpp b/include/libtorrent/bt_peer_connection.hpp index a5ca17b21..e50dd6fd5 100644 --- a/include/libtorrent/bt_peer_connection.hpp +++ b/include/libtorrent/bt_peer_connection.hpp @@ -38,6 +38,8 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include +#include #include "libtorrent/debug.hpp" @@ -45,9 +47,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include -#include #include -#include #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: diff --git a/include/libtorrent/buffer.hpp b/include/libtorrent/buffer.hpp index 4ba1a11c5..f1f26b727 100644 --- a/include/libtorrent/buffer.hpp +++ b/include/libtorrent/buffer.hpp @@ -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 #include // for numeric_limits -#include "libtorrent/invariant_check.hpp" -#include "libtorrent/assert.hpp" #include // malloc/free/realloc #include // for std::swap - -#include "libtorrent/aux_/disable_warnings_push.hpp" #include -#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(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 diff --git a/include/libtorrent/debug.hpp b/include/libtorrent/debug.hpp index 49f513d94..5de8bdc95 100644 --- a/include/libtorrent/debug.hpp +++ b/include/libtorrent/debug.hpp @@ -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; } diff --git a/include/libtorrent/disk_buffer_holder.hpp b/include/libtorrent/disk_buffer_holder.hpp index 2c5a3b07f..d5e083aca 100644 --- a/include/libtorrent/disk_buffer_holder.hpp +++ b/include/libtorrent/disk_buffer_holder.hpp @@ -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); diff --git a/include/libtorrent/entry.hpp b/include/libtorrent/entry.hpp index 084dee089..bf1e76715 100644 --- a/include/libtorrent/entry.hpp +++ b/include/libtorrent/entry.hpp @@ -60,20 +60,15 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/config.hpp" -#include "libtorrent/aux_/disable_warnings_push.hpp" - #include #include #include #include #include -#include #if TORRENT_USE_IOSTREAM #include #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``. diff --git a/include/libtorrent/extensions.hpp b/include/libtorrent/extensions.hpp index efa1ce3cd..2fcee8f1b 100644 --- a/include/libtorrent/extensions.hpp +++ b/include/libtorrent/extensions.hpp @@ -98,7 +98,7 @@ POSSIBILITY OF SUCH DAMAGE. // ``torrent_handle::add_extension()``. // // The function should return a ``boost::shared_ptr`` 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. diff --git a/include/libtorrent/file.hpp b/include/libtorrent/file.hpp index a65bf6825..7890fc470 100644 --- a/include/libtorrent/file.hpp +++ b/include/libtorrent/file.hpp @@ -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: diff --git a/include/libtorrent/file_pool.hpp b/include/libtorrent/file_pool.hpp index 4623df107..153862184 100644 --- a/include/libtorrent/file_pool.hpp +++ b/include/libtorrent/file_pool.hpp @@ -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``. diff --git a/include/libtorrent/file_storage.hpp b/include/libtorrent/file_storage.hpp index b5b178415..4f5a18425 100644 --- a/include/libtorrent/file_storage.hpp +++ b/include/libtorrent/file_storage.hpp @@ -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 #include #include #include - #include -#include - -#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; diff --git a/include/libtorrent/hasher.hpp b/include/libtorrent/hasher.hpp index 3df37be72..fd18f6892 100644 --- a/include/libtorrent/hasher.hpp +++ b/include/libtorrent/hasher.hpp @@ -37,12 +37,8 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/config.hpp" #include "libtorrent/assert.hpp" -#include "libtorrent/aux_/disable_warnings_push.hpp" - #include -#include "libtorrent/aux_/disable_warnings_pop.hpp" - #ifdef TORRENT_USE_GCRYPT #include diff --git a/include/libtorrent/heterogeneous_queue.hpp b/include/libtorrent/heterogeneous_queue.hpp index 9fb34a76c..170adedd3 100644 --- a/include/libtorrent/heterogeneous_queue.hpp +++ b/include/libtorrent/heterogeneous_queue.hpp @@ -34,14 +34,8 @@ POSSIBILITY OF SUCH DAMAGE. #define TORRENT_HETEROGENEOUS_QUEUE_HPP_INCLUDED #include - -#include "libtorrent/aux_/disable_warnings_push.hpp" - #include -#include -#include - -#include "libtorrent/aux_/disable_warnings_pop.hpp" +#include #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 - typename boost::enable_if, U&>::type + typename std::enable_if::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; diff --git a/include/libtorrent/http_connection.hpp b/include/libtorrent/http_connection.hpp index 3b68da44b..2d332d6b2 100644 --- a/include/libtorrent/http_connection.hpp +++ b/include/libtorrent/http_connection.hpp @@ -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 m_recvbuffer; diff --git a/include/libtorrent/http_parser.hpp b/include/libtorrent/http_parser.hpp index 8e705751d..7176c4c3b 100644 --- a/include/libtorrent/http_parser.hpp +++ b/include/libtorrent/http_parser.hpp @@ -37,20 +37,14 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include - -#include "libtorrent/aux_/disable_warnings_push.hpp" - #include -#include - -#include "libtorrent/aux_/disable_warnings_pop.hpp" +#include #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 incoming(buffer::const_interval recv_buffer + std::tuple 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; } diff --git a/include/libtorrent/http_seed_connection.hpp b/include/libtorrent/http_seed_connection.hpp index 6d20c6310..327d93297 100644 --- a/include/libtorrent/http_seed_connection.hpp +++ b/include/libtorrent/http_seed_connection.hpp @@ -37,18 +37,13 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include +#include #include "libtorrent/debug.hpp" #include "libtorrent/aux_/disable_warnings_push.hpp" - -#include -#include -#include -#include #include -#include - #include "libtorrent/aux_/disable_warnings_pop.hpp" #include "libtorrent/config.hpp" diff --git a/include/libtorrent/io.hpp b/include/libtorrent/io.hpp index b082cd133..588b5838e 100644 --- a/include/libtorrent/io.hpp +++ b/include/libtorrent/io.hpp @@ -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 -#include "libtorrent/aux_/disable_warnings_pop.hpp" - #include #include // for copy #include // for memcpy diff --git a/include/libtorrent/ip_filter.hpp b/include/libtorrent/ip_filter.hpp index 2b278c78e..c83936b54 100644 --- a/include/libtorrent/ip_filter.hpp +++ b/include/libtorrent/ip_filter.hpp @@ -35,17 +35,12 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/config.hpp" -#include "libtorrent/aux_/disable_warnings_push.hpp" - #include #include - -#include -#include #include -#include - -#include "libtorrent/aux_/disable_warnings_pop.hpp" +#include +#include // for next +#include #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 > > filter_tuple_t; + using filter_tuple_t = std::tuple > + , std::vector > >; #else - typedef std::vector > filter_tuple_t; + using filter_tuple_t = std::vector >; #endif // This function will return the current state of the filter in the minimum number of diff --git a/include/libtorrent/kademlia/item.hpp b/include/libtorrent/kademlia/item.hpp index 2234af440..7a90e510e 100644 --- a/include/libtorrent/kademlia/item.hpp +++ b/include/libtorrent/kademlia/item.hpp @@ -95,15 +95,15 @@ public: void assign(entry const& v) { - assign(v, std::pair(static_cast(NULL) - , 0), 0, NULL, NULL); + assign(v, std::pair(static_cast(nullptr) + , 0), 0, nullptr, nullptr); } void assign(entry const& v, std::pair salt , std::uint64_t seq, char const* pk, char const* sk); void assign(bdecode_node const& v) { - assign(v, std::pair(static_cast(NULL) - , 0), 0, NULL, NULL); + assign(v, std::pair(static_cast(nullptr) + , 0), 0, nullptr, nullptr); } bool assign(bdecode_node const& v, std::pair salt , std::uint64_t seq, char const* pk, char const* sig); diff --git a/include/libtorrent/kademlia/node.hpp b/include/libtorrent/kademlia/node.hpp index 6b54590f8..660f686ef 100644 --- a/include/libtorrent/kademlia/node.hpp +++ b/include/libtorrent/kademlia/node.hpp @@ -37,6 +37,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #include #include @@ -54,9 +55,6 @@ POSSIBILITY OF SUCH DAMAGE. #include #include -#include -#include - #include "libtorrent/socket.hpp" namespace libtorrent { @@ -126,7 +124,7 @@ public: node_id const& nid() const { return m_id; } - boost::tuple size() const { return m_table.size(); } + std::tuple 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& table , std::vector& requests); - boost::tuple get_stats_counters() const; + std::tuple get_stats_counters() const; #ifndef TORRENT_NO_DEPRECATE void status(libtorrent::session_status& s); diff --git a/include/libtorrent/kademlia/node_id.hpp b/include/libtorrent/kademlia/node_id.hpp index 422a8e830..b0903429a 100644 --- a/include/libtorrent/kademlia/node_id.hpp +++ b/include/libtorrent/kademlia/node_id.hpp @@ -34,10 +34,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include - -#include "libtorrent/aux_/disable_warnings_push.hpp" #include -#include "libtorrent/aux_/disable_warnings_pop.hpp" #include "libtorrent/config.hpp" #include "libtorrent/peer_id.hpp" diff --git a/include/libtorrent/kademlia/observer.hpp b/include/libtorrent/kademlia/observer.hpp index b135e494a..494640c7c 100644 --- a/include/libtorrent/kademlia/observer.hpp +++ b/include/libtorrent/kademlia/observer.hpp @@ -33,15 +33,15 @@ POSSIBILITY OF SUCH DAMAGE. #ifndef OBSERVER_HPP #define OBSERVER_HPP +#include + #include #include #include "libtorrent/aux_/disable_warnings_push.hpp" #include -#include #include -#include #include "libtorrent/aux_/disable_warnings_pop.hpp" diff --git a/include/libtorrent/kademlia/routing_table.hpp b/include/libtorrent/kademlia/routing_table.hpp index ff91c73b1..83def578a 100644 --- a/include/libtorrent/kademlia/routing_table.hpp +++ b/include/libtorrent/kademlia/routing_table.hpp @@ -33,18 +33,15 @@ POSSIBILITY OF SUCH DAMAGE. #ifndef ROUTING_TABLE_HPP #define ROUTING_TABLE_HPP -#include "libtorrent/aux_/disable_warnings_push.hpp" - #include #include - +#include #include -#include -#include +#include #include -#include -#include +#include "libtorrent/aux_/disable_warnings_push.hpp" +//#include #include "libtorrent/aux_/disable_warnings_pop.hpp" #include @@ -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()(*reinterpret_cast(&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()(*reinterpret_cast(&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 m_ip4s; + std::unordered_multiset m_ip4s; #if TORRENT_USE_IPV6 - boost::unordered_multiset m_ip6s; + std::unordered_multiset 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 table_t; + using table_t = std::vector; 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 size() const; + std::tuple size() const; std::int64_t num_global_nodes() const; diff --git a/include/libtorrent/kademlia/rpc_manager.hpp b/include/libtorrent/kademlia/rpc_manager.hpp index e2c5c8167..9a59c77c0 100644 --- a/include/libtorrent/kademlia/rpc_manager.hpp +++ b/include/libtorrent/kademlia/rpc_manager.hpp @@ -33,14 +33,12 @@ POSSIBILITY OF SUCH DAMAGE. #ifndef RPC_MANAGER_HPP #define RPC_MANAGER_HPP -#include "libtorrent/aux_/disable_warnings_push.hpp" #include - #include -#include -#include +#include "libtorrent/aux_/disable_warnings_push.hpp" +#include #include "libtorrent/aux_/disable_warnings_pop.hpp" #include diff --git a/include/libtorrent/lazy_entry.hpp b/include/libtorrent/lazy_entry.hpp index 7d2351c91..1446ceb75 100644 --- a/include/libtorrent/lazy_entry.hpp +++ b/include/libtorrent/lazy_entry.hpp @@ -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(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; } diff --git a/include/libtorrent/linked_list.hpp b/include/libtorrent/linked_list.hpp index 10f939021..9b303f169 100644 --- a/include/libtorrent/linked_list.hpp +++ b/include/libtorrent/linked_list.hpp @@ -68,7 +68,7 @@ namespace libtorrent template 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 iterate() const { return list_iterator(m_first); } diff --git a/include/libtorrent/parse_url.hpp b/include/libtorrent/parse_url.hpp index 902de8464..5fa129c17 100644 --- a/include/libtorrent/parse_url.hpp +++ b/include/libtorrent/parse_url.hpp @@ -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 - -#include "libtorrent/aux_/disable_warnings_pop.hpp" - -#include #include "libtorrent/config.hpp" + +#include +#include + #include "libtorrent/error_code.hpp" namespace libtorrent { // returns protocol, auth, hostname, port, path - TORRENT_EXTRA_EXPORT boost::tuple parse_url_components(std::string url, error_code& ec); diff --git a/include/libtorrent/part_file.hpp b/include/libtorrent/part_file.hpp index 5d5525780..d4f0897ac 100644 --- a/include/libtorrent/part_file.hpp +++ b/include/libtorrent/part_file.hpp @@ -30,16 +30,12 @@ POSSIBILITY OF SUCH DAMAGE. */ -#include "libtorrent/aux_/disable_warnings_push.hpp" - #include #include #include -#include +#include #include -#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 m_piece_map; + std::unordered_map m_piece_map; // this is the file handle to the part file file m_file; diff --git a/include/libtorrent/pe_crypto.hpp b/include/libtorrent/pe_crypto.hpp index 021a9cdbd..5ec39877e 100644 --- a/include/libtorrent/pe_crypto.hpp +++ b/include/libtorrent/pe_crypto.hpp @@ -118,7 +118,7 @@ namespace libtorrent bool is_recv_plaintext() const { - return m_dec_handler.get() == NULL; + return m_dec_handler.get() == nullptr; } private: diff --git a/include/libtorrent/peer_class.hpp b/include/libtorrent/peer_class.hpp index 398d8cbf3..1e4f1f888 100644 --- a/include/libtorrent/peer_class.hpp +++ b/include/libtorrent/peer_class.hpp @@ -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 #include -#include #include +#include "libtorrent/aux_/disable_warnings_push.hpp" +#include #include "libtorrent/aux_/disable_warnings_pop.hpp" namespace libtorrent diff --git a/include/libtorrent/peer_connection.hpp b/include/libtorrent/peer_connection.hpp index 33498ce5b..ffc28a047 100644 --- a/include/libtorrent/peer_connection.hpp +++ b/include/libtorrent/peer_connection.hpp @@ -70,6 +70,7 @@ POSSIBILITY OF SUCH DAMAGE. #include // for std::forward #include // for make_tuple #include +#include #include "libtorrent/aux_/disable_warnings_push.hpp" @@ -77,7 +78,6 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include -#include #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; } diff --git a/include/libtorrent/peer_list.hpp b/include/libtorrent/peer_list.hpp index 59387cf2d..6e5d0267b 100644 --- a/include/libtorrent/peer_list.hpp +++ b/include/libtorrent/peer_list.hpp @@ -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 diff --git a/include/libtorrent/performance_counters.hpp b/include/libtorrent/performance_counters.hpp index 7b63ac95c..ca30650c9 100644 --- a/include/libtorrent/performance_counters.hpp +++ b/include/libtorrent/performance_counters.hpp @@ -35,15 +35,11 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/config.hpp" -#include "libtorrent/aux_/disable_warnings_push.hpp" - #include #include #include #include -#include "libtorrent/aux_/disable_warnings_pop.hpp" - namespace libtorrent { struct TORRENT_EXTRA_EXPORT counters diff --git a/include/libtorrent/piece_picker.hpp b/include/libtorrent/piece_picker.hpp index 612648f95..fb32f8014 100644 --- a/include/libtorrent/piece_picker.hpp +++ b/include/libtorrent/piece_picker.hpp @@ -41,13 +41,8 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include - -#include "libtorrent/aux_/disable_warnings_push.hpp" - #include -#include - -#include "libtorrent/aux_/disable_warnings_pop.hpp" +#include #ifdef TORRENT_DEBUG_REFCOUNTS #include @@ -477,7 +472,7 @@ namespace libtorrent friend struct piece_pos; - boost::tuple requested_from( + std::tuple requested_from( piece_picker::downloading_piece const& p , int num_blocks_in_piece, torrent_peer* peer) const; diff --git a/include/libtorrent/session.hpp b/include/libtorrent/session.hpp index ed85aa4d4..eec8cb351 100644 --- a/include/libtorrent/session.hpp +++ b/include/libtorrent/session.hpp @@ -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 diff --git a/include/libtorrent/session_handle.hpp b/include/libtorrent/session_handle.hpp index 6d5c2e443..ea3c6fd07 100644 --- a/include/libtorrent/session_handle.hpp +++ b/include/libtorrent/session_handle.hpp @@ -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. diff --git a/include/libtorrent/sha1_hash.hpp b/include/libtorrent/sha1_hash.hpp index 4f6bb1979..d54276793 100644 --- a/include/libtorrent/sha1_hash.hpp +++ b/include/libtorrent/sha1_hash.hpp @@ -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) { diff --git a/include/libtorrent/stat_cache.hpp b/include/libtorrent/stat_cache.hpp index c0cf3fcc7..b5d82906a 100644 --- a/include/libtorrent/stat_cache.hpp +++ b/include/libtorrent/stat_cache.hpp @@ -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 #include #include -#include "libtorrent/aux_/disable_warnings_pop.hpp" - #include "libtorrent/config.hpp" #include "libtorrent/error_code.hpp" #include "libtorrent/file_storage.hpp" diff --git a/include/libtorrent/storage.hpp b/include/libtorrent/storage.hpp index 887cbb604..1625a87a7 100644 --- a/include/libtorrent/storage.hpp +++ b/include/libtorrent/storage.hpp @@ -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. diff --git a/include/libtorrent/storage_defs.hpp b/include/libtorrent/storage_defs.hpp index 542dfd1c5..37dc81d7f 100644 --- a/include/libtorrent/storage_defs.hpp +++ b/include/libtorrent/storage_defs.hpp @@ -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; diff --git a/include/libtorrent/string_util.hpp b/include/libtorrent/string_util.hpp index 2fbe2dbb8..eb045bcda 100644 --- a/include/libtorrent/string_util.hpp +++ b/include/libtorrent/string_util.hpp @@ -35,16 +35,12 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/config.hpp" -#include "libtorrent/aux_/disable_warnings_push.hpp" - #include #include #include -#include +#include #include // 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); diff --git a/include/libtorrent/tailqueue.hpp b/include/libtorrent/tailqueue.hpp index ca57d360a..a493cf32b 100644 --- a/include/libtorrent/tailqueue.hpp +++ b/include/libtorrent/tailqueue.hpp @@ -71,7 +71,7 @@ namespace libtorrent //#error boost::enable_if< is_base > > 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 iterate() const { return tailqueue_iterator(m_first); } diff --git a/include/libtorrent/time.hpp b/include/libtorrent/time.hpp index 9279c1fb6..47078b486 100644 --- a/include/libtorrent/time.hpp +++ b/include/libtorrent/time.hpp @@ -35,18 +35,13 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/config.hpp" -#include "libtorrent/aux_/disable_warnings_push.hpp" - #include - #include #if defined TORRENT_BUILD_SIMULATOR #include "simulator/simulator.hpp" #endif -#include "libtorrent/aux_/disable_warnings_pop.hpp" - namespace libtorrent { #if defined TORRENT_BUILD_SIMULATOR diff --git a/include/libtorrent/timestamp_history.hpp b/include/libtorrent/timestamp_history.hpp index a0149f85b..59049188f 100644 --- a/include/libtorrent/timestamp_history.hpp +++ b/include/libtorrent/timestamp_history.hpp @@ -33,9 +33,7 @@ POSSIBILITY OF SUCH DAMAGE. #ifndef TIMESTAMP_HISTORY_HPP #define TIMESTAMP_HISTORY_HPP -#include "libtorrent/aux_/disable_warnings_push.hpp" #include -#include "libtorrent/aux_/disable_warnings_pop.hpp" #include "libtorrent/config.hpp" #include "libtorrent/assert.hpp" diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 2944bb971..53c1dfb7b 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -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 diff --git a/include/libtorrent/torrent_handle.hpp b/include/libtorrent/torrent_handle.hpp index 201e4d8db..a65c2943d 100644 --- a/include/libtorrent/torrent_handle.hpp +++ b/include/libtorrent/torrent_handle.hpp @@ -35,11 +35,10 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/config.hpp" -#include "libtorrent/aux_/disable_warnings_push.hpp" - #include #include +#include "libtorrent/aux_/disable_warnings_push.hpp" #include #include #include @@ -48,7 +47,6 @@ POSSIBILITY OF SUCH DAMAGE. // for deprecated force_reannounce #include #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. diff --git a/include/libtorrent/torrent_info.hpp b/include/libtorrent/torrent_info.hpp index de44a7beb..9c914f1da 100644 --- a/include/libtorrent/torrent_info.hpp +++ b/include/libtorrent/torrent_info.hpp @@ -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 > m_collections; // these are the collections from outside of the info-dict. These are diff --git a/include/libtorrent/torrent_status.hpp b/include/libtorrent/torrent_status.hpp index c013392d6..5b5c307a2 100644 --- a/include/libtorrent/torrent_status.hpp +++ b/include/libtorrent/torrent_status.hpp @@ -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 -#include "libtorrent/aux_/disable_warnings_pop.hpp" - #include 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; diff --git a/include/libtorrent/tracker_manager.hpp b/include/libtorrent/tracker_manager.hpp index e6d3cac4a..63b6935c6 100644 --- a/include/libtorrent/tracker_manager.hpp +++ b/include/libtorrent/tracker_manager.hpp @@ -39,14 +39,14 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include +#include #include "libtorrent/aux_/disable_warnings_push.hpp" #include #include -#include #include -#include #include #include diff --git a/include/libtorrent/udp_tracker_connection.hpp b/include/libtorrent/udp_tracker_connection.hpp index a0326deb4..39e4e9935 100644 --- a/include/libtorrent/udp_tracker_connection.hpp +++ b/include/libtorrent/udp_tracker_connection.hpp @@ -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 #include #include #include #include - -#include #include +#include "libtorrent/aux_/disable_warnings_push.hpp" +#include #include "libtorrent/aux_/disable_warnings_pop.hpp" #include "libtorrent/udp_socket.hpp" diff --git a/include/libtorrent/utp_socket_manager.hpp b/include/libtorrent/utp_socket_manager.hpp index 7a3da6a02..20548af7e 100644 --- a/include/libtorrent/utp_socket_manager.hpp +++ b/include/libtorrent/utp_socket_manager.hpp @@ -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; }; } diff --git a/include/libtorrent/web_connection_base.hpp b/include/libtorrent/web_connection_base.hpp index 07110f95b..a11fcf2be 100644 --- a/include/libtorrent/web_connection_base.hpp +++ b/include/libtorrent/web_connection_base.hpp @@ -35,21 +35,19 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/debug.hpp" -#include "libtorrent/aux_/disable_warnings_push.hpp" - #include #include #include #include #include +#include +#include +#include "libtorrent/aux_/disable_warnings_push.hpp" #include #include #include -#include #include -#include - #include "libtorrent/aux_/disable_warnings_pop.hpp" #include "libtorrent/buffer.hpp" diff --git a/include/libtorrent/web_peer_connection.hpp b/include/libtorrent/web_peer_connection.hpp index 6f98e8c8e..7d66d8e15 100644 --- a/include/libtorrent/web_peer_connection.hpp +++ b/include/libtorrent/web_peer_connection.hpp @@ -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 #include #include #include #include +#include +#include + +#include "libtorrent/aux_/disable_warnings_push.hpp" #include #include #include -#include #include -#include #include "libtorrent/aux_/disable_warnings_pop.hpp" diff --git a/include/libtorrent/xml_parse.hpp b/include/libtorrent/xml_parse.hpp index c2024ad15..4b6011dc5 100644 --- a/include/libtorrent/xml_parse.hpp +++ b/include/libtorrent/xml_parse.hpp @@ -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 callback); diff --git a/simulation/test_auto_manage.cpp b/simulation/test_auto_manage.cpp index 7c839e5a4..ea51f998d 100644 --- a/simulation/test_auto_manage.cpp +++ b/simulation/test_auto_manage.cpp @@ -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(a) == NULL); + TEST_CHECK(alert_cast(a) == nullptr); } for (torrent_handle const& h : ses.get_torrents()) diff --git a/src/alert.cpp b/src/alert.cpp index 4bb034cee..f77650ed0 100644 --- a/src/alert.cpp +++ b/src/alert.cpp @@ -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); diff --git a/src/alert_manager.cpp b/src/alert_manager.cpp index 6c2b3783b..e8426958e 100644 --- a/src/alert_manager.cpp +++ b/src/alert_manager.cpp @@ -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& lock) diff --git a/src/allocator.cpp b/src/allocator.cpp index 3cc7ef3ec..fc87982ce 100644 --- a/src/allocator.cpp +++ b/src/allocator.cpp @@ -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 diff --git a/src/assert.cpp b/src/assert.cpp index 5ba0be60d..a46454809 100644 --- a/src/assert.cpp +++ b/src/assert.cpp @@ -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) diff --git a/src/bandwidth_limit.cpp b/src/bandwidth_limit.cpp index 13ceb38ea..4b9273024 100644 --- a/src/bandwidth_limit.cpp +++ b/src/bandwidth_limit.cpp @@ -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; } diff --git a/src/bandwidth_queue_entry.cpp b/src/bandwidth_queue_entry.cpp index 0ae54044d..84075e3e0 100644 --- a/src/bandwidth_queue_entry.cpp +++ b/src/bandwidth_queue_entry.cpp @@ -30,16 +30,12 @@ POSSIBILITY OF SUCH DAMAGE. */ -#include "libtorrent/aux_/disable_warnings_push.hpp" - #include - -#include "libtorrent/aux_/disable_warnings_pop.hpp" - -#include "libtorrent/bandwidth_queue_entry.hpp" #include #include +#include "libtorrent/bandwidth_queue_entry.hpp" + namespace libtorrent { bw_request::bw_request(boost::shared_ptr const& pe diff --git a/src/bdecode.cpp b/src/bdecode.cpp index bae599af0..e0b6cb393 100644 --- a/src/bdecode.cpp +++ b/src/bdecode.cpp @@ -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); } diff --git a/src/bitfield.cpp b/src/bitfield.cpp index b663ba83f..e6b803af9 100644 --- a/src/bitfield.cpp +++ b/src/bitfield.cpp @@ -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::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::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; diff --git a/src/block_cache.cpp b/src/block_cache.cpp index a2233009a..2c76a6e26 100644 --- a/src/block_cache.cpp +++ b/src/block_cache.cpp @@ -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(&*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& jobs) @@ -914,7 +914,7 @@ bool block_cache::evict_piece(cached_piece_entry* pe, tailqueue& 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& 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(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& 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 diff --git a/src/bt_peer_connection.cpp b/src/bt_peer_connection.cpp index 586024924..6cbf6b926 100644 --- a/src/bt_peer_connection.cpp +++ b/src/bt_peer_connection.cpp @@ -734,7 +734,7 @@ namespace libtorrent // since we'll mutate it char* buf = static_cast(malloc(size)); memcpy(buf, buffer, size); - append_send_buffer(buf, size, ®ular_c_free, NULL); + append_send_buffer(buf, size, ®ular_c_free, nullptr); destructor(const_cast(buffer), userdata, ref); } else diff --git a/src/create_torrent.cpp b/src/create_torrent.cpp index 512428ad9..0a5924273 100644 --- a/src/create_torrent.cpp +++ b/src/create_torrent.cpp @@ -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; } diff --git a/src/disk_buffer_pool.cpp b/src/disk_buffer_pool.cpp index 1a01c6dbb..9803654e6 100644 --- a/src/disk_buffer_pool.cpp +++ b/src/disk_buffer_pool.cpp @@ -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(); diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index 63f40ae93..5b0db463c 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -43,7 +43,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/platform_util.hpp" #include #include -#include +#include #include #include @@ -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 > links(j->d.links); return j->storage->check_fastresume(*rd, links.get(), j->error); @@ -2575,14 +2575,14 @@ namespace libtorrent std::unique_lock 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 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 diff --git a/src/entry.cpp b/src/entry.cpp index 4bc9f45eb..e86e9adec 100644 --- a/src/entry.cpp +++ b/src/entry.cpp @@ -46,12 +46,6 @@ POSSIBILITY OF SUCH DAMAGE. namespace { - template - 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 + 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(&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(&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(&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(&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(&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 += "\n"; break; case undefined_t: - default: out += "\n"; } } diff --git a/src/enum_net.cpp b/src/enum_net.cpp index 1c9475ac2..68cd46a19 100644 --- a/src/enum_net.cpp +++ b/src/enum_net.cpp @@ -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(&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(&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(); } - MIB_IPFORWARDTABLE* routes = NULL; + MIB_IPFORWARDTABLE* routes = nullptr; ULONG out_buf_size = 0; if (GetIpForwardTable(routes, &out_buf_size, FALSE) != ERROR_INSUFFICIENT_BUFFER) { diff --git a/src/escape_string.cpp b/src/escape_string.cpp index cababb576..91bfd71b3 100644 --- a/src/escape_string.cpp +++ b/src/escape_string.cpp @@ -38,6 +38,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #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); diff --git a/src/file.cpp b/src/file.cpp index 54eabaa42..0f5be4b39 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -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::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; diff --git a/src/file_pool.cpp b/src/file_pool.cpp index b9fbeb123..2249dc129 100644 --- a/src/file_pool.cpp +++ b/src/file_pool.cpp @@ -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; diff --git a/src/file_storage.cpp b/src/file_storage.cpp index 786a305db..21fe3e5aa 100644 --- a/src/file_storage.cpp +++ b/src/file_storage.cpp @@ -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(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 diff --git a/src/http_connection.cpp b/src/http_connection.cpp index fc0738788..f4f2f0969 100644 --- a/src/http_connection.cpp +++ b/src/http_connection.cpp @@ -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(NULL), 0)); + , me, ec, static_cast(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(NULL), 0)); + , me, err, static_cast(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(NULL), 0)); + , me, ec, static_cast(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(NULL), 0)); + , me, error_code(errors::no_i2p_router, get_libtorrent_category()), static_cast(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(NULL), 0)); + , me, ec, static_cast(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(NULL), 0)); + , me, ec, static_cast(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(NULL), 0)); + , me, ec, static_cast(nullptr), 0)); return; } diff --git a/src/http_parser.cpp b/src/http_parser.cpp index c5f4e872d..7449b0075 100644 --- a/src/http_parser.cpp +++ b/src/http_parser.cpp @@ -32,7 +32,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include -#include +#include #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 http_parser::incoming( + std::tuple http_parser::incoming( buffer::const_interval recv_buffer, bool& error) { TORRENT_ASSERT(recv_buffer.left() >= m_recv_buffer.left()); - boost::tuple ret(0, 0); + std::tuple 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::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 diff --git a/src/http_seed_connection.cpp b/src/http_seed_connection.cpp index d50cc366c..0151c40d0 100644 --- a/src/http_seed_connection.cpp +++ b/src/http_seed_connection.cpp @@ -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 diff --git a/src/http_tracker_connection.cpp b/src/http_tracker_connection.cpp index 778b8af98..a0eb778eb 100644 --- a/src/http_tracker_connection.cpp +++ b/src/http_tracker_connection.cpp @@ -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() diff --git a/src/i2p_stream.cpp b/src/i2p_stream.cpp index 858151974..93d4059f7 100644 --- a/src/i2p_stream.cpp +++ b/src/i2p_stream.cpp @@ -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; diff --git a/src/ip_filter.cpp b/src/ip_filter.cpp index 25ca4670e..01350899f 100644 --- a/src/ip_filter.cpp +++ b/src/ip_filter.cpp @@ -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() + return std::make_tuple(m_filter4.export_filter() , m_filter6.export_filter()); #else return m_filter4.export_filter(); diff --git a/src/kademlia/dht_storage.cpp b/src/kademlia/dht_storage.cpp index beabe8db2..661fb161f 100644 --- a/src/kademlia/dht_storage.cpp +++ b/src/kademlia/dht_storage.cpp @@ -32,12 +32,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/kademlia/dht_storage.hpp" -#include "libtorrent/aux_/disable_warnings_push.hpp" - -#include - -#include "libtorrent/aux_/disable_warnings_pop.hpp" - +#include #include #include #include @@ -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(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; } diff --git a/src/kademlia/dht_tracker.cpp b/src/kademlia/dht_tracker.cpp index cb86d185e..23ae15e3a 100644 --- a/src/kademlia/dht_tracker.cpp +++ b/src/kademlia/dht_tracker.cpp @@ -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 const&)> f) { - m_dht.get_peers(ih, f, NULL, false); + boost::function > 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 } diff --git a/src/kademlia/get_item.cpp b/src/kademlia/get_item.cpp index f9ad02cdd..31f718a37 100644 --- a/src/kademlia/get_item.cpp +++ b/src/kademlia/get_item.cpp @@ -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"); diff --git a/src/kademlia/node.cpp b/src/kademlia/node.cpp index 16c941a52..596c39221 100644 --- a/src/kademlia/node.cpp +++ b/src/kademlia/node.cpp @@ -38,7 +38,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/aux_/disable_warnings_push.hpp" -#include +#include #include #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& table } } -boost::tuple node::get_stats_counters() const +std::tuple 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 salt(static_cast(NULL), 0); + std::pair salt(static_cast(nullptr), 0); if (msg_keys[6]) salt = std::pair( msg_keys[6].string_ptr(), msg_keys[6].string_length()); diff --git a/src/kademlia/routing_table.cpp b/src/kademlia/routing_table.cpp index 76904bc2f..851cc49b2 100644 --- a/src/kademlia/routing_table.cpp +++ b/src/kademlia/routing_table.cpp @@ -37,6 +37,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include // for snprintf #include // for PRId64 et.al. +#include #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 - -#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(&ip[0])); - } - - size_t hash_value(libtorrent::address_v6::bytes_type ip) - { - return boost::hash_value(*reinterpret_cast(&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 routing_table::size() const +std::tuple routing_table::size() const { int nodes = 0; int replacements = 0; @@ -215,7 +196,7 @@ boost::tuple 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 diff --git a/src/lazy_bdecode.cpp b/src/lazy_bdecode.cpp index e74686f9b..09e90a70e 100644 --- a/src/lazy_bdecode.cpp +++ b/src/lazy_bdecode.cpp @@ -228,7 +228,7 @@ namespace libtorrent int lazy_entry::capacity() const { TORRENT_ASSERT(m_type == dict_t || m_type == list_t); - if (m_data.list == NULL) return 0; + if (m_data.list == nullptr) return 0; if (m_type == dict_t) return m_data.dict[0].val.m_len; else @@ -253,18 +253,18 @@ namespace libtorrent { TORRENT_ASSERT(m_type == dict_t); TORRENT_ASSERT(m_size <= this->capacity()); - if (m_data.dict == NULL) + if (m_data.dict == nullptr) { int capacity = lazy_entry_dict_init; m_data.dict = new (std::nothrow) lazy_dict_entry[capacity+1]; - if (m_data.dict == NULL) return NULL; + if (m_data.dict == nullptr) return nullptr; m_data.dict[0].val.m_len = capacity; } else if (m_size == this->capacity()) { int capacity = this->capacity() * lazy_entry_grow_factor / 100; lazy_dict_entry* tmp = new (std::nothrow) lazy_dict_entry[capacity+1]; - if (tmp == NULL) return NULL; + if (tmp == nullptr) return nullptr; std::memcpy(tmp, m_data.dict, sizeof(lazy_dict_entry) * (m_size + 1)); for (int i = 0; i < int(m_size); ++i) m_data.dict[i+1].val.release(); @@ -312,7 +312,7 @@ namespace libtorrent namespace { - // 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) { @@ -422,7 +422,7 @@ namespace libtorrent { TORRENT_ASSERT(m_type == list_t); TORRENT_ASSERT(m_size <= this->capacity()); - if (m_data.start == NULL) + if (m_data.start == nullptr) { int capacity = lazy_entry_list_init; m_data.list = new (std::nothrow) lazy_entry[capacity+1]; @@ -433,7 +433,7 @@ namespace libtorrent { int capacity = this->capacity() * lazy_entry_grow_factor / 100; lazy_entry* tmp = new (std::nothrow) lazy_entry[capacity+1]; - if (tmp == NULL) return NULL; + if (tmp == nullptr) return nullptr; std::memcpy(tmp, m_data.list, sizeof(lazy_entry) * (m_size+1)); for (int i = 0; i < int(m_size); ++i) m_data.list[i+1].release(); @@ -479,7 +479,7 @@ namespace libtorrent break; default: break; } - m_data.start = NULL; + m_data.start = nullptr; m_size = 0; m_type = none_t; } diff --git a/src/lsd.cpp b/src/lsd.cpp index baff66e37..9388b3c48 100644 --- a/src/lsd.cpp +++ b/src/lsd.cpp @@ -252,7 +252,7 @@ void lsd::on_announce(udp::endpoint const& from, char* buf { // we expect it to be hexadecimal // if it isn't, it's not our cookie anyway - std::int32_t cookie = strtol(cookie_iter->second.c_str(), NULL, 16); + std::int32_t cookie = strtol(cookie_iter->second.c_str(), nullptr, 16); if (cookie == m_cookie) { #ifndef TORRENT_DISABLE_LOGGING diff --git a/src/lt_trackers.cpp b/src/lt_trackers.cpp index 31c3eccaa..477580d8b 100644 --- a/src/lt_trackers.cpp +++ b/src/lt_trackers.cpp @@ -246,7 +246,7 @@ namespace libtorrent { namespace std::string hostname; int port; std::string path; - boost::tie(protocol, auth, hostname, port, path) + std::tie(protocol, auth, hostname, port, path) = parse_url_components(e.url, err); if (err) continue; diff --git a/src/packet_buffer.cpp b/src/packet_buffer.cpp index c5152c4db..be62982ed 100644 --- a/src/packet_buffer.cpp +++ b/src/packet_buffer.cpp @@ -159,7 +159,7 @@ namespace libtorrent { void** new_storage = static_cast(malloc(sizeof(void*) * new_size)); #ifndef BOOST_NO_EXCEPTIONS - if (new_storage == NULL) throw std::bad_alloc(); + if (new_storage == nullptr) throw std::bad_alloc(); #endif for (index_type i = 0; i < new_size; ++i) diff --git a/src/parse_url.cpp b/src/parse_url.cpp index 81ae6224d..1df4de91f 100644 --- a/src/parse_url.cpp +++ b/src/parse_url.cpp @@ -37,7 +37,7 @@ namespace libtorrent { // returns protocol, auth, hostname, port, path - boost::tuple + std::tuple parse_url_components(std::string url, error_code& ec) { std::string hostname; // hostname only @@ -126,7 +126,7 @@ namespace libtorrent start = end; exit: - return boost::make_tuple(protocol, auth, hostname, port + return std::make_tuple(protocol, auth, hostname, port , std::string(start, url.end())); } diff --git a/src/part_file.cpp b/src/part_file.cpp index c9d6c6675..930738052 100644 --- a/src/part_file.cpp +++ b/src/part_file.cpp @@ -64,7 +64,11 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/part_file.hpp" #include "libtorrent/io.hpp" #include "libtorrent/assert.hpp" + +#include "libtorrent/aux_/disable_warnings_push.hpp" +// TODO: 3 use std::unique_ptr #include +#include "libtorrent/aux_/disable_warnings_pop.hpp" namespace { @@ -180,7 +184,7 @@ namespace libtorrent if (ec) return -1; int slot = -1; - boost::unordered_map::iterator i = m_piece_map.find(piece); + std::unordered_map::iterator i = m_piece_map.find(piece); if (i == m_piece_map.end()) slot = allocate_slot(piece); else @@ -198,7 +202,7 @@ namespace libtorrent TORRENT_ASSERT(offset >= 0); std::unique_lock l(m_mutex); - boost::unordered_map::iterator i = m_piece_map.find(piece); + std::unordered_map::iterator i = m_piece_map.find(piece); if (i == m_piece_map.end()) { ec = error_code(boost::system::errc::no_such_file_or_directory @@ -242,7 +246,7 @@ namespace libtorrent { std::lock_guard l(m_mutex); - boost::unordered_map::iterator i = m_piece_map.find(piece); + std::unordered_map::iterator i = m_piece_map.find(piece); if (i == m_piece_map.end()) return; // TODO: what do we do if someone is currently reading from the disk @@ -310,7 +314,7 @@ namespace libtorrent std::int64_t file_offset = 0; for (; piece < end; ++piece) { - boost::unordered_map::iterator i = m_piece_map.find(piece); + std::unordered_map::iterator i = m_piece_map.find(piece); int const block_to_copy = (std::min)(m_piece_size - piece_offset, size); if (i != m_piece_map.end()) { @@ -345,7 +349,7 @@ namespace libtorrent // another thread removed this slot map entry, and invalidated // our iterator. Now that we hold the lock again, perform // another lookup to be sure. - boost::unordered_map::iterator j = m_piece_map.find(piece); + std::unordered_map::iterator j = m_piece_map.find(piece); if (j != m_piece_map.end()) { // if the slot moved, that's really suspicious @@ -404,7 +408,7 @@ namespace libtorrent for (int piece = 0; piece < m_max_pieces; ++piece) { - boost::unordered_map::iterator i = m_piece_map.find(piece); + std::unordered_map::iterator i = m_piece_map.find(piece); int slot = 0xffffffff; if (i != m_piece_map.end()) slot = i->second; diff --git a/src/pe_crypto.cpp b/src/pe_crypto.cpp index 4f03571d8..5c3af2b4d 100644 --- a/src/pe_crypto.cpp +++ b/src/pe_crypto.cpp @@ -32,9 +32,12 @@ POSSIBILITY OF SUCH DAMAGE. #if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) +#include +#include +#include + #include "libtorrent/aux_/disable_warnings_push.hpp" -#include #include #include @@ -46,9 +49,6 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/aux_/disable_warnings_pop.hpp" -#include -#include - #include "libtorrent/random.hpp" #include "libtorrent/alloca.hpp" #include "libtorrent/pe_crypto.hpp" diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index f192d0f30..6afc24693 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -32,9 +32,6 @@ POSSIBILITY OF SUCH DAMAGE. #include #include - -#include "libtorrent/aux_/disable_warnings_push.hpp" - #include #ifdef TORRENT_DEBUG @@ -45,8 +42,6 @@ POSSIBILITY OF SUCH DAMAGE. #include #endif -#include "libtorrent/aux_/disable_warnings_pop.hpp" - #ifndef TORRENT_DISABLE_LOGGING #include // for va_start, va_end #include // for vsnprintf @@ -204,7 +199,7 @@ namespace libtorrent m_superseed_piece[0] = -1; m_superseed_piece[1] = -1; boost::shared_ptr t = m_torrent.lock(); - // if t is NULL, we better not be connecting, since + // if t is nullptr, we better not be connecting, since // we can't decrement the connecting counter TORRENT_ASSERT(t || !m_connecting); if (m_connecting && t) t->inc_num_connecting(); @@ -800,7 +795,7 @@ namespace libtorrent // defensive boost::shared_ptr t = m_torrent.lock(); - // if t is NULL, we better not be connecting, since + // if t is nullptr, we better not be connecting, since // we can't decrement the connecting counter TORRENT_ASSERT(t || !m_connecting); @@ -1322,7 +1317,7 @@ namespace libtorrent std::uint32_t peer_connection::peer_rank() const { TORRENT_ASSERT(is_single_thread()); - return m_peer_info == NULL ? 0 + return m_peer_info == nullptr ? 0 : m_peer_info->rank(m_ses.external_address(), m_ses.listen_port()); } @@ -3662,7 +3657,7 @@ namespace libtorrent if (m_choked) { - TORRENT_ASSERT(m_peer_info == NULL + TORRENT_ASSERT(m_peer_info == nullptr || m_peer_info->optimistically_unchoked == false); return false; } @@ -6190,7 +6185,7 @@ namespace libtorrent RAND_add(&now, 8, 1.5); #endif - // if t is NULL, we better not be connecting, since + // if t is nullptr, we better not be connecting, since // we can't decrement the connecting counter boost::shared_ptr t = m_torrent.lock(); TORRENT_ASSERT(t || !m_connecting); diff --git a/src/peer_connection_handle.cpp b/src/peer_connection_handle.cpp index 9137f5f92..41339bebf 100644 --- a/src/peer_connection_handle.cpp +++ b/src/peer_connection_handle.cpp @@ -67,7 +67,7 @@ peer_plugin const* peer_connection_handle::find_plugin(char const* type) return pc->find_plugin(type); #else TORRENT_UNUSED(type); - return NULL; + return nullptr; #endif } diff --git a/src/peer_list.cpp b/src/peer_list.cpp index 998270769..55f90f08f 100644 --- a/src/peer_list.cpp +++ b/src/peer_list.cpp @@ -125,7 +125,7 @@ namespace namespace libtorrent { peer_list::peer_list() - : m_locked_peer(NULL) + : m_locked_peer(nullptr) , m_num_seeds(0) , m_finished(0) , m_round_robin(0) @@ -690,10 +690,10 @@ namespace libtorrent c.disconnect(errors::duplicate_peer_id, op_bittorrent); return false; } - TORRENT_ASSERT(m_locked_peer == NULL); + TORRENT_ASSERT(m_locked_peer == nullptr); m_locked_peer = i; i->connection->disconnect(errors::duplicate_peer_id, op_bittorrent); - m_locked_peer = NULL; + m_locked_peer = nullptr; } else { @@ -709,10 +709,10 @@ namespace libtorrent c.disconnect(errors::duplicate_peer_id, op_bittorrent); return false; } - TORRENT_ASSERT(m_locked_peer == NULL); + TORRENT_ASSERT(m_locked_peer == nullptr); m_locked_peer = i; i->connection->disconnect(errors::duplicate_peer_id, op_bittorrent); - m_locked_peer = NULL; + m_locked_peer = nullptr; } } } @@ -826,10 +826,10 @@ namespace libtorrent // case will, since it was an incoming peer that just disconnected // and we allow multiple connections per IP. Because of that, // we need to make sure we don't let it do that, locking i - TORRENT_ASSERT(m_locked_peer == NULL); + TORRENT_ASSERT(m_locked_peer == nullptr); m_locked_peer = p; p->connection->disconnect(errors::duplicate_peer_id, op_bittorrent); - m_locked_peer = NULL; + m_locked_peer = nullptr; erase_peer(p, state); return false; } @@ -1028,7 +1028,7 @@ namespace libtorrent // we don't have any info about this peer. // add a new entry p = state->peer_allocator->allocate_peer_entry(torrent_peer_allocator_interface::i2p_peer_type); - if (p == NULL) return NULL; + if (p == nullptr) return nullptr; new (p) i2p_peer(destination, true, src); #if TORRENT_USE_ASSERTS @@ -1054,7 +1054,7 @@ namespace libtorrent } #endif // TORRENT_USE_I2P - // if this returns non-NULL, the torrent need to post status update + // if this returns non-nullptr, the torrent need to post status update torrent_peer* peer_list::add_peer(tcp::endpoint const& remote, int src, char flags , torrent_state* state) { @@ -1106,7 +1106,7 @@ namespace libtorrent p = state->peer_allocator->allocate_peer_entry( is_v6 ? torrent_peer_allocator_interface::ipv6_peer_type : torrent_peer_allocator_interface::ipv4_peer_type); - if (p == NULL) return NULL; + if (p == nullptr) return nullptr; #if TORRENT_USE_IPV6 if (is_v6) @@ -1162,7 +1162,7 @@ namespace libtorrent if (m_candidate_cache.empty()) { find_connect_candidates(m_candidate_cache, session_time, state); - if (m_candidate_cache.empty()) return NULL; + if (m_candidate_cache.empty()) return nullptr; } torrent_peer* p = m_candidate_cache.front(); diff --git a/src/piece_picker.cpp b/src/piece_picker.cpp index 72fdfd4be..17ab6656c 100644 --- a/src/piece_picker.cpp +++ b/src/piece_picker.cpp @@ -36,12 +36,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include - -#include "libtorrent/aux_/disable_warnings_push.hpp" - -#include - -#include "libtorrent/aux_/disable_warnings_pop.hpp" +#include #include "libtorrent/piece_picker.hpp" #include "libtorrent/bitfield.hpp" @@ -343,7 +338,7 @@ namespace libtorrent { torrent_peer* p = info[j].peer; TORRENT_ASSERT(p->in_use); - TORRENT_ASSERT(p->connection == NULL + TORRENT_ASSERT(p->connection == nullptr || static_cast(p->connection)->m_in_use); } } @@ -483,7 +478,7 @@ namespace libtorrent if (!info[j].peer) continue; torrent_peer* p = info[j].peer; TORRENT_ASSERT(p->in_use); - TORRENT_ASSERT(p->connection == NULL + TORRENT_ASSERT(p->connection == nullptr || static_cast(p->connection)->m_in_use); } #endif @@ -2239,7 +2234,7 @@ namespace libtorrent TORRENT_ASSERT(m_piece_map[piece].downloading() == false); int start, end; - boost::tie(start, end) = expand_piece(piece + std::tie(start, end) = expand_piece(piece , prefer_contiguous_blocks, pieces, options); TORRENT_ASSERT(end - start > 0); for (int k = start; k < end; ++k) @@ -2565,7 +2560,7 @@ get_out: // and downloading blocks from this piece. Active means having a connection. // TODO: 2 the first_block returned here is the largest free range, not // the first-fit range, which would be better - boost::tuple piece_picker::requested_from( + std::tuple piece_picker::requested_from( piece_picker::downloading_piece const& p , int num_blocks_in_piece, torrent_peer* peer) const { @@ -2606,7 +2601,7 @@ get_out: max_contiguous = contiguous_blocks; first_block = num_blocks_in_piece - contiguous_blocks; } - return boost::make_tuple(exclusive, exclusive_active, max_contiguous + return std::make_tuple(exclusive, exclusive_active, max_contiguous , first_block); } @@ -2667,7 +2662,7 @@ get_out: else { int start, end; - boost::tie(start, end) = expand_piece(piece, prefer_contiguous_blocks + std::tie(start, end) = expand_piece(piece, prefer_contiguous_blocks , pieces, options); for (int k = start; k < end; ++k) { @@ -2716,7 +2711,7 @@ get_out: // used to report back the largest contiguous block run int contiguous_blocks; int first_block; - boost::tie(exclusive, exclusive_active, contiguous_blocks, first_block) + std::tie(exclusive, exclusive_active, contiguous_blocks, first_block) = requested_from(dp, num_blocks_in_piece, peer); // no need in picking from the largest contiguous block run unless @@ -3531,7 +3526,7 @@ get_out: // peers may have been disconnected in between mark_as_writing // and mark_as_finished. When a peer disconnects, its m_peer_info - // pointer is set to NULL. If so, preserve the previous peer + // pointer is set to nullptr. If so, preserve the previous peer // pointer, instead of forgetting who we downloaded this block from if (info.state != block_info::state_writing || peer != 0) info.peer = peer; @@ -3596,7 +3591,7 @@ get_out: if (state == piece_pos::piece_open) { - for (int i = 0; i < num_blocks; ++i) d.push_back(NULL); + for (int i = 0; i < num_blocks; ++i) d.push_back(nullptr); return; } @@ -3624,7 +3619,7 @@ get_out: block_info const* binfo = blocks_for_piece(*i); TORRENT_ASSERT(binfo[block.block_index].piece_index == block.piece_index); if (binfo[block.block_index].state == block_info::state_none) - return NULL; + return nullptr; torrent_peer* peer = binfo[block.block_index].peer; TORRENT_ASSERT(peer == 0 || static_cast(peer)->in_use); diff --git a/src/platform_util.cpp b/src/platform_util.cpp index c840b0b8a..a146f7f8b 100644 --- a/src/platform_util.cpp +++ b/src/platform_util.cpp @@ -33,17 +33,12 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/config.hpp" #include "libtorrent/platform_util.hpp" -#include "libtorrent/aux_/disable_warnings_push.hpp" - #include #include -#if TORRENT_USE_RLIMIT +#include "libtorrent/aux_/disable_warnings_push.hpp" -#ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wlong-long" -#endif // __GNUC__ +#if TORRENT_USE_RLIMIT #include @@ -52,10 +47,6 @@ const rlim_t rlimit_as = RLIMIT_AS; const rlim_t rlimit_nofile = RLIMIT_NOFILE; const rlim_t rlim_infinity = RLIM_INFINITY; -#ifdef __GNUC__ -#pragma GCC diagnostic pop -#endif // __GNUC__ - #endif // TORRENT_USE_RLIMIT #ifdef TORRENT_BSD @@ -115,7 +106,7 @@ namespace libtorrent int mib[2] = { CTL_HW, HW_PHYSMEM }; #endif size_t len = sizeof(ret); - if (sysctl(mib, 2, &ret, &len, NULL, 0) != 0) + if (sysctl(mib, 2, &ret, &len, nullptr, 0) != 0) ret = 0; #elif defined TORRENT_WINDOWS MEMORYSTATUSEX ms; diff --git a/src/puff.cpp b/src/puff.cpp index 8cd7fb330..c882f7b93 100644 --- a/src/puff.cpp +++ b/src/puff.cpp @@ -806,16 +806,16 @@ local unsigned char *yank(char *name, std::uint32_t *len) struct stat s; *len = 0; - if (stat(name, &s)) return NULL; - if ((s.st_mode & S_IFMT) != S_IFREG) return NULL; + if (stat(name, &s)) return nullptr; + if ((s.st_mode & S_IFMT) != S_IFREG) return nullptr; size = (std::uint32_t)(s.st_size); - if (size == 0 || (off_t)size != s.st_size) return NULL; + if (size == 0 || (off_t)size != s.st_size) return nullptr; in = fopen(name, "r"); - if (in == NULL) return NULL; + if (in == nullptr) return nullptr; buf = malloc(size); - if (buf != NULL && fread(buf, 1, size, in) != size) { + if (buf != nullptr && fread(buf, 1, size, in) != size) { free(buf); - buf = NULL; + buf = nullptr; } fclose(in); *len = size; @@ -830,7 +830,7 @@ int main(int argc, char **argv) if (argc < 2) return 2; source = yank(argv[1], &len); - if (source == NULL) return 2; + if (source == nullptr) return 2; sourcelen = len; ret = puff(NIL, &destlen, source, &sourcelen); if (ret) diff --git a/src/read_resume_data.cpp b/src/read_resume_data.cpp index 6c02a0717..6071524ff 100644 --- a/src/read_resume_data.cpp +++ b/src/read_resume_data.cpp @@ -30,11 +30,10 @@ POSSIBILITY OF SUCH DAMAGE. */ -#include "libtorrent/aux_/disable_warnings_push.hpp" - #include -#include +#include "libtorrent/aux_/disable_warnings_push.hpp" +#include #include "libtorrent/aux_/disable_warnings_pop.hpp" #include "libtorrent/bdecode.hpp" diff --git a/src/session.cpp b/src/session.cpp index aa1962635..aca0759c8 100644 --- a/src/session.cpp +++ b/src/session.cpp @@ -320,7 +320,7 @@ namespace libtorrent void session::start(int flags, settings_pack const& pack, io_service* ios) { - bool const internal_executor = ios == NULL; + bool const internal_executor = ios == nullptr; if (internal_executor) { diff --git a/src/session_handle.cpp b/src/session_handle.cpp index 98d0ebc80..1bd0467c3 100644 --- a/src/session_handle.cpp +++ b/src/session_handle.cpp @@ -772,7 +772,7 @@ namespace libtorrent { settings_pack p; std::string interfaces_str; - if (net_interface == NULL || strlen(net_interface) == 0) + if (net_interface == nullptr || strlen(net_interface) == 0) net_interface = "0.0.0.0"; interfaces_str = print_endpoint(tcp::endpoint(address::from_string(net_interface, ec), port_range.first)); diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 45f061f98..21e59e9e8 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -53,20 +53,9 @@ POSSIBILITY OF SUCH DAMAGE. #if TORRENT_USE_RLIMIT -#ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wlong-long" -#endif // __GNUC__ - #include - // capture this here where warnings are disabled (the macro generates warnings) const rlim_t rlim_infinity = RLIM_INFINITY; - -#ifdef __GNUC__ -#pragma GCC diagnostic pop -#endif // __GNUC__ - #endif // TORRENT_USE_RLIMIT #include "libtorrent/aux_/disable_warnings_pop.hpp" @@ -378,7 +367,7 @@ namespace aux { std::bind(&session_impl::send_udp_packet, this, false, _1, _2, _3, _4) , std::bind(&session_impl::incoming_connection, this, _1) , m_io_service - , m_settings, m_stats_counters, NULL) + , m_settings, m_stats_counters, nullptr) #ifdef TORRENT_USE_OPENSSL , m_ssl_utp_socket_manager( std::bind(&session_impl::send_udp_packet, this, true, _1, _2, _3, _4) @@ -1242,14 +1231,14 @@ namespace aux { bool new_torrent = false; // if t is the only torrent in the LRU list, both - // its prev and next links will be NULL, even though + // its prev and next links will be nullptr, even though // it's already in the list. Cover this case by also // checking to see if it's the first item - if (t->next != NULL || t->prev != NULL || m_torrent_lru.front() == t) + if (t->next != nullptr || t->prev != nullptr || m_torrent_lru.front() == t) { #ifdef TORRENT_DEBUG torrent* i = m_torrent_lru.front(); - while (i != NULL && i != t) i = i->next; + while (i != nullptr && i != t) i = i->next; TORRENT_ASSERT(i == t); #endif @@ -1285,11 +1274,11 @@ namespace aux { // if it's already evicted, there's nothing to do if (!t->is_loaded() || !t->should_be_loaded()) return; - TORRENT_ASSERT(t->next != NULL || t->prev != NULL || m_torrent_lru.front() == t); + TORRENT_ASSERT(t->next != nullptr || t->prev != nullptr || m_torrent_lru.front() == t); #if defined TORRENT_DEBUG && defined TORRENT_EXPENSIVE_INVARIANT_CHECKS torrent* i = m_torrent_lru.front(); - while (i != NULL && i != t) i = i->next; + while (i != nullptr && i != t) i = i->next; TORRENT_ASSERT(i == t); #endif @@ -1324,11 +1313,11 @@ namespace aux { // if the torrent we're ignoring (i.e. making room for), allow // one more torrent in the list. - if (ignore->next != NULL || ignore->prev != NULL || m_torrent_lru.front() == ignore) + if (ignore->next != nullptr || ignore->prev != nullptr || m_torrent_lru.front() == ignore) { #ifdef TORRENT_DEBUG torrent* i = m_torrent_lru.front(); - while (i != NULL && i != ignore) i = i->next; + while (i != nullptr && i != ignore) i = i->next; TORRENT_ASSERT(i == ignore); #endif ++loaded_limit; @@ -1343,7 +1332,7 @@ namespace aux { if (i == ignore) { i = i->next; - if (i == NULL) break; + if (i == nullptr) break; } m_stats_counters.inc_stats_counter(counters::torrent_evicted_counter); TORRENT_ASSERT(i->is_pinned() == false); @@ -1359,7 +1348,7 @@ namespace aux { // we wouldn't be loading the torrent if it was already // in the LRU (and loaded) - TORRENT_ASSERT(t->next == NULL && t->prev == NULL && m_torrent_lru.front() != t); + TORRENT_ASSERT(t->next == nullptr && t->prev == nullptr && m_torrent_lru.front() != t); TORRENT_ASSERT(m_user_load_torrent); // now, load t into RAM @@ -2025,7 +2014,7 @@ namespace aux { m_socks_listen_socket = boost::make_shared(boost::ref(m_io_service)); bool const ret = instantiate_connection(m_io_service, proxy() - , *m_socks_listen_socket, NULL, NULL, false, false); + , *m_socks_listen_socket, nullptr, nullptr, false, false); TORRENT_ASSERT_VAL(ret, ret); TORRENT_UNUSED(ret); @@ -2152,7 +2141,7 @@ namespace aux { m_i2p_listen_socket = boost::shared_ptr(new socket_type(m_io_service)); bool ret = instantiate_connection(m_io_service, m_i2p_conn.proxy() - , *m_i2p_listen_socket, NULL, NULL, true, false); + , *m_i2p_listen_socket, nullptr, nullptr, true, false); TORRENT_ASSERT_VAL(ret, ret); TORRENT_UNUSED(ret); @@ -2744,7 +2733,7 @@ namespace aux { for (int i = 0; i < pcs.num_classes(); ++i) { int pc = pcs.class_at(i); - if (m_classes.at(pc) == NULL) continue; + if (m_classes.at(pc) == nullptr) continue; int f = m_classes.at(pc)->connection_limit_factor; if (connection_limit_factor < f) connection_limit_factor = f; } @@ -3447,7 +3436,7 @@ namespace aux { bool session_impl::has_dht() const { - return m_dht.get() != NULL; + return m_dht.get() != nullptr; } void session_impl::prioritize_dht(boost::weak_ptr t) @@ -3976,20 +3965,20 @@ namespace aux { if (m_next_finished_connect_torrent >= int(want_peers_finished.size())) m_next_finished_connect_torrent = 0; - torrent* t = NULL; + torrent* t = nullptr; // there are prioritized torrents. Pick one of those while (!m_prio_torrents.empty()) { t = m_prio_torrents.front().first.lock().get(); --m_prio_torrents.front().second; if (m_prio_torrents.front().second > 0 - && t != NULL + && t != nullptr && t->want_peers()) break; m_prio_torrents.pop_front(); - t = NULL; + t = nullptr; } - if (t == NULL) + if (t == nullptr) { if ((m_download_connect_attempts >= m_settings.get_int( settings_pack::connect_seed_every_n_download) @@ -4355,7 +4344,7 @@ namespace aux { obfuscated ^= xor_mask; torrent_map::iterator i = m_obfuscated_torrents.find(obfuscated); - if (i == m_obfuscated_torrents.end()) return NULL; + if (i == m_obfuscated_torrents.end()) return nullptr; return i->second.get(); } #endif @@ -5033,10 +5022,10 @@ namespace aux { } if (m_torrent_lru.size() > 0 - && (t.prev != NULL || t.next != NULL || m_torrent_lru.front() == &t)) + && (t.prev != nullptr || t.next != nullptr || m_torrent_lru.front() == &t)) m_torrent_lru.erase(&t); - TORRENT_ASSERT(t.prev == NULL && t.next == NULL); + TORRENT_ASSERT(t.prev == nullptr && t.next == nullptr); tptr->update_gauge(); @@ -5810,7 +5799,7 @@ namespace aux { #if defined TORRENT_ASIO_DEBUGGING FILE* f = fopen("wakeups.log", "w+"); - if (f != NULL) + if (f != nullptr) { time_point m = min_time(); if (!_wakeups.empty()) m = _wakeups[0].timestamp; @@ -5845,8 +5834,8 @@ namespace aux { { list_node* tmp = i; i = i->next; - tmp->next = NULL; - tmp->prev = NULL; + tmp->next = nullptr; + tmp->prev = nullptr; } #endif @@ -6142,7 +6131,7 @@ namespace aux { if (!m_dht) { #ifndef TORRENT_DISABLE_LOGGING - session_log("not starting DHT announce timer: m_dht == NULL"); + session_log("not starting DHT announce timer: m_dht == nullptr"); #endif return; } @@ -6373,10 +6362,10 @@ namespace aux { { pop_alerts(); if (m_alert_pointers.empty()) - return NULL; + return nullptr; } - if (m_alert_pointers.empty()) return NULL; + if (m_alert_pointers.empty()) return nullptr; // clone here to be backwards compatible, to make the client delete the // alert object diff --git a/src/settings_pack.cpp b/src/settings_pack.cpp index 624ac7141..6529639ef 100644 --- a/src/settings_pack.cpp +++ b/src/settings_pack.cpp @@ -109,7 +109,7 @@ namespace libtorrent #ifdef TORRENT_NO_DEPRECATE #define SET(name, default_value, fun) { #name, fun, default_value } #define SET_NOPREV(name, default_value, fun) { #name, fun, default_value } -#define DEPRECATED_SET(name, default_value, fun) { "", NULL, 0 } +#define DEPRECATED_SET(name, default_value, fun) { "", nullptr, 0 } #else #define SET(name, default_value, fun) { #name, fun, default_value, offsetof(libtorrent::session_settings, name) } #define SET_NOPREV(name, default_value, fun) { #name, fun, default_value, 0 } @@ -396,7 +396,7 @@ namespace libtorrent { std::string key; bdecode_node val; - boost::tie(key, val) = settings.dict_at(i); + std::tie(key, val) = settings.dict_at(i); switch (val.type()) { case bdecode_node::dict_t: diff --git a/src/sha1.cpp b/src/sha1.cpp index d46f58a34..a38c56c3e 100644 --- a/src/sha1.cpp +++ b/src/sha1.cpp @@ -15,7 +15,9 @@ changelog at the end of the file. #include "libtorrent/sha1.hpp" +#include "libtorrent/aux_/disable_warnings_push.hpp" #include // for BIG_ENDIAN and LITTLE_ENDIAN macros +#include "libtorrent/aux_/disable_warnings_pop.hpp" typedef std::uint32_t u32; typedef std::uint8_t u8; diff --git a/src/smart_ban.cpp b/src/smart_ban.cpp index 50214fb44..ce6d3ee42 100644 --- a/src/smart_ban.cpp +++ b/src/smart_ban.cpp @@ -151,7 +151,7 @@ namespace for (std::vector::iterator i = downloaders.begin() , end(downloaders.end()); i != end; ++i) { - if (*i != NULL) + if (*i != nullptr) { // for very sad and involved reasons, this read need to force a copy out of the cache // since the piece has failed, this block is very likely to be replaced with a newly @@ -278,13 +278,13 @@ namespace std::pair range = m_torrent.find_peers(a); if (range.first == range.second) return; - torrent_peer* p = NULL; + torrent_peer* p = nullptr; for (; range.first != range.second; ++range.first) { if (b.second.peer != *range.first) continue; p = *range.first; } - if (p == NULL) return; + if (p == nullptr) return; #ifndef TORRENT_DISABLE_LOGGING char const* client = "-"; diff --git a/src/socket_type.cpp b/src/socket_type.cpp index 8ff54f2ca..ee0078f1f 100644 --- a/src/socket_type.cpp +++ b/src/socket_type.cpp @@ -70,9 +70,9 @@ namespace libtorrent bool is_utp(socket_type const& s) { - return s.get() != NULL + return s.get() != nullptr #ifdef TORRENT_USE_OPENSSL - || s.get >() != NULL + || s.get >() != nullptr #endif ; } @@ -80,9 +80,9 @@ namespace libtorrent #if TORRENT_USE_I2P bool is_i2p(socket_type const& s) { - return s.get() != NULL + return s.get() != nullptr #ifdef TORRENT_USE_OPENSSL - || s.get >() != NULL + || s.get >() != nullptr #endif ; } diff --git a/src/socks5_stream.cpp b/src/socks5_stream.cpp index b3561989e..7cfa09b5a 100644 --- a/src/socks5_stream.cpp +++ b/src/socks5_stream.cpp @@ -341,7 +341,7 @@ namespace libtorrent write_uint32(m_remote_endpoint.address().to_v4().to_ulong(), p); std::copy(m_user.begin(), m_user.end(), p); p += m_user.size(); - write_uint8(0, p); // NULL terminator + write_uint8(0, p); // 0-terminator } else { diff --git a/src/storage.cpp b/src/storage.cpp index b53e644c1..cb3d8c8ff 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -178,7 +178,7 @@ namespace libtorrent static std::mutex disk_access_mutex; // this is opened and closed by the disk_io_thread class - FILE* g_access_log = NULL; + FILE* g_access_log = nullptr; enum access_log_flags_t { @@ -190,7 +190,7 @@ namespace libtorrent void write_access_log(std::uint64_t offset, std::uint32_t fileid, int flags, time_point timestamp) { - if (g_access_log == NULL) return; + if (g_access_log == nullptr) return; // the event format in the log is: // uint64_t timestamp (microseconds) @@ -1321,23 +1321,23 @@ namespace libtorrent #ifdef TORRENT_DISK_STATS bool default_storage::disk_write_access_log() { - return g_access_log != NULL; + return g_access_log != nullptr; } void default_storage::disk_write_access_log(bool enable) { if (enable) { - if (g_access_log == NULL) + if (g_access_log == nullptr) { g_access_log = fopen("file_access.log", "a+"); } } else { - if (g_access_log != NULL) + if (g_access_log != nullptr) { FILE* f = g_access_log; - g_access_log = NULL; + g_access_log = nullptr; fclose(f); } } @@ -1541,7 +1541,7 @@ namespace libtorrent // check if the fastresume data is up to date // if it is, use it and return true. If it // isn't return false and the full check - // will be run. If the links pointer is non-null, it has the same number + // will be run. 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 diff --git a/src/string_util.cpp b/src/string_util.cpp index 123dbf6b0..b46fc257e 100644 --- a/src/string_util.cpp +++ b/src/string_util.cpp @@ -37,15 +37,10 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/parse_url.hpp" #include "libtorrent/address.hpp" -#include "libtorrent/aux_/disable_warnings_push.hpp" - -#include - +#include // for tie #include // for malloc #include // for memmov/strcpy/strlen -#include "libtorrent/aux_/disable_warnings_pop.hpp" - namespace libtorrent { @@ -335,7 +330,7 @@ namespace libtorrent { *next = strchr(last + 1, '"'); // consume the actual separator as well. - if (*next != NULL) + if (*next != nullptr) *next = strchr(*next, sep); } else @@ -353,10 +348,10 @@ namespace libtorrent bool is_i2p_url(std::string const& url) { - using boost::tuples::ignore; + using std::ignore; std::string hostname; error_code ec; - boost::tie(ignore, ignore, hostname, ignore, ignore) + std::tie(ignore, ignore, hostname, ignore, ignore) = parse_url_components(url, ec); char const* top_domain = strrchr(hostname.c_str(), '.'); return top_domain && strcmp(top_domain, ".i2p") == 0; diff --git a/src/torrent.cpp b/src/torrent.cpp index ff765a324..64365f8ea 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -849,7 +849,7 @@ namespace libtorrent torrent::~torrent() { TORRENT_ASSERT(m_abort); - TORRENT_ASSERT(prev == NULL && next == NULL); + TORRENT_ASSERT(prev == nullptr && next == nullptr); #if TORRENT_USE_ASSERTS for (int i = 0; i < aux::session_interface::num_torrent_lists; ++i) @@ -1086,7 +1086,7 @@ namespace libtorrent if (j->error.ec == boost::asio::error::operation_aborted) { if (has_picker()) - picker().mark_as_canceled(block_finished, NULL); + picker().mark_as_canceled(block_finished, nullptr); } else { @@ -1701,7 +1701,7 @@ namespace libtorrent lowest_rank = i; } - if (lowest_rank == end()) return NULL; + if (lowest_rank == end()) return nullptr; return *lowest_rank; } @@ -1958,7 +1958,7 @@ namespace libtorrent inc_refcount("check_fastresume"); // async_check_files will gut links m_ses.disk_thread().async_check_files( - m_storage.get(), m_add_torrent_params ? m_add_torrent_params.get() : NULL + m_storage.get(), m_add_torrent_params ? m_add_torrent_params.get() : nullptr , links, std::bind(&torrent::on_resume_data_checked , shared_from_this(), _1)); #ifndef TORRENT_DISABLE_LOGGING @@ -2050,7 +2050,7 @@ namespace libtorrent // TOOD: should we store add_torrent_params::userdata // in torrent just to have it available here? - m_ses.add_extensions_to_torrent(shared_from_this(), NULL); + m_ses.add_extensions_to_torrent(shared_from_this(), nullptr); // and call on_load() on them for (extension_list_t::iterator i = m_extensions.begin() @@ -2142,7 +2142,7 @@ namespace libtorrent if (p->type() != peer_connection::bittorrent_connection) continue; if (p->remote() == ep) return static_cast(p); } - return NULL; + return nullptr; } peer_connection* torrent::find_peer(sha1_hash const& pid) @@ -2409,7 +2409,7 @@ namespace libtorrent std::vector links; inc_refcount("force_recheck"); - m_ses.disk_thread().async_check_files(m_storage.get(), NULL + m_ses.disk_thread().async_check_files(m_storage.get(), nullptr , links, std::bind(&torrent::on_force_recheck , shared_from_this(), _1)); } @@ -3335,7 +3335,7 @@ namespace libtorrent i != resp.peers4.end(); ++i) { tcp::endpoint a(address_v4(i->ip), i->port); - need_update |= bool(add_peer(a, peer_info::tracker) != NULL); + need_update |= bool(add_peer(a, peer_info::tracker) != nullptr); } #if TORRENT_USE_IPV6 @@ -3343,7 +3343,7 @@ namespace libtorrent i != resp.peers6.end(); ++i) { tcp::endpoint a(address_v6(i->ip), i->port); - need_update |= bool(add_peer(a, peer_info::tracker) != NULL); + need_update |= bool(add_peer(a, peer_info::tracker) != nullptr); } #endif if (need_update) state_updated(); @@ -3457,7 +3457,7 @@ namespace libtorrent torrent_peer* p = m_peer_list->connect_one_peer(m_ses.session_time(), &st); peers_erased(st.erased); inc_stats_counter(counters::connection_attempt_loops, st.loop_counter); - if (p == NULL) + if (p == nullptr) { update_want_peers(); continue; @@ -4161,7 +4161,7 @@ namespace libtorrent // these torrent_peer pointers are owned by m_peer_list and they may be // invalidated if a peer disconnects. We cannot keep them across any // significant operations, but we should use them right away - // ignore NULL pointers + // ignore nullptrs std::remove_copy(downloaders.begin(), downloaders.end() , std::inserter(peers, peers.begin()), static_cast(0)); @@ -5175,7 +5175,7 @@ namespace libtorrent m_file_priority[i] = 0; } - // storage may be NULL during construction and shutdown + // storage may be nullptr during construction and shutdown if (m_torrent_file->num_pieces() > 0 && m_storage) { inc_refcount("file_priority"); @@ -5214,7 +5214,7 @@ namespace libtorrent if (!valid_metadata()) return; - // stoage may be NULL during shutdown + // stoage may be nullptr during shutdown if (m_storage) { inc_refcount("file_priority"); @@ -5506,14 +5506,14 @@ namespace libtorrent // if we find one, swap with the udp-tracker error_code ec; std::string udp_hostname; - using boost::tuples::ignore; - boost::tie(ignore, ignore, udp_hostname, ignore, ignore) + using std::ignore; + std::tie(ignore, ignore, udp_hostname, ignore, ignore) = parse_url_components(i->url, ec); for (std::vector::iterator j = m_trackers.begin(); j != i; ++j) { std::string hostname; - boost::tie(ignore, ignore, hostname, ignore, ignore) + std::tie(ignore, ignore, hostname, ignore, ignore) = parse_url_components(j->url, ec); if (hostname != udp_hostname) continue; if (j->url.substr(0, 6) == "udp://") continue; @@ -5721,7 +5721,7 @@ namespace libtorrent torrent_peer* pp = p->peer_info_struct(); if (ready_for_connections()) { - TORRENT_ASSERT(p->associated_torrent().lock().get() == NULL + TORRENT_ASSERT(p->associated_torrent().lock().get() == nullptr || p->associated_torrent().lock().get() == this); if (p->is_seed()) @@ -5841,7 +5841,7 @@ namespace libtorrent int port; std::string path; error_code ec; - boost::tie(protocol, auth, hostname, port, path) + std::tie(protocol, auth, hostname, port, path) = parse_url_components(web->url, ec); if (port == -1) { @@ -6019,11 +6019,11 @@ namespace libtorrent tcp::endpoint a(addrs[0], port); - using boost::tuples::ignore; + using std::ignore; std::string hostname; error_code ec; std::string protocol; - boost::tie(protocol, ignore, hostname, port, ignore) + std::tie(protocol, ignore, hostname, port, ignore) = parse_url_components(web->url, ec); if (port == -1) port = protocol == "http" ? 80 : 443; @@ -6161,10 +6161,10 @@ namespace libtorrent s->get()->set_no_connect(true); } - using boost::tuples::ignore; + using std::ignore; std::string hostname; error_code ec; - boost::tie(ignore, ignore, hostname, ignore, ignore) + std::tie(ignore, ignore, hostname, ignore, ignore) = parse_url_components(web->url, ec); if (ec) { @@ -6837,7 +6837,7 @@ namespace libtorrent // proxy it is configurable. When we use i2p, we want to always prox // everything via i2p. bool ret = instantiate_connection(m_ses.get_io_service() - , m_ses.i2p_proxy(), *s, NULL, NULL, false, false); + , m_ses.i2p_proxy(), *s, nullptr, nullptr, false, false); (void)ret; TORRENT_ASSERT(ret); s->get()->set_destination(static_cast(peerinfo)->destination); @@ -6978,7 +6978,7 @@ namespace libtorrent if (m_share_mode) recalc_share_mode(); - return peerinfo->connection != NULL; + return peerinfo->connection != nullptr; } bool torrent::set_metadata(char const* metadata_buf, int metadata_size) @@ -7184,7 +7184,7 @@ namespace libtorrent for (int i = 0; i < p->num_classes(); ++i) { int pc = p->class_at(i); - if (m_ses.peer_classes().at(pc) == NULL) continue; + if (m_ses.peer_classes().at(pc) == nullptr) continue; int f = m_ses.peer_classes().at(pc)->connection_limit_factor; if (connection_limit_factor < f) connection_limit_factor = f; } @@ -7288,7 +7288,7 @@ namespace libtorrent TORRENT_ASSERT(p->remote() == p->get_socket()->remote_endpoint(ec) || ec); #endif - TORRENT_ASSERT(p->peer_info_struct() != NULL); + TORRENT_ASSERT(p->peer_info_struct() != nullptr); // we need to do this after we've added the peer to the peer_list // since that's when the peer is assigned its peer_info object, @@ -7966,7 +7966,7 @@ namespace libtorrent TORRENT_ASSERT(index >= 0); TORRENT_ASSERT(index < m_torrent_file->num_files()); - // storage may be NULL during shutdown + // storage may be nullptr during shutdown if (!m_storage.get()) { if (alerts().should_post()) @@ -8005,7 +8005,7 @@ namespace libtorrent return; } - // storage may be NULL during shutdown + // storage may be nullptr during shutdown if (m_storage.get()) { #if TORRENT_USE_UNC_PATHS @@ -8477,7 +8477,7 @@ namespace libtorrent disconnect_all(errors::torrent_removed, op_bittorrent); stop_announcing(); - // storage may be NULL during shutdown + // storage may be nullptr during shutdown if (m_storage.get()) { TORRENT_ASSERT(m_storage); @@ -8763,7 +8763,7 @@ namespace libtorrent return; } /* - // storage may be NULL during shutdown + // storage may be nullptr during shutdown if (!m_storage) { TORRENT_ASSERT(m_abort); @@ -8796,7 +8796,7 @@ namespace libtorrent { TORRENT_ASSERT(is_single_thread()); - // storage may be NULL during shutdown + // storage may be nullptr during shutdown if (!m_storage) { TORRENT_ASSERT(m_abort); @@ -10362,7 +10362,7 @@ namespace libtorrent peers_erased(st.erased); inc_stats_counter(counters::connection_attempt_loops, st.loop_counter); - if (p == NULL) + if (p == nullptr) { update_want_peers(); return false; @@ -10391,7 +10391,7 @@ namespace libtorrent debug_log("add_peer() %s unsupported address family" , adr.address().to_string(ec).c_str()); #endif - return NULL; + return nullptr; } #endif @@ -10418,7 +10418,7 @@ namespace libtorrent #ifndef TORRENT_DISABLE_EXTENSIONS notify_extension_add_peer(adr, source, torrent_plugin::filtered); #endif - return NULL; + return nullptr; } if (m_ses.get_port_filter().access(adr.port()) & port_filter::blocked) @@ -10429,7 +10429,7 @@ namespace libtorrent #ifndef TORRENT_DISABLE_EXTENSIONS notify_extension_add_peer(adr, source, torrent_plugin::filtered); #endif - return NULL; + return nullptr; } #if TORRENT_USE_I2P @@ -10440,7 +10440,7 @@ namespace libtorrent if (alerts().should_post()) alerts().emplace_alert(get_handle() , adr, peer_blocked_alert::i2p_mixed); - return NULL; + return nullptr; } #endif @@ -10452,7 +10452,7 @@ namespace libtorrent #ifndef TORRENT_DISABLE_EXTENSIONS notify_extension_add_peer(adr, source, torrent_plugin::filtered); #endif - return NULL; + return nullptr; } need_peer_list(); @@ -11168,7 +11168,7 @@ namespace libtorrent st->num_seeds = num_seeds(); if ((flags & torrent_handle::query_distributed_copies) && m_picker.get()) { - boost::tie(st->distributed_full_copies, st->distributed_fraction) = + std::tie(st->distributed_full_copies, st->distributed_fraction) = m_picker->distributed_copies(); #if TORRENT_NO_FPU st->distributed_copies = -1.f; diff --git a/src/torrent_info.cpp b/src/torrent_info.cpp index 6e9d90f65..028cb3839 100644 --- a/src/torrent_info.cpp +++ b/src/torrent_info.cpp @@ -406,7 +406,7 @@ namespace libtorrent std::string path = root_dir; std::string path_element; - char const* filename = NULL; + char const* filename = nullptr; int filename_len = 0; if (top_level) @@ -481,7 +481,7 @@ namespace libtorrent } bdecode_node fh = dict.dict_find_string("sha1"); - char const* filehash = NULL; + char const* filehash = nullptr; if (fh && fh.string_length() == 20) filehash = fh.string_ptr() + info_ptr_diff; @@ -506,7 +506,7 @@ namespace libtorrent , filename_len) != 0) { // if the filename was sanitized and differ, clear it to just use path - filename = NULL; + filename = nullptr; filename_len = 0; } diff --git a/src/torrent_peer_allocator.cpp b/src/torrent_peer_allocator.cpp index 98a567ead..f282bb517 100644 --- a/src/torrent_peer_allocator.cpp +++ b/src/torrent_peer_allocator.cpp @@ -55,12 +55,12 @@ namespace libtorrent torrent_peer* torrent_peer_allocator::allocate_peer_entry(int type) { - torrent_peer* p = NULL; + torrent_peer* p = nullptr; switch(type) { case torrent_peer_allocator_interface::ipv4_peer_type: p = static_cast(m_ipv4_peer_pool.malloc()); - if (p == NULL) return NULL; + if (p == nullptr) return nullptr; m_ipv4_peer_pool.set_next_size(500); m_total_bytes += sizeof(libtorrent::ipv4_peer); m_live_bytes += sizeof(libtorrent::ipv4_peer); @@ -70,7 +70,7 @@ namespace libtorrent #if TORRENT_USE_IPV6 case torrent_peer_allocator_interface::ipv6_peer_type: p = static_cast(m_ipv6_peer_pool.malloc()); - if (p == NULL) return NULL; + if (p == nullptr) return nullptr; m_ipv6_peer_pool.set_next_size(500); m_total_bytes += sizeof(libtorrent::ipv6_peer); m_live_bytes += sizeof(libtorrent::ipv6_peer); @@ -81,7 +81,7 @@ namespace libtorrent #if TORRENT_USE_I2P case torrent_peer_allocator_interface::i2p_peer_type: p = static_cast(m_i2p_peer_pool.malloc()); - if (p == NULL) return NULL; + if (p == nullptr) return nullptr; m_i2p_peer_pool.set_next_size(500); m_total_bytes += sizeof(libtorrent::i2p_peer); m_live_bytes += sizeof(libtorrent::i2p_peer); diff --git a/src/udp_tracker_connection.cpp b/src/udp_tracker_connection.cpp index e48513637..fd8b86f51 100644 --- a/src/udp_tracker_connection.cpp +++ b/src/udp_tracker_connection.cpp @@ -37,7 +37,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/aux_/disable_warnings_push.hpp" -#include +#include #include "libtorrent/aux_/disable_warnings_pop.hpp" @@ -91,8 +91,8 @@ namespace libtorrent int port; error_code ec; - using boost::tuples::ignore; - boost::tie(protocol, ignore, hostname, port, ignore) + using std::ignore; + std::tie(protocol, ignore, hostname, port, ignore) = parse_url_components(tracker_req().url, ec); if (port == -1) port = protocol == "http" ? 80 : 443; @@ -743,8 +743,8 @@ namespace libtorrent std::string request_string; error_code ec; - using boost::tuples::ignore; - boost::tie(ignore, ignore, ignore, ignore, request_string) + using std::ignore; + std::tie(ignore, ignore, ignore, ignore, request_string) = parse_url_components(req.url, ec); if (ec) request_string.clear(); diff --git a/src/upnp.cpp b/src/upnp.cpp index 3b2aafd3b..4af96233a 100644 --- a/src/upnp.cpp +++ b/src/upnp.cpp @@ -471,7 +471,7 @@ void upnp::on_reply(udp::endpoint const& from, char* buffer std::string protocol; std::string auth; // we don't have this device in our list. Add it - boost::tie(protocol, auth, d.hostname, d.port, d.path) + std::tie(protocol, auth, d.hostname, d.port, d.path) = parse_url_components(d.url, ec); if (d.port == -1) d.port = protocol == "http" ? 80 : 443; @@ -533,7 +533,7 @@ void upnp::on_reply(udp::endpoint const& from, char* buffer m.protocol = j->protocol; d.mapping.push_back(m); } - boost::tie(i, boost::tuples::ignore) = m_devices.insert(d); + std::tie(i, std::ignore) = m_devices.insert(d); } @@ -953,7 +953,7 @@ void upnp::on_upnp_xml(error_code const& e error_code ec; if (!d.control_url.empty() && d.control_url[0] == '/') { - boost::tie(protocol, auth, d.hostname, d.port, d.path) + std::tie(protocol, auth, d.hostname, d.port, d.path) = parse_url_components(d.url, ec); if (d.port == -1) d.port = protocol == "http" ? 80 : 443; d.control_url = protocol + "://" + d.hostname + ":" @@ -969,7 +969,7 @@ void upnp::on_upnp_xml(error_code const& e log(msg); } - boost::tie(protocol, auth, d.hostname, d.port, d.path) + std::tie(protocol, auth, d.hostname, d.port, d.path) = parse_url_components(d.control_url, ec); if (d.port == -1) d.port = protocol == "http" ? 80 : 443; diff --git a/src/ut_metadata.cpp b/src/ut_metadata.cpp index bd890827a..4e34af0ec 100644 --- a/src/ut_metadata.cpp +++ b/src/ut_metadata.cpp @@ -139,7 +139,7 @@ namespace libtorrent { namespace buffer::const_interval metadata() const { - if (!m_torrent.need_loaded()) return buffer::const_interval(NULL, NULL); + if (!m_torrent.need_loaded()) return buffer::const_interval(nullptr, nullptr); TORRENT_ASSERT(m_torrent.valid_metadata()); if (!m_metadata) { diff --git a/src/ut_pex.cpp b/src/ut_pex.cpp index 5fa2d97c3..e52731d5d 100644 --- a/src/ut_pex.cpp +++ b/src/ut_pex.cpp @@ -168,7 +168,7 @@ namespace libtorrent { namespace if (!p->is_outgoing()) { torrent_peer const* const pi = peer->peer_info_struct(); - if (pi != NULL && pi->port > 0) + if (pi != nullptr && pi->port > 0) remote.port(pi->port); } @@ -583,7 +583,7 @@ namespace libtorrent { namespace if (!p->is_outgoing()) { torrent_peer const* const pi = peer->peer_info_struct(); - if (pi != NULL && pi->port > 0) + if (pi != nullptr && pi->port > 0) remote.port(pi->port); } diff --git a/src/utp_socket_manager.cpp b/src/utp_socket_manager.cpp index bd6b58a5c..a503829a3 100644 --- a/src/utp_socket_manager.cpp +++ b/src/utp_socket_manager.cpp @@ -225,7 +225,7 @@ namespace libtorrent instantiate_connection(m_ios, aux::proxy_settings(), *c , m_ssl_context, this, true, false); - utp_stream* str = NULL; + utp_stream* str = nullptr; #ifdef TORRENT_USE_OPENSSL if (is_ssl(*c)) str = &c->get >()->next_layer(); diff --git a/src/utp_stream.cpp b/src/utp_stream.cpp index 71b4d2747..412e8d7eb 100644 --- a/src/utp_stream.cpp +++ b/src/utp_stream.cpp @@ -66,7 +66,7 @@ static struct utp_logger FILE* utp_log_file; std::mutex utp_log_mutex; - utp_logger() : utp_log_file(NULL) {} + utp_logger() : utp_log_file(nullptr) {} ~utp_logger() { if (utp_log_file) fclose(utp_log_file); @@ -76,7 +76,7 @@ static struct utp_logger TORRENT_FORMAT(1, 2) void utp_log(char const* fmt, ...) { - if (log_file_holder.utp_log_file == NULL) return; + if (log_file_holder.utp_log_file == nullptr) return; std::lock_guard lock(log_file_holder.utp_log_mutex); static time_point start = clock_type::now(); @@ -88,23 +88,23 @@ void utp_log(char const* fmt, ...) } bool is_utp_stream_logging() { - return log_file_holder.utp_log_file != NULL; + return log_file_holder.utp_log_file != nullptr; } void set_utp_stream_logging(bool enable) { if (enable) { - if (log_file_holder.utp_log_file == NULL) + if (log_file_holder.utp_log_file == nullptr) { log_file_holder.utp_log_file = fopen("utp.log", "w+"); } } else { - if (log_file_holder.utp_log_file != NULL) + if (log_file_holder.utp_log_file != nullptr) { FILE* f = log_file_holder.utp_log_file; - log_file_holder.utp_log_file = NULL; + log_file_holder.utp_log_file = nullptr; fclose(f); } } @@ -264,7 +264,7 @@ struct utp_socket_impl , void* userdata, utp_socket_manager* sm) : m_sm(sm) , m_userdata(userdata) - , m_nagle_packet(NULL) + , m_nagle_packet(nullptr) , m_read_handler(false) , m_write_handler(false) , m_connect_handler(false) @@ -428,7 +428,7 @@ public: // buffers. Buffers that empty are erased from the vector. std::vector m_write_buffer; - // if this is non NULL, it's a packet. This packet was held off because + // if this is non nullptr, it's a packet. This packet was held off because // of NAGLE. We couldn't send it immediately. It's left // here to accrue more bytes before we send it. packet* m_nagle_packet; @@ -686,7 +686,7 @@ public: bool m_cwnd_full:1; // this is set to one if the current read operation - // has a null-buffer. i.e. we're not reading into a user-provided + // has a null_buffer. i.e. we're not reading into a user-provided // buffer, we're just signalling when there's something // to read from our internal receive buffer bool m_null_buffers:1; @@ -922,7 +922,7 @@ void utp_stream::on_close_reason(void* self, std::uint16_t close_reason) utp_stream* s = static_cast(self); // it's possible the socket has been unlinked already, in which case m_impl - // will be NULL + // will be nullptr if (s->m_impl) s->m_incoming_close_reason = close_reason; } @@ -1233,7 +1233,7 @@ utp_socket_impl::~utp_socket_impl() } free(m_nagle_packet); - m_nagle_packet = NULL; + m_nagle_packet = nullptr; } bool utp_socket_impl::should_delete() const @@ -1723,7 +1723,7 @@ void utp_socket_impl::remove_sack_header(packet* p) struct holder { - holder(char* buf = NULL): m_buf(buf) {} + holder(char* buf = nullptr): m_buf(buf) {} ~holder() { free(m_buf); } void reset(char* buf) @@ -1735,7 +1735,7 @@ struct holder char* release() { char* ret = m_buf; - m_buf = NULL; + m_buf = nullptr; return ret; } @@ -1876,9 +1876,9 @@ bool utp_socket_impl::send_pkt(int const flags) int packet_size = header_size + payload_size; - packet* p = NULL; - std::uint8_t* ptr = NULL; - utp_header* h = NULL; + packet* p = nullptr; + std::uint8_t* ptr = nullptr; + utp_header* h = nullptr; #if TORRENT_USE_ASSERTS bool stack_alloced = false; @@ -1988,7 +1988,7 @@ bool utp_socket_impl::send_pkt(int const flags) // clear the nagle packet pointer and fall through // sending p - m_nagle_packet = NULL; + m_nagle_packet = nullptr; packet_size = p->size; payload_size = p->size - p->header_size; @@ -2024,7 +2024,7 @@ bool utp_socket_impl::send_pkt(int const flags) "adv_wnd:%d in-flight:%d mtu:%d effective_mtu:%d\n" , static_cast(this), m_write_buffer_size, int(m_cwnd >> 16) , m_adv_wnd, m_bytes_in_flight, m_mtu, effective_mtu); - TORRENT_ASSERT(m_nagle_packet == NULL); + TORRENT_ASSERT(m_nagle_packet == nullptr); TORRENT_ASSERT(h->seq_nr == m_seq_nr); m_nagle_packet = p; buf_holder.release(); @@ -2134,7 +2134,7 @@ bool utp_socket_impl::send_pkt(int const flags) { // if we're sending a payload packet, there should not // be a nagle packet waiting for more data - TORRENT_ASSERT(m_nagle_packet == NULL); + TORRENT_ASSERT(m_nagle_packet == nullptr); #if !TORRENT_UT_SEQ // if the other end closed the connection immediately @@ -2511,7 +2511,7 @@ bool utp_socket_impl::cancel_handlers(error_code const& ec, bool kill) bool ret = m_read_handler || m_write_handler || m_connect_handler; // calling the callbacks with m_userdata being 0 will just crash - TORRENT_ASSERT((ret && m_userdata != NULL) || !ret); + TORRENT_ASSERT((ret && m_userdata != nullptr) || !ret); bool read = m_read_handler; bool write = m_write_handler; diff --git a/src/web_connection_base.cpp b/src/web_connection_base.cpp index a92ce373e..40682a013 100644 --- a/src/web_connection_base.cpp +++ b/src/web_connection_base.cpp @@ -82,7 +82,7 @@ namespace libtorrent std::string protocol; error_code ec; - boost::tie(protocol, m_basic_auth, m_host, m_port, m_path) + std::tie(protocol, m_basic_auth, m_host, m_port, m_path) = parse_url_components(web.url, ec); TORRENT_ASSERT(!ec); diff --git a/src/web_peer_connection.cpp b/src/web_peer_connection.cpp index f3c2e46dc..2c37b931b 100644 --- a/src/web_peer_connection.cpp +++ b/src/web_peer_connection.cpp @@ -455,14 +455,14 @@ namespace { return ret; } - boost::tuple get_range( + std::tuple get_range( http_parser const& parser, error_code& ec) { std::int64_t range_start; std::int64_t range_end; if (parser.status_code() == 206) { - boost::tie(range_start, range_end) = parser.content_range(); + std::tie(range_start, range_end) = parser.content_range(); if (range_start < 0 || range_end < range_start) { ec = errors::invalid_range; @@ -485,7 +485,7 @@ namespace { ec = errors::no_content_length; } } - return boost::tuple(range_start, range_end); + return std::tuple(range_start, range_end); } } @@ -581,7 +581,7 @@ void web_peer_connection::handle_redirect(int bytes_left) { // we should not try this server again. t->remove_web_seed_conn(this, errors::missing_location, op_bittorrent, 2); - m_web = NULL; + m_web = nullptr; TORRENT_ASSERT(is_disconnecting()); return; } @@ -614,7 +614,7 @@ void web_peer_connection::handle_redirect(int bytes_left) if (i == std::string::npos) { t->remove_web_seed_conn(this, errors::invalid_redirection, op_bittorrent, 2); - m_web = NULL; + m_web = nullptr; TORRENT_ASSERT(is_disconnecting()); return; } @@ -630,7 +630,7 @@ void web_peer_connection::handle_redirect(int bytes_left) #endif t->add_web_seed(location, web_seed_entry::url_seed, m_external_auth, m_extra_headers); t->remove_web_seed_conn(this, errors::redirecting, op_bittorrent, 2); - m_web = NULL; + m_web = nullptr; TORRENT_ASSERT(is_disconnecting()); return; } @@ -667,7 +667,7 @@ void web_peer_connection::on_receive(error_code const& error if (!header_finished) { bool failed = false; - boost::tie(payload, protocol) = m_parser.incoming(recv_buffer, failed); + std::tie(payload, protocol) = m_parser.incoming(recv_buffer, failed); received_bytes(0, protocol); TORRENT_ASSERT(int(recv_buffer.left()) >= protocol); @@ -757,13 +757,13 @@ void web_peer_connection::on_receive(error_code const& error std::int64_t range_start; std::int64_t range_end; error_code ec; - boost::tie(range_start, range_end) = get_range(m_parser, ec); + std::tie(range_start, range_end) = get_range(m_parser, ec); if (ec) { received_bytes(0, recv_buffer.left()); // we should not try this server again. t->remove_web_seed_conn(this, ec, op_bittorrent, 2); - m_web = NULL; + m_web = nullptr; TORRENT_ASSERT(is_disconnecting()); return; } diff --git a/src/xml_parse.cpp b/src/xml_parse.cpp index 801e0bb54..3e372c072 100644 --- a/src/xml_parse.cpp +++ b/src/xml_parse.cpp @@ -51,7 +51,7 @@ namespace libtorrent { token = xml_string; const int name_len = p - start; - callback(token, start, name_len, NULL, 0); + callback(token, start, name_len, nullptr, 0); } if (p == end) break; @@ -70,13 +70,13 @@ namespace libtorrent { token = xml_parse_error; start = "unexpected end of file"; - callback(token, start, int(strlen(start)), NULL, 0); + callback(token, start, int(strlen(start)), nullptr, 0); break; } token = xml_string; const int name_len = p - start - 2; - callback(token, start, name_len, NULL, 0); + callback(token, start, name_len, nullptr, 0); continue; } @@ -93,7 +93,7 @@ namespace libtorrent { token = xml_parse_error; start = "unexpected end of file"; - callback(token, start, int(strlen(start)), NULL, 0); + callback(token, start, int(strlen(start)), nullptr, 0); break; } @@ -105,13 +105,13 @@ namespace libtorrent ++start; token = xml_end_tag; const int name_len = tag_name_end - start; - callback(token, start, name_len, NULL, 0); + callback(token, start, name_len, nullptr, 0); } else if (*(p-1) == '/') { token = xml_empty_tag; const int name_len = (std::min)(tag_name_end - start, p - start - 1); - callback(token, start, name_len, NULL, 0); + callback(token, start, name_len, nullptr, 0); tag_end = p - 1; } else if (*start == '?' && *(p-1) == '?') @@ -119,7 +119,7 @@ namespace libtorrent ++start; token = xml_declaration_tag; const int name_len = (std::min)(tag_name_end - start, p - start - 1); - callback(token, start, name_len, NULL, 0); + callback(token, start, name_len, nullptr, 0); tag_end = p - 1; } else if (start + 5 < p && std::memcmp(start, "!--", 3) == 0 && std::memcmp(p-2, "--", 2) == 0) @@ -127,7 +127,7 @@ namespace libtorrent start += 3; token = xml_comment; const int name_len = tag_name_end - start - 2; - callback(token, start, name_len, NULL, 0); + callback(token, start, name_len, nullptr, 0); tag_end = p - 2; continue; } @@ -135,13 +135,13 @@ namespace libtorrent { token = xml_start_tag; const int name_len = tag_name_end - start; - callback(token, start, name_len, NULL, 0); + callback(token, start, name_len, nullptr, 0); } // parse attributes for (char const* i = tag_name_end; i < tag_end; ++i) { - char const* val_start = NULL; + char const* val_start = nullptr; // find start of attribute name for (; i != tag_end && is_space(*i); ++i); @@ -159,7 +159,7 @@ namespace libtorrent if (i == tag_end) { token = xml_tag_content; - callback(token, start, i - start, NULL, 0); + callback(token, start, i - start, nullptr, 0); break; } @@ -170,7 +170,7 @@ namespace libtorrent { token = xml_parse_error; start = "unquoted attribute value"; - callback(token, start, int(strlen(start)), NULL, 0); + callback(token, start, int(strlen(start)), nullptr, 0); break; } char quote = *i; @@ -182,7 +182,7 @@ namespace libtorrent { token = xml_parse_error; start = "missing end quote on attribute"; - callback(token, start, int(strlen(start)), NULL, 0); + callback(token, start, int(strlen(start)), nullptr, 0); break; } const int val_len = i - val_start; diff --git a/test/setup_transfer.cpp b/test/setup_transfer.cpp index 4a1ad3ed2..904366487 100644 --- a/test/setup_transfer.cpp +++ b/test/setup_transfer.cpp @@ -50,7 +50,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/broadcast_socket.hpp" // for supports_ipv6() #include "libtorrent/hex.hpp" // to_hex -#include +#include #include #include @@ -715,7 +715,7 @@ boost::shared_ptr create_torrent(std::ostream* file &tmp[0], tmp.size(), boost::ref(ec), 0); } -boost::tuple +std::tuple setup_transfer(lt::session* ses1, lt::session* ses2, lt::session* ses3 , bool clear_files, bool use_metadata_transfer, bool connect_peers , std::string suffix, int piece_size @@ -811,7 +811,7 @@ setup_transfer(lt::session* ses1, lt::session* ses2, lt::session* ses3 if (ec) { std::fprintf(stderr, "ses1.add_torrent: %s\n", ec.message().c_str()); - return boost::make_tuple(torrent_handle(), torrent_handle(), torrent_handle()); + return std::make_tuple(torrent_handle(), torrent_handle(), torrent_handle()); } tor1.super_seeding(super_seeding); @@ -905,7 +905,7 @@ setup_transfer(lt::session* ses1, lt::session* ses2, lt::session* ses3 } } - return boost::make_tuple(tor1, tor2, tor3); + return std::make_tuple(tor1, tor2, tor3); } pid_type web_server_pid = 0; diff --git a/test/setup_transfer.hpp b/test/setup_transfer.hpp index 556948bda..724a687c7 100644 --- a/test/setup_transfer.hpp +++ b/test/setup_transfer.hpp @@ -34,7 +34,7 @@ POSSIBILITY OF SUCH DAMAGE. #define SETUP_TRANSFER_HPP #include "libtorrent/session.hpp" -#include +#include #include "test.hpp" namespace libtorrent @@ -88,7 +88,7 @@ EXPORT boost::shared_ptr create_torrent(std::ostream* , char const* name = "temporary", int piece_size = 16 * 1024, int num_pieces = 13 , bool add_tracker = true, std::string ssl_certificate = ""); -EXPORT boost::tuple setup_transfer(libtorrent::session* ses1, libtorrent::session* ses2 diff --git a/test/swarm_suite.cpp b/test/swarm_suite.cpp index 87096b6fa..002720a94 100644 --- a/test/swarm_suite.cpp +++ b/test/swarm_suite.cpp @@ -37,7 +37,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/time.hpp" #include "libtorrent/random.hpp" #include -#include +#include #include "test.hpp" #include "setup_transfer.hpp" @@ -130,7 +130,7 @@ void test_swarm(int flags) p.flags &= ~add_torrent_params::flag_auto_managed; if (flags & seed_mode) p.flags |= add_torrent_params::flag_seed_mode; // test using piece sizes smaller than 16kB - boost::tie(tor1, tor2, tor3) = setup_transfer(&ses1, &ses2, &ses3, true + std::tie(tor1, tor2, tor3) = setup_transfer(&ses1, &ses2, &ses3, true , false, true, "_swarm", 8 * 1024, 0, flags & super_seeding, &p); if (flags & time_critical) diff --git a/test/test_auto_unchoke.cpp b/test/test_auto_unchoke.cpp index 2851dae6c..d88dcc5ea 100644 --- a/test/test_auto_unchoke.cpp +++ b/test/test_auto_unchoke.cpp @@ -35,7 +35,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/hasher.hpp" #include "libtorrent/alert_types.hpp" #include "libtorrent/ip_filter.hpp" -#include +#include #include #include "test.hpp" @@ -95,7 +95,7 @@ void test_swarm() torrent_handle tor2; torrent_handle tor3; - boost::tie(tor1, tor2, tor3) = setup_transfer(&ses1, &ses2, &ses3, true, false, true, "_unchoke"); + std::tie(tor1, tor2, tor3) = setup_transfer(&ses1, &ses2, &ses3, true, false, true, "_unchoke"); std::map cnt = get_counters(ses1); diff --git a/test/test_dht.cpp b/test/test_dht.cpp index 76bbf58fd..342af7973 100644 --- a/test/test_dht.cpp +++ b/test/test_dht.cpp @@ -753,7 +753,7 @@ void do_test_dht(address(&rand_addr)()) // verify that we reject invalid node IDs // this is now an invalid node-id for 'source' nid[0] = 0x18; - int nodes_num = node.size().get<0>(); + int nodes_num = std::get<0>(node.size()); send_dht_request(node, "find_node", source, &response , msg_args().target("0101010101010101010101010101010101010101").nid(nid)); @@ -781,7 +781,7 @@ void do_test_dht(address(&rand_addr)()) } // a node with invalid node-id shouldn't be added to routing table. - TEST_EQUAL(node.size().get<0>(), nodes_num); + TEST_EQUAL(std::get<0>(node.size()), nodes_num); // now the node-id is valid. if (source.protocol() == udp::v4()) @@ -813,7 +813,7 @@ void do_test_dht(address(&rand_addr)()) std::fprintf(stderr, " invalid error response: %s\n", error_string); } // node with valid node-id should be added to routing table. - TEST_EQUAL(node.size().get<0>(), nodes_num + 1); + TEST_EQUAL(std::get<0>(node.size()), nodes_num + 1); sett.enforce_node_id = false; @@ -1183,7 +1183,7 @@ void do_test_dht(address(&rand_addr)()) const int bucket_size = 10; dht::routing_table table(id, source.protocol(), bucket_size, s, &observer); std::vector nodes; - TEST_EQUAL(table.size().get<0>(), 0); + TEST_EQUAL(std::get<0>(table.size()), 0); node_id tmp = id; node_id diff = to_hash("15764f7459456a9453f8719b09547c11d5f34061"); @@ -1206,7 +1206,7 @@ void do_test_dht(address(&rand_addr)()) table.node_seen(tmp, udp::endpoint(node_addr, 4), 10); table.find_node(id, nodes, 0, 10); TEST_EQUAL(table.bucket_size(0), 1); - TEST_EQUAL(table.size().get<0>(), 1); + TEST_EQUAL(std::get<0>(table.size()), 1); TEST_EQUAL(nodes.size(), 1); if (!nodes.empty()) { @@ -1295,7 +1295,7 @@ void do_test_dht(address(&rand_addr)()) } std::printf("active buckets: %d\n", table.num_active_buckets()); TEST_EQUAL(table.num_active_buckets(), 10); - TEST_CHECK(table.size().get<0>() >= 10 * 10); + TEST_CHECK(std::get<0>(table.size()) >= 10 * 10); //#error test num_global_nodes //#error test need_refresh @@ -2517,7 +2517,7 @@ TORRENT_TEST(read_only_node) TEST_EQUAL(response.type(), bdecode_node::none_t); // also, the sender shouldn't be added to routing table. - TEST_EQUAL(node.size().get<0>(), 0); + TEST_EQUAL(std::get<0>(node.size()), 0); // for outgoing requests, read_only node will add 'ro' key (value == 1) // in top-level of request. @@ -2550,7 +2550,7 @@ TORRENT_TEST(read_only_node) TEST_EQUAL(parsed[3].int_value(), 1); // should have one node now, which is 4.4.4.4:1234 - TEST_EQUAL(node.size().get<0>(), 1); + TEST_EQUAL(std::get<0>(node.size()), 1); // now, disable read_only, try again. g_sent_packets.clear(); @@ -2558,7 +2558,7 @@ TORRENT_TEST(read_only_node) send_dht_request(node, "get", source, &response); // sender should be added to routing table, there are 2 nodes now. - TEST_EQUAL(node.size().get<0>(), 2); + TEST_EQUAL(std::get<0>(node.size()), 2); g_sent_packets.clear(); target = generate_next(); @@ -2757,7 +2757,7 @@ TORRENT_TEST(dht_verify_node_address) const int bucket_size = 10; dht::routing_table table(id, udp::v4(), bucket_size, s, &observer); std::vector nodes; - TEST_EQUAL(table.size().get<0>(), 0); + TEST_EQUAL(std::get<0>(table.size()), 0); node_id tmp = id; node_id diff = to_hash("15764f7459456a9453f8719b09547c11d5f34061"); @@ -2765,7 +2765,7 @@ TORRENT_TEST(dht_verify_node_address) add_and_replace(tmp, diff); table.node_seen(tmp, udp::endpoint(address::from_string("4.4.4.4"), 4), 10); table.find_node(id, nodes, 0, 10); - TEST_EQUAL(table.size().get<0>(), 1); + TEST_EQUAL(std::get<0>(table.size()), 1); TEST_EQUAL(nodes.size(), 1); // incorrect data, wrong id @@ -2773,7 +2773,7 @@ TORRENT_TEST(dht_verify_node_address) , udp::endpoint(address::from_string("4.4.4.4"), 4), 10); table.find_node(id, nodes, 0, 10); - TEST_EQUAL(table.size().get<0>(), 1); + TEST_EQUAL(std::get<0>(table.size()), 1); TEST_EQUAL(nodes.size(), 1); // incorrect data, wrong IP @@ -2781,7 +2781,7 @@ TORRENT_TEST(dht_verify_node_address) , udp::endpoint(address::from_string("4.4.4.6"), 4), 10); table.find_node(id, nodes, 0, 10); - TEST_EQUAL(table.size().get<0>(), 1); + TEST_EQUAL(std::get<0>(table.size()), 1); TEST_EQUAL(nodes.size(), 1); } diff --git a/test/test_http_parser.cpp b/test/test_http_parser.cpp index d7b6860e0..45f38d8bd 100644 --- a/test/test_http_parser.cpp +++ b/test/test_http_parser.cpp @@ -34,21 +34,17 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/http_parser.hpp" #include "libtorrent/parse_url.hpp" -#include -#include +#include using namespace libtorrent; -using boost::tuple; -using boost::make_tuple; -using boost::tie; -tuple feed_bytes(http_parser& parser, char const* str) +std::tuple feed_bytes(http_parser& parser, char const* str) { - tuple ret(0, 0, false); - tuple prev(0, 0, false); + std::tuple ret(0, 0, false); + std::tuple prev(0, 0, false); for (int chunks = 1; chunks < 70; ++chunks) { - ret = make_tuple(0, 0, false); + ret = std::make_tuple(0, 0, false); parser.reset(); buffer::const_interval recv_buf(str, str); for (; *str;) @@ -58,17 +54,17 @@ tuple feed_bytes(http_parser& parser, char const* str) recv_buf.end += chunk_size; int payload, protocol; bool error = false; - tie(payload, protocol) = parser.incoming(recv_buf, error); - ret.get<0>() += payload; - ret.get<1>() += protocol; - ret.get<2>() |= error; + std::tie(payload, protocol) = parser.incoming(recv_buf, error); + std::get<0>(ret) += payload; + std::get<1>(ret) += protocol; + std::get<2>(ret) |= error; // std::cerr << payload << ", " << protocol << ", " << chunk_size << std::endl; - TORRENT_ASSERT(payload + protocol == chunk_size || ret.get<2>()); + TORRENT_ASSERT(payload + protocol == chunk_size || std::get<2>(ret)); } - TEST_CHECK(prev == make_tuple(0, 0, false) || ret == prev || ret.get<2>()); - if (!ret.get<2>()) + TEST_CHECK(prev == std::make_tuple(0, 0, false) || ret == prev || std::get<2>(ret)); + if (!std::get<2>(ret)) { - TEST_EQUAL(ret.get<0>() + ret.get<1>(), int(strlen(str))); + TEST_EQUAL(std::get<0>(ret) + std::get<1>(ret), int(strlen(str))); } prev = ret; @@ -80,7 +76,7 @@ TORRENT_TEST(http_parser) { // HTTP request parser http_parser parser; - boost::tuple received; + std::tuple received; received = feed_bytes(parser , "HTTP/1.1 200 OK\r\n" @@ -89,7 +85,7 @@ TORRENT_TEST(http_parser) "\r\n" "test"); - TEST_CHECK(received == make_tuple(4, 64, false)); + TEST_CHECK(received == std::make_tuple(4, 64, false)); TEST_CHECK(parser.finished()); TEST_CHECK(std::equal(parser.get_body().begin, parser.get_body().end, "test")); TEST_CHECK(parser.header("content-type") == "text/plain"); @@ -111,7 +107,7 @@ TORRENT_TEST(http_parser) received = feed_bytes(parser, upnp_response); - TEST_CHECK(received == make_tuple(0, int(strlen(upnp_response)), false)); + TEST_CHECK(received == std::make_tuple(0, int(strlen(upnp_response)), false)); TEST_CHECK(parser.get_body().left() == 0); TEST_CHECK(parser.header("st") == "upnp:rootdevice"); TEST_CHECK(parser.header("location") @@ -132,7 +128,7 @@ TORRENT_TEST(http_parser) received = feed_bytes(parser, http1_response); - TEST_CHECK(received == make_tuple(0, int(strlen(http1_response)), false)); + TEST_CHECK(received == std::make_tuple(0, int(strlen(http1_response)), false)); TEST_CHECK(parser.get_body().left() == 0); TEST_CHECK(parser.header("date") == "Fri, 02 Jan 1970 08:10:38 GMT"); TEST_EQUAL(parser.connection_close(), true); @@ -148,7 +144,7 @@ TORRENT_TEST(http_parser) received = feed_bytes(parser, close_response); - TEST_CHECK(received == make_tuple(0, int(strlen(close_response)), false)); + TEST_CHECK(received == std::make_tuple(0, int(strlen(close_response)), false)); TEST_CHECK(parser.get_body().left() == 0); TEST_CHECK(parser.header("date") == "Fri, 02 Jan 1970 08:10:38 GMT"); TEST_EQUAL(parser.connection_close(), true); @@ -164,7 +160,7 @@ TORRENT_TEST(http_parser) received = feed_bytes(parser, keep_alive_response); - TEST_CHECK(received == make_tuple(0, int(strlen(keep_alive_response)), false)); + TEST_CHECK(received == std::make_tuple(0, int(strlen(keep_alive_response)), false)); TEST_CHECK(parser.get_body().left() == 0); TEST_CHECK(parser.header("date") == "Fri, 02 Jan 1970 08:10:38 GMT"); TEST_EQUAL(parser.connection_close(), false); @@ -184,7 +180,7 @@ TORRENT_TEST(http_parser) received = feed_bytes(parser, upnp_notify); - TEST_CHECK(received == make_tuple(0, int(strlen(upnp_notify)), false)); + TEST_CHECK(received == std::make_tuple(0, int(strlen(upnp_notify)), false)); TEST_CHECK(parser.method() == "notify"); TEST_CHECK(parser.path() == "*"); @@ -199,7 +195,7 @@ TORRENT_TEST(http_parser) received = feed_bytes(parser, bt_lsd); - TEST_CHECK(received == make_tuple(0, int(strlen(bt_lsd)), false)); + TEST_CHECK(received == std::make_tuple(0, int(strlen(bt_lsd)), false)); TEST_CHECK(parser.method() == "bt-search"); TEST_CHECK(parser.path() == "*"); TEST_CHECK(atoi(parser.header("port").c_str()) == 6881); @@ -226,8 +222,8 @@ TORRENT_TEST(http_parser) received = feed_bytes(parser, chunked_test); - std::printf("payload: %d protocol: %d\n", received.get<0>(), received.get<1>()); - TEST_CHECK(received == make_tuple(20, int(strlen(chunked_test)) - 20, false)); + std::printf("payload: %d protocol: %d\n", std::get<0>(received), std::get<1>(received)); + TEST_CHECK(received == std::make_tuple(20, int(strlen(chunked_test)) - 20, false)); TEST_CHECK(parser.finished()); TEST_CHECK(std::equal(parser.get_body().begin, parser.get_body().end , "4\r\ntest\r\n10\r\n0123456789abcdef")); @@ -251,7 +247,7 @@ TORRENT_TEST(http_parser) received = feed_bytes(parser, tracker_response); - TEST_CHECK(received == make_tuple(5, int(strlen(tracker_response) - 5), false)); + TEST_CHECK(received == std::make_tuple(5, int(strlen(tracker_response) - 5), false)); TEST_CHECK(parser.get_body().left() == 5); parser.reset(); @@ -267,7 +263,7 @@ TORRENT_TEST(http_parser) received = feed_bytes(parser, web_seed_response); - TEST_CHECK(received == make_tuple(5, int(strlen(web_seed_response) - 5), false)); + TEST_CHECK(received == std::make_tuple(5, int(strlen(web_seed_response) - 5), false)); TEST_CHECK(parser.content_range() == (std::pair(0, 4))); TEST_CHECK(parser.content_length() == 5); @@ -283,7 +279,7 @@ TORRENT_TEST(http_parser) received = feed_bytes(parser, invalid_range_response); - TEST_CHECK(received.get<2>() == true); + TEST_CHECK(std::get<2>(received) == true); parser.reset(); @@ -297,7 +293,7 @@ TORRENT_TEST(http_parser) received = feed_bytes(parser, invalid_status_response); - TEST_CHECK(received.get<2>() == true); + TEST_CHECK(std::get<2>(received) == true); parser.reset(); @@ -311,7 +307,7 @@ TORRENT_TEST(http_parser) received = feed_bytes(parser, invalid_status_response2); - TEST_CHECK(received.get<2>() == true); + TEST_CHECK(std::get<2>(received) == true); parser.reset(); @@ -328,7 +324,7 @@ TORRENT_TEST(http_parser) received = feed_bytes(parser, one_hundred_response); - TEST_CHECK(received == make_tuple(4, int(strlen(one_hundred_response) - 4), false)); + TEST_CHECK(received == std::make_tuple(4, int(strlen(one_hundred_response) - 4), false)); TEST_EQUAL(parser.content_length(), 4); { @@ -365,26 +361,26 @@ TORRENT_TEST(http_parser) error_code ec; TEST_CHECK(parse_url_components("http://foo:bar@host.com:80/path/to/file", ec) - == make_tuple("http", "foo:bar", "host.com", 80, "/path/to/file")); + == std::make_tuple("http", "foo:bar", "host.com", 80, "/path/to/file")); TEST_CHECK(parse_url_components("http://host.com/path/to/file", ec) - == make_tuple("http", "", "host.com", -1, "/path/to/file")); + == std::make_tuple("http", "", "host.com", -1, "/path/to/file")); TEST_CHECK(parse_url_components("ftp://host.com:21/path/to/file", ec) - == make_tuple("ftp", "", "host.com", 21, "/path/to/file")); + == std::make_tuple("ftp", "", "host.com", 21, "/path/to/file")); TEST_CHECK(parse_url_components("http://host.com/path?foo:bar@foo:", ec) - == make_tuple("http", "", "host.com", -1, "/path?foo:bar@foo:")); + == std::make_tuple("http", "", "host.com", -1, "/path?foo:bar@foo:")); TEST_CHECK(parse_url_components("http://192.168.0.1/path/to/file", ec) - == make_tuple("http", "", "192.168.0.1", -1, "/path/to/file")); + == std::make_tuple("http", "", "192.168.0.1", -1, "/path/to/file")); TEST_CHECK(parse_url_components("http://[2001:ff00::1]:42/path/to/file", ec) - == make_tuple("http", "", "2001:ff00::1", 42, "/path/to/file")); + == std::make_tuple("http", "", "2001:ff00::1", 42, "/path/to/file")); // leading spaces are supposed to be stripped TEST_CHECK(parse_url_components(" \thttp://[2001:ff00::1]:42/path/to/file", ec) - == make_tuple("http", "", "2001:ff00::1", 42, "/path/to/file")); + == std::make_tuple("http", "", "2001:ff00::1", 42, "/path/to/file")); parse_url_components("http://[2001:ff00::1:42/path/to/file", ec); TEST_CHECK(ec == error_code(errors::expected_close_bracket_in_address)); @@ -464,11 +460,11 @@ TORRENT_TEST(chunked_encoding) "0\r\n\r\n"; http_parser parser; - boost::tuple const received + std::tuple const received = feed_bytes(parser, chunked_input); TEST_EQUAL(strlen(chunked_input), 24 + 94) - TEST_CHECK(received == make_tuple(24, 94, false)); + TEST_CHECK(received == std::make_tuple(24, 94, false)); TEST_CHECK(parser.finished()); char mutable_buffer[100]; @@ -487,10 +483,10 @@ TORRENT_TEST(invalid_content_length) "\r\n"; http_parser parser; - boost::tuple const received + std::tuple const received = feed_bytes(parser, chunked_input); - TEST_CHECK(boost::get<2>(received) == true); + TEST_CHECK(std::get<2>(received) == true); } TORRENT_TEST(invalid_chunked) @@ -503,10 +499,10 @@ TORRENT_TEST(invalid_chunked) "foobar"; http_parser parser; - boost::tuple const received + std::tuple const received = feed_bytes(parser, chunked_input); - TEST_CHECK(boost::get<2>(received) == true); + TEST_CHECK(std::get<2>(received) == true); } TORRENT_TEST(invalid_content_range_start) @@ -517,10 +513,10 @@ TORRENT_TEST(invalid_content_range_start) "\n"; http_parser parser; - boost::tuple const received + std::tuple const received = feed_bytes(parser, chunked_input); - TEST_CHECK(boost::get<2>(received) == true); + TEST_CHECK(std::get<2>(received) == true); } TORRENT_TEST(invalid_content_range_end) @@ -531,10 +527,10 @@ TORRENT_TEST(invalid_content_range_end) "\n"; http_parser parser; - boost::tuple const received + std::tuple const received = feed_bytes(parser, chunked_input); - TEST_CHECK(boost::get<2>(received) == true); + TEST_CHECK(std::get<2>(received) == true); } TORRENT_TEST(invalid_chunk_afl) @@ -563,9 +559,9 @@ TORRENT_TEST(invalid_chunk_afl) }; http_parser parser; - boost::tuple const received + std::tuple const received = feed_bytes(parser, reinterpret_cast(invalid_chunked_input)); - TEST_CHECK(boost::get<2>(received) == true); + TEST_CHECK(std::get<2>(received) == true); } diff --git a/test/test_ip_filter.cpp b/test/test_ip_filter.cpp index 83b7ecadb..fbe8c9433 100644 --- a/test/test_ip_filter.cpp +++ b/test/test_ip_filter.cpp @@ -107,7 +107,7 @@ TORRENT_TEST(ip_filter) f.add_rule(addr("2.0.0.1"), addr("3.0.0.0"), ip_filter::blocked); #if TORRENT_USE_IPV6 - range = boost::get<0>(f.export_filter()); + range = std::get<0>(f.export_filter()); #else range = f.export_filter(); #endif @@ -126,7 +126,7 @@ TORRENT_TEST(ip_filter) f.add_rule(addr("1.0.0.0"), addr("2.0.0.0"), ip_filter::blocked); #if TORRENT_USE_IPV6 - range = boost::get<0>(f.export_filter()); + range = std::get<0>(f.export_filter()); #else range = f.export_filter(); #endif @@ -146,7 +146,7 @@ TORRENT_TEST(ip_filter) f.add_rule(addr("1.0.0.0"), addr("2.4.0.0"), ip_filter::blocked); #if TORRENT_USE_IPV6 - range = boost::get<0>(f.export_filter()); + range = std::get<0>(f.export_filter()); #else range = f.export_filter(); #endif @@ -166,7 +166,7 @@ TORRENT_TEST(ip_filter) f.add_rule(addr("2.0.0.1"), addr("3.0.0.0"), ip_filter::blocked); #if TORRENT_USE_IPV6 - range = boost::get<0>(f.export_filter()); + range = std::get<0>(f.export_filter()); #else range = f.export_filter(); #endif @@ -190,7 +190,7 @@ TORRENT_TEST(ip_filter) f.add_rule(addr("1.0.1.0"), addr("9.0.0.0"), ip_filter::blocked); #if TORRENT_USE_IPV6 - range = boost::get<0>(f.export_filter()); + range = std::get<0>(f.export_filter()); #else range = f.export_filter(); #endif @@ -220,7 +220,7 @@ TORRENT_TEST(ip_filter) f.add_rule(addr("0.0.1.0"), addr("7.0.4.0"), ip_filter::blocked); #if TORRENT_USE_IPV6 - range = boost::get<0>(f.export_filter()); + range = std::get<0>(f.export_filter()); #else range = f.export_filter(); #endif @@ -255,7 +255,7 @@ TORRENT_TEST(ip_filter) f.add_rule(addr("1::"), addr("2::"), ip_filter::blocked); std::vector > range; - range = boost::get<1>(f.export_filter()); + range = std::get<1>(f.export_filter()); test_rules_invariant(range, f); TEST_EQUAL(range.size(), 3); diff --git a/test/test_lsd.cpp b/test/test_lsd.cpp index 752e13d52..144e70b66 100644 --- a/test/test_lsd.cpp +++ b/test/test_lsd.cpp @@ -34,7 +34,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/session_settings.hpp" #include "libtorrent/torrent_status.hpp" #include "libtorrent/hasher.hpp" -#include +#include #include "test.hpp" #include "setup_transfer.hpp" @@ -67,8 +67,8 @@ void test_lsd() torrent_handle tor1; torrent_handle tor2; - using boost::tuples::ignore; - boost::tie(tor1, tor2, ignore) = setup_transfer(&ses1, &ses2, 0, true, false, false, "_lsd" + using std::ignore; + std::tie(tor1, tor2, ignore) = setup_transfer(&ses1, &ses2, 0, true, false, false, "_lsd" , 16 * 1024, 0, false, 0, false); for (int i = 0; i < 30; ++i) diff --git a/test/test_pex.cpp b/test/test_pex.cpp index 8d7adeeca..50defe8c1 100644 --- a/test/test_pex.cpp +++ b/test/test_pex.cpp @@ -40,7 +40,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/extensions/ut_pex.hpp" #include "libtorrent/ip_filter.hpp" #include "libtorrent/torrent_status.hpp" -#include +#include #include "setup_transfer.hpp" #include @@ -97,7 +97,7 @@ void test_pex() torrent_handle tor2; torrent_handle tor3; - boost::tie(tor1, tor2, tor3) = setup_transfer(&ses1, &ses2, &ses3, true, false, false, "_pex"); + std::tie(tor1, tor2, tor3) = setup_transfer(&ses1, &ses2, &ses3, true, false, false, "_pex"); ses2.apply_settings(pack); diff --git a/test/test_priority.cpp b/test/test_priority.cpp index 627567c4c..788af6afd 100644 --- a/test/test_priority.cpp +++ b/test/test_priority.cpp @@ -39,7 +39,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/file.hpp" #include "libtorrent/torrent_info.hpp" #include "libtorrent/read_resume_data.hpp" -#include +#include #include #include "test.hpp" @@ -49,7 +49,7 @@ POSSIBILITY OF SUCH DAMAGE. using namespace libtorrent; namespace lt = libtorrent; -using boost::tuples::ignore; +using std::ignore; const int mask = alert::all_categories & ~(alert::performance_warning | alert::stats_notification); @@ -132,7 +132,7 @@ void test_transfer(settings_pack const& sett, bool test_deprecated = false) peer_disconnects = 0; // test using piece sizes smaller than 16kB - boost::tie(tor1, tor2, ignore) = setup_transfer(&ses1, &ses2, 0 + std::tie(tor1, tor2, ignore) = setup_transfer(&ses1, &ses2, 0 , true, false, true, "_priority", 8 * 1024, &t, false, 0); int num_pieces = tor2.torrent_file()->num_pieces(); diff --git a/test/test_recheck.cpp b/test/test_recheck.cpp index 5859aca72..c72d30e7e 100644 --- a/test/test_recheck.cpp +++ b/test/test_recheck.cpp @@ -38,7 +38,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/time.hpp" #include "libtorrent/file.hpp" #include "libtorrent/error_code.hpp" -#include +#include #include #include "test.hpp" diff --git a/test/test_remap_files.cpp b/test/test_remap_files.cpp index ebf66d88f..b52593c49 100644 --- a/test/test_remap_files.cpp +++ b/test/test_remap_files.cpp @@ -40,11 +40,11 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include -#include +#include using namespace libtorrent; namespace lt = libtorrent; -using boost::tuples::ignore; +using std::ignore; namespace { @@ -145,7 +145,7 @@ void test_remap_files_gather(storage_mode_t storage_mode = storage_mode_sparse) peer_disconnects = 0; // test using piece sizes smaller than 16kB - boost::tie(tor1, tor2, ignore) = setup_transfer(&ses1, &ses2, 0 + std::tie(tor1, tor2, ignore) = setup_transfer(&ses1, &ses2, 0 , true, false, true, "_remap", 8 * 1024, &t, false, ¶ms , true, false, &t2); @@ -289,7 +289,7 @@ void test_remap_files_scatter(storage_mode_t storage_mode = storage_mode_sparse) peer_disconnects = 0; // test using piece sizes smaller than 16kB - boost::tie(tor1, tor2, ignore) = setup_transfer(&ses1, &ses2, 0 + std::tie(tor1, tor2, ignore) = setup_transfer(&ses1, &ses2, 0 , true, false, true, "_remap2", 8 * 1024, &t, false, ¶ms , true, false, &t2); @@ -453,7 +453,7 @@ void test_remap_files_prio(storage_mode_t storage_mode = storage_mode_sparse) peer_disconnects = 0; // test using piece sizes smaller than 16kB - boost::tie(tor1, tor2, ignore) = setup_transfer(&ses1, &ses2, 0 + std::tie(tor1, tor2, ignore) = setup_transfer(&ses1, &ses2, 0 , true, false, true, "_remap3", 8 * 1024, &t, false, ¶ms , true, false, &t2); diff --git a/test/test_ssl.cpp b/test/test_ssl.cpp index 8e7f44086..e6d613496 100644 --- a/test/test_ssl.cpp +++ b/test/test_ssl.cpp @@ -43,8 +43,6 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/aux_/disable_warnings_push.hpp" -#include - #include #ifdef TORRENT_USE_OPENSSL @@ -54,12 +52,13 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/aux_/disable_warnings_pop.hpp" #include +#include #include #include using namespace std::placeholders; using namespace libtorrent; -using boost::tuples::ignore; +using std::ignore; int const alert_mask = alert::all_categories & ~alert::progress_notification @@ -195,7 +194,7 @@ void test_ssl(int test_idx, bool use_utp) ssl_peer_disconnects = 0; peer_errors = 0; - boost::tie(tor1, tor2, ignore) = setup_transfer(&ses1, &ses2, 0 + std::tie(tor1, tor2, ignore) = setup_transfer(&ses1, &ses2, 0 , true, false, false, "_ssl", 16 * 1024, &t, false, &addp, true); if (test.seed_has_cert) diff --git a/test/test_torrent.cpp b/test/test_torrent.cpp index ac9c61711..aa18ec169 100644 --- a/test/test_torrent.cpp +++ b/test/test_torrent.cpp @@ -38,10 +38,13 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/alert_types.hpp" #include "libtorrent/torrent.hpp" #include "libtorrent/peer_info.hpp" -#include -#include +#include #include +#include "libtorrent/aux_/disable_warnings_push.hpp" +#include +#include "libtorrent/aux_/disable_warnings_pop.hpp" + #include "test.hpp" #include "setup_transfer.hpp" diff --git a/test/test_transfer.cpp b/test/test_transfer.cpp index d7b9b2aa2..caf7bdebe 100644 --- a/test/test_transfer.cpp +++ b/test/test_transfer.cpp @@ -43,7 +43,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "setup_transfer.hpp" #include "test_utils.hpp" -#include +#include #include #include @@ -52,7 +52,7 @@ POSSIBILITY OF SUCH DAMAGE. using namespace libtorrent; namespace lt = libtorrent; -using boost::tuples::ignore; +using std::ignore; const int mask = alert::all_categories & ~(alert::performance_warning | alert::stats_notification); @@ -247,7 +247,7 @@ void test_transfer(int proxy_type, settings_pack const& sett peer_disconnects = 0; // test using piece sizes smaller than 16kB - boost::tie(tor1, tor2, ignore) = setup_transfer(&ses1, &ses2, 0 + std::tie(tor1, tor2, ignore) = setup_transfer(&ses1, &ses2, 0 , true, false, true, "_transfer", 8 * 1024, &t, false, test_disk_full?&addp:¶ms); int num_pieces = tor2.torrent_file()->num_pieces(); diff --git a/test/test_utp.cpp b/test/test_utp.cpp index 41fcb70a2..29d1d0ce8 100644 --- a/test/test_utp.cpp +++ b/test/test_utp.cpp @@ -37,7 +37,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/bencode.hpp" #include "libtorrent/time.hpp" #include "libtorrent/file.hpp" -#include +#include #include #include "test.hpp" @@ -47,7 +47,7 @@ POSSIBILITY OF SUCH DAMAGE. using namespace libtorrent; namespace lt = libtorrent; -using boost::tuples::ignore; +using std::ignore; void test_transfer() { @@ -102,7 +102,7 @@ void test_transfer() // atp.storage = &disabled_storage_constructor; // test using piece sizes smaller than 16kB - boost::tie(tor1, tor2, ignore) = setup_transfer(&ses1, &ses2, 0 + std::tie(tor1, tor2, ignore) = setup_transfer(&ses1, &ses2, 0 , true, false, true, "_utp", 0, &t, false, &atp); const int timeout = 8; diff --git a/test/web_seed_suite.cpp b/test/web_seed_suite.cpp index 4151c0bea..6c2e97dc7 100644 --- a/test/web_seed_suite.cpp +++ b/test/web_seed_suite.cpp @@ -46,7 +46,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "web_seed_suite.hpp" #include "make_torrent.hpp" -#include +#include #include #include #include "setup_transfer.hpp" diff --git a/tools/dht_put.cpp b/tools/dht_put.cpp index 0637ddaa9..1b0a01204 100644 --- a/tools/dht_put.cpp +++ b/tools/dht_put.cpp @@ -83,7 +83,7 @@ void usage() alert* wait_for_alert(lt::session& s, int alert_type) { - alert* ret = NULL; + alert* ret = nullptr; bool found = false; while (!found) { @@ -140,7 +140,7 @@ void bootstrap(lt::session& s) int dump_key(char *filename) { FILE* f = std::fopen(filename, "rb+"); - if (f == NULL) + if (f == nullptr) { std::fprintf(stderr, "failed to open file \"%s\": (%d) %s\n" , filename, errno, strerror(errno)); @@ -174,7 +174,7 @@ int generate_key(char* filename) ed25519_create_seed(seed); FILE* f = std::fopen(filename, "wb+"); - if (f == NULL) + if (f == nullptr) { std::fprintf(stderr, "failed to open file for writing \"%s\": (%d) %s\n" , filename, errno, strerror(errno)); @@ -195,7 +195,7 @@ int generate_key(char* filename) void load_dht_state(lt::session& s) { FILE* f = std::fopen(".dht", "rb"); - if (f == NULL) return; + if (f == nullptr) return; fseek(f, 0, SEEK_END); int size = ftell(f); @@ -230,7 +230,7 @@ int save_dht_state(lt::session& s) std::vector state; bencode(std::back_inserter(state), e); FILE* f = std::fopen(".dht", "wb+"); - if (f == NULL) + if (f == nullptr) { std::fprintf(stderr, "failed to open file .dht for writing"); return 1; @@ -337,7 +337,7 @@ int main(int argc, char* argv[]) if (argc < 1) usage(); FILE* f = std::fopen(argv[0], "rb+"); - if (f == NULL) + if (f == nullptr) { std::fprintf(stderr, "failed to open file \"%s\": (%d) %s\n" , argv[0], errno, strerror(errno)); diff --git a/tools/fuzz_torrent.cpp b/tools/fuzz_torrent.cpp index 9aca82843..3390e2ca3 100644 --- a/tools/fuzz_torrent.cpp +++ b/tools/fuzz_torrent.cpp @@ -292,7 +292,7 @@ int load_file(std::string const& filename, std::vector& v { ec.clear(); FILE* f = fopen(filename.c_str(), "rb"); - if (f == NULL) + if (f == nullptr) { ec.assign(errno, boost::system::system_category()); return -1;