From 6bb24bea807f64c43ae8f4947e72728736c8e1a8 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sun, 16 May 2010 05:26:43 +0000 Subject: [PATCH] added feature to make asserts log to a file instead of breaking the process --- ChangeLog | 2 ++ include/libtorrent/assert.hpp | 8 ++++++-- src/assert.cpp | 6 +++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index a8298b5ce..03cc68436 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,5 @@ + * added feature to make asserts log to a file instead of breaking the process + (production asserts) * optimized disk I/O cache clearing * added feature to ask a torrent if it needs to save its resume data or not * added setting to ignore file modification time when loading resume files diff --git a/include/libtorrent/assert.hpp b/include/libtorrent/assert.hpp index 7b4b43bb9..eec83281e 100644 --- a/include/libtorrent/assert.hpp +++ b/include/libtorrent/assert.hpp @@ -34,17 +34,21 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/config.hpp" -#if !defined TORRENT_DEBUG || TORRENT_NO_ASSERTS +#if (!defined TORRENT_DEBUG && !TORRENT_PRODUCTION_ASSERTS) || TORRENT_NO_ASSERTS #define TORRENT_ASSERT(a) do {} while(false) #else +#if TORRENT_PRODUCTION_ASSERTS +extern char const* libtorrent_assert_log; +#endif + #include #ifdef __GNUC__ std::string demangle(char const* name); #endif -#if (defined __linux__ || defined __MACH__) && defined __GNUC__ && defined TORRENT_DEBUG +#if (defined __linux__ || defined __MACH__) && defined __GNUC__ TORRENT_EXPORT void assert_fail(const char* expr, int line, char const* file, char const* function); #define TORRENT_ASSERT(x) do { if (x) {} else assert_fail(#x, __LINE__, __FILE__, __PRETTY_FUNCTION__); } while (false) diff --git a/src/assert.cpp b/src/assert.cpp index 9088ebfad..82d4f5754 100644 --- a/src/assert.cpp +++ b/src/assert.cpp @@ -117,11 +117,15 @@ void print_backtrace(FILE* out, char const* label) {} #endif +#if TORRENT_PRODUCTION_ASSERTS +char const* libtorrent_assert_log = "asserts.log"; +#endif + void assert_fail(char const* expr, int line, char const* file, char const* function) { #if TORRENT_PRODUCTION_ASSERTS - FILE* out = fopen("asserts.log", "a+"); + FILE* out = fopen(libtorrent_assert_log, "a+"); if (out == 0) out = stderr; #else FILE* out = stderr;