mirror of
https://github.com/transmission/transmission
synced 2024-12-24 00:34:04 +00:00
(trunk libT) new macro, tr_assert(). use it to help smoke out #1749
This commit is contained in:
parent
f47cc0cf4d
commit
29661cf245
3 changed files with 46 additions and 4 deletions
|
@ -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 ) )
|
||||
|
|
|
@ -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 )
|
||||
{
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue