diff --git a/Jamfile b/Jamfile index d72ed522f..0e42c1b66 100644 --- a/Jamfile +++ b/Jamfile @@ -83,9 +83,7 @@ rule linking ( properties * ) result += /libsimulator//simulator ; } - # dbghelp doesn't appear to exist in mingw if windows in $(properties) - && ! gcc in $(properties) && ( debug in $(properties) || on in $(properties) || production in $(properties) @@ -298,6 +296,13 @@ rule building ( properties * ) result += /bigobj ; } + if gcc in $(properties) + && windows in $(properties) + { + # allow larger .obj files in GCC + result += -Wa,-mbig-obj ; + } + if ( debug in $(properties) && ( clang in $(properties) || gcc in $(properties) @@ -455,7 +460,7 @@ feature mutable-torrents : on off : composite propagated link-incompatible ; feature.compose off : TORRENT_DISABLE_MUTABLE_TORRENTS ; feature crypto : built-in openssl gcrypt : composite propagated ; -feature.compose openssl : TORRENT_USE_OPENSSL ; +feature.compose openssl : TORRENT_USE_OPENSSL OPENSSL_NO_SSL2 ; feature.compose gcrypt : TORRENT_USE_GCRYPT ; feature character-set : unicode ansi : composite propagated link-incompatible ; diff --git a/appveyor.yml b/appveyor.yml index 9b888a9e7..c6ffd715e 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -24,13 +24,11 @@ environment: model: 64 linkflags: '"/LIBPATH:C:\\openssl-1.0.1p-vs2015\\lib"' include: '"c:\\openssl-1.0.1p-vs2015\\include"' - -# mingw and boost.random don't like each other. Comment this back in once there -# is support - -# - variant: test_debug -# compiler: gcc -# linkflags: '"-LC:\\OpenSSL-Win32\\lib"' + - variant: test_debug + compiler: gcc + model: 64 + include: '"c:\\OpenSSL-Win64\\include"' + linkflags: '"-LC:\\OpenSSL-Win64\\lib"' install: - if defined sim ( git submodule update --init --recursive ) @@ -56,11 +54,10 @@ install: - echo %BOOST_ROOT% - echo %BOOST_BUILD_PATH% - set PATH=%PATH%;%BOOST_BUILD_PATH%\src\engine\bin.ntx86 -- 'echo using msvc : 12.0 ; >%HOMEDRIVE%%HOMEPATH%/user-config.jam' -- 'echo using msvc : 14.0 ; >>%HOMEDRIVE%%HOMEPATH%/user-config.jam' +- ps: '"using msvc : 14.0 ;`nusing gcc : : : -std=c++11 ;`n" | Set-Content $env:HOMEDRIVE\$env:HOMEPATH\user-config.jam' - type %HOMEDRIVE%%HOMEPATH%\user-config.jam - cd %ROOT_DIRECTORY% -- set PATH=%PATH%;c:\Mingw\bin +- set PATH=c:\msys64\mingw64\bin;%PATH% - g++ --version - python --version - echo %ROOT_DIRECTORY% @@ -94,7 +91,8 @@ build_script: test_script: - cd %ROOT_DIRECTORY%\test -- b2.exe --hash -j2 address-model=%model% win-tests %compiler% variant=%variant% link=shared linkflags=%linkflags% include=%include% +# mingw tests crash currently. needs resolving +- if not %compiler% == gcc ( b2.exe --hash -j2 address-model=%model% win-tests %compiler% variant=%variant% link=shared linkflags=%linkflags% include=%include% ) - cd %ROOT_DIRECTORY%\bindings\python # 64 bit python module builds don't work - if %model% == 32 ( python test.py ) diff --git a/examples/make_torrent.cpp b/examples/make_torrent.cpp index 0cb573b78..2cbb1fa77 100644 --- a/examples/make_torrent.cpp +++ b/examples/make_torrent.cpp @@ -41,13 +41,14 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/file_pool.hpp" #include "libtorrent/hex.hpp" // for from_hex -#include +#include #ifdef TORRENT_WINDOWS #include // for _getcwd #endif using namespace libtorrent; +using namespace std::placeholders; int load_file(std::string const& filename, std::vector& v, libtorrent::error_code& ec, int limit = 8000000) { @@ -369,7 +370,7 @@ int main(int argc, char* argv[]) error_code ec; set_piece_hashes(t, branch_path(full_path) - , boost::bind(&print_progress, _1, t.num_pieces()), ec); + , std::bind(&print_progress, _1, t.num_pieces()), ec); if (ec) { fprintf(stderr, "%s\n", ec.message().c_str()); diff --git a/examples/print.cpp b/examples/print.cpp index 6b3f09eb2..973bec309 100644 --- a/examples/print.cpp +++ b/examples/print.cpp @@ -159,8 +159,11 @@ std::string const& piece_bar(libtorrent::bitfield const& p, int width) double piece = 0; // we print two blocks at a time, so calculate the color in pair +#ifndef _WIN32 int color[2]; int last_color[2] = { -1, -1}; +#endif + for (int i = 0; i < width; ++i, piece += piece_per_char) { int num_pieces = 0; @@ -169,9 +172,10 @@ std::string const& piece_bar(libtorrent::bitfield const& p, int width) for (int k = int(piece); k < end; ++k, ++num_pieces) if (p[k]) ++num_have; int const c = int(std::ceil(num_have / float((std::max)(num_pieces, 1)) * (table_size - 1))); - color[i & 1] = c; #ifndef _WIN32 + color[i & 1] = c; + if ((i & 1) == 1) { // now, print color[0] and [1] diff --git a/examples/simple_client.cpp b/examples/simple_client.cpp index ef43ffc7b..f684ef5d6 100644 --- a/examples/simple_client.cpp +++ b/examples/simple_client.cpp @@ -31,12 +31,22 @@ POSSIBILITY OF SUCH DAMAGE. */ #include -#include #include "libtorrent/entry.hpp" #include "libtorrent/bencode.hpp" #include "libtorrent/session.hpp" #include "libtorrent/torrent_info.hpp" +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated" +#endif + +#include + +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif + int main(int argc, char* argv[]) { using namespace libtorrent; diff --git a/include/libtorrent/assert.hpp b/include/libtorrent/assert.hpp index 05532aaba..4eda8fd9a 100644 --- a/include/libtorrent/assert.hpp +++ b/include/libtorrent/assert.hpp @@ -42,7 +42,7 @@ POSSIBILITY OF SUCH DAMAGE. #include std::string demangle(char const* name); -TORRENT_EXPORT void print_backtrace(char* out, int len, int max_depth = 0); +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 diff --git a/include/libtorrent/config.hpp b/include/libtorrent/config.hpp index 95cc36c65..b097674e6 100644 --- a/include/libtorrent/config.hpp +++ b/include/libtorrent/config.hpp @@ -37,21 +37,16 @@ POSSIBILITY OF SUCH DAMAGE. #define _FILE_OFFSET_BITS 64 -#if !defined _MSC_VER || _MSC_VER >= 1600 -#ifndef __STDC_LIMIT_MACROS -#define __STDC_LIMIT_MACROS 1 -#endif -#ifndef __STDC_CONSTANT_MACROS -#define __STDC_CONSTANT_MACROS 1 -#endif -#endif - #include #include #include #include + +#include "libtorrent/aux_/disable_warnings_pop.hpp" + #include // for snprintf #include // for IOV_MAX +#include // for PRId64 et.al. #include "libtorrent/export.hpp" @@ -67,29 +62,12 @@ POSSIBILITY OF SUCH DAMAGE. #define BOOST_ASIO_SEPARATE_COMPILATION #endif -#ifndef _MSC_VER -#ifndef __STDC_FORMAT_MACROS -#define __STDC_FORMAT_MACROS 1 +#if defined __MINGW64__ || defined __MINGW32__ +// GCC warns on format codes that are incompatible with glibc, which the windows +// format codes are. So we need to disable those for mingw targets +#pragma GCC diagnostic ignored "-Wformat" +#pragma GCC diagnostic ignored "-Wformat-extra-args" #endif -#include // for PRId64 et.al. -#endif - -#ifndef PRId64 -// MinGW uses microsofts runtime -#if defined _MSC_VER || defined __MINGW32__ -#define PRId64 "I64d" -#define PRIu64 "I64u" -#define PRIx64 "I64x" -#define PRIu32 "u" -#else -#define PRId64 "lld" -#define PRIu64 "llu" -#define PRIx64 "llx" -#define PRIu32 "u" -#endif -#endif - -#include "libtorrent/aux_/disable_warnings_pop.hpp" // ======= GCC ========= @@ -255,7 +233,7 @@ POSSIBILITY OF SUCH DAMAGE. #endif // ==== MINGW === -#elif defined __MINGW32__ +#elif defined __MINGW32__ || defined __MINGW64__ #define TORRENT_MINGW #define TORRENT_WINDOWS #ifndef TORRENT_USE_ICONV diff --git a/src/assert.cpp b/src/assert.cpp index 50b0b79e2..304fb2b76 100644 --- a/src/assert.cpp +++ b/src/assert.cpp @@ -53,6 +53,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #include "libtorrent/aux_/disable_warnings_pop.hpp" @@ -124,7 +125,7 @@ std::string demangle(char const* name) { return name; } #if TORRENT_USE_EXECINFO #include -TORRENT_EXPORT void print_backtrace(char* out, int len, int max_depth) +TORRENT_EXPORT void print_backtrace(char* out, int len, int max_depth, void*) { void* stack[50]; int size = backtrace(stack, 50); @@ -141,8 +142,7 @@ TORRENT_EXPORT void print_backtrace(char* out, int len, int max_depth) free(symbols); } -// visual studio 9 and up appears to support this -#elif defined WIN32 && _MSC_VER >= 1500 +#elif defined WIN32 #include "windows.h" #include "libtorrent/utf8.hpp" @@ -150,35 +150,56 @@ TORRENT_EXPORT void print_backtrace(char* out, int len, int max_depth) #include "winbase.h" #include "dbghelp.h" -TORRENT_EXPORT void print_backtrace(char* out, int len, int max_depth) +TORRENT_EXPORT void print_backtrace(char* out, int len, int max_depth + , void* ctx) { - typedef USHORT (WINAPI *RtlCaptureStackBackTrace_t)( - __in ULONG FramesToSkip, - __in ULONG FramesToCapture, - __out PVOID *BackTrace, - __out_opt PULONG BackTraceHash); - - static RtlCaptureStackBackTrace_t RtlCaptureStackBackTrace = 0; - - if (RtlCaptureStackBackTrace == 0) + CONTEXT context_record; + if (ctx) { - // we don't actually have to free this library, everyone has it loaded - HMODULE lib = LoadLibrary(TEXT("kernel32.dll")); - RtlCaptureStackBackTrace = (RtlCaptureStackBackTrace_t)GetProcAddress(lib, "RtlCaptureStackBackTrace"); - if (RtlCaptureStackBackTrace == 0) - { - out[0] = 0; - return; - } + context_record = *static_cast(ctx); + } + else + { + // use the current thread's context + RtlCaptureContext(&context_record); } - int i; - void* stack[50]; - int size = CaptureStackBackTrace(0, 50, stack, 0); + int size = 0; + std::array stack; - SYMBOL_INFO* symbol = (SYMBOL_INFO*)calloc(sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(TCHAR), 1); - symbol->MaxNameLen = MAX_SYM_NAME; - symbol->SizeOfStruct = sizeof(SYMBOL_INFO); + STACKFRAME64 stack_frame; + memset(&stack_frame, 0, sizeof(stack_frame)); +#if defined(_WIN64) + int const machine_type = IMAGE_FILE_MACHINE_AMD64; + stack_frame.AddrPC.Offset = context_record.Rip; + stack_frame.AddrFrame.Offset = context_record.Rbp; + stack_frame.AddrStack.Offset = context_record.Rsp; +#else + int const machine_type = IMAGE_FILE_MACHINE_I386; + stack_frame.AddrPC.Offset = context_record.Eip; + stack_frame.AddrFrame.Offset = context_record.Ebp; + stack_frame.AddrStack.Offset = context_record.Esp; +#endif + stack_frame.AddrPC.Mode = AddrModeFlat; + stack_frame.AddrFrame.Mode = AddrModeFlat; + stack_frame.AddrStack.Mode = AddrModeFlat; + while (StackWalk64(machine_type, + GetCurrentProcess(), + GetCurrentThread(), + &stack_frame, + &context_record, + nullptr, + &SymFunctionTableAccess64, + &SymGetModuleBase64, + nullptr) && size < stack.size()) + { + stack[size++] = reinterpret_cast(stack_frame.AddrPC.Offset); + } + + struct symbol_bundle : SYMBOL_INFO + { + wchar_t name[MAX_SYM_NAME]; + }; HANDLE p = GetCurrentProcess(); static bool sym_initialized = false; @@ -187,24 +208,52 @@ TORRENT_EXPORT void print_backtrace(char* out, int len, int max_depth) sym_initialized = true; SymInitialize(p, NULL, true); } - for (i = 0; i < size && len > 0; ++i) + SymRefreshModuleList(p); + for (int i = 0; i < size && len > 0; ++i) { - int ret; - if (SymFromAddr(p, uintptr_t(stack[i]), 0, symbol)) - ret = snprintf(out, len, "%d: %s\n", i, symbol->Name); - else - ret = snprintf(out, len, "%d: \n", i); + DWORD_PTR frame_ptr = reinterpret_cast(stack[i]); + DWORD64 displacement = 0; + symbol_bundle symbol; + symbol.MaxNameLen = MAX_SYM_NAME; + symbol.SizeOfStruct = sizeof(SYMBOL_INFO); + BOOL const has_symbol = SymFromAddr(p, frame_ptr, &displacement, &symbol); + + DWORD line_displacement = 0; + IMAGEHLP_LINE64 line = {}; + line.SizeOfStruct = sizeof(IMAGEHLP_LINE64); + BOOL const has_line = SymGetLineFromAddr64(GetCurrentProcess(), frame_ptr, + &line_displacement, &line); + + int ret = snprintf(out, len, "%2d: %p", i, stack[i]); + out += ret; len -= ret; if (len <= 0) break; + + if (has_symbol) + { + ret = snprintf(out, len, " %s +%-4" PRId64 " " + , i, stack[i], demangle(symbol.Name), displacement); + out += ret; len -= ret; if (len <= 0) break; + } + + if (has_line) + { + ret = snprintf(out, len, " %s:%d" + , line.FileName, line.LineNumber); + out += ret; len -= ret; if (len <= 0) break; + } + + + ret = snprintf(out, len, "\n"); out += ret; len -= ret; + if (i == max_depth && max_depth > 0) break; } - free(symbol); } #else -TORRENT_EXPORT void print_backtrace(char* out, int len, int max_depth) +TORRENT_EXPORT void print_backtrace(char* out, int len, int /*max_depth*/, void* /* ctx */) { out[0] = 0; strncat(out, "", len); diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index b644cc96a..d645990ca 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -63,24 +63,12 @@ POSSIBILITY OF SUCH DAMAGE. #define DEBUG_DISK_THREAD 0 -#if __cplusplus >= 201103L || defined __clang__ - #if DEBUG_DISK_THREAD #define DLOG(...) debug_log(__VA_ARGS__) #else #define DLOG(...) do {} while(false) #endif -#else - -#if DEBUG_DISK_THREAD -#define DLOG debug_log -#else -#define DLOG TORRENT_WHILE_0 debug_log -#endif - -#endif // cplusplus - namespace libtorrent { @@ -97,12 +85,10 @@ namespace libtorrent #define TORRENT_PIECE_ASSERT_FAIL(piece) do {} TORRENT_WHILE_0 #endif // TORRENT_USE_ASSERTS + namespace { -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunused-function" -#endif +#if DEBUG_DISK_THREAD void debug_log(char const* fmt, ...) { @@ -135,6 +121,9 @@ namespace libtorrent #endif } +#endif // DEBUG_DISK_THREAD + + int file_flags_for_job(disk_io_job* j , bool const coalesce_buffers) { @@ -144,10 +133,6 @@ namespace libtorrent return ret; } -#ifdef __clang__ -#pragma clang diagnostic pop -#endif - } // anonymous namespace // ------- disk_io_thread ------ diff --git a/src/file.cpp b/src/file.cpp index d2337ac2f..ce5d54267 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -64,6 +64,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/alloca.hpp" #include "libtorrent/allocator.hpp" // page_size #include "libtorrent/file.hpp" +#include "libtorrent/error_code.hpp" #include #include @@ -1591,11 +1592,11 @@ namespace libtorrent overlapped_t ol; if (ol.ol.hEvent == NULL) return false; -#ifdef TORRENT_MINGW +#ifndef FSCTL_QUERY_ALLOCATED_RANGES typedef struct _FILE_ALLOCATED_RANGE_BUFFER { LARGE_INTEGER FileOffset; LARGE_INTEGER Length; -} FILE_ALLOCATED_RANGE_BUFFER, *PFILE_ALLOCATED_RANGE_BUFFER; +} FILE_ALLOCATED_RANGE_BUFFER; #define FSCTL_QUERY_ALLOCATED_RANGES ((0x9 << 16) | (1 << 14) | (51 << 2) | 3) #endif FILE_ALLOCATED_RANGE_BUFFER in; @@ -1653,7 +1654,7 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER { #ifdef TORRENT_MINGW typedef struct _FILE_SET_SPARSE_BUFFER { BOOLEAN SetSparse; - } FILE_SET_SPARSE_BUFFER, *PFILE_SET_SPARSE_BUFFER; + } FILE_SET_SPARSE_BUFFER; #endif DWORD temp; FILE_SET_SPARSE_BUFFER b; @@ -1680,6 +1681,7 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER { namespace { +#if !TORRENT_USE_PREADV void gather_copy(file::iovec_t const* bufs, int num_bufs, char* dst) { std::size_t offset = 0; @@ -1700,7 +1702,6 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER { } } -#if !TORRENT_USE_PREADV bool coalesce_read_buffers(file::iovec_t const*& bufs, int& num_bufs , file::iovec_t* tmp) { @@ -1834,7 +1835,7 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER { return ret; -#endif +#endif // USE_PREADV } } // anonymous namespace @@ -2247,11 +2248,11 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER { { #ifdef TORRENT_WINDOWS -#ifdef TORRENT_MINGW +#ifndef FSCTL_QUERY_ALLOCATED_RANGES typedef struct _FILE_ALLOCATED_RANGE_BUFFER { LARGE_INTEGER FileOffset; LARGE_INTEGER Length; -} FILE_ALLOCATED_RANGE_BUFFER, *PFILE_ALLOCATED_RANGE_BUFFER; +} FILE_ALLOCATED_RANGE_BUFFER; #define FSCTL_QUERY_ALLOCATED_RANGES ((0x9 << 16) | (1 << 14) | (51 << 2) | 3) #endif // TORRENT_MINGW diff --git a/src/mpi.c b/src/mpi.c index db5ba9454..025f8422e 100644 --- a/src/mpi.c +++ b/src/mpi.c @@ -4,6 +4,13 @@ // disable warning C4334: '<<': result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?) #pragma warning(disable: 4334) #endif + +#if defined __GNUC__ && __GNUC__ >= 5 +// tommath triggers this warning alot +#pragma GCC diagnostic ignored "-Wshift-count-overflow" +#pragma GCC diagnostic ignored "-Woverflow" +#endif + #ifdef BN_ERROR_C /* LibTomMath, multiple-precision integer library -- Tom St Denis * diff --git a/src/pe_crypto.cpp b/src/pe_crypto.cpp index c5001c58d..be5d4f711 100644 --- a/src/pe_crypto.cpp +++ b/src/pe_crypto.cpp @@ -102,7 +102,11 @@ namespace libtorrent return; // key is now our local key - int size = mp_unsigned_bin_size(&key); + int const size = mp_unsigned_bin_size(&key); + TORRENT_ASSERT(size >= 0); + TORRENT_ASSERT(size <= sizeof(m_dh_local_key)); + if (size < 0 || size > sizeof(m_dh_local_key)) + return; memset(m_dh_local_key, 0, sizeof(m_dh_local_key) - size); mp_to_unsigned_bin(&key , reinterpret_cast(m_dh_local_key) diff --git a/test/main.cpp b/test/main.cpp index 8489205fe..0e90174c4 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -42,12 +42,13 @@ POSSIBILITY OF SUCH DAMAGE. #include "dht_server.hpp" // for stop_dht #include "peer_server.hpp" // for stop_peer #include "udp_tracker.hpp" // for stop_udp_tracker +#include #include "libtorrent/assert.hpp" #include "libtorrent/file.hpp" #include -#ifdef WIN32 +#ifdef _WIN32 #include // fot SetErrorMode #include // for _dup and _dup2 #include // for _getpid @@ -67,7 +68,7 @@ using namespace libtorrent; // out, such as the log int old_stdout = -1; int old_stderr = -1; -bool redirect_output = true; +bool redirect_output = false; bool keep_files = false; extern int _g_test_idx; @@ -96,6 +97,64 @@ void output_test_log_to_terminal() } while (size > 0); } +#ifdef _WIN32 +LONG WINAPI seh_exception_handler(LPEXCEPTION_POINTERS p) +{ + char stack_text[10000]; + +#if (defined TORRENT_DEBUG && TORRENT_USE_ASSERTS) \ + || defined TORRENT_ASIO_DEBUGGING \ + || defined TORRENT_PROFILE_CALLS \ + || defined TORRENT_RELEASE_ASSERTS \ + || defined TORRENT_DEBUG_BUFFERS + print_backtrace(stack_text, sizeof(stack_text), 30 + , p->ContextRecord); +#elif defined __FUNCTION__ + strcat(stack_text, __FUNCTION__); +#else + stack_text[0] = 0; + strcat(stack_text, ""); +#endif + + int const code = p->ExceptionRecord->ExceptionCode; + char const* name = ""; + switch (code) + { +#define EXC(x) case x: name = #x; break + EXC(EXCEPTION_ACCESS_VIOLATION); + EXC(EXCEPTION_ARRAY_BOUNDS_EXCEEDED); + EXC(EXCEPTION_BREAKPOINT); + EXC(EXCEPTION_DATATYPE_MISALIGNMENT); + EXC(EXCEPTION_FLT_DENORMAL_OPERAND); + EXC(EXCEPTION_FLT_DIVIDE_BY_ZERO); + EXC(EXCEPTION_FLT_INEXACT_RESULT); + EXC(EXCEPTION_FLT_INVALID_OPERATION); + EXC(EXCEPTION_FLT_OVERFLOW); + EXC(EXCEPTION_FLT_STACK_CHECK); + EXC(EXCEPTION_FLT_UNDERFLOW); + EXC(EXCEPTION_ILLEGAL_INSTRUCTION); + EXC(EXCEPTION_IN_PAGE_ERROR); + EXC(EXCEPTION_INT_DIVIDE_BY_ZERO); + EXC(EXCEPTION_INT_OVERFLOW); + EXC(EXCEPTION_INVALID_DISPOSITION); + EXC(EXCEPTION_NONCONTINUABLE_EXCEPTION); + EXC(EXCEPTION_PRIV_INSTRUCTION); + EXC(EXCEPTION_SINGLE_STEP); + EXC(EXCEPTION_STACK_OVERFLOW); +#undef EXC + }; + + fprintf(stderr, "exception: (0x%x) %s caught:\n%s\n" + , code, name, stack_text); + + output_test_log_to_terminal(); + + exit(code); + return EXCEPTION_EXECUTE_HANDLER; +} + +#else + void sig_handler(int sig) { char stack_text[10000]; @@ -112,10 +171,10 @@ void sig_handler(int sig) stack_text[0] = 0; strcat(stack_text, ""); #endif - char const* sig_name = 0; + char const* name = ""; switch (sig) { -#define SIG(x) case x: sig_name = #x; break +#define SIG(x) case x: name = #x; break SIG(SIGSEGV); #ifdef SIGBUS SIG(SIGBUS); @@ -130,17 +189,16 @@ void sig_handler(int sig) #endif #undef SIG }; - fprintf(stderr, "signal: %s caught:\n%s\n", sig_name, stack_text); + fprintf(stderr, "signal: (%d) %s caught:\n%s\n" + , sig, name, stack_text); output_test_log_to_terminal(); -#ifdef WIN32 - exit(sig); -#else exit(128 + sig); -#endif } +#endif // _WIN32 + void print_usage(char const* executable) { printf("%s [options] [tests...]\n" @@ -158,17 +216,6 @@ void print_usage(char const* executable) "by -l. If no test is specified, all tests are run\n", executable); } -#ifdef WIN32 -LONG WINAPI seh_exception_handler(LPEXCEPTION_POINTERS p) -{ - int sig = p->ExceptionRecord->ExceptionCode; - fprintf(stderr, "SEH exception: %u\n" - , p->ExceptionRecord->ExceptionCode); - sig_handler(sig); - exit(sig); -} -#endif - EXPORT int main(int argc, char const* argv[]) { char const* executable = argv[0]; @@ -217,15 +264,6 @@ EXPORT int main(int argc, char const* argv[]) filter = true; } -#ifdef WIN32 - // try to suppress hanging the process by windows displaying - // modal dialogs. - SetErrorMode( SEM_NOALIGNMENTFAULTEXCEPT - | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX); - - SetUnhandledExceptionFilter(&seh_exception_handler); -#endif - #ifdef O_NONBLOCK // on darwin, stdout is set to non-blocking mode by default // which sometimes causes tests to fail with EAGAIN just @@ -236,6 +274,16 @@ EXPORT int main(int argc, char const* argv[]) fcntl(fileno(stderr), F_SETFL, flags & ~O_NONBLOCK); #endif +#ifdef _WIN32 + // try to suppress hanging the process by windows displaying + // modal dialogs. + SetErrorMode( SEM_NOALIGNMENTFAULTEXCEPT + | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX); + + SetUnhandledExceptionFilter(&seh_exception_handler); + +#else + signal(SIGSEGV, &sig_handler); #ifdef SIGBUS signal(SIGBUS, &sig_handler); @@ -248,6 +296,8 @@ EXPORT int main(int argc, char const* argv[]) signal(SIGSYS, &sig_handler); #endif +#endif // _WIN32 + int process_id = -1; #ifdef _WIN32 process_id = _getpid(); @@ -337,6 +387,15 @@ EXPORT int main(int argc, char const* argv[]) (*t.fun)(); #ifndef BOOST_NO_EXCEPTIONS } + catch (boost::system::system_error const& e) + { + char buf[200]; + snprintf(buf, sizeof(buf), "Terminated with system_error: (%d) [%s] \"%s\"" + , e.code().value() + , e.code().category().name() + , e.code().message().c_str()); + report_failure(buf, __FILE__, __LINE__); + } catch (std::exception const& e) { char buf[200]; diff --git a/test/make_torrent.cpp b/test/make_torrent.cpp index 4fbad03da..1b75827af 100644 --- a/test/make_torrent.cpp +++ b/test/make_torrent.cpp @@ -30,7 +30,10 @@ POSSIBILITY OF SUCH DAMAGE. */ +#include "libtorrent/aux_/disable_warnings_push.hpp" #include +#include "libtorrent/aux_/disable_warnings_pop.hpp" + #include #include "make_torrent.hpp"