]> granicus.if.org Git - transmission/commitdiff
(trunk libT) new macro, tr_assert(). use it to help smoke out #1749
authorCharles Kerr <charles@transmissionbt.com>
Sun, 25 Jan 2009 16:14:11 +0000 (16:14 +0000)
committerCharles Kerr <charles@transmissionbt.com>
Sun, 25 Jan 2009 16:14:11 +0000 (16:14 +0000)
libtransmission/completion.c
libtransmission/utils.c
libtransmission/utils.h

index 276cbf2240d34c3547291d4eaa84d60bb893112b..ef8eeecd8d184d971f761e86ebe27c13eb68c36d 100644 (file)
@@ -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 ) )
index 72e37c5015c78ba69a0f23508cc2a42e5c671b1d..ee8ecffd127c563aa0b494f96b9f258158bb131d 100644 (file)
@@ -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 <http://trac.transmissionbt.com/newticket>; Thank you.\n", stderr );
+    abort( );
+}
+
+
 tr_bool
 tr_deepLoggingIsActive( void )
 {
index f7e53fb81b6a5cddf808b7e7483f1cbf132337c5..5bc555ab661a6c0d2bc3f0c16ac331f19006d93e 100644 (file)
@@ -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,