From ccdfd7383e2a5d94c809986e89d4a0f3698739d2 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sun, 13 May 2018 21:59:50 +0200 Subject: [PATCH] move export.hpp into aux_ folder. put assert symbols in libtorrent namespace --- CMakeLists.txt | 2 +- bindings/c/library.cpp | 2 +- include/libtorrent/Makefile.am | 2 +- include/libtorrent/assert.hpp | 16 ++++++++------ include/libtorrent/{ => aux_}/export.hpp | 0 include/libtorrent/aux_/ffs.hpp | 2 +- include/libtorrent/aux_/file_progress.hpp | 2 +- include/libtorrent/aux_/storage_piece_set.hpp | 2 +- include/libtorrent/bandwidth_socket.hpp | 2 +- include/libtorrent/config.hpp | 2 +- include/libtorrent/crc32c.hpp | 2 +- include/libtorrent/disk_interface.hpp | 2 +- include/libtorrent/disk_io_thread_pool.hpp | 2 +- include/libtorrent/ed25519.hpp | 2 +- include/libtorrent/fingerprint.hpp | 2 +- include/libtorrent/read_resume_data.hpp | 2 +- include/libtorrent/resolve_links.hpp | 2 +- include/libtorrent/utf8.hpp | 2 +- include/libtorrent/version.hpp | 2 +- include/libtorrent/write_resume_data.hpp | 2 +- simulation/test_error_handling.cpp | 2 +- src/assert.cpp | 21 +++++++++++++++++++ 22 files changed, 50 insertions(+), 25 deletions(-) rename include/libtorrent/{ => aux_}/export.hpp (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index e10a09c08..1928e0238 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,7 +56,6 @@ set(libtorrent_include_files enum_net error error_code - export extensions file file_pool @@ -223,6 +222,7 @@ set(libtorrent_aux_include_files disable_warnings_push disk_job_fence escape_string + export ffs file_progress has_block diff --git a/bindings/c/library.cpp b/bindings/c/library.cpp index 5e9a30dbe..abddb54f3 100644 --- a/bindings/c/library.cpp +++ b/bindings/c/library.cpp @@ -290,7 +290,7 @@ TORRENT_EXPORT void session_remove_torrent(void* ses, int tor, int flags) if (!h.is_valid()) return; session* s = (session*)ses; - s->remove_torrent(h, flags); + s->remove_torrent(h, flags); } TORRENT_EXPORT int session_pop_alert(void* ses, char* dest, int len, int* category) diff --git a/include/libtorrent/Makefile.am b/include/libtorrent/Makefile.am index f75f6178d..27940789f 100644 --- a/include/libtorrent/Makefile.am +++ b/include/libtorrent/Makefile.am @@ -44,7 +44,6 @@ nobase_include_HEADERS = \ enum_net.hpp \ error.hpp \ error_code.hpp \ - export.hpp \ extensions.hpp \ file.hpp \ file_pool.hpp \ @@ -175,6 +174,7 @@ nobase_include_HEADERS = \ aux_/dev_random.hpp \ aux_/deque.hpp \ aux_/escape_string.hpp \ + aux_/export.hpp \ aux_/io.hpp \ aux_/listen_socket_handle.hpp \ aux_/max_path.hpp \ diff --git a/include/libtorrent/assert.hpp b/include/libtorrent/assert.hpp index 5e02d8b1e..bb2df5d18 100644 --- a/include/libtorrent/assert.hpp +++ b/include/libtorrent/assert.hpp @@ -33,6 +33,7 @@ POSSIBILITY OF SUCH DAMAGE. #ifndef TORRENT_ASSERT #include "libtorrent/config.hpp" +#include "libtorrent/aux_/export.hpp" #if TORRENT_USE_ASSERTS \ || defined TORRENT_ASIO_DEBUGGING \ @@ -40,8 +41,10 @@ POSSIBILITY OF SUCH DAMAGE. || defined TORRENT_DEBUG_BUFFERS #include +namespace libtorrent { std::string demangle(char const* name); TORRENT_EXPORT void print_backtrace(char* out, int len, int max_depth = 0, void* ctx = nullptr); +} #endif // this is to disable the warning of conditional expressions @@ -57,6 +60,7 @@ TORRENT_EXPORT void print_backtrace(char* out, int len, int max_depth = 0, void* #endif +namespace libtorrent { // declarations of the two functions // internal @@ -66,7 +70,7 @@ TORRENT_EXPORT void assert_print(char const* fmt, ...) TORRENT_FORMAT(1,2); TORRENT_EXPORT void assert_fail(const char* expr, int line , char const* file, char const* function, char const* val, int kind = 0); - +} #if TORRENT_USE_ASSERTS @@ -81,19 +85,19 @@ extern TORRENT_EXPORT char const* libtorrent_assert_log; #ifndef TORRENT_USE_SYSTEM_ASSERTS #define TORRENT_ASSERT_PRECOND(x) \ - do { if (x) {} else assert_fail(#x, __LINE__, __FILE__, TORRENT_FUNCTION, nullptr, 1); } TORRENT_WHILE_0 + do { if (x) {} else libtorrent::assert_fail(#x, __LINE__, __FILE__, TORRENT_FUNCTION, nullptr, 1); } TORRENT_WHILE_0 #define TORRENT_ASSERT(x) \ - do { if (x) {} else assert_fail(#x, __LINE__, __FILE__, TORRENT_FUNCTION, nullptr, 0); } TORRENT_WHILE_0 + do { if (x) {} else libtorrent::assert_fail(#x, __LINE__, __FILE__, TORRENT_FUNCTION, nullptr, 0); } TORRENT_WHILE_0 #if TORRENT_USE_IOSTREAM #define TORRENT_ASSERT_VAL(x, y) \ do { if (x) {} else { std::stringstream __s__; __s__ << #y ": " << y; \ - assert_fail(#x, __LINE__, __FILE__, TORRENT_FUNCTION, __s__.str().c_str(), 0); } } TORRENT_WHILE_0 + libtorrent::assert_fail(#x, __LINE__, __FILE__, TORRENT_FUNCTION, __s__.str().c_str(), 0); } } TORRENT_WHILE_0 #define TORRENT_ASSERT_FAIL_VAL(y) \ do { std::stringstream __s__; __s__ << #y ": " << y; \ - assert_fail("", __LINE__, __FILE__, TORRENT_FUNCTION, __s__.str().c_str(), 0); } TORRENT_WHILE_0 + libtorrent::assert_fail("", __LINE__, __FILE__, TORRENT_FUNCTION, __s__.str().c_str(), 0); } TORRENT_WHILE_0 #else #define TORRENT_ASSERT_VAL(x, y) TORRENT_ASSERT(x) @@ -101,7 +105,7 @@ extern TORRENT_EXPORT char const* libtorrent_assert_log; #endif #define TORRENT_ASSERT_FAIL() \ - assert_fail("", __LINE__, __FILE__, TORRENT_FUNCTION, nullptr, 0) + libtorrent::assert_fail("", __LINE__, __FILE__, TORRENT_FUNCTION, nullptr, 0) #else #include diff --git a/include/libtorrent/export.hpp b/include/libtorrent/aux_/export.hpp similarity index 100% rename from include/libtorrent/export.hpp rename to include/libtorrent/aux_/export.hpp diff --git a/include/libtorrent/aux_/ffs.hpp b/include/libtorrent/aux_/ffs.hpp index 88d05aab2..12ffba387 100644 --- a/include/libtorrent/aux_/ffs.hpp +++ b/include/libtorrent/aux_/ffs.hpp @@ -34,7 +34,7 @@ POSSIBILITY OF SUCH DAMAGE. #define TORRENT_FFS_HPP_INCLUDE #include -#include "libtorrent/export.hpp" +#include "libtorrent/aux_/export.hpp" #include "libtorrent/span.hpp" namespace libtorrent { namespace aux { diff --git a/include/libtorrent/aux_/file_progress.hpp b/include/libtorrent/aux_/file_progress.hpp index 6ec8bb6a1..a63299c85 100644 --- a/include/libtorrent/aux_/file_progress.hpp +++ b/include/libtorrent/aux_/file_progress.hpp @@ -36,7 +36,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include -#include "libtorrent/export.hpp" +#include "libtorrent/aux_/export.hpp" #include "libtorrent/units.hpp" #include "libtorrent/aux_/vector.hpp" diff --git a/include/libtorrent/aux_/storage_piece_set.hpp b/include/libtorrent/aux_/storage_piece_set.hpp index 9073d95aa..ad058484c 100644 --- a/include/libtorrent/aux_/storage_piece_set.hpp +++ b/include/libtorrent/aux_/storage_piece_set.hpp @@ -37,7 +37,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include "libtorrent/aux_/disable_warnings_pop.hpp" -#include "libtorrent/export.hpp" +#include "libtorrent/aux_/export.hpp" #include "libtorrent/block_cache.hpp" // for cached_piece_entry namespace libtorrent { diff --git a/include/libtorrent/bandwidth_socket.hpp b/include/libtorrent/bandwidth_socket.hpp index 72fc81e41..ddf963781 100644 --- a/include/libtorrent/bandwidth_socket.hpp +++ b/include/libtorrent/bandwidth_socket.hpp @@ -33,7 +33,7 @@ POSSIBILITY OF SUCH DAMAGE. #ifndef TORRENT_BANDWIDTH_SOCKET_HPP_INCLUDED #define TORRENT_BANDWIDTH_SOCKET_HPP_INCLUDED -#include "libtorrent/export.hpp" +#include "libtorrent/aux_/export.hpp" namespace libtorrent { diff --git a/include/libtorrent/config.hpp b/include/libtorrent/config.hpp index 392a234e1..2117327e9 100644 --- a/include/libtorrent/config.hpp +++ b/include/libtorrent/config.hpp @@ -43,7 +43,7 @@ POSSIBILITY OF SUCH DAMAGE. // TODO: don't include that here. Make each header that use the export macros // include it instead. and move it to aux_ -#include "libtorrent/export.hpp" +#include "libtorrent/aux_/export.hpp" #ifdef __linux__ #include // for LINUX_VERSION_CODE and KERNEL_VERSION diff --git a/include/libtorrent/crc32c.hpp b/include/libtorrent/crc32c.hpp index c4f10ed85..20a365a41 100644 --- a/include/libtorrent/crc32c.hpp +++ b/include/libtorrent/crc32c.hpp @@ -34,7 +34,7 @@ POSSIBILITY OF SUCH DAMAGE. #define TORRENT_CRC32C_HPP_INCLUDE #include -#include "libtorrent/export.hpp" +#include "libtorrent/aux_/export.hpp" namespace libtorrent { diff --git a/include/libtorrent/disk_interface.hpp b/include/libtorrent/disk_interface.hpp index 23ec7779d..9d9494a71 100644 --- a/include/libtorrent/disk_interface.hpp +++ b/include/libtorrent/disk_interface.hpp @@ -42,7 +42,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/units.hpp" #include "libtorrent/disk_buffer_holder.hpp" #include "libtorrent/aux_/vector.hpp" -#include "libtorrent/export.hpp" +#include "libtorrent/aux_/export.hpp" #include "libtorrent/storage_defs.hpp" #include "libtorrent/time.hpp" #include "libtorrent/sha1_hash.hpp" diff --git a/include/libtorrent/disk_io_thread_pool.hpp b/include/libtorrent/disk_io_thread_pool.hpp index 810e819e7..5b4e6315a 100644 --- a/include/libtorrent/disk_io_thread_pool.hpp +++ b/include/libtorrent/disk_io_thread_pool.hpp @@ -34,7 +34,7 @@ POSSIBILITY OF SUCH DAMAGE. #define TORRENT_DISK_IO_THREAD_POOL #include "libtorrent/config.hpp" -#include "libtorrent/export.hpp" +#include "libtorrent/aux_/export.hpp" #include "libtorrent/deadline_timer.hpp" #include "libtorrent/io_service_fwd.hpp" #include "libtorrent/error_code.hpp" diff --git a/include/libtorrent/ed25519.hpp b/include/libtorrent/ed25519.hpp index 654ed8f74..8b89c307b 100644 --- a/include/libtorrent/ed25519.hpp +++ b/include/libtorrent/ed25519.hpp @@ -1,7 +1,7 @@ #ifndef ED25519_HPP #define ED25519_HPP -#include "libtorrent/export.hpp" // for TORRENT_EXPORT +#include "libtorrent/aux_/export.hpp" // for TORRENT_EXPORT #include // for size_t namespace libtorrent { diff --git a/include/libtorrent/fingerprint.hpp b/include/libtorrent/fingerprint.hpp index 20a380400..cf33f8645 100644 --- a/include/libtorrent/fingerprint.hpp +++ b/include/libtorrent/fingerprint.hpp @@ -38,7 +38,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/config.hpp" #include "libtorrent/peer_id.hpp" -#include "libtorrent/export.hpp" +#include "libtorrent/aux_/export.hpp" namespace libtorrent { diff --git a/include/libtorrent/read_resume_data.hpp b/include/libtorrent/read_resume_data.hpp index 6d2d9f136..87c21b4d6 100644 --- a/include/libtorrent/read_resume_data.hpp +++ b/include/libtorrent/read_resume_data.hpp @@ -35,7 +35,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/fwd.hpp" #include "libtorrent/error_code.hpp" -#include "libtorrent/export.hpp" +#include "libtorrent/aux_/export.hpp" #include "libtorrent/span.hpp" namespace libtorrent { diff --git a/include/libtorrent/resolve_links.hpp b/include/libtorrent/resolve_links.hpp index 77036c12b..e5775aa5d 100644 --- a/include/libtorrent/resolve_links.hpp +++ b/include/libtorrent/resolve_links.hpp @@ -39,7 +39,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include -#include "libtorrent/export.hpp" +#include "libtorrent/aux_/export.hpp" #include "libtorrent/units.hpp" #include "libtorrent/aux_/vector.hpp" diff --git a/include/libtorrent/utf8.hpp b/include/libtorrent/utf8.hpp index a2f546c0c..22f929ee1 100644 --- a/include/libtorrent/utf8.hpp +++ b/include/libtorrent/utf8.hpp @@ -33,7 +33,7 @@ POSSIBILITY OF SUCH DAMAGE. #ifndef TORRENT_UTF8_HPP_INCLUDED #define TORRENT_UTF8_HPP_INCLUDED -#include "libtorrent/export.hpp" +#include "libtorrent/aux_/export.hpp" #include #include diff --git a/include/libtorrent/version.hpp b/include/libtorrent/version.hpp index 0e590565b..a54df058a 100644 --- a/include/libtorrent/version.hpp +++ b/include/libtorrent/version.hpp @@ -33,7 +33,7 @@ POSSIBILITY OF SUCH DAMAGE. #ifndef TORRENT_VERSION_HPP_INCLUDED #define TORRENT_VERSION_HPP_INCLUDED -#include "libtorrent/export.hpp" +#include "libtorrent/aux_/export.hpp" #define LIBTORRENT_VERSION_MAJOR 1 #define LIBTORRENT_VERSION_MINOR 2 diff --git a/include/libtorrent/write_resume_data.hpp b/include/libtorrent/write_resume_data.hpp index c04bd3777..c55cd8d57 100644 --- a/include/libtorrent/write_resume_data.hpp +++ b/include/libtorrent/write_resume_data.hpp @@ -36,7 +36,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include "libtorrent/fwd.hpp" -#include "libtorrent/export.hpp" +#include "libtorrent/aux_/export.hpp" #include "libtorrent/bencode.hpp" namespace libtorrent { diff --git a/simulation/test_error_handling.cpp b/simulation/test_error_handling.cpp index 83123564a..815765ee8 100644 --- a/simulation/test_error_handling.cpp +++ b/simulation/test_error_handling.cpp @@ -152,7 +152,7 @@ void* operator new(std::size_t sz) if (--g_alloc_counter == 0) { char stack[10000]; - print_backtrace(stack, sizeof(stack), 40, nullptr); + libtorrent::print_backtrace(stack, sizeof(stack), 40, nullptr); #ifdef _MSC_VER // this is a bit unfortunate. Some MSVC standard containers really don't move // with noexcept, by actually allocating memory (i.e. it's not just a matter diff --git a/src/assert.cpp b/src/assert.cpp index d8223e7b8..7499530a5 100644 --- a/src/assert.cpp +++ b/src/assert.cpp @@ -64,6 +64,7 @@ POSSIBILITY OF SUCH DAMAGE. #include +namespace libtorrent { std::string demangle(char const* name) { // in case this string comes @@ -101,11 +102,13 @@ std::string demangle(char const* name) ::free(unmangled); return ret; } +} #elif defined _WIN32 #include "windows.h" #include "dbghelp.h" +namespace libtorrent { std::string demangle(char const* name) { char demangled_name[256]; @@ -113,9 +116,12 @@ std::string demangle(char const* name) demangled_name[0] = 0; return demangled_name; } +} #else +namespace libtorrent { std::string demangle(char const* name) { return name; } +} #endif #include @@ -126,6 +132,8 @@ std::string demangle(char const* name) { return name; } #if TORRENT_USE_EXECINFO #include +namespace libtorrent { + TORRENT_EXPORT void print_backtrace(char* out, int len, int max_depth, void*) { void* stack[50]; @@ -142,6 +150,7 @@ TORRENT_EXPORT void print_backtrace(char* out, int len, int max_depth, void*) ::free(symbols); } +} #elif defined _WIN32 @@ -152,6 +161,8 @@ TORRENT_EXPORT void print_backtrace(char* out, int len, int max_depth, void*) #include "winbase.h" #include "dbghelp.h" +namespace libtorrent { + TORRENT_EXPORT void print_backtrace(char* out, int len, int max_depth , void* ctx) { @@ -256,19 +267,26 @@ TORRENT_EXPORT void print_backtrace(char* out, int len, int max_depth if (i == max_depth && max_depth > 0) break; } } +} #else +namespace libtorrent { + TORRENT_EXPORT void print_backtrace(char* out, int len, int /*max_depth*/, void* /* ctx */) { out[0] = 0; std::strncat(out, "", std::size_t(len)); } +} + #endif #endif +namespace libtorrent { + #if TORRENT_USE_ASSERTS || defined TORRENT_ASIO_DEBUGGING #ifdef TORRENT_PRODUCTION_ASSERTS @@ -379,3 +397,6 @@ TORRENT_EXPORT void assert_fail(char const*, int, char const* , char const*, char const*, int) {} #endif + +} // libtorrent namespace +