diff --git a/libtransmission/bitfield.c b/libtransmission/bitfield.c index a21ec43f2..7e46d4fdb 100644 --- a/libtransmission/bitfield.c +++ b/libtransmission/bitfield.c @@ -15,6 +15,7 @@ #include "transmission.h" #include "bitfield.h" +#include "bitset.h" tr_bitfield* tr_bitfieldConstruct( tr_bitfield * b, size_t bitCount ) @@ -209,3 +210,24 @@ tr_bitfieldCountTrueBits( const tr_bitfield* b ) return ret; } + +/*** +**** +***/ + +void +tr_bitsetReserve( tr_bitset * b, size_t size ) +{ + if( b->bitfield.bitCount < size ) + { + tr_bitfield * tmp = tr_bitfieldDup( &b->bitfield ); + + tr_bitfieldDestruct( &b->bitfield ); + tr_bitfieldConstruct( &b->bitfield, size ); + + if( ( tmp->bits != NULL ) && ( tmp->byteCount > 0 ) ) + memcpy( b->bitfield.bits, tmp->bits, tmp->byteCount ); + + tr_bitfieldFree( tmp ); + } +} diff --git a/libtransmission/bitset.h b/libtransmission/bitset.h index b8662dffb..c3246c2f2 100644 --- a/libtransmission/bitset.h +++ b/libtransmission/bitset.h @@ -41,22 +41,7 @@ tr_bitsetDestructor( tr_bitset * b ) tr_bitfieldDestruct( &b->bitfield ); } -static inline void -tr_bitsetReserve( tr_bitset * b, size_t size ) -{ - if( b->bitfield.bitCount < size ) - { - tr_bitfield * tmp = tr_bitfieldDup( &b->bitfield ); - - tr_bitfieldDestruct( &b->bitfield ); - tr_bitfieldConstruct( &b->bitfield, size ); - - if( ( tmp->bits != NULL ) && ( tmp->byteCount > 0 ) ) - memcpy( b->bitfield.bits, tmp->bits, tmp->byteCount ); - - tr_bitfieldFree( tmp ); - } -} +void tr_bitsetReserve( tr_bitset * b, size_t size ); static inline tr_bool tr_bitsetHasFast( const tr_bitset * b, const size_t nth ) diff --git a/libtransmission/peer-io.c b/libtransmission/peer-io.c index 82c3634fe..301bf3e48 100644 --- a/libtransmission/peer-io.c +++ b/libtransmission/peer-io.c @@ -612,6 +612,11 @@ tr_peerIoAddrStr( const tr_address * addr, tr_port port ) return buf; } +const char* tr_peerIoGetAddrStr( const tr_peerIo * io ) +{ + return tr_isPeerIo( io ) ? tr_peerIoAddrStr( &io->addr, io->port ) : "error"; +} + void tr_peerIoSetIOFuncs( tr_peerIo * io, tr_can_read_cb readcb, @@ -820,6 +825,24 @@ tr_peerIoWriteBuf( tr_peerIo * io, evbuffer_drain( buf, n ); } +void +tr_peerIoWriteUint16( tr_peerIo * io, + struct evbuffer * outbuf, + uint16_t writeme ) +{ + const uint16_t tmp = htons( writeme ); + tr_peerIoWriteBytes( io, outbuf, &tmp, sizeof( uint16_t ) ); +} + +void +tr_peerIoWriteUint32( tr_peerIo * io, + struct evbuffer * outbuf, + uint32_t writeme ) +{ + const uint32_t tmp = htonl( writeme ); + tr_peerIoWriteBytes( io, outbuf, &tmp, sizeof( uint32_t ) ); +} + /*** **** ***/ @@ -851,6 +874,25 @@ tr_peerIoReadBytes( tr_peerIo * io, } } +void +tr_peerIoReadUint16( tr_peerIo * io, + struct evbuffer * inbuf, + uint16_t * setme ) +{ + uint16_t tmp; + tr_peerIoReadBytes( io, inbuf, &tmp, sizeof( uint16_t ) ); + *setme = ntohs( tmp ); +} + +void tr_peerIoReadUint32( tr_peerIo * io, + struct evbuffer * inbuf, + uint32_t * setme ) +{ + uint32_t tmp; + tr_peerIoReadBytes( io, inbuf, &tmp, sizeof( uint32_t ) ); + *setme = ntohl( tmp ); +} + void tr_peerIoDrain( tr_peerIo * io, struct evbuffer * inbuf, diff --git a/libtransmission/peer-io.h b/libtransmission/peer-io.h index d9de33e01..9d55f8951 100644 --- a/libtransmission/peer-io.h +++ b/libtransmission/peer-io.h @@ -192,10 +192,7 @@ static inline tr_session* tr_peerIoGetSession ( tr_peerIo * io ) const char* tr_peerIoAddrStr( const struct tr_address * addr, tr_port port ); -static inline const char* tr_peerIoGetAddrStr( const tr_peerIo * io ) -{ - return tr_isPeerIo( io ) ? tr_peerIoAddrStr( &io->addr, io->port ) : "error"; -} +const char* tr_peerIoGetAddrStr( const tr_peerIo * io ); const struct tr_address * tr_peerIoGetAddress( const tr_peerIo * io, tr_port * port ); @@ -300,21 +297,13 @@ static inline void tr_peerIoWriteUint8( tr_peerIo * io, tr_peerIoWriteBytes( io, outbuf, &writeme, sizeof( uint8_t ) ); } -static inline void tr_peerIoWriteUint16( tr_peerIo * io, - struct evbuffer * outbuf, - uint16_t writeme ) -{ - const uint16_t tmp = htons( writeme ); - tr_peerIoWriteBytes( io, outbuf, &tmp, sizeof( uint16_t ) ); -} +void tr_peerIoWriteUint16( tr_peerIo * io, + struct evbuffer * outbuf, + uint16_t writeme ); -static inline void tr_peerIoWriteUint32( tr_peerIo * io, - struct evbuffer * outbuf, - uint32_t writeme ) -{ - const uint32_t tmp = htonl( writeme ); - tr_peerIoWriteBytes( io, outbuf, &tmp, sizeof( uint32_t ) ); -} +void tr_peerIoWriteUint32( tr_peerIo * io, + struct evbuffer * outbuf, + uint32_t writeme ); void tr_peerIoReadBytes( tr_peerIo * io, struct evbuffer * inbuf, @@ -328,23 +317,13 @@ static inline void tr_peerIoReadUint8( tr_peerIo * io, tr_peerIoReadBytes( io, inbuf, setme, sizeof( uint8_t ) ); } -static inline void tr_peerIoReadUint16( tr_peerIo * io, - struct evbuffer * inbuf, - uint16_t * setme ) -{ - uint16_t tmp; - tr_peerIoReadBytes( io, inbuf, &tmp, sizeof( uint16_t ) ); - *setme = ntohs( tmp ); -} +void tr_peerIoReadUint16( tr_peerIo * io, + struct evbuffer * inbuf, + uint16_t * setme ); -static inline void tr_peerIoReadUint32( tr_peerIo * io, - struct evbuffer * inbuf, - uint32_t * setme ) -{ - uint32_t tmp; - tr_peerIoReadBytes( io, inbuf, &tmp, sizeof( uint32_t ) ); - *setme = ntohl( tmp ); -} +void tr_peerIoReadUint32( tr_peerIo * io, + struct evbuffer * inbuf, + uint32_t * setme ); void tr_peerIoDrain( tr_peerIo * io, struct evbuffer * inbuf, diff --git a/libtransmission/peer-msgs.c b/libtransmission/peer-msgs.c index 9e9d77db8..b267f1e4f 100644 --- a/libtransmission/peer-msgs.c +++ b/libtransmission/peer-msgs.c @@ -306,7 +306,7 @@ pokeBatchPeriod( tr_peermsgs * msgs, } } -static inline void +static void dbgOutMessageLen( tr_peermsgs * msgs ) { dbgmsg( msgs, "outMessage size is now %zu", EVBUFFER_LENGTH( msgs->outMessages ) ); diff --git a/libtransmission/session.c b/libtransmission/session.c index bb530a3ff..e0c379785 100644 --- a/libtransmission/session.c +++ b/libtransmission/session.c @@ -1161,7 +1161,7 @@ tr_sessionGetActiveSpeedLimit_KBps( const tr_session * session, tr_direction dir, double * setme_KBps ) { - int Bps; + int Bps = 0; const tr_bool is_active = tr_sessionGetActiveSpeedLimit_Bps( session, dir, &Bps ); *setme_KBps = toSpeedKBps( Bps ); return is_active; diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index 70387824b..a0f42ef4c 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -401,7 +401,6 @@ static tr_bool tr_torrentIsSeedIdleLimitDone( tr_torrent * tor ) { uint16_t idleMinutes; -#warning can this use the idleSecs from tr_stat? return tr_torrentGetSeedIdle( tor, &idleMinutes ) && difftime(tr_time(), MAX(tor->startDate, tor->activityDate)) >= idleMinutes * 60u; } diff --git a/libtransmission/tr-lpd.c b/libtransmission/tr-lpd.c index 93b215e95..34a7f4bf5 100644 --- a/libtransmission/tr-lpd.c +++ b/libtransmission/tr-lpd.c @@ -254,7 +254,8 @@ static int lpd_extractParam( const char* const str, const char* const name, int /** * @brief Configures additional capabilities for a socket */ -static inline int lpd_configureSocket( int sock, int add ) +static int +lpd_configureSocket( int sock, int add ) { #ifdef WIN32 unsigned long flags = 1; diff --git a/libtransmission/utils.c b/libtransmission/utils.c index 13c5f45bb..1c937ab14 100644 --- a/libtransmission/utils.c +++ b/libtransmission/utils.c @@ -333,6 +333,35 @@ tr_msg( const char * file, int line, **** ***/ +void* +tr_malloc( size_t size ) +{ + return size ? malloc( size ) : NULL; +} + +void* +tr_malloc0( size_t size ) +{ + return size ? calloc( 1, size ) : NULL; +} + +void +tr_free( void * p ) +{ + if( p != NULL ) + free( p ); +} + +void* +tr_memdup( const void * src, size_t byteCount ) +{ + return memcpy( tr_malloc( byteCount ), src, byteCount ); +} + +/*** +**** +***/ + void tr_set_compare( const void * va, size_t aCount, @@ -660,6 +689,12 @@ tr_buildPath( const char *first_element, ... ) ***** ****/ +char* +tr_strdup( const void * in ) +{ + return tr_strndup( in, in ? (int)strlen((const char *)in) : 0 ); +} + char* tr_strndup( const void * in, int len ) { @@ -1128,6 +1163,19 @@ tr_base64_decode( const void * input, **** ***/ +void +tr_removeElementFromArray( void * array, + unsigned int index_to_remove, + size_t sizeof_element, + size_t nmemb ) +{ + char * a = (char*) array; + + memmove( a + sizeof_element * index_to_remove, + a + sizeof_element * ( index_to_remove + 1 ), + sizeof_element * ( --nmemb - index_to_remove ) ); +} + int tr_lowerBound( const void * key, const void * base, diff --git a/libtransmission/utils.h b/libtransmission/utils.h index 0aebe23fa..83d879e53 100644 --- a/libtransmission/utils.h +++ b/libtransmission/utils.h @@ -295,23 +295,13 @@ char* tr_utf8clean( const char * str, int len ) TR_GNUC_MALLOC; ***/ /** @brief Portability wrapper around malloc() in which `0' is a safe argument */ -static inline void* tr_malloc( size_t size ) -{ - return size ? malloc( size ) : NULL; -} +void* tr_malloc( size_t size ); /** @brief Portability wrapper around calloc() in which `0' is a safe argument */ -static inline void* tr_malloc0( size_t size ) -{ - return size ? calloc( 1, size ) : NULL; -} +void* tr_malloc0( size_t size ); /** @brief Portability wrapper around free() in which `NULL' is a safe argument */ -static inline void tr_free( void * p ) -{ - if( p != NULL ) - free( p ); -} +void tr_free( void * p ); /** * @brief make a newly-allocated copy of a chunk of memory @@ -319,10 +309,7 @@ static inline void tr_free( void * p ) * @param byteCount the number of bytes to copy * @return a newly-allocated copy of `src' that can be freed with tr_free() */ -static inline void* tr_memdup( const void * src, size_t byteCount ) -{ - return memcpy( tr_malloc( byteCount ), src, byteCount ); -} +void* tr_memdup( const void * src, size_t byteCount ); #define tr_new( struct_type, n_structs ) \ ( (struct_type *) tr_malloc ( ( (size_t) sizeof ( struct_type ) ) * ( ( size_t) ( n_structs ) ) ) ) @@ -348,10 +335,7 @@ char* tr_strndup( const void * in, int len ) TR_GNUC_MALLOC; * @param in is a void* so that callers can pass in both signed & unsigned without a cast * @return a newly-allocated copy of `in' that can be freed with tr_free() */ -static inline char* tr_strdup( const void * in ) -{ - return tr_strndup( in, in ? (int)strlen((const char *)in) : 0 ); -} +char* tr_strdup( const void * in ); /** @brief similar to bsearch() but returns the index of the lower bound */ int tr_lowerBound( const void * key, @@ -520,17 +504,10 @@ int tr_moveFile( const char * oldpath, const char * newpath, tr_bool * renamed ) TR_GNUC_NONNULL(1,2); /** @brief convenience function to remove an item from an array */ -static inline void tr_removeElementFromArray( void * array, - unsigned int index_to_remove, - size_t sizeof_element, - size_t nmemb ) -{ - char * a = (char*) array; - - memmove( a + sizeof_element * index_to_remove, - a + sizeof_element * ( index_to_remove + 1 ), - sizeof_element * ( --nmemb - index_to_remove ) ); -} +void tr_removeElementFromArray( void * array, + unsigned int index_to_remove, + size_t sizeof_element, + size_t nmemb ); /*** ****