From 0f1f84898b1522b89f6162bb662f5293a2e22caf Mon Sep 17 00:00:00 2001 From: Jordan Lee Date: Sat, 17 Aug 2013 17:20:31 +0000 Subject: [PATCH] silence a small handful of minor gcc compiler warnings in libtransmission --- libtransmission/bandwidth.c | 8 +------- libtransmission/peer-mgr.c | 16 ++++------------ libtransmission/ptrarray.c | 23 +++++++++++++++++++---- libtransmission/ptrarray.h | 10 +++++----- 4 files changed, 29 insertions(+), 28 deletions(-) diff --git a/libtransmission/bandwidth.c b/libtransmission/bandwidth.c index 24695e570..016159620 100644 --- a/libtransmission/bandwidth.c +++ b/libtransmission/bandwidth.c @@ -141,14 +141,8 @@ tr_bandwidthSetParent (tr_bandwidth * b, if (b->parent) { - void * removed; - assert (tr_isBandwidth (b->parent)); - - removed = tr_ptrArrayRemoveSorted (&b->parent->children, b, compareBandwidth); - assert (removed == b); - assert (tr_ptrArrayFindSorted (&b->parent->children, b, compareBandwidth) == NULL); - + tr_ptrArrayRemoveSortedPointer (&b->parent->children, b, compareBandwidth); b->parent = NULL; } diff --git a/libtransmission/peer-mgr.c b/libtransmission/peer-mgr.c index cb6d184c1..ee624d896 100644 --- a/libtransmission/peer-mgr.c +++ b/libtransmission/peer-mgr.c @@ -1954,7 +1954,6 @@ myHandshakeDoneCB (tr_handshake * handshake, const tr_address * addr; tr_peerMgr * manager = vmanager; tr_swarm * s; - tr_handshake * ours; assert (io); assert (tr_isBool (ok)); @@ -1964,16 +1963,11 @@ myHandshakeDoneCB (tr_handshake * handshake, : NULL; if (tr_peerIoIsIncoming (io)) - ours = tr_ptrArrayRemoveSorted (&manager->incomingHandshakes, + tr_ptrArrayRemoveSortedPointer (&manager->incomingHandshakes, handshake, handshakeCompare); else if (s) - ours = tr_ptrArrayRemoveSorted (&s->outgoingHandshakes, + tr_ptrArrayRemoveSortedPointer (&s->outgoingHandshakes, handshake, handshakeCompare); - else - ours = handshake; - - assert (ours); - assert (ours == handshake); if (s) swarmLock (s); @@ -3307,7 +3301,6 @@ getReconnectIntervalSecs (const struct peer_atom * atom, const time_t now) static void removePeer (tr_swarm * s, tr_peer * peer) { - tr_peer * removed; struct peer_atom * atom = peer->atom; assert (swarmIsLocked (s)); @@ -3315,18 +3308,17 @@ removePeer (tr_swarm * s, tr_peer * peer) atom->time = tr_time (); - removed = tr_ptrArrayRemoveSorted (&s->peers, peer, peerCompare); + tr_ptrArrayRemoveSortedPointer (&s->peers, peer, peerCompare); --s->stats.peerCount; --s->stats.peerFromCount[atom->fromFirst]; if (replicationExists (s)) tr_decrReplicationFromBitfield (s, &peer->have); - assert (removed == peer); assert (s->stats.peerCount == tr_ptrArraySize (&s->peers)); assert (s->stats.peerFromCount[atom->fromFirst] >= 0); - tr_peerFree (removed); + tr_peerFree (peer); } static void diff --git a/libtransmission/ptrarray.c b/libtransmission/ptrarray.c index 36842ef5d..09046df4f 100644 --- a/libtransmission/ptrarray.c +++ b/libtransmission/ptrarray.c @@ -215,10 +215,10 @@ tr_ptrArrayFindSorted (tr_ptrArray * t, return match ? t->items[pos] : NULL; } -void* -tr_ptrArrayRemoveSorted (tr_ptrArray * t, - const void * ptr, - int compare (const void*, const void*)) +static void* +tr_ptrArrayRemoveSortedValue (tr_ptrArray * t, + const void * ptr, + int compare (const void*, const void*)) { int pos; bool match; @@ -238,3 +238,18 @@ tr_ptrArrayRemoveSorted (tr_ptrArray * t, assert ((ret == NULL) || (compare (ret, ptr) == 0)); return ret; } + +void +tr_ptrArrayRemoveSortedPointer (tr_ptrArray * t, + const void * ptr, + int compare (const void*, const void*)) +{ +#ifdef NDEBUG + tr_ptrArrayRemoveSortedValue (t, ptr, compare); +#else + void * removed = tr_ptrArrayRemoveSortedValue (t, ptr, compare); + assert (removed != NULL); + assert (removed == ptr); + assert (tr_ptrArrayFindSorted (t, ptr, compare) == NULL); +#endif +} diff --git a/libtransmission/ptrarray.h b/libtransmission/ptrarray.h index 0f8667806..6d3c9de56 100644 --- a/libtransmission/ptrarray.h +++ b/libtransmission/ptrarray.h @@ -130,11 +130,11 @@ int tr_ptrArrayInsertSorted (tr_ptrArray * array, void * value, int compare (const void*, const void*)); -/** @brief Remove a pointer from an array sorted by the specified sort function - @return the matching pointer, or NULL if no match was found */ -void* tr_ptrArrayRemoveSorted (tr_ptrArray * array, - const void * value, - int compare (const void*, const void*)); +/** @brief Remove this specific pointer from a sorted ptrarray */ +void tr_ptrArrayRemoveSortedPointer (tr_ptrArray * t, + const void * ptr, + int compare (const void*, const void*)); + /** @brief Find a pointer from an array sorted by the specified sort function @return the matching pointer, or NULL if no match was found */ -- 2.40.0