]> granicus.if.org Git - transmission/commitdiff
(libT) low-hanging fruit discovered from softwareelves' shark profile.
authorCharles Kerr <charles@transmissionbt.com>
Sun, 26 Oct 2008 15:39:04 +0000 (15:39 +0000)
committerCharles Kerr <charles@transmissionbt.com>
Sun, 26 Oct 2008 15:39:04 +0000 (15:39 +0000)
12 files changed:
libtransmission/fdlimit.c
libtransmission/handshake.c
libtransmission/peer-io.c
libtransmission/peer-mgr.c
libtransmission/rpc-server.c
libtransmission/session.c
libtransmission/torrent.h
libtransmission/tracker.c
libtransmission/trevent.c
libtransmission/utils.c
libtransmission/utils.h
libtransmission/web.c

index 8f65b6c253627ea66b1db2d24548baa7a37d2a66..30011fc7a389a0700afa281446212574cb256317 100644 (file)
 #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 )
 
 /**
 ***
index 8d6a655e12f90d383fea680a23e494d3e5c93214..5cfea8239be7013ab612b1ada8018cc97b2a1111 100644 (file)
@@ -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 )
index 08d76e29f978aac0a857abbef87b5a92848c9d0c..2b0b55fe7250c1670d72d8cc988aa862f8d4a502 100644 (file)
 **/
 
 #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
 {
index 712bb8013fcee3d19f98253a15565816cb0c16ab..0056c7eda2d794ab2c1bd65114c5ffeaffdd1a84 100644 (file)
@@ -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 ) );
 
index 9962db0d6831fa2759442405847f3976c4cf0256..47c1ab02bc0fbc4a1c80356b87daa8a45396d8e7 100644 (file)
@@ -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 )
+
 
 /**
 ***
index 4a8bb452a930fd0c5ae15e1261423eb7b7032282..0cb1d1566ce15753b537ae6e3658179e4d3a4dd3 100644 (file)
@@ -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 )
index 4e5c83c9ef4e39f53fb337cfeaf9ff885787a133..09353357c82640870e76677324ec1132c0cc2570 100644 (file)
@@ -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
 {
index 791dfcd8c051ac5d2bea9de44039eff3957b0fe0..0dc3bd3a43073812bc9f27f05b25b208ff62b200 100644 (file)
@@ -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 )
 
 /***
 ****
index 24033aa6bcdbb472ff1d07ab2ed4eaf29f777576..c0042a3d82cf7a21bd7afe7b3e6e08273ab93e88 100644 (file)
@@ -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,
index 48598b42ea79085026212faaf358652822a51123..978cc6f37f5045fc2e09f22afb1bee29595c3ba4 100644 (file)
@@ -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( );
index f5dfae3df02965abb1c481a3e172938ec902180b..5d90d610a49a1e4d1bd35c26f534c503d3a6da37 100644 (file)
@@ -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,
index 661ce4cb414f3c32ee7489904cf8c4dfda2cfe54..1cffc49596de7d4fd3dddcf79dc10e556d889dad 100644 (file)
 /* 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 ) */