From: Mike Gelfand Date: Wed, 24 May 2017 19:53:06 +0000 (+0300) Subject: Include stdbool.h unconditionally X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f27596238d37f14477cc474c62c52eb53c4dcea6;p=transmission 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. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index fc0d28ccf..3774945c7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -432,7 +432,6 @@ endif() include(LargeFileSupport) set(NEEDED_HEADERS - stdbool.h sys/statvfs.h xfs/xfs.h xlocale.h) diff --git a/configure.ac b/configure.ac index 18200e76a..c1a41886a 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/libtransmission/blocklist.c b/libtransmission/blocklist.c index b8e4dfa3d..0992ecc1b 100644 --- a/libtransmission/blocklist.c +++ b/libtransmission/blocklist.c @@ -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; } diff --git a/libtransmission/log.c b/libtransmission/log.c index d8bef40d0..9a8dada4d 100644 --- a/libtransmission/log.c +++ b/libtransmission/log.c @@ -97,8 +97,6 @@ void tr_logSetLevel(tr_log_level level) void tr_logSetQueueEnabled(bool isEnabled) { - assert(tr_isBool(isEnabled)); - myQueueEnabled = isEnabled; } diff --git a/libtransmission/makemeta.c b/libtransmission/makemeta.c index 51c37b3f8..99dcc6119 100644 --- a/libtransmission/makemeta.c +++ b/libtransmission/makemeta.c @@ -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) { diff --git a/libtransmission/peer-io.c b/libtransmission/peer-io.c index 4b27b5d45..5cffa1dfe 100644 --- a/libtransmission/peer-io.c +++ b/libtransmission/peer-io.c @@ -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 diff --git a/libtransmission/peer-mgr.c b/libtransmission/peer-mgr.c index ccd7441da..6d19ff3fb 100644 --- a/libtransmission/peer-mgr.c +++ b/libtransmission/peer-mgr.c @@ -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; diff --git a/libtransmission/peer-msgs.c b/libtransmission/peer-msgs.c index 07293b000..158502e2d 100644 --- a/libtransmission/peer-msgs.c +++ b/libtransmission/peer-msgs.c @@ -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) { diff --git a/libtransmission/rpc-server.c b/libtransmission/rpc-server.c index 80a77228d..3cea274c3 100644 --- a/libtransmission/rpc-server.c +++ b/libtransmission/rpc-server.c @@ -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; } diff --git a/libtransmission/session.c b/libtransmission/session.c index c18ff1b21..9a17b80a3 100644 --- a/libtransmission/session.c +++ b/libtransmission/session.c @@ -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; } diff --git a/libtransmission/torrent-ctor.c b/libtransmission/torrent-ctor.c index 4722f86b1..d7f23914b 100644 --- a/libtransmission/torrent-ctor.c +++ b/libtransmission/torrent-ctor.c @@ -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; diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index 3e9161400..049afe815 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -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) { diff --git a/libtransmission/transmission.h b/libtransmission/transmission.h index 2a914c3a6..57ed77be5 100644 --- a/libtransmission/transmission.h +++ b/libtransmission/transmission.h @@ -34,18 +34,9 @@ extern "C" ***/ #include /* uintN_t */ +#include /* bool */ #include /* time_t */ -#if !defined(__cplusplus) -#ifdef HAVE_STDBOOL_H -#include -#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