Skip to content

Commit

Permalink
code cleanup: remove all instances of assert(this);
Browse files Browse the repository at this point in the history
  • Loading branch information
dspeterson committed Jun 21, 2020
1 parent af143f3 commit dd0e770
Show file tree
Hide file tree
Showing 247 changed files with 40 additions and 1,831 deletions.
1 change: 0 additions & 1 deletion doc/status_monitoring.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ for class `TMsg`, which represents a single message:
```C++
TMsg::~TMsg() {
assert(this);
MsgDestroy.Increment();
if (State != TState::Processed) {
Expand Down
3 changes: 0 additions & 3 deletions src/base/backoff_rate_limiter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ TBackoffRateLimiter::TBackoffRateLimiter(
}

size_t TBackoffRateLimiter::ComputeDelay() {
assert(this);
struct timespec now;
GetCurrentTime(now);

Expand All @@ -79,8 +78,6 @@ size_t TBackoffRateLimiter::ComputeDelay() {

bool
TBackoffRateLimiter::InBackoffWindow(const struct timespec &now) noexcept {
assert(this);

if (FirstTime) {
FirstTime = false;
return false;
Expand Down
1 change: 0 additions & 1 deletion src/base/backoff_rate_limiter.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ namespace Base {
the internal state of the rate limiter so it will correctly compute the
next delay value. */
void OnAction() noexcept {
assert(this);
GetCurrentTime(LastEventTime);
}

Expand Down
5 changes: 0 additions & 5 deletions src/base/blocking_asset.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,22 @@ namespace Base {
The target must not currently be locked by any thread.
Destroying a locked target has undefined results. */
~TBlockingAsset() {
assert(this);
Wr::pthread_rwlock_destroy(&RwLock);
}

void AcquireExclusive() const noexcept {
assert(this);
Wr::pthread_rwlock_wrlock(&RwLock);
}

void AcquireShared() const noexcept {
assert(this);
Wr::pthread_rwlock_rdlock(&RwLock);
}

void ReleaseExclusive() const noexcept {
assert(this);
Wr::pthread_rwlock_unlock(&RwLock);
}

void ReleaseShared() const noexcept {
assert(this);
Wr::pthread_rwlock_unlock(&RwLock);
}

Expand Down
22 changes: 0 additions & 22 deletions src/base/buf.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ namespace Base {

/* Move assignment operator leaves 'that' empty. */
TBuf &operator=(TBuf &&that) noexcept {
assert(this);

if (&that != this) {
Storage = std::move(that.Storage);
ItemOffset = that.ItemOffset;
Expand All @@ -90,7 +88,6 @@ namespace Base {
/* Move-assign 'items' into buffer, making 'items' its new contents. May
be used in combination with TakeStorage() to refill buffer. */
TBuf &operator=(TStorage &&items) {
assert(this);
Storage = std::move(items);
ItemOffset = 0;
ItemCount = Storage.size();
Expand All @@ -99,9 +96,6 @@ namespace Base {

/* Swap contents with contents of 'that'. */
void Swap(TBuf &that) noexcept {
assert(this);
assert(&that);

if (&that != this) {
Storage.swap(that.Storage);
std::swap(ItemOffset, that.ItemOffset);
Expand All @@ -111,7 +105,6 @@ namespace Base {

/* Mark all data as consumed, leaving nothing but empty space. */
void Clear() noexcept {
assert(this);
MarkDataConsumed(ItemCount);
}

Expand All @@ -122,7 +115,6 @@ namespace Base {
by routines that take as input a vector to fill with data. It allows
underlying memory allocated for storage to be reused. */
TStorage TakeStorage() noexcept {
assert(this);
ItemOffset = 0;
ItemCount = 0;
return std::move(Storage);
Expand All @@ -131,7 +123,6 @@ namespace Base {
/* Return pointer to start location where additional items are expected to
be deposited. Do not call unless SpaceSize() returns a value > 0. */
T *Space() noexcept {
assert(this);
assert(ItemOffset < Storage.size());
assert(ItemCount < (Storage.size() - ItemOffset));
assert(SpaceSize() > 0);
Expand All @@ -140,7 +131,6 @@ namespace Base {

/* Return number of items the region returned by Space() can hold. */
size_t SpaceSize() const noexcept {
assert(this);
assert(Storage.empty() || (ItemOffset < Storage.size()));
assert(ItemCount <= (Storage.size() - ItemOffset));
return Storage.size() - ItemOffset - ItemCount;
Expand All @@ -149,7 +139,6 @@ namespace Base {
/* Return true if buffer currently has no space where additional items can
be deposited, or false otherwise. */
bool SpaceIsEmpty() const noexcept {
assert(this);
assert(Storage.empty() || (ItemOffset < Storage.size()));
assert(ItemCount <= (Storage.size() - ItemOffset));
return (SpaceSize() == 0);
Expand All @@ -158,7 +147,6 @@ namespace Base {
/* Return pointer to start location of received items that are ready to be
consumed. Do not call unless DataSize() returns a value > 0. */
T *Data() noexcept {
assert(this);
assert(ItemOffset < Storage.size());
assert(ItemCount <= (Storage.size() - ItemOffset));
assert(DataSize() > 0);
Expand All @@ -168,7 +156,6 @@ namespace Base {
/* Return const pointer to start location of received items that are ready
to be consumed. Do not call unless DataSize() returns a value > 0. */
const T *Data() const noexcept {
assert(this);
assert(ItemOffset < Storage.size());
assert(ItemCount <= (Storage.size() - ItemOffset));
assert(DataSize() > 0);
Expand All @@ -177,7 +164,6 @@ namespace Base {

/* Return number of items the region returned by Data() holds. */
size_t DataSize() const noexcept {
assert(this);
assert(Storage.empty() || (ItemOffset < Storage.size()));
assert(ItemCount <= (Storage.size() - ItemOffset));
return ItemCount;
Expand All @@ -186,7 +172,6 @@ namespace Base {
/* Return true if buffer currently has no received items that are ready to
be consumed, or false otherwise. */
bool DataIsEmpty() const noexcept {
assert(this);
assert(Storage.empty() || (ItemOffset < Storage.size()));
assert(ItemCount <= (Storage.size() - ItemOffset));
return (DataSize() == 0);
Expand All @@ -196,7 +181,6 @@ namespace Base {
without allocating memory. This method is a no-op if the buffer is
empty or its items are already at the front. */
void MoveDataToFront() noexcept {
assert(this);
assert(Storage.empty() || (ItemOffset < Storage.size()));
assert(ItemCount <= (Storage.size() - ItemOffset));

Expand All @@ -215,7 +199,6 @@ namespace Base {
'min_to_add' items. Note that moving the items to the front may make
more than 'min_to_add' extra space available. */
void AddSpace(size_t min_to_add) {
assert(this);
assert(Storage.empty() || (ItemOffset < Storage.size()));
assert(ItemCount <= (Storage.size() - ItemOffset));

Expand All @@ -228,7 +211,6 @@ namespace Base {
necessary, move items to front of buffer and possibly allocate
additional storage. */
void EnsureSpace(size_t min_size) {
assert(this);
assert(Storage.empty() || (ItemOffset < Storage.size()));
assert(ItemCount <= (Storage.size() - ItemOffset));
size_t actual = SpaceSize();
Expand All @@ -242,7 +224,6 @@ namespace Base {
items the buffer can hold is at least 'min_size'. If necessary, move
items to front of buffer and possibly allocate additional storage. */
void EnsureDataPlusSpace(size_t min_size) {
assert(this);
assert(Storage.empty() || (ItemOffset < Storage.size()));
assert(ItemCount <= (Storage.size() - ItemOffset));
size_t actual = Storage.size() - ItemOffset;
Expand All @@ -257,7 +238,6 @@ namespace Base {
consumed. This increases the value returned by DataSize() and decreases
the value returned by SpaceSize(). */
void MarkSpaceConsumed(size_t size) noexcept {
assert(this);
assert(Storage.empty() || (ItemOffset < Storage.size()));
assert(ItemCount <= (Storage.size() - ItemOffset));
assert(size <= SpaceSize());
Expand All @@ -270,7 +250,6 @@ namespace Base {
available space indicated by SpaceSize() follows the unconsumed items,
and consuming items makes space available at the front. */
void MarkDataConsumed(size_t size) noexcept {
assert(this);
assert(Storage.empty() || (ItemOffset < Storage.size()));
assert(ItemCount <= (Storage.size() - ItemOffset));
assert(size <= DataSize());
Expand All @@ -284,7 +263,6 @@ namespace Base {

private:
void DoAddSpace(size_t min_to_add) {
assert(this);
assert(min_to_add);
assert(Storage.empty() || (ItemOffset < Storage.size()));
assert(ItemCount <= (Storage.size() - ItemOffset));
Expand Down
2 changes: 0 additions & 2 deletions src/base/code_location.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@
using namespace Base;

const char *TCodeLocation::GetFile() const noexcept {
assert(this);
return File + ((std::strncmp(File, SrcRoot, SrcRootLen) == 0) ?
(SrcRootLen) : 0);
}

void TCodeLocation::Write(std::ostream &strm) const {
assert(this);
strm << '[' << GetFile() << ", " << LineNumber << ']';
}

Expand Down
1 change: 0 additions & 1 deletion src/base/code_location.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ namespace Base {

/* Returns the line number. Always returns > 0. */
unsigned GetLineNumber() const {
assert(this);
return LineNumber;
}

Expand Down
18 changes: 0 additions & 18 deletions src/base/convert.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ namespace Base {
the next character at the head of the input stream, it returns
TOpt::Unknown. */
TOpt<bool> TryReadSign() {
assert(this);

if(!(*this)) {
return *TOpt<bool>::Unknown;
}
Expand All @@ -60,7 +58,6 @@ namespace Base {

/* TryReadSign wrapper that asserts that a sign is read or throws. */
bool ReadSign() {
assert(this);
TOpt<bool> ret = TryReadSign();

if (ret) {
Expand All @@ -73,20 +70,16 @@ namespace Base {
/* Returns true if there is a next character in the input stream and it is
a digit, false otherwise. */
bool HasDigit() {
assert(this);
return ((*this) && isdigit(*(*this)));
}

void ConsumeWhitespace() {
assert(this);
while(isspace(**this)) { ++(*this); }
}

/* Reads in a character from Input and converts it to it's decimal value.
*/
template<typename TVal> bool TryReadDigit(TVal &output) {
assert(this);
assert(&output);
assert(std::numeric_limits<TVal>::is_exact);
assert(std::numeric_limits<TVal>::min() <= 0);
assert(std::numeric_limits<TVal>::max() >= 9);
Expand All @@ -109,8 +102,6 @@ namespace Base {
bounds checking. */
template<typename TVal> bool TryReadUnsignedInt(TVal &output,
bool positive = true) {
assert(this);
assert(&output);
assert(std::numeric_limits<TVal>::is_integer);
assert(std::numeric_limits<TVal>::is_exact);
assert(positive || std::numeric_limits<TVal>::is_signed);
Expand Down Expand Up @@ -165,8 +156,6 @@ namespace Base {
read or an exception thrown. */
template <typename TVal>
TConverter &ReadUnsignedInt(TVal &output, bool positive=true) {
assert(this);

if (!TryReadUnsignedInt(output, positive)) {
throw TSyntaxError(HERE,
"No integer exists at current location in stream.");
Expand All @@ -187,8 +176,6 @@ namespace Base {
support hexadecimal and octal. */
template <typename TVal>
bool TryReadInt(TVal &output, bool sign_required = false) {
assert(this);
assert(&output);
assert(std::numeric_limits<TVal>::is_integer);
assert(std::numeric_limits<TVal>::is_exact);
assert(sign_required ? std::numeric_limits<TVal>::is_signed : true);
Expand Down Expand Up @@ -219,8 +206,6 @@ namespace Base {
at the current stream head, then an exception should be thrown. */
template <typename TVal>
TConverter &ReadInt(TVal &output, bool sign_required = false) {
assert(this);

if (!TryReadInt(output, sign_required)) {
throw TSyntaxError(HERE, "No integer exists at current location.");
}
Expand All @@ -241,7 +226,6 @@ namespace Base {
void ReadDouble(double &output, bool sign_required=false);

operator bool() const {
assert(this);
return Working;
}

Expand All @@ -267,8 +251,6 @@ namespace Base {
}

TConverter &operator++() {
assert(this);

if (!Working) {
throw TSyntaxError(HERE, "unexpectedly out of text");
}
Expand Down
5 changes: 0 additions & 5 deletions src/base/counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,33 +100,28 @@ namespace Base {

/* The code location at which the counter was declared. */
const Base::TCodeLocation &GetCodeLocation() const noexcept {
assert(this);
return CodeLocation;
}

/* The count as of the last time the counters were sampled. */
uint32_t GetCount() const noexcept {
assert(this);
return SampledCount;
}

/* The name of this counter. This should be unique within its module.
Never null. */
const char *GetName() const noexcept {
assert(this);
return Name;
}

/* The next counter in the program, if any. */
const TCounter *GetNextCounter() const noexcept {
assert(this);
return NextCounter;
}

/* Increment the counter. This will not change the current frozen value,
but will be reflected in the next frozen value. */
void Increment(uint32_t delta = 1) noexcept {
assert(this);
Base::TSharedLock<Base::TBlockingAsset> lock(Asset);
__sync_add_and_fetch(&UnsampledCount, delta);
}
Expand Down
2 changes: 0 additions & 2 deletions src/base/demangle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,11 @@ TDemangle::TDemangle(const char *mangled) : Buf(nullptr) {
}

TDemangle::~TDemangle() {
assert(this);
assert(Buf);
free(Buf); //The gcc man pages use free, so we use free.
}

const char *TDemangle::Get() const {
assert(this);
assert(Buf);
return Buf;
}
Expand Down
4 changes: 0 additions & 4 deletions src/base/dir_iter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,15 @@ TDirIter::TDirIter(const char *dir)
}

TDirIter::~TDirIter() {
assert(this);
Wr::closedir(Handle);
}

void TDirIter::Rewind() noexcept {
assert(this);
rewinddir(Handle);
Pos = NotFresh;
}

bool TDirIter::TryRefresh() const noexcept {
assert(this);

while (Pos == NotFresh) {
dirent *const ptr = Wr::readdir(Handle);

Expand Down
Loading

0 comments on commit dd0e770

Please sign in to comment.