From: Charles Kerr Date: Sun, 26 Oct 2008 15:39:04 +0000 (+0000) Subject: (libT) low-hanging fruit discovered from softwareelves' shark profile. X-Git-Tag: 1.40~123 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=06939cafa61f58fedf913664e23b35f7b993616e;p=transmission (libT) low-hanging fruit discovered from softwareelves' shark profile. --- diff --git a/libtransmission/fdlimit.c b/libtransmission/fdlimit.c index 8f65b6c25..30011fc7a 100644 --- a/libtransmission/fdlimit.c +++ b/libtransmission/fdlimit.c @@ -52,7 +52,11 @@ #include "platform.h" /* tr_lock */ #include "utils.h" -#define dbgmsg( ... ) tr_deepLog( __FILE__, __LINE__, NULL, __VA_ARGS__ ) +#define dbgmsg( ... ) \ + do { \ + if( tr_deepLoggingIsActive( ) ) \ + tr_deepLog( __FILE__, __LINE__, NULL, __VA_ARGS__ ); \ + } while( 0 ) /** *** diff --git a/libtransmission/handshake.c b/libtransmission/handshake.c index 8d6a655e1..5cfea8239 100644 --- a/libtransmission/handshake.c +++ b/libtransmission/handshake.c @@ -134,8 +134,11 @@ enum *** **/ -#define dbgmsg( handshake, ... ) tr_deepLog(\ - __FILE__, __LINE__, tr_peerIoGetAddrStr( handshake->io ), __VA_ARGS__ ) +#define dbgmsg( handshake, ... ) \ + do { \ + if( tr_deepLoggingIsActive( ) ) \ + tr_deepLog( __FILE__, __LINE__, tr_peerIoGetAddrStr( handshake->io ), __VA_ARGS__ ); \ + } while( 0 ) static const char* getStateName( short state ) diff --git a/libtransmission/peer-io.c b/libtransmission/peer-io.c index 08d76e29f..2b0b55fe7 100644 --- a/libtransmission/peer-io.c +++ b/libtransmission/peer-io.c @@ -40,7 +40,10 @@ **/ #define dbgmsg( io, ... ) \ - tr_deepLog( __FILE__, __LINE__, tr_peerIoGetAddrStr( io ), __VA_ARGS__ ) + do { \ + if( tr_deepLoggingIsActive( ) ) \ + tr_deepLog( __FILE__, __LINE__, tr_peerIoGetAddrStr( io ), __VA_ARGS__ ); \ + } while( 0 ) struct tr_bandwidth { diff --git a/libtransmission/peer-mgr.c b/libtransmission/peer-mgr.c index 712bb8013..0056c7eda 100644 --- a/libtransmission/peer-mgr.c +++ b/libtransmission/peer-mgr.c @@ -132,10 +132,16 @@ struct tr_peerMgr }; #define tordbg( t, ... ) \ - tr_deepLog( __FILE__, __LINE__, t->tor->info.name, __VA_ARGS__ ) + do { \ + if( tr_deepLoggingIsActive( ) ) \ + tr_deepLog( __FILE__, __LINE__, t->tor->info.name, __VA_ARGS__ ); \ + } while( 0 ) #define dbgmsg( ... ) \ - tr_deepLog( __FILE__, __LINE__, NULL, __VA_ARGS__ ) + do { \ + if( tr_deepLoggingIsActive( ) ) \ + tr_deepLog( __FILE__, __LINE__, NULL, __VA_ARGS__ ); \ + } while( 0 ) /** *** @@ -863,7 +869,6 @@ refillPulse( void * vtorrent ) const uint32_t length = tr_torBlockCountBytes( tor, block ); assert( tr_torrentReqIsValid( tor, index, offset, length ) ); - assert( _tr_block( tor, index, offset ) == block ); assert( offset < tr_torPieceCountBytes( tor, index ) ); assert( (offset + length) <= tr_torPieceCountBytes( tor, index ) ); diff --git a/libtransmission/rpc-server.c b/libtransmission/rpc-server.c index 9962db0d6..47c1ab02b 100644 --- a/libtransmission/rpc-server.c +++ b/libtransmission/rpc-server.c @@ -58,7 +58,12 @@ struct tr_rpc_server char * whitelist; }; -#define dbgmsg( ... ) tr_deepLog( __FILE__, __LINE__, MY_NAME, __VA_ARGS__ ) +#define dbgmsg( ... ) \ + do { \ + if( tr_deepLoggingIsActive( ) ) \ + tr_deepLog( __FILE__, __LINE__, MY_NAME, __VA_ARGS__ ); \ + } while( 0 ) + /** *** diff --git a/libtransmission/session.c b/libtransmission/session.c index 4a8bb452a..0cb1d1566 100644 --- a/libtransmission/session.c +++ b/libtransmission/session.c @@ -573,7 +573,11 @@ deadlineReached( const uint64_t deadline ) #define SHUTDOWN_MAX_SECONDS 30 -#define dbgmsg( ... ) tr_deepLog( __FILE__, __LINE__, NULL, __VA_ARGS__ ) +#define dbgmsg( ... ) \ + do { \ + if( tr_deepLoggingIsActive( ) ) \ + tr_deepLog( __FILE__, __LINE__, NULL, __VA_ARGS__ ); \ + } while( 0 ) void tr_sessionClose( tr_handle * session ) diff --git a/libtransmission/torrent.h b/libtransmission/torrent.h index 4e5c83c9e..09353357c 100644 --- a/libtransmission/torrent.h +++ b/libtransmission/torrent.h @@ -120,38 +120,34 @@ uint64_t tr_pieceOffset( const tr_torrent * tor, uint32_t offset, uint32_t length ); -void tr_torrentInitFilePriority( tr_torrent * tor, - tr_file_index_t fileIndex, - tr_priority_t priority ); +void tr_torrentInitFilePriority( tr_torrent * tor, + tr_file_index_t fileIndex, + tr_priority_t priority ); int tr_torrentCountUncheckedPieces( const tr_torrent * ); -int tr_torrentIsPieceChecked( const tr_torrent *, - tr_piece_index_t piece ); +int tr_torrentIsPieceChecked( const tr_torrent * tor, + tr_piece_index_t piece ); -int tr_torrentIsFileChecked( const tr_torrent *, - tr_file_index_t file ); +int tr_torrentIsFileChecked( const tr_torrent * tor, + tr_file_index_t file ); -void tr_torrentSetPieceChecked( - tr_torrent *, - tr_piece_index_t piece, - int isChecked ); +void tr_torrentSetPieceChecked( tr_torrent * tor, + tr_piece_index_t piece, + int isChecked ); -void tr_torrentSetFileChecked( - tr_torrent *, - tr_file_index_t - file, - int - isChecked ); +void tr_torrentSetFileChecked( tr_torrent * tor, + tr_file_index_t file, + int isChecked ); -void tr_torrentUncheck( tr_torrent * ); +void tr_torrentUncheck( tr_torrent * tor ); -int tr_torrentPromoteTracker( tr_torrent *, - int trackerIndex ); +int tr_torrentPromoteTracker( tr_torrent * tor, + int trackerIndex ); -time_t* tr_torrentGetMTimes( const tr_torrent *, - size_t * setmeCount ); +time_t* tr_torrentGetMTimes( const tr_torrent * tor, + size_t * setmeCount ); typedef enum { diff --git a/libtransmission/tracker.c b/libtransmission/tracker.c index 791dfcd8c..0dc3bd3a4 100644 --- a/libtransmission/tracker.c +++ b/libtransmission/tracker.c @@ -124,7 +124,11 @@ struct tr_tracker long lastAnnounceResponse; }; -#define dbgmsg( name, ... ) tr_deepLog( __FILE__, __LINE__, name, __VA_ARGS__ ) +#define dbgmsg( name, ... ) \ + do { \ + if( tr_deepLoggingIsActive( ) ) \ + tr_deepLog( __FILE__, __LINE__, name, __VA_ARGS__ ); \ + } while( 0 ) /*** **** diff --git a/libtransmission/trevent.c b/libtransmission/trevent.c index 24033aa6b..c0042a3d8 100644 --- a/libtransmission/trevent.c +++ b/libtransmission/trevent.c @@ -146,7 +146,11 @@ struct tr_run_data void * user_data; }; -#define dbgmsg( ... ) tr_deepLog( __FILE__, __LINE__, "event", __VA_ARGS__ ) +#define dbgmsg( ... ) \ + do { \ + if( tr_deepLoggingIsActive( ) ) \ + tr_deepLog( __FILE__, __LINE__, "event", __VA_ARGS__ ); \ + } while( 0 ) static void readFromPipe( int fd, diff --git a/libtransmission/utils.c b/libtransmission/utils.c index 48598b42e..978cc6f37 100644 --- a/libtransmission/utils.c +++ b/libtransmission/utils.c @@ -209,11 +209,17 @@ tr_getLogTimeStr( char * buf, return buf; } +int +tr_deepLoggingIsActive( void ) +{ + return IsDebuggerPresent() || (tr_getLog()!=NULL); +} + void -tr_deepLog( const char * file, - int line, - const char * name, - const char * fmt, +tr_deepLog( const char * file, + int line, + const char * name, + const char * fmt, ... ) { FILE * fp = tr_getLog( ); diff --git a/libtransmission/utils.h b/libtransmission/utils.h index f5dfae3df..5d90d610a 100644 --- a/libtransmission/utils.h +++ b/libtransmission/utils.h @@ -133,6 +133,8 @@ void tr_msg( const char * file, FILE* tr_getLog( void ); +int tr_deepLoggingIsActive( void ); + void tr_deepLog( const char * file, int line, const char * name, diff --git a/libtransmission/web.c b/libtransmission/web.c index 661ce4cb4..1cffc4959 100644 --- a/libtransmission/web.c +++ b/libtransmission/web.c @@ -29,7 +29,11 @@ /* arbitrary number */ #define DEFAULT_TIMER_MSEC 2000 -#define dbgmsg( ... ) tr_deepLog( __FILE__, __LINE__, "web", __VA_ARGS__ ) +#define dbgmsg( ... ) \ + do { \ + if( tr_deepLoggingIsActive( ) ) \ + tr_deepLog( __FILE__, __LINE__, "web", __VA_ARGS__ ); \ + } while( 0 ) /* #define dbgmsg(...) \ do { fprintf( stderr, __VA_ARGS__ ); fprintf( stderr, "\n" ); } while( 0 ) */