diff --git a/bindings/python/src/alert.cpp b/bindings/python/src/alert.cpp index 4739c16ec..a94d76c38 100644 --- a/bindings/python/src/alert.cpp +++ b/bindings/python/src/alert.cpp @@ -243,7 +243,7 @@ void bind_alert() { using boost::noncopyable; - typedef return_value_policy by_value; + using by_value = return_value_policy; { scope alert_scope = class_("alert", no_init) diff --git a/bindings/python/src/create_torrent.cpp b/bindings/python/src/create_torrent.cpp index 23c0dd7fb..3f33a02d6 100644 --- a/bindings/python/src/create_torrent.cpp +++ b/bindings/python/src/create_torrent.cpp @@ -65,11 +65,11 @@ namespace struct FileIter { - typedef lt::file_entry value_type; - typedef lt::file_entry reference; - typedef lt::file_entry* pointer; - typedef int difference_type; - typedef std::forward_iterator_tag iterator_category; + using value_type = lt::file_entry; + using reference = lt::file_entry; + using pointer = lt::file_entry*; + using difference_type = int; + using iterator_category = std::forward_iterator_tag; FileIter(file_storage const& fs, file_index_t i) : m_fs(&fs), m_i(i) {} FileIter(FileIter const&) = default; diff --git a/docs/gen_reference_doc.py b/docs/gen_reference_doc.py index 177361e22..9cef4dc8a 100644 --- a/docs/gen_reference_doc.py +++ b/docs/gen_reference_doc.py @@ -211,6 +211,7 @@ def looks_like_variable(line): if line.startswith(','): return False if line.startswith(':'): return False if line.startswith('typedef'): return False + if line.startswith('using'): return False if ' = ' in line: return True if line.endswith(';'): return True return False diff --git a/docs/manual.rst b/docs/manual.rst index d9772abd1..316f0dada 100644 --- a/docs/manual.rst +++ b/docs/manual.rst @@ -91,9 +91,9 @@ network primitives There are a few typedefs in the ``libtorrent`` namespace which pulls in network types from the ``boost::asio`` namespace. These are:: - typedef boost::asio::ip::address address; - typedef boost::asio::ip::address_v4 address_v4; - typedef boost::asio::ip::address_v6 address_v6; + using address = boost::asio::ip::address; + using address_v4 = boost::asio::ip::address_v4; + using address_v6 = boost::asio::ip::address_v6; using boost::asio::ip::tcp; using boost::asio::ip::udp; diff --git a/include/libtorrent/ConvertUTF.h b/include/libtorrent/ConvertUTF.h index 5777cb0dc..226663dfb 100644 --- a/include/libtorrent/ConvertUTF.h +++ b/include/libtorrent/ConvertUTF.h @@ -1,8 +1,8 @@ /* * Copyright 2001-2004 Unicode, Inc. - * + * * Disclaimer - * + * * This source code is provided as is by Unicode, Inc. No claims are * made as to fitness for any particular purpose. No warranties of any * kind are expressed or implied. The recipient agrees to determine @@ -10,9 +10,9 @@ * purchased on magnetic or optical media from Unicode, Inc., the * sole remedy for any claim will be exchange of defective media * within 90 days of receipt. - * + * * Limitations on Rights to Redistribute This Code - * + * * Unicode, Inc. hereby grants the right to freely use the information * supplied in this file in the creation of products supporting the * Unicode Standard, and to make copies of this file in any form @@ -33,7 +33,7 @@ Each routine converts the text between *sourceStart and sourceEnd, putting the result into the buffer between *targetStart and - targetEnd. Note: the end pointers are *after* the last item: e.g. + targetEnd. Note: the end pointers are *after* the last item: e.g. *(sourceEnd - 1) is the last item. The return result indicates whether the conversion was successful, @@ -71,7 +71,7 @@ sequence is malformed. When "sourceIllegal" is returned, the source value will point to the illegal value that caused the problem. E.g., in UTF-8 when a sequence is malformed, it points to the start of the - malformed sequence. + malformed sequence. Author: Mark E. Davis, 1994. Rev History: Rick McGowan, fixes & updates May 2001. @@ -81,12 +81,12 @@ #include "libtorrent/config.hpp" #include -typedef std::uint32_t UTF32; -typedef std::uint16_t UTF16; -typedef std::uint8_t UTF8; +using UTF32 = std::uint32_t; +using UTF16 = std::uint16_t; +using UTF8 = std::uint8_t; extern "C" { -typedef unsigned char Boolean; /* 0 or 1 */ +using Boolean = unsigned char; /* 0 or 1 */ /* Some fundamental constants */ #define UNI_REPLACEMENT_CHAR UTF32(0x0000FFFD) @@ -95,12 +95,12 @@ typedef unsigned char Boolean; /* 0 or 1 */ #define UNI_MAX_UTF32 UTF32(0x7FFFFFFF) #define UNI_MAX_LEGAL_UTF32 UTF32(0x0010FFFF) -typedef enum { - conversionOK, /* conversion successful */ - sourceExhausted, /* partial character in source, but hit end */ - targetExhausted, /* insuff. room in target for conversion */ - sourceIllegal /* source sequence is illegal/malformed */ -} ConversionResult; +enum ConversionResult { + conversionOK, /* conversion successful */ + sourceExhausted, /* partial character in source, but hit end */ + targetExhausted, /* insuff. room in target for conversion */ + sourceIllegal /* source sequence is illegal/malformed */ +}; typedef enum { strictConversion = 0, @@ -108,38 +108,36 @@ typedef enum { } ConversionFlags; TORRENT_EXTRA_EXPORT ConversionResult ConvertUTF8toUTF16 ( - const UTF8** sourceStart, const UTF8* sourceEnd, - UTF16** targetStart, UTF16* targetEnd, ConversionFlags flags); + const UTF8** sourceStart, const UTF8* sourceEnd, + UTF16** targetStart, UTF16* targetEnd, ConversionFlags flags); TORRENT_EXTRA_EXPORT ConversionResult ConvertUTF16toUTF8 ( - const UTF16** sourceStart, const UTF16* sourceEnd, - UTF8** targetStart, UTF8* targetEnd, ConversionFlags flags); - + const UTF16** sourceStart, const UTF16* sourceEnd, + UTF8** targetStart, UTF8* targetEnd, ConversionFlags flags); + TORRENT_EXTRA_EXPORT ConversionResult ConvertUTF8toUTF32 ( - const UTF8** sourceStart, const UTF8* sourceEnd, - UTF32** targetStart, UTF32* targetEnd, ConversionFlags flags); + const UTF8** sourceStart, const UTF8* sourceEnd, + UTF32** targetStart, UTF32* targetEnd, ConversionFlags flags); TORRENT_EXTRA_EXPORT ConversionResult ConvertUTF32toUTF8 ( - const UTF32** sourceStart, const UTF32* sourceEnd, - UTF8** targetStart, UTF8* targetEnd, ConversionFlags flags); - + const UTF32** sourceStart, const UTF32* sourceEnd, + UTF8** targetStart, UTF8* targetEnd, ConversionFlags flags); + TORRENT_EXTRA_EXPORT ConversionResult ConvertUTF16toUTF32 ( - const UTF16** sourceStart, const UTF16* sourceEnd, - UTF32** targetStart, UTF32* targetEnd, ConversionFlags flags); + const UTF16** sourceStart, const UTF16* sourceEnd, + UTF32** targetStart, UTF32* targetEnd, ConversionFlags flags); TORRENT_EXTRA_EXPORT ConversionResult ConvertUTF32toUTF16 ( - const UTF32** sourceStart, const UTF32* sourceEnd, - UTF16** targetStart, UTF16* targetEnd, ConversionFlags flags); + const UTF32** sourceStart, const UTF32* sourceEnd, + UTF16** targetStart, UTF16* targetEnd, ConversionFlags flags); TORRENT_EXTRA_EXPORT Boolean isLegalUTF8Sequence(const UTF8 *source, - const UTF8 *sourceEnd); + const UTF8 *sourceEnd); TORRENT_EXTRA_EXPORT Boolean isLegalUTF8(const UTF8 *source, int length); extern const char trailingBytesForUTF8[256]; extern const UTF32 offsetsFromUTF8[6]; -#ifdef __cplusplus } -#endif /* --------------------------------------------------------------------- */ diff --git a/include/libtorrent/alert_types.hpp b/include/libtorrent/alert_types.hpp index 6b56eef40..89c80041f 100644 --- a/include/libtorrent/alert_types.hpp +++ b/include/libtorrent/alert_types.hpp @@ -281,8 +281,17 @@ namespace libtorrent { private: aux::allocation_slot m_name_idx; #ifndef TORRENT_NO_DEPRECATE +#if defined __clang__ && __clang_major__ > 9 +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wshadow-field" +#endif + public: std::string TORRENT_DEPRECATED_MEMBER name; + +#if defined __clang__ && __clang_major__ > 9 +#pragma clang diagnostic pop +#endif #endif }; diff --git a/include/libtorrent/allocator.hpp b/include/libtorrent/allocator.hpp index 838c9079d..84db80176 100644 --- a/include/libtorrent/allocator.hpp +++ b/include/libtorrent/allocator.hpp @@ -40,17 +40,11 @@ namespace libtorrent { TORRENT_EXTRA_EXPORT int page_size(); - struct TORRENT_EXTRA_EXPORT page_aligned_allocator - { - typedef int size_type; - typedef std::ptrdiff_t difference_type; - - static char* malloc(size_type bytes); - static void free(char* block); + TORRENT_EXTRA_EXPORT char* page_malloc(std::size_t bytes); + TORRENT_EXTRA_EXPORT void page_free(char* block); #ifdef TORRENT_DEBUG_BUFFERS - static bool in_use(char const* block); + TORRENT_EXTRA_EXPORT bool page_in_use(char const* block); #endif - }; } diff --git a/include/libtorrent/bdecode.hpp b/include/libtorrent/bdecode.hpp index 1342f4dce..cc07b3193 100644 --- a/include/libtorrent/bdecode.hpp +++ b/include/libtorrent/bdecode.hpp @@ -151,7 +151,7 @@ namespace boost { namespace system { namespace libtorrent { - typedef boost::system::error_code error_code; + using error_code = boost::system::error_code; TORRENT_EXTRA_EXPORT char const* parse_int(char const* start , char const* end, char delimiter, std::int64_t& val diff --git a/include/libtorrent/bitfield.hpp b/include/libtorrent/bitfield.hpp index f6f3727bd..9742e8d37 100644 --- a/include/libtorrent/bitfield.hpp +++ b/include/libtorrent/bitfield.hpp @@ -164,11 +164,11 @@ namespace libtorrent { { friend struct bitfield; - typedef bool value_type; - typedef ptrdiff_t difference_type; - typedef bool const* pointer; - typedef bool& reference; - typedef std::forward_iterator_tag iterator_category; + using value_type = bool; + using difference_type = ptrdiff_t; + using pointer = bool const*; + using reference = bool&; + using iterator_category = std::forward_iterator_tag; bool operator*() { return (*buf & aux::host_to_network(bit)) != 0; } const_iterator& operator++() { inc(); return *this; } diff --git a/include/libtorrent/broadcast_socket.hpp b/include/libtorrent/broadcast_socket.hpp index 7d6d45d02..f564c59e2 100644 --- a/include/libtorrent/broadcast_socket.hpp +++ b/include/libtorrent/broadcast_socket.hpp @@ -57,8 +57,8 @@ namespace libtorrent { TORRENT_EXTRA_EXPORT bool supports_ipv6(); address ensure_v6(address const& a); - typedef std::function buffer)> receive_handler_t; + using receive_handler_t = std::function buffer)>; class TORRENT_EXTRA_EXPORT broadcast_socket { diff --git a/include/libtorrent/deadline_timer.hpp b/include/libtorrent/deadline_timer.hpp index 4d75a365f..b8a94216a 100644 --- a/include/libtorrent/deadline_timer.hpp +++ b/include/libtorrent/deadline_timer.hpp @@ -46,9 +46,9 @@ POSSIBILITY OF SUCH DAMAGE. namespace libtorrent { #if defined TORRENT_BUILD_SIMULATOR - typedef sim::asio::high_resolution_timer deadline_timer; + using deadline_timer = sim::asio::high_resolution_timer; #else - typedef boost::asio::high_resolution_timer deadline_timer; + using deadline_timer = boost::asio::high_resolution_timer; #endif } diff --git a/include/libtorrent/disk_io_thread.hpp b/include/libtorrent/disk_io_thread.hpp index 84c60a614..70d383142 100644 --- a/include/libtorrent/disk_io_thread.hpp +++ b/include/libtorrent/disk_io_thread.hpp @@ -95,7 +95,7 @@ namespace aux { bool need_readback; }; - typedef tailqueue jobqueue_t; + using jobqueue_t = tailqueue; // this struct holds a number of statistics counters // relevant for the disk io thread and disk cache. diff --git a/include/libtorrent/http_connection.hpp b/include/libtorrent/http_connection.hpp index a733b6001..acb102421 100644 --- a/include/libtorrent/http_connection.hpp +++ b/include/libtorrent/http_connection.hpp @@ -66,12 +66,12 @@ struct resolver_interface; constexpr int default_max_bottled_buffer_size = 2 * 1024 * 1024; -typedef std::function data, http_connection&)> http_handler; +using http_handler = std::function data, http_connection&)>; -typedef std::function http_connect_handler; +using http_connect_handler = std::function; -typedef std::function&)> http_filter_handler; +using http_filter_handler = std::function&)>; // when bottled, the last two arguments to the handler // will always be 0 diff --git a/include/libtorrent/i2p_stream.hpp b/include/libtorrent/i2p_stream.hpp index 29777aa1e..27c23f2e9 100644 --- a/include/libtorrent/i2p_stream.hpp +++ b/include/libtorrent/i2p_stream.hpp @@ -183,7 +183,7 @@ public: char const* session_id() const { return m_session_id.c_str(); } std::string const& local_endpoint() const { return m_i2p_local_endpoint; } - typedef std::function name_lookup_handler; + using name_lookup_handler = std::function; void async_name_lookup(char const* name, name_lookup_handler handler); private: diff --git a/include/libtorrent/kademlia/find_data.hpp b/include/libtorrent/kademlia/find_data.hpp index 5268c7223..770285660 100644 --- a/include/libtorrent/kademlia/find_data.hpp +++ b/include/libtorrent/kademlia/find_data.hpp @@ -51,7 +51,7 @@ class node; struct find_data : traversal_algorithm { - typedef std::function> const&)> nodes_callback; + using nodes_callback = std::function> const&)>; find_data(node& dht_node, node_id const& target , nodes_callback const& ncallback); diff --git a/include/libtorrent/kademlia/get_item.hpp b/include/libtorrent/kademlia/get_item.hpp index adac96bb0..2729e45ec 100644 --- a/include/libtorrent/kademlia/get_item.hpp +++ b/include/libtorrent/kademlia/get_item.hpp @@ -43,7 +43,7 @@ namespace libtorrent { namespace dht { class get_item : public find_data { public: - typedef std::function data_callback; + using data_callback = std::function; void got_data(bdecode_node const& v, public_key const& pk, diff --git a/include/libtorrent/kademlia/get_peers.hpp b/include/libtorrent/kademlia/get_peers.hpp index f8d720f1c..a540b4536 100644 --- a/include/libtorrent/kademlia/get_peers.hpp +++ b/include/libtorrent/kademlia/get_peers.hpp @@ -39,7 +39,7 @@ namespace libtorrent { namespace dht { struct get_peers : find_data { - typedef std::function const&)> data_callback; + using data_callback = std::function const&)>; void got_peers(std::vector const& peers); diff --git a/include/libtorrent/kademlia/put_data.hpp b/include/libtorrent/kademlia/put_data.hpp index 0bd985556..9c62e9264 100644 --- a/include/libtorrent/kademlia/put_data.hpp +++ b/include/libtorrent/kademlia/put_data.hpp @@ -47,7 +47,7 @@ class node; struct put_data: traversal_algorithm { - typedef std::function put_callback; + using put_callback = std::function; put_data(node& node, put_callback const& callback); diff --git a/include/libtorrent/kademlia/refresh.hpp b/include/libtorrent/kademlia/refresh.hpp index 5a8893fd3..5e5f2f8c3 100644 --- a/include/libtorrent/kademlia/refresh.hpp +++ b/include/libtorrent/kademlia/refresh.hpp @@ -41,7 +41,7 @@ namespace libtorrent { namespace dht { class bootstrap : public get_peers { public: - typedef get_peers::nodes_callback done_callback; + using done_callback = get_peers::nodes_callback; bootstrap(node& dht_node, node_id const& target , done_callback const& callback); diff --git a/include/libtorrent/kademlia/routing_table.hpp b/include/libtorrent/kademlia/routing_table.hpp index 6089cce0d..6cbd5329f 100644 --- a/include/libtorrent/kademlia/routing_table.hpp +++ b/include/libtorrent/kademlia/routing_table.hpp @@ -59,7 +59,7 @@ namespace libtorrent { namespace dht { struct dht_settings; struct dht_logger; -typedef aux::vector bucket_t; +using bucket_t = aux::vector; struct routing_table_node { @@ -161,7 +161,7 @@ public: void add_router_node(udp::endpoint const& router); // iterates over the router nodes added - typedef std::set::const_iterator router_iterator; + using router_iterator = std::set::const_iterator; router_iterator begin() const { return m_router_nodes.begin(); } router_iterator end() const { return m_router_nodes.end(); } diff --git a/include/libtorrent/proxy_base.hpp b/include/libtorrent/proxy_base.hpp index ea342c65e..60dcc81b5 100644 --- a/include/libtorrent/proxy_base.hpp +++ b/include/libtorrent/proxy_base.hpp @@ -47,10 +47,10 @@ public: using handler_type = std::function; - typedef tcp::socket next_layer_type; - typedef tcp::socket::lowest_layer_type lowest_layer_type; - typedef tcp::socket::endpoint_type endpoint_type; - typedef tcp::socket::protocol_type protocol_type; + using next_layer_type = tcp::socket; + using lowest_layer_type = tcp::socket::lowest_layer_type; + using endpoint_type = tcp::socket::endpoint_type; + using protocol_type = tcp::socket::protocol_type; explicit proxy_base(io_service& io_service); ~proxy_base(); @@ -64,7 +64,7 @@ public: } #if BOOST_VERSION >= 106600 - typedef tcp::socket::executor_type executor_type; + using executor_type = tcp::socket::executor_type; executor_type get_executor() { return m_sock.get_executor(); } #endif diff --git a/include/libtorrent/ssl_stream.hpp b/include/libtorrent/ssl_stream.hpp index 31f2a5c5f..9a5f11cff 100644 --- a/include/libtorrent/ssl_stream.hpp +++ b/include/libtorrent/ssl_stream.hpp @@ -74,13 +74,13 @@ public: { } - typedef typename boost::asio::ssl::stream sock_type; - typedef typename sock_type::next_layer_type next_layer_type; - typedef typename Stream::lowest_layer_type lowest_layer_type; - typedef typename Stream::endpoint_type endpoint_type; - typedef typename Stream::protocol_type protocol_type; + using sock_type = typename boost::asio::ssl::stream; + using next_layer_type = typename sock_type::next_layer_type; + using lowest_layer_type = typename Stream::lowest_layer_type; + using endpoint_type = typename Stream::endpoint_type; + using protocol_type = typename Stream::protocol_type; #if BOOST_VERSION >= 106600 - typedef typename sock_type::executor_type executor_type; + using executor_type = typename sock_type::executor_type; executor_type get_executor() { return m_sock.get_executor(); } #endif diff --git a/include/libtorrent/torrent_info.hpp b/include/libtorrent/torrent_info.hpp index 5820c9f32..06690fb4e 100644 --- a/include/libtorrent/torrent_info.hpp +++ b/include/libtorrent/torrent_info.hpp @@ -77,7 +77,7 @@ namespace libtorrent { // http seed spec. by John Hoffman enum type_t { url_seed, http_seed }; - typedef std::vector> headers_t; + using headers_t = std::vector>; web_seed_entry(std::string const& url_, type_t type_ , std::string const& auth_ = std::string() @@ -351,8 +351,8 @@ namespace libtorrent { #ifndef TORRENT_NO_DEPRECATE // deprecated in 1.0. Use the variants that take an index instead // internal_file_entry is no longer exposed in the API - typedef file_storage::iterator file_iterator; - typedef file_storage::reverse_iterator reverse_file_iterator; + using file_iterator = file_storage::iterator; + using reverse_file_iterator = file_storage::reverse_iterator; // This class will need some explanation. First of all, to get a list of // all files in the torrent, you can use ``begin_files()``, diff --git a/include/libtorrent/tracker_manager.hpp b/include/libtorrent/tracker_manager.hpp index ac8b01c52..0f1543365 100644 --- a/include/libtorrent/tracker_manager.hpp +++ b/include/libtorrent/tracker_manager.hpp @@ -336,14 +336,14 @@ namespace libtorrent { { public: - typedef std::function - , error_code&, udp_send_flags_t)> send_fun_t; - typedef std::function; + using send_fun_hostname_t = std::function - , error_code&, udp_send_flags_t)> send_fun_hostname_t; + , error_code&, udp_send_flags_t)>; tracker_manager(send_fun_t const& send_fun , send_fun_hostname_t const& send_fun_hostname diff --git a/include/libtorrent/udp_socket.hpp b/include/libtorrent/udp_socket.hpp index fc1d135c9..3a5e33874 100644 --- a/include/libtorrent/udp_socket.hpp +++ b/include/libtorrent/udp_socket.hpp @@ -111,8 +111,8 @@ namespace libtorrent { return local_endpoint(ec); } - typedef udp::socket::receive_buffer_size receive_buffer_size; - typedef udp::socket::send_buffer_size send_buffer_size; + using receive_buffer_size = udp::socket::receive_buffer_size; + using send_buffer_size = udp::socket::send_buffer_size; template void get_option(SocketOption const& opt, error_code& ec) diff --git a/include/libtorrent/utp_socket_manager.hpp b/include/libtorrent/utp_socket_manager.hpp index c6d0e5fdb..e2860c1f8 100644 --- a/include/libtorrent/utp_socket_manager.hpp +++ b/include/libtorrent/utp_socket_manager.hpp @@ -141,7 +141,7 @@ namespace libtorrent { incoming_utp_callback_t m_cb; // replace with a hash-map - typedef std::multimap socket_map_t; + using socket_map_t = std::multimap; socket_map_t m_utp_sockets; using socket_vector_t = std::vector; diff --git a/include/libtorrent/utp_stream.hpp b/include/libtorrent/utp_stream.hpp index 883801ab0..fade8476f 100644 --- a/include/libtorrent/utp_stream.hpp +++ b/include/libtorrent/utp_stream.hpp @@ -98,12 +98,12 @@ namespace libtorrent { char m_storage[sizeof(T)]; }; - typedef big_endian_int be_uint64; - typedef big_endian_int be_uint32; - typedef big_endian_int be_uint16; - typedef big_endian_int be_int64; - typedef big_endian_int be_int32; - typedef big_endian_int be_int16; + using be_uint64 = big_endian_int; + using be_uint32 = big_endian_int; + using be_uint16 = big_endian_int; + using be_int64 = big_endian_int; + using be_int32 = big_endian_int; + using be_int16 = big_endian_int; /* uTP header from BEP 29 @@ -188,7 +188,7 @@ struct TORRENT_EXTRA_EXPORT utp_stream using protocol_type = tcp::socket::protocol_type; #if BOOST_VERSION >= 106600 - typedef tcp::socket::executor_type executor_type; + using executor_type = tcp::socket::executor_type; executor_type get_executor() { return m_io_service.get_executor(); } #endif diff --git a/src/allocator.cpp b/src/allocator.cpp index 0db3d3bde..e07741c6c 100644 --- a/src/allocator.cpp +++ b/src/allocator.cpp @@ -93,7 +93,7 @@ namespace libtorrent { return s; } - char* page_aligned_allocator::malloc(page_aligned_allocator::size_type bytes) + char* page_malloc(std::size_t bytes) { TORRENT_ASSERT(bytes > 0); // just sanity check (this needs to be pretty high @@ -147,7 +147,7 @@ namespace libtorrent { #endif // TORRENT_DEBUG_BUFFERS } - void page_aligned_allocator::free(char* block) + void page_free(char* block) { if (block == nullptr) return; @@ -187,7 +187,7 @@ namespace libtorrent { } #ifdef TORRENT_DEBUG_BUFFERS - bool page_aligned_allocator::in_use(char const* block) + bool page_in_use(char const* block) { const int page = page_size(); alloc_header const* h = reinterpret_cast(block - page); diff --git a/src/disk_buffer_pool.cpp b/src/disk_buffer_pool.cpp index b95c56efa..3f065223a 100644 --- a/src/disk_buffer_pool.cpp +++ b/src/disk_buffer_pool.cpp @@ -138,7 +138,7 @@ namespace libtorrent { #if TORRENT_USE_INVARIANT_CHECKS return m_buffers_in_use.count(buffer) == 1; #elif defined TORRENT_DEBUG_BUFFERS - return page_aligned_allocator::in_use(buffer); + return page_in_use(buffer); #else TORRENT_UNUSED(buffer); return true; @@ -227,7 +227,7 @@ namespace libtorrent { TORRENT_ASSERT(l.owns_lock()); TORRENT_UNUSED(l); - char* ret = page_aligned_allocator::malloc(default_block_size); + char* ret = page_malloc(default_block_size); if (ret == nullptr) { @@ -375,7 +375,7 @@ namespace libtorrent { TORRENT_ASSERT(l.owns_lock()); TORRENT_UNUSED(l); - page_aligned_allocator::free(buf); + page_free(buf); --m_in_use; } diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index fc7858392..3ab21dffb 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -1059,7 +1059,7 @@ constexpr disk_job_flags_t disk_interface::cache_hit; namespace { - typedef status_t (disk_io_thread::*disk_io_fun_t)(disk_io_job* j, jobqueue_t& completed_jobs); + using disk_io_fun_t = status_t (disk_io_thread::*)(disk_io_job*, jobqueue_t&); // this is a jump-table for disk I/O jobs std::array const job_functions = diff --git a/src/enum_net.cpp b/src/enum_net.cpp index 56cc7f73c..57250e9a6 100644 --- a/src/enum_net.cpp +++ b/src/enum_net.cpp @@ -506,7 +506,7 @@ int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldl { if (family == AF_INET) { - typedef boost::asio::ip::address_v4::bytes_type bytes_t; + using bytes_t = boost::asio::ip::address_v4::bytes_type; bytes_t b; std::memset(&b[0], 0xff, b.size()); for (int i = int(sizeof(bytes_t)) / 8 - 1; i > 0; --i) @@ -524,7 +524,7 @@ int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldl #if TORRENT_USE_IPV6 else if (family == AF_INET6) { - typedef boost::asio::ip::address_v6::bytes_type bytes_t; + using bytes_t = boost::asio::ip::address_v6::bytes_type; bytes_t b; std::memset(&b[0], 0xff, b.size()); for (int i = int(sizeof(bytes_t)) / 8 - 1; i > 0; --i) @@ -709,7 +709,7 @@ int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldl #elif TORRENT_USE_GETADAPTERSADDRESSES #if _WIN32_WINNT >= 0x0501 - typedef ULONG (WINAPI *GetAdaptersAddresses_t)(ULONG,ULONG,PVOID,PIP_ADAPTER_ADDRESSES,PULONG); + using GetAdaptersAddresses_t = ULONG (WINAPI *)(ULONG,ULONG,PVOID,PIP_ADAPTER_ADDRESSES,PULONG); // Get GetAdaptersAddresses() pointer auto GetAdaptersAddresses = aux::get_library_procedure("GetAdaptersAddresses"); @@ -1031,7 +1031,7 @@ int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldl /* move this to enum_net_interfaces // Get GetAdaptersInfo() pointer - typedef DWORD (WINAPI *GetAdaptersInfo_t)(PIP_ADAPTER_INFO, PULONG); + using GetAdaptersInfo_t = DWORD (WINAPI*)(PIP_ADAPTER_INFO, PULONG); GetAdaptersInfo_t GetAdaptersInfo = get_library_procedure("GetAdaptersInfo"); if (GetAdaptersInfo == nullptr) { @@ -1079,8 +1079,9 @@ int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldl free(adapter_info); */ - typedef DWORD (WINAPI *GetIfEntry_t)(PMIB_IFROW pIfRow); - auto GetIfEntry = aux::get_library_procedure("GetIfEntry"); + using GetIfEntry_t = DWORD (WINAPI *)(PMIB_IFROW pIfRow); + auto GetIfEntry = aux::get_library_procedure( + "GetIfEntry"); if (GetIfEntry == nullptr) { @@ -1089,9 +1090,9 @@ int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldl } #if _WIN32_WINNT >= 0x0600 - typedef DWORD (WINAPI *GetIpForwardTable2_t)( + using GetIpForwardTable2_t = DWORD (WINAPI *)( ADDRESS_FAMILY, PMIB_IPFORWARD_TABLE2*); - typedef void (WINAPI *FreeMibTable_t)(PVOID Memory); + using FreeMibTable_t = void (WINAPI *)(PVOID Memory); auto GetIpForwardTable2 = aux::get_library_procedure("GetIpForwardTable2"); auto FreeMibTable = aux::get_library_procedure("FreeMibTable"); @@ -1126,7 +1127,7 @@ int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldl #endif // Get GetIpForwardTable() pointer - typedef DWORD (WINAPI *GetIpForwardTable_t)(PMIB_IPFORWARDTABLE pIpForwardTable,PULONG pdwSize,BOOL bOrder); + using GetIpForwardTable_t = DWORD (WINAPI*)(PMIB_IPFORWARDTABLE pIpForwardTable,PULONG pdwSize,BOOL bOrder); auto GetIpForwardTable = aux::get_library_procedure("GetIpForwardTable"); if (GetIpForwardTable == nullptr) diff --git a/src/file.cpp b/src/file.cpp index dcfacc3c6..650daa7f2 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -1047,23 +1047,14 @@ namespace { #ifdef TORRENT_WINDOWS bool get_manage_volume_privs() { - typedef BOOL (WINAPI *OpenProcessToken_t)( - HANDLE ProcessHandle, - DWORD DesiredAccess, - PHANDLE TokenHandle); + using OpenProcessToken_t = BOOL (WINAPI*)( + HANDLE, DWORD, PHANDLE); - typedef BOOL (WINAPI *LookupPrivilegeValue_t)( - LPCSTR lpSystemName, - LPCSTR lpName, - PLUID lpLuid); + using LookupPrivilegeValue_t = BOOL (WINAPI*)( + LPCSTR, LPCSTR, PLUID); - typedef BOOL (WINAPI *AdjustTokenPrivileges_t)( - HANDLE TokenHandle, - BOOL DisableAllPrivileges, - PTOKEN_PRIVILEGES NewState, - DWORD BufferLength, - PTOKEN_PRIVILEGES PreviousState, - PDWORD ReturnLength); + using AdjustTokenPrivileges_t = BOOL (WINAPI*)( + HANDLE, BOOL, PTOKEN_PRIVILEGES, DWORD, PTOKEN_PRIVILEGES, PDWORD); auto OpenProcessToken = aux::get_library_procedure("OpenProcessToken"); @@ -1101,7 +1092,7 @@ namespace { void set_file_valid_data(HANDLE f, std::int64_t size) { - typedef BOOL (WINAPI *SetFileValidData_t)(HANDLE, LONGLONG); + using SetFileValidData_t = BOOL (WINAPI*)(HANDLE, LONGLONG); auto SetFileValidData = aux::get_library_procedure("SetFileValidData"); diff --git a/src/file_pool.cpp b/src/file_pool.cpp index 3e422851f..9cb75d5b0 100644 --- a/src/file_pool.cpp +++ b/src/file_pool.cpp @@ -55,7 +55,7 @@ namespace libtorrent { { // file prio is only supported on vista and up // so load the functions dynamically - typedef enum { + enum FILE_INFO_BY_HANDLE_CLASS_LOCAL { FileBasicInfo, FileStandardInfo, FileNameInfo, @@ -71,22 +71,24 @@ namespace libtorrent { FileIoPriorityHintInfo, FileRemoteProtocolInfo, MaximumFileInfoByHandleClass - } FILE_INFO_BY_HANDLE_CLASS_LOCAL; + }; - typedef enum { + enum PRIORITY_HINT_LOCAL { IoPriorityHintVeryLow = 0, IoPriorityHintLow, IoPriorityHintNormal, MaximumIoPriorityHintType - } PRIORITY_HINT_LOCAL; + }; - typedef struct { + struct FILE_IO_PRIORITY_HINT_INFO_LOCAL { PRIORITY_HINT_LOCAL PriorityHint; - } FILE_IO_PRIORITY_HINT_INFO_LOCAL; + }; - typedef BOOL (WINAPI *SetFileInformationByHandle_t)(HANDLE hFile, FILE_INFO_BY_HANDLE_CLASS_LOCAL FileInformationClass, LPVOID lpFileInformation, DWORD dwBufferSize); + using SetFileInformationByHandle_t = BOOL (WINAPI *)(HANDLE + , FILE_INFO_BY_HANDLE_CLASS_LOCAL, LPVOID, DWORD); auto SetFileInformationByHandle = - aux::get_library_procedure("SetFileInformationByHandle"); + aux::get_library_procedure( + "SetFileInformationByHandle"); if (SetFileInformationByHandle == nullptr) return; diff --git a/src/piece_picker.cpp b/src/piece_picker.cpp index 84441d5ea..ec142df2b 100644 --- a/src/piece_picker.cpp +++ b/src/piece_picker.cpp @@ -3452,10 +3452,10 @@ get_out: m_pad_blocks.insert(block); // if we mark and entire piece as a pad file, we need to also // consder that piece as "had" and increment some counters - typedef std::set::iterator iter; - iter begin = m_pad_blocks.lower_bound(piece_block(block.piece_index, 0)); + using iter = std::set::const_iterator; + iter const begin = m_pad_blocks.lower_bound(piece_block(block.piece_index, 0)); int const blocks = blocks_in_piece(block.piece_index); - iter end = m_pad_blocks.upper_bound(piece_block(block.piece_index, blocks)); + iter const end = m_pad_blocks.upper_bound(piece_block(block.piece_index, blocks)); if (std::distance(begin, end) == blocks) { // the entire piece is a pad file diff --git a/src/settings_pack.cpp b/src/settings_pack.cpp index 533c617ed..5f85d42a1 100644 --- a/src/settings_pack.cpp +++ b/src/settings_pack.cpp @@ -449,7 +449,7 @@ constexpr int CLOSE_FILE_INTERVAL = 0; void run_all_updates(aux::session_impl& ses) { - typedef void (aux::session_impl::*fun_t)(); + using fun_t = void (aux::session_impl::*)(); for (int i = 0; i < settings_pack::num_string_settings; ++i) { fun_t const& f = str_settings[i].fun; @@ -516,7 +516,7 @@ constexpr int CLOSE_FILE_INTERVAL = 0; void apply_pack(settings_pack const* pack, aux::session_settings& sett , aux::session_impl* ses) { - typedef void (aux::session_impl::*fun_t)(); + using fun_t = void (aux::session_impl::*)(); std::vector callbacks; for (auto const& p : pack->m_strings) diff --git a/src/sha1.cpp b/src/sha1.cpp index 8348e1359..d1e84da5f 100644 --- a/src/sha1.cpp +++ b/src/sha1.cpp @@ -19,13 +19,13 @@ changelog at the end of the file. #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; - namespace libtorrent { namespace { +using u32 = std::uint32_t; +using u8 = std::uint8_t; + union CHAR64LONG16 { u8 c[64]; diff --git a/src/sha512.cpp b/src/sha512.cpp index 40836beba..64aa61250 100644 --- a/src/sha512.cpp +++ b/src/sha512.cpp @@ -160,7 +160,7 @@ static int sha512_compress(sha512_ctx *md, unsigned char *buf) @return 0 if successful */ int SHA512_init(sha512_ctx* md) { - if (md == NULL) return 1; + if (md == nullptr) return 1; md->curlen = 0; md->length = 0; @@ -188,8 +188,8 @@ int SHA512_update(sha512_ctx* md, std::uint8_t const* in, std::size_t inlen) std::size_t n; std::size_t i; int err; - if (md == NULL) return 1; - if (in == NULL) return 1; + if (md == nullptr) return 1; + if (in == nullptr) return 1; if (md->curlen > sizeof(md->buf)) { return 1; } @@ -234,8 +234,8 @@ int SHA512_final(std::uint8_t* out, sha512_ctx* md) { int i; - if (md == NULL) return 1; - if (out == NULL) return 1; + if (md == nullptr) return 1; + if (out == nullptr) return 1; if (md->curlen >= sizeof(md->buf)) { return 1; diff --git a/src/socket_type.cpp b/src/socket_type.cpp index 467f9343a..bf0b62b2c 100644 --- a/src/socket_type.cpp +++ b/src/socket_type.cpp @@ -196,7 +196,7 @@ namespace aux { void socket_type::destruct() { - typedef tcp::socket tcp_socket; + using tcp_socket = tcp::socket; switch (m_type) { case 0: break; diff --git a/test/setup_transfer.cpp b/test/setup_transfer.cpp index adf05b7bb..f45947ef5 100644 --- a/test/setup_transfer.cpp +++ b/test/setup_transfer.cpp @@ -320,7 +320,7 @@ void wait_for_listen(lt::session& ses, char const* name) alert const* a = nullptr; do { - listen_done = print_alerts(ses, name, true, true, [&listen_done](lt::alert const* al) + listen_done = print_alerts(ses, name, true, true, [](lt::alert const* al) { return alert_cast(al) || alert_cast(al); } , false); if (listen_done) break; @@ -338,7 +338,7 @@ void wait_for_downloading(lt::session& ses, char const* name) do { downloading_done = print_alerts(ses, name, true, true - , [&downloading_done](lt::alert const* al) + , [](lt::alert const* al) { state_changed_alert const* sc = alert_cast(al); return sc && sc->state == torrent_status::downloading; @@ -391,9 +391,9 @@ void print_ses_rate(float const time } #ifdef _WIN32 -typedef DWORD pid_type; +using pid_type = DWORD; #else -typedef pid_t pid_type; +using pid_type = pid_t; #endif namespace { diff --git a/test/test.hpp b/test/test.hpp index 7a83dd523..9b1457d72 100644 --- a/test/test.hpp +++ b/test/test.hpp @@ -75,7 +75,7 @@ int EXPORT print_failures(); int EXPORT test_counter(); void EXPORT reset_output(); -typedef void (*unit_test_fun_t)(); +using unit_test_fun_t = void (*)(); struct unit_test_t { @@ -100,7 +100,7 @@ extern int _g_test_idx; t.name = __FILE__ "." #test_name; \ t.num_failures = 0; \ t.run = false; \ - t.output = NULL; \ + t.output = nullptr; \ _g_num_unit_tests++; \ } \ } BOOST_PP_CAT(_static_registrar_, test_name); \ diff --git a/test/test_bandwidth_limiter.cpp b/test/test_bandwidth_limiter.cpp index 986b4e217..4d99f3a3d 100644 --- a/test/test_bandwidth_limiter.cpp +++ b/test/test_bandwidth_limiter.cpp @@ -113,7 +113,7 @@ void peer_connection::start() } -typedef std::vector> connections_t; +using connections_t = std::vector>; void do_change_rate(bandwidth_channel& t1, bandwidth_channel& t2, int limit) { diff --git a/test/test_buffer.cpp b/test/test_buffer.cpp index 9cf834b11..61dd86baf 100644 --- a/test/test_buffer.cpp +++ b/test/test_buffer.cpp @@ -212,7 +212,7 @@ TORRENT_TEST(chained_buffer) // there are no buffers, we should not be able to allocate // an appendix in an existing buffer - TEST_EQUAL(b.allocate_appendix(1), 0); + TEST_EQUAL(b.allocate_appendix(1), static_cast(nullptr)); char* b1 = allocate_buffer(512); std::memcpy(b1, data_test, 6); diff --git a/test/test_http_connection.cpp b/test/test_http_connection.cpp index dbf15c679..923a1d497 100644 --- a/test/test_http_connection.cpp +++ b/test/test_http_connection.cpp @@ -184,7 +184,7 @@ void run_suite(std::string const& protocol if (ps.type != settings_pack::none) ps.port = aux::numeric_cast(start_proxy(ps.type)); - typedef boost::optional err; + using err = boost::optional; char url[256]; std::snprintf(url, sizeof(url), "%s://127.0.0.1:%d/", protocol.c_str(), port); diff --git a/test/test_http_parser.cpp b/test/test_http_parser.cpp index 00accebb5..d7813b198 100644 --- a/test/test_http_parser.cpp +++ b/test/test_http_parser.cpp @@ -239,7 +239,7 @@ TORRENT_TEST(http_parser) TEST_CHECK(parser.header("content-type") == "text/plain"); TEST_CHECK(atoi(parser.header("content-length").c_str()) == 20); TEST_CHECK(parser.chunked_encoding()); - typedef std::pair chunk_range; + using chunk_range = std::pair; std::vector cmp; cmp.push_back(chunk_range(96, 100)); cmp.push_back(chunk_range(106, 122)); diff --git a/test/test_piece_picker.cpp b/test/test_piece_picker.cpp index 32f384626..eb854b084 100644 --- a/test/test_piece_picker.cpp +++ b/test/test_piece_picker.cpp @@ -183,7 +183,7 @@ std::shared_ptr setup_picker( int const idx = static_cast(i); if (priority[idx] == 0) break; download_priority_t const prio((priority[idx] - '0') & 0xff); - assert(prio >= dont_download); + TEST_CHECK(prio >= dont_download); p->set_piece_priority(i, prio); TEST_CHECK(p->piece_priority(i) == prio); @@ -2067,10 +2067,10 @@ TORRENT_TEST(mark_as_pad_whole_piece_seeding) TEST_CHECK(!p->is_seeding()); - p->mark_as_finished({piece_index_t{1}, 0}, NULL); - p->mark_as_finished({piece_index_t{1}, 1}, NULL); - p->mark_as_finished({piece_index_t{1}, 2}, NULL); - p->mark_as_finished({piece_index_t{1}, 3}, NULL); + p->mark_as_finished({piece_index_t{1}, 0}, nullptr); + p->mark_as_finished({piece_index_t{1}, 1}, nullptr); + p->mark_as_finished({piece_index_t{1}, 2}, nullptr); + p->mark_as_finished({piece_index_t{1}, 3}, nullptr); TEST_CHECK(!p->is_seeding()); p->piece_passed(piece_index_t{1}); diff --git a/test/test_remove_torrent.cpp b/test/test_remove_torrent.cpp index d4921fafc..29ecb6236 100644 --- a/test/test_remove_torrent.cpp +++ b/test/test_remove_torrent.cpp @@ -91,8 +91,8 @@ void test_remove_torrent(remove_flags_t const remove_options wait_for_listen(ses2, "ses2"); // test using piece sizes smaller than 16kB - std::tie(tor1, tor2, ignore) = setup_transfer(&ses1, &ses2, 0 - , true, false, true, "_remove", 8 * 1024, &t, false, 0); + std::tie(tor1, tor2, ignore) = setup_transfer(&ses1, &ses2, nullptr + , true, false, true, "_remove", 8 * 1024, &t, false, nullptr); if (test == partial_download) { diff --git a/tools/parse_access_log.cpp b/tools/parse_access_log.cpp index 7ec26057e..3046347fa 100644 --- a/tools/parse_access_log.cpp +++ b/tools/parse_access_log.cpp @@ -76,7 +76,7 @@ int main(int argc, char* argv[]) FILE* reads_elev_file = std::fopen("reads_elevator.log", "w+"); - typedef std::map op_map; + using op_map = std::map; op_map outstanding_ops; std::uint64_t first_timestamp = 0;