treat bool args as booleans rather than ints; no need to compare them a la 'if (boolVal != 0)'

This commit is contained in:
Jordan Lee 2013-08-24 18:08:38 +00:00
parent 28fe36f1f8
commit f762c2ce6a
4 changed files with 43 additions and 22 deletions

View File

@ -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);
}

View File

@ -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

View File

@ -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);

View File

@ -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;
args->isSet_connected = 1;
assert (ctor != NULL);
assert ((mode == TR_FALLBACK) || (mode == TR_FORCE));
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)