Include stdbool.h unconditionally

All the compilers should provide the header file by now. Remove `tr_isBool`
sanity checks along the way as compiler should guarantee that bool (_Bool)
values are 0 or 1 and nothing else.
This commit is contained in:
Mike Gelfand 2017-05-24 22:53:06 +03:00
parent 295d3359b2
commit f27596238d
13 changed files with 2 additions and 53 deletions

View File

@ -432,7 +432,6 @@ endif()
include(LargeFileSupport)
set(NEEDED_HEADERS
stdbool.h
sys/statvfs.h
xfs/xfs.h
xlocale.h)

View File

@ -109,7 +109,7 @@ AC_PROG_MKDIR_P
AC_HEADER_STDC
AC_HEADER_TIME
AC_CHECK_HEADERS([stdbool.h xlocale.h])
AC_CHECK_HEADERS([xlocale.h])
AC_CHECK_FUNCS([iconv pread pwrite lrintf strlcpy daemon dirname basename canonicalize_file_name strcasecmp localtime_r fallocate64 posix_fallocate memmem strsep strtold syslog valloc getpagesize posix_memalign statvfs htonll ntohll mkdtemp uselocale _configthreadlocale])
AC_PROG_INSTALL
AC_PROG_MAKE_SET

View File

@ -184,7 +184,6 @@ bool tr_blocklistFileIsEnabled(tr_blocklistFile* b)
void tr_blocklistFileSetEnabled(tr_blocklistFile* b, bool isEnabled)
{
assert(b != NULL);
assert(tr_isBool(isEnabled));
b->isEnabled = isEnabled;
}

View File

@ -97,8 +97,6 @@ void tr_logSetLevel(tr_log_level level)
void tr_logSetQueueEnabled(bool isEnabled)
{
assert(tr_isBool(isEnabled));
myQueueEnabled = isEnabled;
}

View File

@ -560,8 +560,6 @@ void tr_makeMetaInfo(tr_metainfo_builder* builder, char const* outputFile, tr_tr
{
tr_lock* lock;
assert(tr_isBool(isPrivate));
/* free any variables from a previous run */
for (int i = 0; i < builder->trackerCount; ++i)
{

View File

@ -619,8 +619,6 @@ static tr_peerIo* tr_peerIoNew(tr_session* session, tr_bandwidth* parent, tr_add
assert(session != NULL);
assert(session->events != NULL);
assert(tr_isBool(isIncoming));
assert(tr_isBool(isSeed));
assert(tr_amInEventThread(session));
assert((socket == TR_BAD_SOCKET) == (utp_socket != NULL));
#ifndef WITH_UTP

View File

@ -575,7 +575,6 @@ static bool isAtomBlocklisted(tr_session* session, struct peer_atom* atom)
atom->blocklisted = tr_sessionIsAddressBlocked(session, &atom->addr);
}
assert(tr_isBool(atom->blocklisted));
return atom->blocklisted;
}
@ -2007,7 +2006,6 @@ static bool myHandshakeDoneCB(tr_handshake* handshake, tr_peerIo* io, bool readA
tr_swarm* s;
assert(io != NULL);
assert(tr_isBool(ok));
s = tr_peerIoHasTorrentHash(io) ? getExistingSwarm(manager, tr_peerIoGetTorrentHash(io)) : NULL;

View File

@ -728,7 +728,6 @@ static void sendInterest(tr_peerMsgs* msgs, bool b)
struct evbuffer* out = msgs->outMessages;
assert(msgs != NULL);
assert(tr_isBool(b));
msgs->client_is_interested = b;
dbgmsg(msgs, "Sending %s", b ? "Interested" : "Not Interested");
@ -746,8 +745,6 @@ static void updateInterest(tr_peerMsgs* msgs UNUSED)
void tr_peerMsgsSetInterested(tr_peerMsgs* msgs, bool b)
{
assert(tr_isBool(b));
if (msgs->client_is_interested != b)
{
sendInterest(msgs, b);
@ -804,7 +801,6 @@ void tr_peerMsgsSetChoke(tr_peerMsgs* msgs, bool peer_is_choked)
time_t const fibrillationTime = now - MIN_CHOKE_PERIOD_SEC;
assert(msgs != NULL);
assert(tr_isBool(peer_is_choked));
if (msgs->chokeChangedAt > fibrillationTime)
{

View File

@ -879,8 +879,6 @@ char const* tr_rpcGetWhitelist(tr_rpc_server const* server)
void tr_rpcSetWhitelistEnabled(tr_rpc_server* server, bool isEnabled)
{
assert(tr_isBool(isEnabled));
server->isWhitelistEnabled = isEnabled;
}

View File

@ -1200,7 +1200,6 @@ int64_t tr_sessionGetDirFreeSpace(tr_session* session, char const* dir)
void tr_sessionSetIncompleteFileNamingEnabled(tr_session* session, bool b)
{
assert(tr_isSession(session));
assert(tr_isBool(b));
session->isIncompleteFileNamingEnabled = b;
}
@ -1238,7 +1237,6 @@ char const* tr_sessionGetIncompleteDir(tr_session const* session)
void tr_sessionSetIncompleteDirEnabled(tr_session* session, bool b)
{
assert(tr_isSession(session));
assert(tr_isBool(b));
session->isIncompleteDirEnabled = b;
}
@ -1510,8 +1508,6 @@ static void useAltSpeed(tr_session* s, struct tr_turtle_info* t, bool enabled, b
{
assert(tr_isSession(s));
assert(t != NULL);
assert(tr_isBool(enabled));
assert(tr_isBool(byUser));
if (t->isEnabled != enabled)
{
@ -1624,7 +1620,6 @@ void tr_sessionLimitSpeed(tr_session* s, tr_direction d, bool b)
{
assert(tr_isSession(s));
assert(tr_isDirection(d));
assert(tr_isBool(b));
s->speedLimitEnabled[d] = b;
@ -1692,7 +1687,6 @@ void tr_sessionUseAltSpeedTime(tr_session* s, bool b)
struct tr_turtle_info* t = &s->turtle;
assert(tr_isSession(s));
assert(tr_isBool(b));
if (t->isClockEnabled != b)
{
@ -2214,7 +2208,6 @@ tr_torrent** tr_sessionLoadTorrents(tr_session* session, tr_ctor* ctor, int* set
void tr_sessionSetPexEnabled(tr_session* session, bool enabled)
{
assert(tr_isSession(session));
assert(tr_isBool(enabled));
session->isPexEnabled = enabled;
}
@ -2251,7 +2244,6 @@ static void toggleDHTImpl(void* data)
void tr_sessionSetDHTEnabled(tr_session* session, bool enabled)
{
assert(tr_isSession(session));
assert(tr_isBool(enabled));
if (enabled != session->isDHTEnabled)
{
@ -2291,7 +2283,6 @@ static void toggle_utp(void* data)
void tr_sessionSetUTPEnabled(tr_session* session, bool enabled)
{
assert(tr_isSession(session));
assert(tr_isBool(enabled));
if (enabled != session->isUTPEnabled)
{
@ -2324,7 +2315,6 @@ static void toggleLPDImpl(void* data)
void tr_sessionSetLPDEnabled(tr_session* session, bool enabled)
{
assert(tr_isSession(session));
assert(tr_isBool(enabled));
if (enabled != session->isLPDEnabled)
{
@ -2560,7 +2550,6 @@ bool tr_blocklistIsEnabled(tr_session const* session)
void tr_blocklistSetEnabled(tr_session* session, bool isEnabled)
{
assert(tr_isSession(session));
assert(tr_isBool(isEnabled));
session->isBlocklistEnabled = isEnabled;
@ -2858,7 +2847,6 @@ bool tr_sessionIsTorrentDoneScriptEnabled(tr_session const* session)
void tr_sessionSetTorrentDoneScriptEnabled(tr_session* session, bool isEnabled)
{
assert(tr_isSession(session));
assert(tr_isBool(isEnabled));
session->isTorrentDoneScriptEnabled = isEnabled;
}
@ -2905,7 +2893,6 @@ void tr_sessionSetQueueEnabled(tr_session* session, tr_direction dir, bool is_en
{
assert(tr_isSession(session));
assert(tr_isDirection(dir));
assert(tr_isBool(is_enabled));
session->queueEnabled[dir] = is_enabled;
}
@ -2929,7 +2916,6 @@ void tr_sessionSetQueueStalledMinutes(tr_session* session, int minutes)
void tr_sessionSetQueueStalledEnabled(tr_session* session, bool is_enabled)
{
assert(tr_isSession(session));
assert(tr_isBool(is_enabled));
session->stalledEnabled = is_enabled;
}

View File

@ -273,8 +273,6 @@ void tr_ctorInitTorrentWanted(tr_ctor const* ctor, tr_torrent* tor)
void tr_ctorSetDeleteSource(tr_ctor* ctor, bool deleteSource)
{
assert(tr_isBool(deleteSource));
ctor->doDelete = deleteSource;
ctor->isSet_delete = true;
}
@ -301,8 +299,6 @@ bool tr_ctorGetDeleteSource(tr_ctor const* ctor, bool* setme)
void tr_ctorSetSave(tr_ctor* ctor, bool saveInOurTorrentsDir)
{
assert(tr_isBool(saveInOurTorrentsDir));
ctor->saveInOurTorrentsDir = saveInOurTorrentsDir;
}
@ -317,7 +313,6 @@ void tr_ctorSetPaused(tr_ctor* ctor, tr_ctorMode mode, bool isPaused)
assert(ctor != NULL);
assert(mode == TR_FALLBACK || mode == TR_FORCE);
assert(tr_isBool(isPaused));
args = &ctor->optionalArgs[mode];
args->isSet_paused = true;

View File

@ -3817,7 +3817,6 @@ void tr_torrentsQueueMoveBottom(tr_torrent** torrents_in, int n)
static void torrentSetQueued(tr_torrent* tor, bool queued)
{
assert(tr_isTorrent(tor));
assert(tr_isBool(queued));
if (tr_torrentIsQueued(tor) != queued)
{

View File

@ -34,18 +34,9 @@ extern "C"
***/
#include <inttypes.h> /* uintN_t */
#include <stdbool.h> /* bool */
#include <time.h> /* time_t */
#if !defined(__cplusplus)
#ifdef HAVE_STDBOOL_H
#include <stdbool.h>
#elif !defined(__bool_true_false_are_defined)
#define bool uint8_t
#define true 1
#define false 0
#endif
#endif
#define SHA_DIGEST_LENGTH 20
#define TR_INET6_ADDRSTRLEN 46
@ -1895,12 +1886,6 @@ static inline bool tr_isDirection(tr_direction d)
return d == TR_UP || d == TR_DOWN;
}
/** @brief Sanity checker to test that a bool is true or false */
static inline bool tr_isBool(bool b)
{
return b == 1 || b == 0;
}
#ifdef __cplusplus
}
#endif