From 29661cf245f954b3c4a6281d129cb3e33fa41a06 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sun, 25 Jan 2009 16:14:11 +0000 Subject: [PATCH] (trunk libT) new macro, tr_assert(). use it to help smoke out #1749 --- libtransmission/completion.c | 17 +++++++++++++++-- libtransmission/utils.c | 24 ++++++++++++++++++++++-- libtransmission/utils.h | 9 +++++++++ 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/libtransmission/completion.c b/libtransmission/completion.c index 276cbf224..ef8eeecd8 100644 --- a/libtransmission/completion.c +++ b/libtransmission/completion.c @@ -326,8 +326,21 @@ tr_cpFileIsComplete( const tr_completion * cp, tr_file_index_t fileIndex ) const tr_block_index_t firstBlock = file->offset / tor->blockSize; const tr_block_index_t lastBlock = file->length ? ( ( file->offset + file->length - 1 ) / tor->blockSize ) : firstBlock; - assert( tr_torBlockPiece( tor, firstBlock ) == file->firstPiece ); - assert( tr_torBlockPiece( tor, lastBlock ) == file->lastPiece ); + tr_assert( tr_torBlockPiece( tor, firstBlock ) == file->firstPiece, + "file->offset %"PRIu64"; file->length %"PRIu64"; " + "pieceSize %"PRIu32"; blockSize %"PRIu32"; " + "firstBlock %"PRIu64"; lastBlock %"PRIu64, + file->offset, file->length, + tor->info.pieceSize, tor->blockSize, + firstBlock, lastBlock ); + + tr_assert( tr_torBlockPiece( tor, lastBlock ) == file->lastPiece, + "file->offset %"PRIu64"; file->length %"PRIu64"; " + "pieceSize %"PRIu32"; blockSize %"PRIu32"; " + "firstBlock %"PRIu64"; lastBlock %"PRIu64, + file->offset, file->length, + tor->info.pieceSize, tor->blockSize, + firstBlock, lastBlock ); for( block=firstBlock; block<=lastBlock; ++block ) if( !tr_cpBlockIsComplete( cp, block ) ) diff --git a/libtransmission/utils.c b/libtransmission/utils.c index 72e37c501..ee8ecffd1 100644 --- a/libtransmission/utils.c +++ b/libtransmission/utils.c @@ -36,6 +36,7 @@ #include "list.h" #include "utils.h" #include "platform.h" +#include "version.h" static tr_lock * messageLock = NULL; static int messageLevel = 0; @@ -191,8 +192,7 @@ tr_localtime_r( time_t *_clock, struct tm *_result ) } char* -tr_getLogTimeStr( char * buf, - int buflen ) +tr_getLogTimeStr( char * buf, int buflen ) { char tmp[64]; time_t now; @@ -211,6 +211,26 @@ tr_getLogTimeStr( char * buf, return buf; } +void +tr_assertImpl( const char * file, int line, const char * test, const char * fmt, ... ) +{ + char buf[64]; + fprintf( stderr, "[%s] Transmission %s Assertion \"%s\" failed at %s:%d. ", + tr_getLogTimeStr( buf, sizeof( buf ) ), + LONG_VERSION_STRING, test, file, line ); + if( fmt && *fmt ) { + va_list args; + fputc( '(', stderr ); + va_start( args, fmt ); + vfprintf( stderr, fmt, args ); + va_end( args ); + fputs( ") ", stderr ); + } + fputs( "Please report this bug at ; Thank you.\n", stderr ); + abort( ); +} + + tr_bool tr_deepLoggingIsActive( void ) { diff --git a/libtransmission/utils.h b/libtransmission/utils.h index f7e53fb81..5bc555ab6 100644 --- a/libtransmission/utils.h +++ b/libtransmission/utils.h @@ -103,6 +103,15 @@ extern "C" { ***** ****/ +void tr_assertImpl( const char * file, int line, const char * test, const char * fmt, ... ) TR_GNUC_PRINTF( 4, 5 ); + +#ifdef NDEBUG + #define tr_assert( test, fmt, ... ) +#else + #define tr_assert( test, fmt, ... ) \ + do { if( ! ( test ) ) tr_assertImpl( __FILE__, __LINE__, #test, fmt, __VA_ARGS__ ); } while( 0 ) +#endif + int tr_msgLoggingIsActive( int level ); void tr_msg( const char * file,