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 ) )
#include "list.h"
#include "utils.h"
#include "platform.h"
+#include "version.h"
static tr_lock * messageLock = NULL;
static int messageLevel = 0;
}
char*
-tr_getLogTimeStr( char * buf,
- int buflen )
+tr_getLogTimeStr( char * buf, int buflen )
{
char tmp[64];
time_t now;
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 )
{
*****
****/
+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,