Skip to content

Commit 19d1c7a

Browse files
committed
Trying NDEBUG.
1 parent e129a41 commit 19d1c7a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+263
-250
lines changed

Blocks/HTTP/impl/posix_client.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ struct ImplWrapper<HTTPClientPOSIX> {
203203
inline static void PrepareInput(const KeepResponseInMemory&, HTTPClientPOSIX&) {}
204204

205205
inline static void PrepareInput(const SaveResponseToFile& save_to_file_request, HTTPClientPOSIX&) {
206-
assert(!save_to_file_request.file_name.empty());
206+
CURRENT_ASSERT(!save_to_file_request.file_name.empty());
207207
}
208208

209209
template <typename REQUEST_PARAMS, typename RESPONSE_PARAMS>

Blocks/HTTP/types.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ struct HTTPImpl {
236236

237237
// TODO(dkorolev): Deprecate the below some time in the future. And perhaps add an `http_port_t`.
238238
server_impl_t& operator()(int port) {
239-
assert(port > 0 && port < 65536);
239+
CURRENT_ASSERT(port > 0 && port < 65536);
240240
return operator()(static_cast<uint16_t>(port));
241241
}
242242

Blocks/MMQ/mmq.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class MMQImpl {
8484
// Destructor waits for the consumer thread to terminate, which implies committing all the queued messages.
8585
~MMQImpl() {
8686
if (consumer_thread_created_) {
87-
assert(consumer_thread_.joinable());
87+
CURRENT_ASSERT(consumer_thread_.joinable());
8888
{
8989
std::lock_guard<std::mutex> lock(mutex_);
9090
destructing_ = true;

Blocks/MMQ/test.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ TEST(InMemoryMQ, SmokeTest) {
4444
std::atomic_size_t processed_messages_;
4545
ConsumerImpl() : processed_messages_(0u) {}
4646
EntryResponse operator()(const std::string& s, idxts_t current, idxts_t) {
47-
assert(current.index >= expected_next_message_index_);
47+
CURRENT_ASSERT(current.index >= expected_next_message_index_);
4848
dropped_messages_ += (current.index - expected_next_message_index_);
4949
expected_next_message_index_ = (current.index + 1);
5050
messages_ += s + '\n';
5151
++processed_messages_;
52-
assert(expected_next_message_index_ - processed_messages_ - 1 == dropped_messages_);
52+
CURRENT_ASSERT(expected_next_message_index_ - processed_messages_ - 1 == dropped_messages_);
5353
return EntryResponse::More;
5454
}
5555
};
@@ -82,7 +82,7 @@ struct SuspendableConsumerImpl {
8282
; // Spin lock.
8383
}
8484
messages_.push_back(s);
85-
assert(last.index >= total_messages_accepted_by_the_queue_);
85+
CURRENT_ASSERT(last.index >= total_messages_accepted_by_the_queue_);
8686
total_messages_accepted_by_the_queue_ = last.index;
8787
if (processing_delay_ms_) {
8888
std::this_thread::sleep_for(std::chrono::milliseconds(processing_delay_ms_));

Blocks/Persistence/file.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class IteratorOverFileOfPersistedEntries {
5656
public:
5757
explicit IteratorOverFileOfPersistedEntries(std::istream& fi, std::streampos offset, uint64_t index_at_offset)
5858
: fi_(fi), next_(index_at_offset, std::chrono::microseconds(0)) {
59-
assert(!fi_.bad());
59+
CURRENT_ASSERT(!fi_.bad());
6060
if (offset) {
6161
fi_.seekg(offset, std::ios_base::beg);
6262
}
@@ -152,8 +152,8 @@ class FilePersister {
152152
std::streampos current_offset(0);
153153
while (cit.ProcessNextEntry(
154154
[&fi, &offset, &timestamp, &current_offset](const idxts_t& current, const char*) {
155-
assert(current.index == offset.size());
156-
assert(current.index == timestamp.size());
155+
CURRENT_ASSERT(current.index == offset.size());
156+
CURRENT_ASSERT(current.index == timestamp.size());
157157
offset.push_back(current_offset);
158158
timestamp.push_back(current.us);
159159
current_offset = fi.tellg();
@@ -312,8 +312,8 @@ class FilePersister {
312312
const auto current = idxts_t(iterator.index, iterator.us);
313313
{
314314
std::lock_guard<std::mutex> lock(file_persister_impl_->mutex);
315-
assert(file_persister_impl_->offset.size() == iterator.index);
316-
assert(file_persister_impl_->timestamp.size() == iterator.index);
315+
CURRENT_ASSERT(file_persister_impl_->offset.size() == iterator.index);
316+
CURRENT_ASSERT(file_persister_impl_->timestamp.size() == iterator.index);
317317
file_persister_impl_->offset.push_back(file_persister_impl_->appender.tellp());
318318
file_persister_impl_->timestamp.push_back(timestamp);
319319
}
@@ -377,8 +377,8 @@ class FilePersister {
377377
CURRENT_THROW(InvalidIterableRangeException());
378378
}
379379
std::lock_guard<std::mutex> lock(file_persister_impl_->mutex);
380-
assert(file_persister_impl_->offset.size() >=
381-
current_size); // "Greater" is OK, `Iterate()` is multithreaded. -- D.K.
380+
CURRENT_ASSERT(file_persister_impl_->offset.size() >=
381+
current_size); // "Greater" is OK, `Iterate()` is multithreaded. -- D.K.
382382
return IterableRange(
383383
file_persister_impl_, begin_index, end_index, file_persister_impl_->offset[begin_index]);
384384
}

Blocks/SS/pubsub.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ SOFTWARE.
2727
#define BLOCKS_SS_PUBSUB_H
2828

2929
#include "../../port.h"
30-
#include <cassert>
3130

3231
#include "idx_ts.h"
3332

@@ -168,7 +167,7 @@ struct PassEntryToSubscriberIfTypeMatchesImpl {
168167
if (Exists<TYPE_SUBSCRIBED_TO>(entry_cref)) {
169168
return f(Value<TYPE_SUBSCRIBED_TO>(std::forward<E>(entry)), current, last);
170169
} else {
171-
assert(current.index <= last.index);
170+
CURRENT_ASSERT(current.index <= last.index);
172171
if (current.index < last.index) {
173172
return EntryResponse::More;
174173
} else {

Bricks/dot/graphviz.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ SOFTWARE.
2929

3030
#include "../port.h"
3131

32-
#include <cassert>
3332
#include <vector>
3433
#include <string>
3534
#include <sstream>
@@ -254,8 +253,9 @@ struct GenericGraph {
254253
const auto output_file_deleter = current::FileSystem::ScopedRmFile(output_file_name);
255254

256255
current::FileSystem::WriteStringToFile(AsDOT(), input_file_name.c_str());
257-
assert(!::system(current::strings::Printf(
258-
"dot -T svg %s -o %s\n", input_file_name.c_str(), output_file_name.c_str()).c_str()));
256+
CURRENT_ASSERT(
257+
!::system(current::strings::Printf(
258+
"dot -T svg %s -o %s\n", input_file_name.c_str(), output_file_name.c_str()).c_str()));
259259
return current::FileSystem::ReadFileAsString(output_file_name.c_str());
260260
}
261261
};

Bricks/file/file.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ SOFTWARE.
2929

3030
#include "../port.h"
3131

32-
#include <cassert>
3332
#include <cstdio>
3433
#include <fstream>
3534
#include <string>
@@ -108,12 +107,12 @@ struct FileSystem {
108107
static inline std::string GenTmpFileName() {
109108
char buffer[L_tmpnam];
110109
#if defined(CURRENT_WINDOWS)
111-
assert(!(::tmpnam_s(buffer)));
110+
CURRENT_ASSERT(!(::tmpnam_s(buffer)));
112111
#elif defined(CURRENT_APPLE)
113112
// TODO(dkorolev): Fix temporary file names generation.
114113
return strings::Printf("/tmp/.current-tmp-%08x", rand());
115114
#else
116-
assert(buffer == ::tmpnam(buffer));
115+
CURRENT_ASSERT(buffer == ::tmpnam(buffer));
117116
#endif
118117
return buffer;
119118
}

Bricks/graph/gnuplot.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ SOFTWARE.
2727
#ifndef BRICKS_GRAPH_GNUPLOT_H
2828
#define BRICKS_GRAPH_GNUPLOT_H
2929

30-
#include <cassert>
3130
#include <vector>
3231
#include <string>
3332
#include <map>
@@ -204,7 +203,7 @@ struct GNUPlot {
204203
}
205204

206205
operator std::string() const {
207-
assert(!plots_.empty()); // TODO(dkorolev): Exception?
206+
CURRENT_ASSERT(!plots_.empty()); // TODO(dkorolev): Exception?
208207

209208
const std::string input_file_name = current::FileSystem::GenTmpFileName();
210209
const std::string output_file_name = current::FileSystem::GenTmpFileName();
@@ -231,8 +230,9 @@ struct GNUPlot {
231230
}
232231
}
233232
if (output_format_ != "gnuplot") {
234-
assert(!::system(strings::Printf("gnuplot <%s >%s\n", input_file_name.c_str(), output_file_name.c_str())
235-
.c_str()));
233+
CURRENT_ASSERT(
234+
!::system(
235+
strings::Printf("gnuplot <%s >%s\n", input_file_name.c_str(), output_file_name.c_str()).c_str()));
236236
return current::FileSystem::ReadFileAsString(output_file_name.c_str());
237237
} else {
238238
// For unit tests, just compare the inputs.

Bricks/net/http/headers/headers.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ SOFTWARE.
2828
#include "../../../port.h"
2929

3030
#include <algorithm>
31-
#include <cassert>
3231
#include <map>
3332
#include <string>
3433
#include <vector>
@@ -228,7 +227,8 @@ struct Headers final {
228227
Header::ThrowIfHeaderIsCookie(header);
229228
const auto rhs = map.find(header);
230229
if (rhs != map.end()) {
231-
assert(rhs->second); // Invariant: If `header` exists in map, its `std::unique_ptr<>` value is valid.
230+
CURRENT_ASSERT(
231+
rhs->second); // Invariant: If `header` exists in map, its `std::unique_ptr<>` value is valid.
232232
return rhs->second->value;
233233
} else {
234234
CURRENT_THROW(HeaderNotFoundException(header));
@@ -239,7 +239,8 @@ struct Headers final {
239239
Header::ThrowIfHeaderIsCookie(header);
240240
const auto rhs = map.find(header);
241241
if (rhs != map.end()) {
242-
assert(rhs->second); // Invariant: If `header` exists in map, its `std::unique_ptr<>` value is valid.
242+
CURRENT_ASSERT(
243+
rhs->second); // Invariant: If `header` exists in map, its `std::unique_ptr<>` value is valid.
243244
return rhs->second->value;
244245
} else {
245246
return value_if_not_found;
@@ -253,7 +254,8 @@ struct Headers final {
253254
Header::ThrowIfHeaderIsCookie(header);
254255
const auto rhs = map.find(header);
255256
if (rhs != map.end()) {
256-
assert(rhs->second); // Invariant: If `header` exists in map, its `std::unique_ptr<>` value is valid.
257+
CURRENT_ASSERT(
258+
rhs->second); // Invariant: If `header` exists in map, its `std::unique_ptr<>` value is valid.
257259
return *rhs->second;
258260
} else {
259261
CURRENT_THROW(HeaderNotFoundException(header));

Bricks/net/http/impl/server.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class GenericHTTPRequestData : public HELPER {
156156
size_t chunk;
157157
size_t read_count;
158158
// Use `- offset - 1` instead of just `- offset` to leave room for the '\0'.
159-
assert(buffer_.size() > offset + 1);
159+
CURRENT_ASSERT(buffer_.size() > offset + 1);
160160
// NOTE: This `if` should not be made a `while`, as it may so happen that the boundary between two
161161
// consecutively received packets lays right on the final size, but instead of parsing the received body,
162162
// the server would wait forever for more data to arrive from the client.
@@ -218,7 +218,8 @@ class GenericHTTPRequestData : public HELPER {
218218
// during the next iteration of the outer loop.
219219
// The original version of this code was only adding one to `next_offset`.
220220
// This had a bug, which got revealed as the `while` loop above has been corrected into `if`.
221-
// Upon changing the `while` to an `if`, the `assert (buffer_.size() > offset + 1);` check above
221+
// Upon changing the `while` to an `if`, the `CURRENT_ASSERT(buffer_.size() > offset + 1);`
222+
// check above
222223
// would fail on a chunked HTTP body of several large chunks. Thus, `next_offset + 2` is it.
223224
// Note that the actual `resize()` would always allocate more room than the extra two bytes.
224225
// The `std::max()` condition is kept just in case we compile Current for a device
@@ -319,7 +320,7 @@ class GenericHTTPRequestData : public HELPER {
319320

320321
inline size_t BodyLength() const {
321322
if (body_buffer_begin_) {
322-
assert(body_buffer_end_);
323+
CURRENT_ASSERT(body_buffer_end_);
323324
return body_buffer_end_ - body_buffer_begin_;
324325
} else {
325326
return 0u;

Bricks/net/http/test.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ TEST(PosixHTTPServerTest, ChunkedBodyLargeFirstChunk) {
345345
struct HTTPClientImplCURL {
346346
static string Syscall(const string& cmdline) {
347347
FILE* pipe = ::popen(cmdline.c_str(), "r");
348-
assert(pipe);
348+
CURRENT_ASSERT(pipe);
349349
char s[1024];
350350
const auto warn_unused_result_catch_warning = ::fgets(s, sizeof(s), pipe);
351351
static_cast<void>(warn_unused_result_catch_warning);
@@ -404,7 +404,7 @@ class HTTPClientImplPOSIX {
404404
connection.BlockingWrite("\r\n", false);
405405
}
406406
HTTPRequestData http_request(connection);
407-
assert(!http_request.Body().empty());
407+
CURRENT_ASSERT(!http_request.Body().empty());
408408
const string body = http_request.Body();
409409
server_thread.join();
410410
return body;

Bricks/net/tcp/impl/posix.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ SOFTWARE.
3434
#include "../../../util/singleton.h"
3535
#include "../../../template/enable_if.h"
3636

37-
#include <cassert>
3837
#include <cstring>
3938
#include <string>
4039
#include <utility>
@@ -374,7 +373,7 @@ class Connection : public SocketHandle {
374373
#if defined(CURRENT_APPLE) || defined(CURRENT_WINDOWS)
375374
static_cast<void>(more); // Supress the 'unused parameter' warning.
376375
#endif
377-
assert(buffer);
376+
CURRENT_ASSERT(buffer);
378377
BRICKS_NET_LOG(
379378
"S%05d BlockingWrite(%d bytes) ...\n", static_cast<SOCKET>(socket), static_cast<int>(write_length));
380379
#if !defined(CURRENT_WINDOWS) && !defined(CURRENT_APPLE)
@@ -397,7 +396,7 @@ class Connection : public SocketHandle {
397396
}
398397

399398
inline Connection& BlockingWrite(const char* s, bool more) {
400-
assert(s);
399+
CURRENT_ASSERT(s);
401400
return BlockingWrite(s, strlen(s), more);
402401
}
403402

Bricks/strings/chunk.h

+4-5
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ SOFTWARE.
6161
#include "../port.h"
6262

6363
#include <algorithm>
64-
#include <cassert>
6564
#include <cmath>
6665
#include <cstring>
6766
#include <unordered_map>
@@ -73,13 +72,13 @@ namespace strings {
7372
class Chunk {
7473
public:
7574
Chunk() : S(""), N(0u) {}
76-
Chunk(const char* s, size_t n) : S(s), N(n) { assert(S[N] == '\0'); }
75+
Chunk(const char* s, size_t n) : S(s), N(n) { CURRENT_ASSERT(S[N] == '\0'); }
7776
Chunk(const char* s) : S(s), N(strlen(s)) {}
7877
template <int L>
7978
Chunk(const char s[L])
8079
: S(s), N(L - 1) {
8180
// The above line break is `clang-format`, not me. -- D.K.
82-
assert(S[N] == '\0');
81+
CURRENT_ASSERT(S[N] == '\0');
8382
}
8483
Chunk(const std::string& s) : S(s.data()), N(s.size()) {}
8584
// Copyable and assignable by design.
@@ -92,15 +91,15 @@ class Chunk {
9291
void assign(const char* s, size_t n) {
9392
S = s;
9493
N = n;
95-
assert(S[N] == '\0');
94+
CURRENT_ASSERT(S[N] == '\0');
9695
}
9796

9897
void clear() {
9998
S = "";
10099
N = 0u;
101100
}
102101

103-
void CheckPrivilege(size_t i) const { assert(i <= N); }
102+
void CheckPrivilege(size_t i) const { CURRENT_ASSERT(i <= N); }
104103

105104
char operator[](size_t i) const {
106105
CheckPrivilege(i); // Once is enough.

Bricks/strings/rounding.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,20 @@ SOFTWARE.
2525
#ifndef BRICKS_STRINGS_ROUNDING_H
2626
#define BRICKS_STRINGS_ROUNDING_H
2727

28+
#include "../../port.h"
29+
2830
#include <cstring>
2931
#include <string>
3032
#include <sstream>
3133
#include <cmath>
32-
#include <cassert>
3334

3435
namespace current {
3536
namespace strings {
3637

3738
// Rounds the number to have `n_digits` significant digits.
3839
inline std::string RoundDoubleToString(double value, size_t n_digits) {
39-
assert(n_digits >= 1);
40-
assert(n_digits <= 100);
40+
CURRENT_ASSERT(n_digits >= 1);
41+
CURRENT_ASSERT(n_digits <= 100);
4142
// `value` will be between `10^dim` and `10^(dim+1)`.
4243
const int dim = static_cast<int>(std::floor((std::log(value) / std::log(10.0)) + 1e-6));
4344
const double k = std::pow(10.0, static_cast<double>(dim - static_cast<int>(n_digits) + 1));

Bricks/util/lazy_instantiation.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,10 @@ class LazilyInstantiated {
134134
T& InstantiateAsSharedPtr(std::shared_ptr<T>& shared_instance,
135135
LazyInstantiationStrategy strategy = LazyInstantiationStrategy::Flexible) const {
136136
if (strategy == LazyInstantiationStrategy::ShouldNotBeInitialized) {
137-
assert(!shared_instance);
137+
CURRENT_ASSERT(!shared_instance);
138138
}
139139
if (strategy == LazyInstantiationStrategy::ShouldAlreadyBeInitialized) {
140-
assert(shared_instance);
140+
CURRENT_ASSERT(shared_instance);
141141
}
142142
if (!shared_instance) {
143143
shared_instance = InstantiateAsSharedPtr();

Bricks/util/test.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ TEST(Util, MakeScopeGuard) {
122122
story_ += "helper_end\n";
123123
called_ = true;
124124
} else {
125-
assert(false); // LCOV_EXCL_LINE
125+
CURRENT_ASSERT(false); // LCOV_EXCL_LINE
126126
}
127127
}
128128

Bricks/util/waitable_terminate_signal.h

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ SOFTWARE.
2626
#define BRICKS_UTIL_WAITABLE_TERMINATE_SIGNAL_H
2727

2828
#include <atomic>
29-
#include <cassert>
3029
#include <condition_variable>
3130
#include <mutex>
3231
#include <unordered_set>

0 commit comments

Comments
 (0)