From 92ac49d9c4023b8fef2cc17a3962e6870cbad3fa Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sat, 27 Oct 2007 21:29:41 +0000 Subject: [PATCH] compatability with older C copmilers (ticket #422, patch by fizz) --- configure.ac | 17 +++++++++++++++++ gtk/tr_torrent.c | 2 +- libtransmission/handshake.c | 5 +++-- libtransmission/inout.c | 7 ++++--- libtransmission/peer-mgr.c | 21 +++++++++++---------- libtransmission/peer-msgs.c | 3 ++- 6 files changed, 38 insertions(+), 17 deletions(-) diff --git a/configure.ac b/configure.ac index 843c1d50b..cb3d2513f 100644 --- a/configure.ac +++ b/configure.ac @@ -36,6 +36,23 @@ AC_CHECK_LIB([ssl],[SSL_library_init]) AC_SEARCH_LIBS([socket], [socket net]) AC_SEARCH_LIBS([gethostbyname], [nsl bind]) +dnl ---------------------------------------------------------------------------- +dnl +dnl va_copy + +AC_MSG_CHECKING([how to copy va_list]) +AC_TRY_LINK([#include ], [va_list ap1, ap2; va_copy(ap1, ap2);], + AC_MSG_RESULT([va_copy]), + [ AH_TEMPLATE([va_copy], [define if va_copy is not available]) + AC_TRY_LINK([#include ], [va_list ap1, ap2; __va_copy(ap1, ap2);], + [ AC_DEFINE([va_copy], [__va_copy]) + AC_MSG_RESULT([__va_copy])], + [ AC_DEFINE([va_copy(dest,src)], [memcpy(&dest,&src,sizeof(va_list))]) + AC_MSG_RESULT([memcpy])] + ) +]) + + dnl ---------------------------------------------------------------------------- dnl dnl libevent fun diff --git a/gtk/tr_torrent.c b/gtk/tr_torrent.c index 6b7327b6d..7642c9799 100644 --- a/gtk/tr_torrent.c +++ b/gtk/tr_torrent.c @@ -177,8 +177,8 @@ tr_torrent_stop( TrTorrent * self ) static TrTorrent * maketorrent( tr_torrent * handle ) { - tr_torrentDisablePex( handle, !pref_flag_get( PREF_KEY_PEX ) ); TrTorrent * tor = g_object_new( TR_TORRENT_TYPE, NULL ); + tr_torrentDisablePex( handle, !pref_flag_get( PREF_KEY_PEX ) ); tor->handle = handle; return tor; } diff --git a/libtransmission/handshake.c b/libtransmission/handshake.c index 200adacce..8fe683608 100644 --- a/libtransmission/handshake.c +++ b/libtransmission/handshake.c @@ -968,9 +968,10 @@ gotError( struct bufferevent * evbuf UNUSED, short what, void * arg ) && ( handshake->allowUnencryptedPeers ) && ( !tr_peerIoReconnect( handshake->io ) ) ) { - dbgmsg( handshake, "handshake failed, trying plaintext..." ); int msgSize; - uint8_t * msg = buildHandshakeMessage( handshake, &msgSize ); + uint8_t * msg; + dbgmsg( handshake, "handshake failed, trying plaintext..." ); + msg = buildHandshakeMessage( handshake, &msgSize ); handshake->haveSentBitTorrentHandshake = 1; setReadState( handshake, AWAITING_HANDSHAKE ); tr_peerIoWrite( handshake->io, msg, msgSize ); diff --git a/libtransmission/inout.c b/libtransmission/inout.c index d297dab99..cc7b703ec 100644 --- a/libtransmission/inout.c +++ b/libtransmission/inout.c @@ -427,10 +427,11 @@ tr_ioRecheckRemove( tr_torrent * tor ) else { struct recheck_node tmp; + struct recheck_node * node; tmp.torrent = tor; - struct recheck_node * node = tr_list_remove( &recheckList, - &tmp, - compareRecheckByTorrent ); + node = tr_list_remove( &recheckList, + &tmp, + compareRecheckByTorrent ); tr_free( node ); tor->recheckState = TR_RECHECK_NONE; } diff --git a/libtransmission/peer-mgr.c b/libtransmission/peer-mgr.c index dad3be623..7b80e95ec 100644 --- a/libtransmission/peer-mgr.c +++ b/libtransmission/peer-mgr.c @@ -441,16 +441,18 @@ generate : /* TODO : We should translate link-local IPv4 adresses to external IP, * so that being on same local network gives us the same allowed pieces */ + uint8_t *seed; + char buf[4]; + uint32_t allowedPieceCount = 0; + tr_bitfield_t * ret; + printf( "%d piece allowed fast set for torrent with %d pieces and hex infohash\n", setCount, pieceCount ); printf( "%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x for node with IP %s:\n", infohash[0], infohash[1], infohash[2], infohash[3], infohash[4], infohash[5], infohash[6], infohash[7], infohash[8], infohash[9], infohash[10], infohash[11], infohash[12], infohash[13], infohash[14], infohash[15], infohash[16], infohash[7], infohash[18], infohash[19], inet_ntoa( *ip ) ); - uint8_t *seed = malloc(4 + SHA_DIGEST_LENGTH); - char buf[4]; - uint32_t allowedPieceCount = 0; - tr_bitfield_t * ret; + seed = malloc(4 + SHA_DIGEST_LENGTH); ret = tr_bitfieldNew( pieceCount ); @@ -1690,20 +1692,19 @@ reconnectPulse( void * vtorrent ) for( i=0; imanager; - struct peer_atom * atom = candidates[i]; - tr_peerIo * io; + tr_handshake * handshake; tordbg( t, "Starting an OUTGOING connection with %s", tr_peerIoAddrStr( &atom->addr, atom->port ) ); io = tr_peerIoNewOutgoing( mgr->handle, &atom->addr, atom->port, t->hash ); - tr_handshake * handshake = tr_handshakeNew( io, - mgr->handle->encryptionMode, - myHandshakeDoneCB, - mgr ); + handshake = tr_handshakeNew( io, + mgr->handle->encryptionMode, + myHandshakeDoneCB, + mgr ); assert( tr_peerIoGetTorrentHash( io ) != NULL ); diff --git a/libtransmission/peer-msgs.c b/libtransmission/peer-msgs.c index cc6baca48..539e5a888 100644 --- a/libtransmission/peer-msgs.c +++ b/libtransmission/peer-msgs.c @@ -1692,6 +1692,7 @@ tr_peerMsgsNew( struct tr_torrent * torrent, sendBitfield( m ); else { /* This peer is fastpeer-enabled, send it have-all or have-none if appropriate */ + uint32_t peerProgress; float completion = tr_cpPercentComplete( m->torrent->completion ); if ( completion == 0.0f ) { sendFastHave( m, 0 ); @@ -1700,7 +1701,7 @@ tr_peerMsgsNew( struct tr_torrent * torrent, } else { sendBitfield( m ); } - uint32_t peerProgress = m->torrent->info.pieceCount * m->info->progress; + peerProgress = m->torrent->info.pieceCount * m->info->progress; if ( peerProgress < MAX_ALLOWED_SET_COUNT ) sendFastAllowedSet( m );