From 3803661863f40421b63fc067f194d3ff7906aba2 Mon Sep 17 00:00:00 2001 From: Alden Torres Date: Fri, 27 Jan 2017 12:43:34 -0500 Subject: [PATCH] moved alloca.hpp to private aux_ and size refactor (#1634) moved alloca.hpp to private aux_ and size refactor --- include/libtorrent/Makefile.am | 2 +- include/libtorrent/{ => aux_}/alloca.hpp | 16 ++++++++++------ include/libtorrent/aux_/numeric_cast.hpp | 1 + src/bdecode.cpp | 2 +- src/block_cache.cpp | 2 +- src/bt_peer_connection.cpp | 2 +- src/disk_io_thread.cpp | 2 +- src/file.cpp | 2 +- src/pe_crypto.cpp | 2 +- src/peer_connection.cpp | 2 +- src/piece_picker.cpp | 2 +- src/storage_utils.cpp | 2 +- src/torrent.cpp | 2 +- src/utp_stream.cpp | 2 +- test/test_fast_extension.cpp | 2 +- 15 files changed, 24 insertions(+), 19 deletions(-) rename include/libtorrent/{ => aux_}/alloca.hpp (71%) diff --git a/include/libtorrent/Makefile.am b/include/libtorrent/Makefile.am index 414f55d6d..d34165725 100644 --- a/include/libtorrent/Makefile.am +++ b/include/libtorrent/Makefile.am @@ -6,7 +6,6 @@ nobase_include_HEADERS = \ alert.hpp \ alert_manager.hpp \ alert_types.hpp \ - alloca.hpp \ allocator.hpp \ announce_entry.hpp \ assert.hpp \ @@ -196,6 +195,7 @@ nobase_include_HEADERS = \ aux_/storage_utils.hpp \ aux_/numeric_cast.hpp \ aux_/unique_ptr.hpp \ + aux_/alloca.hpp \ \ extensions/smart_ban.hpp \ extensions/ut_metadata.hpp \ diff --git a/include/libtorrent/alloca.hpp b/include/libtorrent/aux_/alloca.hpp similarity index 71% rename from include/libtorrent/alloca.hpp rename to include/libtorrent/aux_/alloca.hpp index 2b3b4b6d1..b09cf1aaf 100644 --- a/include/libtorrent/alloca.hpp +++ b/include/libtorrent/aux_/alloca.hpp @@ -34,27 +34,31 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/config.hpp" #include "libtorrent/span.hpp" +#include "libtorrent/aux_/numeric_cast.hpp" #if defined TORRENT_WINDOWS || defined TORRENT_MINGW #include #define TORRENT_ALLOCA(v, t, n) ::libtorrent::span v; { \ - t* TORRENT_ALLOCA_tmp = static_cast(_alloca(sizeof(t) * (std::size_t(n)))); \ - v = ::libtorrent::span(TORRENT_ALLOCA_tmp, std::size_t(n)); } + std::size_t TORRENT_ALLOCA_size = ::libtorrent::aux::numeric_cast(n); \ + t* TORRENT_ALLOCA_tmp = static_cast(_alloca(sizeof(t) * TORRENT_ALLOCA_size)); \ + v = ::libtorrent::span(TORRENT_ALLOCA_tmp, TORRENT_ALLOCA_size); } #elif defined TORRENT_BSD #include #define TORRENT_ALLOCA(v, t, n) ::libtorrent::span v; { \ - t* TORRENT_ALLOCA_tmp = static_cast(alloca(sizeof(t) * (std::size_t(n)))); \ - v = ::libtorrent::span(TORRENT_ALLOCA_tmp, std::size_t(n)); } + std::size_t TORRENT_ALLOCA_size = ::libtorrent::aux::numeric_cast(n); \ + t* TORRENT_ALLOCA_tmp = static_cast(alloca(sizeof(t) * TORRENT_ALLOCA_size)); \ + v = ::libtorrent::span(TORRENT_ALLOCA_tmp, TORRENT_ALLOCA_size); } #else #include #define TORRENT_ALLOCA(v, t, n) ::libtorrent::span v; { \ - t* TORRENT_ALLOCA_tmp = static_cast(alloca(sizeof(t) * (std::size_t(n)))); \ - v = ::libtorrent::span(TORRENT_ALLOCA_tmp, std::size_t(n)); } + std::size_t TORRENT_ALLOCA_size = ::libtorrent::aux::numeric_cast(n); \ + t* TORRENT_ALLOCA_tmp = static_cast(alloca(sizeof(t) * TORRENT_ALLOCA_size)); \ + v = ::libtorrent::span(TORRENT_ALLOCA_tmp, TORRENT_ALLOCA_size); } #endif diff --git a/include/libtorrent/aux_/numeric_cast.hpp b/include/libtorrent/aux_/numeric_cast.hpp index bb367e25a..b48aea7bf 100644 --- a/include/libtorrent/aux_/numeric_cast.hpp +++ b/include/libtorrent/aux_/numeric_cast.hpp @@ -34,6 +34,7 @@ POSSIBILITY OF SUCH DAMAGE. #define TORRENT_NUMERIC_CAST_HPP #include +#include #include "libtorrent/assert.hpp" diff --git a/src/bdecode.cpp b/src/bdecode.cpp index 607c9d858..bec22a8db 100644 --- a/src/bdecode.cpp +++ b/src/bdecode.cpp @@ -31,7 +31,7 @@ POSSIBILITY OF SUCH DAMAGE. */ #include "libtorrent/bdecode.hpp" -#include "libtorrent/alloca.hpp" +#include "libtorrent/aux_/alloca.hpp" #include "libtorrent/aux_/numeric_cast.hpp" #include #include // for memset diff --git a/src/block_cache.cpp b/src/block_cache.cpp index 0f088df57..226422466 100644 --- a/src/block_cache.cpp +++ b/src/block_cache.cpp @@ -38,7 +38,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/error.hpp" #include "libtorrent/disk_io_thread.hpp" // disk_operation_failed #include "libtorrent/invariant_check.hpp" -#include "libtorrent/alloca.hpp" +#include "libtorrent/aux_/alloca.hpp" #include "libtorrent/performance_counters.hpp" #include "libtorrent/aux_/time.hpp" #include "libtorrent/aux_/block_cache_reference.hpp" diff --git a/src/bt_peer_connection.cpp b/src/bt_peer_connection.cpp index 2418286e4..2765ce381 100644 --- a/src/bt_peer_connection.cpp +++ b/src/bt_peer_connection.cpp @@ -64,7 +64,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/broadcast_socket.hpp" #include "libtorrent/peer_info.hpp" #include "libtorrent/random.hpp" -#include "libtorrent/alloca.hpp" +#include "libtorrent/aux_/alloca.hpp" #include "libtorrent/socket_type.hpp" #include "libtorrent/performance_counters.hpp" // for counters diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index e17016c32..b05508aea 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -35,7 +35,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/disk_io_thread.hpp" #include "libtorrent/string_util.hpp" // for allocate_string_copy #include "libtorrent/disk_buffer_holder.hpp" -#include "libtorrent/alloca.hpp" +#include "libtorrent/aux_/alloca.hpp" #include "libtorrent/error_code.hpp" #include "libtorrent/error.hpp" #include "libtorrent/file_pool.hpp" diff --git a/src/file.cpp b/src/file.cpp index 35fb2b182..499a8845a 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -67,7 +67,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/aux_/disable_warnings_pop.hpp" #include "libtorrent/config.hpp" -#include "libtorrent/alloca.hpp" +#include "libtorrent/aux_/alloca.hpp" #include "libtorrent/file.hpp" #include "libtorrent/string_util.hpp" #include "libtorrent/aux_/max_path.hpp" // for TORRENT_MAX_PATH diff --git a/src/pe_crypto.cpp b/src/pe_crypto.cpp index ed2b3f503..e81a65784 100644 --- a/src/pe_crypto.cpp +++ b/src/pe_crypto.cpp @@ -50,7 +50,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/aux_/disable_warnings_pop.hpp" #include "libtorrent/random.hpp" -#include "libtorrent/alloca.hpp" +#include "libtorrent/aux_/alloca.hpp" #include "libtorrent/pe_crypto.hpp" #include "libtorrent/hasher.hpp" diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index e9c0494f5..debab96b6 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -52,7 +52,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/peer_info.hpp" #include "libtorrent/bt_peer_connection.hpp" #include "libtorrent/error.hpp" -#include "libtorrent/alloca.hpp" +#include "libtorrent/aux_/alloca.hpp" #include "libtorrent/disk_interface.hpp" #include "libtorrent/bandwidth_manager.hpp" #include "libtorrent/request_blocks.hpp" // for request_a_block diff --git a/src/piece_picker.cpp b/src/piece_picker.cpp index 99201572f..e546c9566 100644 --- a/src/piece_picker.cpp +++ b/src/piece_picker.cpp @@ -41,7 +41,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/piece_picker.hpp" #include "libtorrent/bitfield.hpp" #include "libtorrent/random.hpp" -#include "libtorrent/alloca.hpp" +#include "libtorrent/aux_/alloca.hpp" #include "libtorrent/aux_/range.hpp" #include "libtorrent/performance_counters.hpp" // for counters #include "libtorrent/alert_types.hpp" // for picker_log_alert diff --git a/src/storage_utils.cpp b/src/storage_utils.cpp index 213d367a3..dc4c00963 100644 --- a/src/storage_utils.cpp +++ b/src/storage_utils.cpp @@ -32,7 +32,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/aux_/storage_utils.hpp" #include "libtorrent/file_storage.hpp" -#include "libtorrent/alloca.hpp" +#include "libtorrent/aux_/alloca.hpp" #include "libtorrent/file.hpp" // for count_bufs #include "libtorrent/part_file.hpp" #include "libtorrent/session.hpp" // for session::delete_files diff --git a/src/torrent.cpp b/src/torrent.cpp index fcd224d49..b41e97dfc 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -86,7 +86,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/request_blocks.hpp" #include "libtorrent/performance_counters.hpp" // for counters #include "libtorrent/resolver_interface.hpp" -#include "libtorrent/alloca.hpp" +#include "libtorrent/aux_/alloca.hpp" #include "libtorrent/resolve_links.hpp" #include "libtorrent/aux_/file_progress.hpp" #include "libtorrent/aux_/has_block.hpp" diff --git a/src/utp_stream.cpp b/src/utp_stream.cpp index 92f96d64f..ce10de7ea 100644 --- a/src/utp_stream.cpp +++ b/src/utp_stream.cpp @@ -34,7 +34,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/utp_stream.hpp" #include "libtorrent/sliding_average.hpp" #include "libtorrent/utp_socket_manager.hpp" -#include "libtorrent/alloca.hpp" +#include "libtorrent/aux_/alloca.hpp" #include "libtorrent/timestamp_history.hpp" #include "libtorrent/error.hpp" #include "libtorrent/random.hpp" diff --git a/test/test_fast_extension.cpp b/test/test_fast_extension.cpp index 4c44a15a9..48c4466d6 100644 --- a/test/test_fast_extension.cpp +++ b/test/test_fast_extension.cpp @@ -36,7 +36,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/socket.hpp" #include "libtorrent/io.hpp" -#include "libtorrent/alloca.hpp" +#include "libtorrent/aux_/alloca.hpp" // for use of private TORRENT_ALLOCA #include "libtorrent/time.hpp" #include "libtorrent/peer_info.hpp" #include "libtorrent/bdecode.hpp"