From f762c2ce6a1f3035c1b3ac2494934056614a0df8 Mon Sep 17 00:00:00 2001 From: Jordan Lee Date: Sat, 24 Aug 2013 18:08:38 +0000 Subject: [PATCH] treat bool args as booleans rather than ints; no need to compare them a la 'if (boolVal != 0)' --- libtransmission/peer-io.c | 4 +-- libtransmission/rpc-server.c | 4 ++- libtransmission/session.c | 12 +++++---- libtransmission/torrent-ctor.c | 45 +++++++++++++++++++++++----------- 4 files changed, 43 insertions(+), 22 deletions(-) diff --git a/libtransmission/peer-io.c b/libtransmission/peer-io.c index a8c41bed2..e9faa27ae 100644 --- a/libtransmission/peer-io.c +++ b/libtransmission/peer-io.c @@ -624,7 +624,7 @@ tr_peerIoNew (tr_session * session, io->port = port; io->socket = socket; io->utp_socket = utp_socket; - io->isIncoming = isIncoming != 0; + io->isIncoming = isIncoming; io->timeCreated = tr_time (); io->inbuf = evbuffer_new (); io->outbuf = evbuffer_new (); @@ -1051,7 +1051,7 @@ addDatatype (tr_peerIo * io, size_t byteCount, bool isPieceData) { struct tr_datatype * d; d = datatype_new (); - d->isPieceData = isPieceData != 0; + d->isPieceData = isPieceData; d->length = byteCount; peer_io_push_datatype (io, d); } diff --git a/libtransmission/rpc-server.c b/libtransmission/rpc-server.c index a97a32c88..9df5ddd1e 100644 --- a/libtransmission/rpc-server.c +++ b/libtransmission/rpc-server.c @@ -843,7 +843,9 @@ void tr_rpcSetWhitelistEnabled (tr_rpc_server * server, bool isEnabled) { - server->isWhitelistEnabled = isEnabled != 0; + assert (tr_isBool (isEnabled)); + + server->isWhitelistEnabled = isEnabled; } bool diff --git a/libtransmission/session.c b/libtransmission/session.c index 748647a0f..e8aed846f 100644 --- a/libtransmission/session.c +++ b/libtransmission/session.c @@ -2028,8 +2028,9 @@ void tr_sessionSetPexEnabled (tr_session * session, bool enabled) { assert (tr_isSession (session)); + assert (tr_isBool (enabled)); - session->isPexEnabled = enabled != 0; + session->isPexEnabled = enabled; } bool @@ -2071,7 +2072,7 @@ tr_sessionSetDHTEnabled (tr_session * session, bool enabled) assert (tr_isSession (session)); assert (tr_isBool (enabled)); - if ((enabled != 0) != (session->isDHTEnabled != 0)) + if (enabled != session->isDHTEnabled) tr_runInEventThread (session, toggleDHTImpl, session); } @@ -2112,7 +2113,7 @@ tr_sessionSetUTPEnabled (tr_session * session, bool enabled) assert (tr_isSession (session)); assert (tr_isBool (enabled)); - if ((enabled != 0) != (session->isUTPEnabled != 0)) + if (enabled != session->isUTPEnabled) tr_runInEventThread (session, toggle_utp, session); } @@ -2141,7 +2142,7 @@ tr_sessionSetLPDEnabled (tr_session * session, bool enabled) assert (tr_isSession (session)); assert (tr_isBool (enabled)); - if ((enabled != 0) != (session->isLPDEnabled != 0)) + if (enabled != session->isLPDEnabled) tr_runInEventThread (session, toggleLPDImpl, session); } @@ -2372,8 +2373,9 @@ tr_blocklistSetEnabled (tr_session * session, bool isEnabled) tr_list * l; assert (tr_isSession (session)); + assert (tr_isBool (isEnabled)); - session->isBlocklistEnabled = isEnabled != 0; + session->isBlocklistEnabled = isEnabled; for (l=session->blocklists; l!=NULL; l=l->next) tr_blocklistFileSetEnabled (l->data, isEnabled); diff --git a/libtransmission/torrent-ctor.c b/libtransmission/torrent-ctor.c index 2e19a0aee..fe45ed919 100644 --- a/libtransmission/torrent-ctor.c +++ b/libtransmission/torrent-ctor.c @@ -253,8 +253,10 @@ tr_ctorInitTorrentWanted (const tr_ctor * ctor, tr_torrent * tor) void tr_ctorSetDeleteSource (tr_ctor * ctor, bool deleteSource) { - ctor->doDelete = deleteSource != 0; - ctor->isSet_delete = 1; + assert (tr_isBool (deleteSource)); + + ctor->doDelete = deleteSource; + ctor->isSet_delete = true; } int @@ -277,7 +279,9 @@ tr_ctorGetDeleteSource (const tr_ctor * ctor, bool * setme) void tr_ctorSetSave (tr_ctor * ctor, bool saveInOurTorrentsDir) { - ctor->saveInOurTorrentsDir = saveInOurTorrentsDir != 0; + assert (tr_isBool (saveInOurTorrentsDir)); + + ctor->saveInOurTorrentsDir = saveInOurTorrentsDir; } int @@ -291,10 +295,15 @@ tr_ctorSetPaused (tr_ctor * ctor, tr_ctorMode mode, bool isPaused) { - struct optional_args * args = &ctor->optionalArgs[mode]; + struct optional_args * args; - args->isSet_paused = 1; - args->isPaused = isPaused ? 1 : 0; + assert (ctor != NULL); + assert ((mode == TR_FALLBACK) || (mode == TR_FORCE)); + assert (tr_isBool (isPaused)); + + args = &ctor->optionalArgs[mode]; + args->isSet_paused = true; + args->isPaused = isPaused; } void @@ -302,9 +311,13 @@ tr_ctorSetPeerLimit (tr_ctor * ctor, tr_ctorMode mode, uint16_t peerLimit) { - struct optional_args * args = &ctor->optionalArgs[mode]; + struct optional_args * args; + + assert (ctor != NULL); + assert ((mode == TR_FALLBACK) || (mode == TR_FORCE)); - args->isSet_connected = 1; + args = &ctor->optionalArgs[mode]; + args->isSet_connected = true; args->peerLimit = peerLimit; } @@ -313,15 +326,19 @@ tr_ctorSetDownloadDir (tr_ctor * ctor, tr_ctorMode mode, const char * directory) { - struct optional_args * args = &ctor->optionalArgs[mode]; + struct optional_args * args; + assert (ctor != NULL); + assert ((mode == TR_FALLBACK) || (mode == TR_FORCE)); + + args = &ctor->optionalArgs[mode]; tr_free (args->downloadDir); args->downloadDir = NULL; - args->isSet_downloadDir = 0; + args->isSet_downloadDir = false; if (directory && *directory) { - args->isSet_downloadDir = 1; + args->isSet_downloadDir = true; args->downloadDir = tr_strdup (directory); } } @@ -352,13 +369,13 @@ tr_ctorGetPeerLimit (const tr_ctor * ctor, int tr_ctorGetPaused (const tr_ctor * ctor, tr_ctorMode mode, bool * setmeIsPaused) { - int err = 0; + int err = 0; const struct optional_args * args = &ctor->optionalArgs[mode]; if (!args->isSet_paused) err = 1; else if (setmeIsPaused) - *setmeIsPaused = args->isPaused ? 1 : 0; + *setmeIsPaused = args->isPaused; return err; } @@ -368,7 +385,7 @@ tr_ctorGetDownloadDir (const tr_ctor * ctor, tr_ctorMode mode, const char ** setmeDownloadDir) { - int err = 0; + int err = 0; const struct optional_args * args = &ctor->optionalArgs[mode]; if (!args->isSet_downloadDir) -- 2.40.0