Commit 6d346575 authored by Kenton Varda's avatar Kenton Varda

CHECK -> ASSERT

parent 20272ec5
......@@ -168,7 +168,7 @@ kj::ArrayPtr<const kj::ArrayPtr<const word>> BuilderArena::getSegmentsForOutput(
return kj::arrayPtr(&segment0ForOutput, 1);
}
} else {
DCHECK(moreSegments->forOutput.size() == moreSegments->builders.size() + 1,
DASSERT(moreSegments->forOutput.size() == moreSegments->builders.size() + 1,
"moreSegments->forOutput wasn't resized correctly when the last builder was added.",
moreSegments->forOutput.size(), moreSegments->builders.size());
......@@ -201,7 +201,7 @@ SegmentReader* BuilderArena::tryGetSegment(SegmentId id) {
}
void BuilderArena::reportReadLimitReached() {
FAIL_RECOVERABLE_CHECK(
FAIL_RECOVERABLE_ASSERT(
"Read limit reached for BuilderArena, but it should have been unlimited.") {}
}
......
......@@ -128,8 +128,8 @@ void TextBlob::allocate(size_t textSize, size_t branchCount,
}
void TextBlob::fill(char* textPos, Branch* branchesPos) {
CHECK(textPos == text.end(), textPos - text.end());
CHECK(branchesPos == branches.end(), branchesPos - branches.end());
ASSERT(textPos == text.end(), textPos - text.end());
ASSERT(branchesPos == branches.end(), branchesPos - branches.end());
}
template <typename First, typename... Rest>
......
......@@ -83,7 +83,7 @@ internal::FieldSize elementSizeFor(schema::Type::Body::Which elementType) {
case schema::Type::Body::ENUM_TYPE: return internal::FieldSize::TWO_BYTES;
case schema::Type::Body::STRUCT_TYPE: return internal::FieldSize::INLINE_COMPOSITE;
case schema::Type::Body::INTERFACE_TYPE: return internal::FieldSize::POINTER;
case schema::Type::Body::OBJECT_TYPE: FAIL_CHECK("List(Object) not supported."); break;
case schema::Type::Body::OBJECT_TYPE: FAIL_ASSERT("List(Object) not supported."); break;
}
// Unknown type. Treat it as zero-size.
......@@ -255,7 +255,7 @@ Data::Builder DynamicUnion::Builder::initObjectAsData(Text::Reader name, uint si
StructSchema::Member DynamicUnion::Builder::checkIsObject() {
KJ_IF_MAYBE(w, which()) {
CHECK(w->getProto().getBody().which() == schema::StructNode::Member::Body::FIELD_MEMBER,
ASSERT(w->getProto().getBody().which() == schema::StructNode::Member::Body::FIELD_MEMBER,
"Unsupported union member type.");
REQUIRE(w->getProto().getBody().getFieldMember().getType().getBody().which() ==
schema::Type::Body::OBJECT_TYPE, "Expected Object.");
......@@ -456,7 +456,7 @@ DynamicStruct::Builder DynamicStruct::Builder::getObject(
}
}
FAIL_CHECK("switch() missing case.", (uint)member.getProto().getBody().which());
FAIL_ASSERT("switch() missing case.", (uint)member.getProto().getBody().which());
return DynamicStruct::Builder();
}
DynamicList::Builder DynamicStruct::Builder::getObject(
......@@ -475,7 +475,7 @@ DynamicList::Builder DynamicStruct::Builder::getObject(
}
}
FAIL_CHECK("switch() missing case.", (uint)member.getProto().getBody().which());
FAIL_ASSERT("switch() missing case.", (uint)member.getProto().getBody().which());
return DynamicList::Builder();
}
Text::Builder DynamicStruct::Builder::getObjectAsText(StructSchema::Member member) {
......@@ -493,7 +493,7 @@ Text::Builder DynamicStruct::Builder::getObjectAsText(StructSchema::Member membe
}
}
FAIL_CHECK("switch() missing case.", (uint)member.getProto().getBody().which());
FAIL_ASSERT("switch() missing case.", (uint)member.getProto().getBody().which());
return Text::Builder();
}
Data::Builder DynamicStruct::Builder::getObjectAsData(StructSchema::Member member) {
......@@ -511,7 +511,7 @@ Data::Builder DynamicStruct::Builder::getObjectAsData(StructSchema::Member membe
}
}
FAIL_CHECK("switch() missing case.", (uint)member.getProto().getBody().which());
FAIL_ASSERT("switch() missing case.", (uint)member.getProto().getBody().which());
return Data::Builder();
}
......@@ -531,7 +531,7 @@ DynamicStruct::Builder DynamicStruct::Builder::initObject(
}
}
FAIL_CHECK("switch() missing case.", (uint)member.getProto().getBody().which());
FAIL_ASSERT("switch() missing case.", (uint)member.getProto().getBody().which());
return DynamicStruct::Builder();
}
DynamicList::Builder DynamicStruct::Builder::initObject(
......@@ -550,7 +550,7 @@ DynamicList::Builder DynamicStruct::Builder::initObject(
}
}
FAIL_CHECK("switch() missing case.", (uint)member.getProto().getBody().which());
FAIL_ASSERT("switch() missing case.", (uint)member.getProto().getBody().which());
return DynamicList::Builder();
}
Text::Builder DynamicStruct::Builder::initObjectAsText(StructSchema::Member member, uint size) {
......@@ -568,7 +568,7 @@ Text::Builder DynamicStruct::Builder::initObjectAsText(StructSchema::Member memb
}
}
FAIL_CHECK("switch() missing case.", (uint)member.getProto().getBody().which());
FAIL_ASSERT("switch() missing case.", (uint)member.getProto().getBody().which());
return Text::Builder();
}
Data::Builder DynamicStruct::Builder::initObjectAsData(StructSchema::Member member, uint size) {
......@@ -586,7 +586,7 @@ Data::Builder DynamicStruct::Builder::initObjectAsData(StructSchema::Member memb
}
}
FAIL_CHECK("switch() missing case.", (uint)member.getProto().getBody().which());
FAIL_ASSERT("switch() missing case.", (uint)member.getProto().getBody().which());
return Data::Builder();
}
......@@ -723,7 +723,7 @@ DynamicValue::Reader DynamicStruct::Reader::getImpl(
}
case schema::Type::Body::INTERFACE_TYPE:
FAIL_CHECK("Interfaces not yet implemented.");
FAIL_ASSERT("Interfaces not yet implemented.");
break;
}
......@@ -731,7 +731,7 @@ DynamicValue::Reader DynamicStruct::Reader::getImpl(
}
}
FAIL_CHECK("switch() missing case.", (uint)member.getProto().getBody().which());
FAIL_ASSERT("switch() missing case.", (uint)member.getProto().getBody().which());
return nullptr;
}
......@@ -826,7 +826,7 @@ DynamicValue::Builder DynamicStruct::Builder::getImpl(
}
case schema::Type::Body::INTERFACE_TYPE:
FAIL_CHECK("Interfaces not yet implemented.");
FAIL_ASSERT("Interfaces not yet implemented.");
break;
}
......@@ -834,7 +834,7 @@ DynamicValue::Builder DynamicStruct::Builder::getImpl(
}
}
FAIL_CHECK("switch() missing case.", (uint)member.getProto().getBody().which());
FAIL_ASSERT("switch() missing case.", (uint)member.getProto().getBody().which());
return nullptr;
}
DynamicStruct::Builder DynamicStruct::Builder::getObjectImpl(
......@@ -963,7 +963,7 @@ void DynamicStruct::Builder::setImpl(
}
case schema::Type::Body::INTERFACE_TYPE:
FAIL_CHECK("Interfaces not yet implemented.");
FAIL_ASSERT("Interfaces not yet implemented.");
return;
}
......@@ -972,7 +972,7 @@ void DynamicStruct::Builder::setImpl(
}
}
FAIL_CHECK("switch() missing case.", (uint)member.getProto().getBody().which());
FAIL_ASSERT("switch() missing case.", (uint)member.getProto().getBody().which());
}
DynamicValue::Builder DynamicStruct::Builder::initImpl(
......@@ -1109,7 +1109,7 @@ DynamicValue::Reader DynamicList::Reader::operator[](uint index) const {
reader.getObjectElement(index * ELEMENTS)));
case schema::Type::Body::INTERFACE_TYPE:
FAIL_RECOVERABLE_CHECK("Interfaces not implemented.") {}
FAIL_RECOVERABLE_ASSERT("Interfaces not implemented.") {}
return nullptr;
}
......@@ -1167,11 +1167,11 @@ DynamicValue::Builder DynamicList::Builder::operator[](uint index) const {
schema.getEnumElementType(), builder.getDataElement<uint16_t>(index * ELEMENTS)));
case schema::Type::Body::OBJECT_TYPE:
FAIL_CHECK("List(Object) not supported.");
FAIL_ASSERT("List(Object) not supported.");
return nullptr;
case schema::Type::Body::INTERFACE_TYPE:
FAIL_RECOVERABLE_CHECK("Interfaces not implemented.") {}
FAIL_RECOVERABLE_ASSERT("Interfaces not implemented.") {}
return nullptr;
}
......@@ -1219,7 +1219,7 @@ void DynamicList::Builder::set(uint index, DynamicValue::Reader value) {
// Not supported for the same reason List<struct> doesn't support it -- the space for the
// element is already allocated, and if it's smaller than the input value the copy would
// have to be lossy.
FAIL_RECOVERABLE_CHECK("DynamicList of structs does not support set().");
FAIL_RECOVERABLE_ASSERT("DynamicList of structs does not support set().");
return;
case schema::Type::Body::ENUM_TYPE: {
......@@ -1240,11 +1240,11 @@ void DynamicList::Builder::set(uint index, DynamicValue::Reader value) {
}
case schema::Type::Body::OBJECT_TYPE:
FAIL_RECOVERABLE_CHECK("List(Object) not supported.");
FAIL_RECOVERABLE_ASSERT("List(Object) not supported.");
return;
case schema::Type::Body::INTERFACE_TYPE:
FAIL_RECOVERABLE_CHECK("Interfaces not implemented.") {}
FAIL_RECOVERABLE_ASSERT("Interfaces not implemented.") {}
return;
}
......@@ -1296,7 +1296,7 @@ DynamicValue::Builder DynamicList::Builder::init(uint index, uint size) {
}
case schema::Type::Body::OBJECT_TYPE: {
FAIL_CHECK("List(Object) not supported.");
FAIL_ASSERT("List(Object) not supported.");
return nullptr;
}
}
......@@ -1332,10 +1332,10 @@ DynamicValue::Reader DynamicValue::Builder::asReader() {
case ENUM: return Reader(enumValue);
case STRUCT: return Reader(structValue.asReader());
case UNION: return Reader(unionValue.asReader());
case INTERFACE: FAIL_CHECK("Interfaces not implemented."); return Reader();
case INTERFACE: FAIL_ASSERT("Interfaces not implemented."); return Reader();
case OBJECT: return Reader(objectValue);
}
FAIL_CHECK("Missing switch case.");
FAIL_ASSERT("Missing switch case.");
return Reader();
}
......
......@@ -279,7 +279,7 @@ UnionState initUnion(Func&& initializer) {
initializer(builder.getRoot<StructType>());
kj::ArrayPtr<const word> segment = builder.getSegmentsForOutput()[0];
CHECK(segment.size() > 2, segment.size());
ASSERT(segment.size() > 2, segment.size());
// Find the offset of the first set bit after the union discriminants.
int offset = 0;
......
......@@ -338,7 +338,7 @@ struct WireHelpers {
break;
}
case WirePointer::RESERVED_3:
FAIL_RECOVERABLE_CHECK("Don't know how to handle RESERVED_3.") {}
FAIL_RECOVERABLE_ASSERT("Don't know how to handle RESERVED_3.") {}
break;
}
}
......@@ -380,7 +380,7 @@ struct WireHelpers {
case FieldSize::INLINE_COMPOSITE: {
WirePointer* elementTag = reinterpret_cast<WirePointer*>(ptr);
CHECK(elementTag->kind() == WirePointer::STRUCT,
ASSERT(elementTag->kind() == WirePointer::STRUCT,
"Don't know how to handle non-STRUCT inline composite.");
WordCount dataSize = elementTag->structRef.dataSize.get();
WirePointerCount pointerCount = elementTag->structRef.ptrCount.get();
......@@ -404,10 +404,10 @@ struct WireHelpers {
break;
}
case WirePointer::FAR:
FAIL_RECOVERABLE_CHECK("Unexpected FAR pointer.") {}
FAIL_RECOVERABLE_ASSERT("Unexpected FAR pointer.") {}
break;
case WirePointer::RESERVED_3:
FAIL_RECOVERABLE_CHECK("Don't know how to handle RESERVED_3.") {}
FAIL_RECOVERABLE_ASSERT("Don't know how to handle RESERVED_3.") {}
break;
}
}
......@@ -538,7 +538,7 @@ struct WireHelpers {
break;
}
case WirePointer::FAR:
FAIL_RECOVERABLE_CHECK("Unexpected FAR pointer.") {
FAIL_RECOVERABLE_ASSERT("Unexpected FAR pointer.") {
break;
}
break;
......@@ -640,7 +640,7 @@ struct WireHelpers {
const word* srcElement = srcPtr + POINTER_SIZE_IN_WORDS;
word* dstElement = dstPtr + POINTER_SIZE_IN_WORDS;
CHECK(srcTag->kind() == WirePointer::STRUCT,
ASSERT(srcTag->kind() == WirePointer::STRUCT,
"INLINE_COMPOSITE of lists is not yet supported.");
uint n = srcTag->inlineCompositeListElementCount() / ELEMENTS;
......@@ -689,7 +689,7 @@ struct WireHelpers {
// Darn, need a double-far.
SegmentBuilder* farSegment = srcSegment->getArena()->getSegmentWithAvailable(2 * WORDS);
landingPad = reinterpret_cast<WirePointer*>(farSegment->allocate(2 * WORDS));
DCHECK(landingPad != nullptr,
DASSERT(landingPad != nullptr,
"getSegmentWithAvailable() returned segment without space available.");
landingPad[0].setFar(false, srcSegment->getOffsetTo(src->target()));
......@@ -915,7 +915,7 @@ struct WireHelpers {
break;
case FieldSize::INLINE_COMPOSITE:
FAIL_CHECK("Can't get here.");
FAIL_ASSERT("Can't get here.");
break;
}
......@@ -1148,11 +1148,11 @@ struct WireHelpers {
} else {
// If oldSize were POINTER or EIGHT_BYTES then the preferred size must be
// INLINE_COMPOSITE because any other compatible size would not require an upgrade.
CHECK(oldSize < FieldSize::EIGHT_BYTES);
ASSERT(oldSize < FieldSize::EIGHT_BYTES);
// If the preferred size were BIT then oldSize must be VOID, but we handled that case
// above.
CHECK(elementSize.preferredListEncoding >= FieldSize::BIT);
ASSERT(elementSize.preferredListEncoding >= FieldSize::BIT);
// OK, so the expected list elements are all data and between 1 byte and 1 word each,
// and the old element are data between 1 bit and 4 bytes. We're upgrading from one
......@@ -1364,7 +1364,7 @@ struct WireHelpers {
case 32: elementSize = FieldSize::FOUR_BYTES; break;
case 64: elementSize = FieldSize::EIGHT_BYTES; break;
default:
FAIL_CHECK("invalid list step size", value.step * ELEMENTS / BITS);
FAIL_ASSERT("invalid list step size", value.step * ELEMENTS / BITS);
break;
}
......@@ -2142,7 +2142,7 @@ StructReader ListReader::getStructElement(ElementCount index) const {
reinterpret_cast<const WirePointer*>(structData + structDataSize / BITS_PER_BYTE);
// This check should pass if there are no bugs in the list pointer validation code.
DCHECK(structPointerCount == 0 * POINTERS ||
DASSERT(structPointerCount == 0 * POINTERS ||
(uintptr_t)structPointers % sizeof(WirePointer) == 0,
"Pointer segment of struct list element not aligned.");
......@@ -2153,7 +2153,7 @@ StructReader ListReader::getStructElement(ElementCount index) const {
}
static const WirePointer* checkAlignment(const void* ptr) {
DCHECK((uintptr_t)ptr % sizeof(WirePointer) == 0,
DASSERT((uintptr_t)ptr % sizeof(WirePointer) == 0,
"Pointer segment of struct list element not aligned.");
return reinterpret_cast<const WirePointer*>(ptr);
}
......
......@@ -80,10 +80,10 @@ internal::SegmentBuilder* MessageBuilder::getRootSegment() {
WordCount ptrSize = 1 * POINTERS * WORDS_PER_POINTER;
internal::SegmentBuilder* segment = arena()->getSegmentWithAvailable(ptrSize);
CHECK(segment->getSegmentId() == internal::SegmentId(0),
ASSERT(segment->getSegmentId() == internal::SegmentId(0),
"First allocated word of new arena was not in segment ID 0.");
word* location = segment->allocate(ptrSize);
CHECK(location == segment->getPtrUnchecked(0 * WORDS),
ASSERT(location == segment->getPtrUnchecked(0 * WORDS),
"First allocated word of new arena was not the first word in its segment.");
return segment;
}
......@@ -161,7 +161,7 @@ MallocMessageBuilder::~MallocMessageBuilder() {
// Must zero first segment.
kj::ArrayPtr<const kj::ArrayPtr<const word>> segments = getSegmentsForOutput();
if (segments.size() > 0) {
CHECK(segments[0].begin() == firstSegment,
ASSERT(segments[0].begin() == firstSegment,
"First segment in getSegmentsForOutput() is not the first segment allocated?");
memset(firstSegment, 0, segments[0].size() * sizeof(word));
}
......
......@@ -119,7 +119,7 @@ public:
for (auto& dep: dependencies) {
result[pos++] = dep.second;
}
DCHECK(pos == *count);
DASSERT(pos == *count);
return result;
}
......@@ -131,7 +131,7 @@ public:
for (auto& member: members) {
result[pos++] = internal::RawSchema::MemberInfo(member.first.first, member.second);
}
DCHECK(pos == *count);
DASSERT(pos == *count);
return result;
}
......@@ -934,7 +934,7 @@ private:
schema::Value::Reader replacement) {
// Note that we test default compatibility only after testing type compatibility, and default
// values have already been validated as matching their types, so this should pass.
RECOVERABLE_CHECK(value.getBody().which() == replacement.getBody().which()) {
RECOVERABLE_ASSERT(value.getBody().which() == replacement.getBody().which()) {
compatibility = INCOMPATIBLE;
return;
}
......
......@@ -62,7 +62,7 @@ public:
}
size_t read(void* buffer, size_t minBytes, size_t maxBytes) override {
CHECK(maxBytes <= data.size() - readPos, "Overran end of stream.");
ASSERT(maxBytes <= data.size() - readPos, "Overran end of stream.");
size_t amount = std::min(maxBytes, std::max(minBytes, preferredReadSize));
memcpy(buffer, data.data() + readPos, amount);
readPos += amount;
......@@ -70,7 +70,7 @@ public:
}
void skip(size_t bytes) override {
CHECK(bytes <= data.size() - readPos, "Overran end of stream.");
ASSERT(bytes <= data.size() - readPos, "Overran end of stream.");
readPos += bytes;
}
......
......@@ -66,7 +66,7 @@ size_t PackedInputStream::read(void* dst, size_t minBytes, size_t maxBytes) {
for (;;) {
uint8_t tag;
DCHECK((out - reinterpret_cast<uint8_t*>(dst)) % sizeof(word) == 0,
DASSERT((out - reinterpret_cast<uint8_t*>(dst)) % sizeof(word) == 0,
"Output pointer should always be aligned here.");
if (BUFFER_REMAINING < 10) {
......@@ -122,7 +122,7 @@ size_t PackedInputStream::read(void* dst, size_t minBytes, size_t maxBytes) {
}
if (tag == 0) {
DCHECK(BUFFER_REMAINING > 0, "Should always have non-empty buffer here.");
DASSERT(BUFFER_REMAINING > 0, "Should always have non-empty buffer here.");
uint runLength = *in++ * sizeof(word);
......@@ -134,7 +134,7 @@ size_t PackedInputStream::read(void* dst, size_t minBytes, size_t maxBytes) {
out += runLength;
} else if (tag == 0xffu) {
DCHECK(BUFFER_REMAINING > 0, "Should always have non-empty buffer here.");
DASSERT(BUFFER_REMAINING > 0, "Should always have non-empty buffer here.");
uint runLength = *in++ * sizeof(word);
......@@ -177,8 +177,8 @@ size_t PackedInputStream::read(void* dst, size_t minBytes, size_t maxBytes) {
}
}
FAIL_CHECK("Can't get here.");
return 0; // GCC knows FAIL_CHECK doesn't return, but Eclipse CDT still warns...
FAIL_ASSERT("Can't get here.");
return 0; // GCC knows FAIL_ASSERT doesn't return, but Eclipse CDT still warns...
#undef REFRESH_BUFFER
}
......@@ -248,7 +248,7 @@ void PackedInputStream::skip(size_t bytes) {
}
if (tag == 0) {
DCHECK(BUFFER_REMAINING > 0, "Should always have non-empty buffer here.");
DASSERT(BUFFER_REMAINING > 0, "Should always have non-empty buffer here.");
uint runLength = *in++ * sizeof(word);
......@@ -260,7 +260,7 @@ void PackedInputStream::skip(size_t bytes) {
bytes -= runLength;
} else if (tag == 0xffu) {
DCHECK(BUFFER_REMAINING > 0, "Should always have non-empty buffer here.");
DASSERT(BUFFER_REMAINING > 0, "Should always have non-empty buffer here.");
uint runLength = *in++ * sizeof(word);
......@@ -298,7 +298,7 @@ void PackedInputStream::skip(size_t bytes) {
}
}
FAIL_CHECK("Can't get here.");
FAIL_ASSERT("Can't get here.");
}
// -------------------------------------------------------------------
......
......@@ -96,7 +96,7 @@ public:
}
size_t read(void* buffer, size_t minBytes, size_t maxBytes) override {
CHECK(maxBytes <= data.size() - readPos, "Overran end of stream.");
ASSERT(maxBytes <= data.size() - readPos, "Overran end of stream.");
size_t amount = std::min(maxBytes, std::max(minBytes, preferredReadSize));
memcpy(buffer, data.data() + readPos, amount);
readPos += amount;
......@@ -104,7 +104,7 @@ public:
}
void skip(size_t bytes) override {
CHECK(bytes <= data.size() - readPos, "Overran end of stream.");
ASSERT(bytes <= data.size() - readPos, "Overran end of stream.");
readPos += bytes;
}
......
......@@ -40,7 +40,7 @@ public:
// implements snappy::Source ---------------------------------------
size_t Available() const override {
FAIL_CHECK("Snappy doesn't actually call this.");
FAIL_ASSERT("Snappy doesn't actually call this.");
return 0;
}
......@@ -121,7 +121,7 @@ void SnappyInputStream::refill() {
SnappyOutputStream::SnappyOutputStream(
OutputStream& inner, kj::ArrayPtr<byte> buffer, kj::ArrayPtr<byte> compressedBuffer)
: inner(inner) {
DCHECK(SNAPPY_COMPRESSED_BUFFER_SIZE >= snappy::MaxCompressedLength(snappy::kBlockSize),
DASSERT(SNAPPY_COMPRESSED_BUFFER_SIZE >= snappy::MaxCompressedLength(snappy::kBlockSize),
"snappy::MaxCompressedLength() changed?");
if (buffer.size() < SNAPPY_BUFFER_SIZE) {
......@@ -159,7 +159,7 @@ void SnappyOutputStream::flush() {
snappy::UncheckedByteArraySink sink(reinterpret_cast<char*>(compressedBuffer.begin()));
size_t n = snappy::Compress(&source, &sink);
CHECK(n <= compressedBuffer.size(),
ASSERT(n <= compressedBuffer.size(),
"Critical security bug: Snappy compression overran its output buffer.");
inner.write(compressedBuffer.begin(), n);
......
......@@ -104,7 +104,7 @@ public:
~TestInputStream() {}
size_t read(void* buffer, size_t minBytes, size_t maxBytes) override {
CHECK(maxBytes <= size_t(end - pos), "Overran end of stream.");
ASSERT(maxBytes <= size_t(end - pos), "Overran end of stream.");
size_t amount = lazy ? minBytes : maxBytes;
memcpy(buffer, pos, amount);
pos += amount;
......
......@@ -122,7 +122,7 @@ kj::Array<word> messageToFlatArray(kj::ArrayPtr<const kj::ArrayPtr<const word>>
dst += segment.size();
}
DCHECK(dst == result.end(), "Buffer overrun/underrun bug in code above.");
DASSERT(dst == result.end(), "Buffer overrun/underrun bug in code above.");
return kj::mv(result);
}
......
......@@ -162,7 +162,7 @@ static void print(std::ostream& os, DynamicValue::Reader value,
break;
}
case DynamicValue::INTERFACE:
FAIL_RECOVERABLE_CHECK("Don't know how to print interfaces.") {}
FAIL_RECOVERABLE_ASSERT("Don't know how to print interfaces.") {}
break;
case DynamicValue::OBJECT:
os << "(opaque object)";
......
......@@ -33,11 +33,11 @@ namespace {
struct TestObject {
TestObject() {
index = count;
CHECK(index != throwAt);
ASSERT(index != throwAt);
++count;
}
TestObject(const TestObject& other) {
CHECK(other.index != throwAt);
ASSERT(other.index != throwAt);
index = -1;
copiedCount++;
}
......@@ -47,7 +47,7 @@ struct TestObject {
} else {
--count;
EXPECT_EQ(index, count);
CHECK(count != throwAt);
ASSERT(count != throwAt);
}
}
......
......@@ -257,7 +257,7 @@ void FdOutputStream::write(const void* buffer, size_t size) {
while (size > 0) {
ssize_t n = SYSCALL(::write(fd, pos, size), fd);
CHECK(n > 0, "write() returned zero.");
ASSERT(n > 0, "write() returned zero.");
pos += n;
size -= n;
}
......@@ -281,7 +281,7 @@ void FdOutputStream::write(ArrayPtr<const ArrayPtr<const byte>> pieces) {
while (current < iov.end()) {
ssize_t n = SYSCALL(::writev(fd, current, iov.end() - current), fd);
CHECK(n > 0, "writev() returned zero.");
ASSERT(n > 0, "writev() returned zero.");
while (static_cast<size_t>(n) >= current->iov_len) {
n -= current->iov_len;
......
......@@ -101,24 +101,24 @@ TEST(Logging, Log) {
mockCallback.text);
mockCallback.text.clear();
CHECK(1 == 1);
EXPECT_THROW(CHECK(1 == 2), MockException); line = __LINE__;
ASSERT(1 == 1);
EXPECT_THROW(ASSERT(1 == 2), MockException); line = __LINE__;
EXPECT_EQ("fatal exception: " + fileLine(__FILE__, line) + ": bug in code: expected "
"1 == 2\n", mockCallback.text);
mockCallback.text.clear();
RECOVERABLE_CHECK(1 == 1) {
RECOVERABLE_ASSERT(1 == 1) {
ADD_FAILURE() << "Shouldn't call recovery code when check passes.";
};
bool recovered = false;
RECOVERABLE_CHECK(1 == 2, "1 is not 2") { recovered = true; } line = __LINE__;
RECOVERABLE_ASSERT(1 == 2, "1 is not 2") { recovered = true; } line = __LINE__;
EXPECT_EQ("recoverable exception: " + fileLine(__FILE__, line) + ": bug in code: expected "
"1 == 2; 1 is not 2\n", mockCallback.text);
EXPECT_TRUE(recovered);
mockCallback.text.clear();
EXPECT_THROW(CHECK(1 == 2, i, "hi", str), MockException); line = __LINE__;
EXPECT_THROW(ASSERT(1 == 2, i, "hi", str), MockException); line = __LINE__;
EXPECT_EQ("fatal exception: " + fileLine(__FILE__, line) + ": bug in code: expected "
"1 == 2; i = 123; hi; str = foo\n", mockCallback.text);
mockCallback.text.clear();
......@@ -128,7 +128,7 @@ TEST(Logging, Log) {
"1 == 2; i = 123; hi; str = foo\n", mockCallback.text);
mockCallback.text.clear();
EXPECT_THROW(CHECK(false, "foo"), MockException); line = __LINE__;
EXPECT_THROW(ASSERT(false, "foo"), MockException); line = __LINE__;
EXPECT_EQ("fatal exception: " + fileLine(__FILE__, line) + ": bug in code: foo\n",
mockCallback.text);
mockCallback.text.clear();
......@@ -164,7 +164,7 @@ TEST(Logging, Context) {
{
CONTEXT("foo"); int cline = __LINE__;
EXPECT_THROW(FAIL_CHECK("bar"), MockException); int line = __LINE__;
EXPECT_THROW(FAIL_ASSERT("bar"), MockException); int line = __LINE__;
EXPECT_EQ("fatal exception: " + fileLine(__FILE__, cline) + ": context: foo\n"
+ fileLine(__FILE__, line) + ": bug in code: bar\n",
......@@ -175,7 +175,7 @@ TEST(Logging, Context) {
int i = 123;
const char* str = "qux";
CONTEXT("baz", i, "corge", str); int cline2 = __LINE__;
EXPECT_THROW(FAIL_CHECK("bar"), MockException); line = __LINE__;
EXPECT_THROW(FAIL_ASSERT("bar"), MockException); line = __LINE__;
EXPECT_EQ("fatal exception: " + fileLine(__FILE__, cline) + ": context: foo\n"
+ fileLine(__FILE__, cline2) + ": context: baz; i = 123; corge; str = qux\n"
......@@ -186,7 +186,7 @@ TEST(Logging, Context) {
{
CONTEXT("grault"); int cline2 = __LINE__;
EXPECT_THROW(FAIL_CHECK("bar"), MockException); line = __LINE__;
EXPECT_THROW(FAIL_ASSERT("bar"), MockException); line = __LINE__;
EXPECT_EQ("fatal exception: " + fileLine(__FILE__, cline) + ": context: foo\n"
+ fileLine(__FILE__, cline2) + ": context: grault\n"
......
......@@ -24,7 +24,7 @@
// This file declares convenient macros for debug logging and error handling. The macros make
// it excessively easy to extract useful context information from code. Example:
//
// CHECK(a == b, a, b, "a and b must be the same.");
// ASSERT(a == b, a, b, "a and b must be the same.");
//
// On failure, this will throw an exception whose description looks like:
//
......@@ -39,19 +39,19 @@
// `FATAL`. If the severity is not higher than the global logging threshold, nothing will be
// written and in fact the log message won't even be evaluated.
//
// * `CHECK(condition, ...)`: Throws an exception if `condition` is false, or aborts if exceptions
// * `ASSERT(condition, ...)`: Throws an exception if `condition` is false, or aborts if exceptions
// are disabled. This macro should be used to check for bugs in the surrounding code and its
// dependencies, but NOT to check for invalid input.
//
// * `REQUIRE(condition, ...)`: Like `CHECK` but used to check preconditions -- e.g. to validate
// * `REQUIRE(condition, ...)`: Like `ASSERT` but used to check preconditions -- e.g. to validate
// parameters passed from a caller. A failure indicates that the caller is buggy.
//
// * `RECOVERABLE_CHECK(condition, ...) { ... }`: Like `CHECK` except that if exceptions are
// * `RECOVERABLE_ASSERT(condition, ...) { ... }`: Like `ASSERT` except that if exceptions are
// disabled, instead of aborting, the following code block will be executed. This block should
// do whatever it can to fill in dummy values so that the code can continue executing, even if
// this means the eventual output will be garbage.
//
// * `RECOVERABLE_REQUIRE(condition, ...) { ... }`: Like `RECOVERABLE_CHECK` and `REQUIRE`.
// * `RECOVERABLE_REQUIRE(condition, ...) { ... }`: Like `RECOVERABLE_ASSERT` and `REQUIRE`.
//
// * `VALIDATE_INPUT(condition, ...) { ... }`: Like `RECOVERABLE_PRECOND` but used to validate
// input that may have come from the user or some other untrusted source. Recoverability is
......@@ -64,7 +64,7 @@
//
// int fd = SYSCALL(open(filename, O_RDONLY), filename);
//
// * `RECOVERABLE_SYSCALL(code, ...) { ... }`: Like `RECOVERABLE_CHECK` and `SYSCALL`. Note that
// * `RECOVERABLE_SYSCALL(code, ...) { ... }`: Like `RECOVERABLE_ASSERT` and `SYSCALL`. Note that
// unfortunately this macro cannot return a value since it implements control flow, but you can
// assign to a variable *inside* the parameter instead:
//
......@@ -226,14 +226,14 @@ ArrayPtr<const char> KJ_STRINGIFY(Log::Severity severity);
::kj::Exception::Nature::nature, #cond, #__VA_ARGS__, ##__VA_ARGS__), false) {} \
else
#define CHECK(...) FAULT(LOCAL_BUG, __VA_ARGS__)
#define RECOVERABLE_CHECK(...) RECOVERABLE_FAULT(LOCAL_BUG, __VA_ARGS__)
#define ASSERT(...) FAULT(LOCAL_BUG, __VA_ARGS__)
#define RECOVERABLE_ASSERT(...) RECOVERABLE_FAULT(LOCAL_BUG, __VA_ARGS__)
#define REQUIRE(...) FAULT(PRECONDITION, __VA_ARGS__)
#define RECOVERABLE_REQUIRE(...) RECOVERABLE_FAULT(PRECONDITION, __VA_ARGS__)
#define VALIDATE_INPUT(...) RECOVERABLE_FAULT(INPUT, __VA_ARGS__)
#define FAIL_CHECK(...) CHECK(false, ##__VA_ARGS__)
#define FAIL_RECOVERABLE_CHECK(...) RECOVERABLE_CHECK(false, ##__VA_ARGS__)
#define FAIL_ASSERT(...) ASSERT(false, ##__VA_ARGS__)
#define FAIL_RECOVERABLE_ASSERT(...) RECOVERABLE_ASSERT(false, ##__VA_ARGS__)
#define FAIL_REQUIRE(...) REQUIRE(false, ##__VA_ARGS__)
#define FAIL_RECOVERABLE_REQUIRE(...) RECOVERABLE_REQUIRE(false, ##__VA_ARGS__)
#define FAIL_VALIDATE_INPUT(...) VALIDATE_INPUT(false, ##__VA_ARGS__)
......@@ -272,14 +272,14 @@ ArrayPtr<const char> KJ_STRINGIFY(Log::Severity severity);
#ifdef NDEBUG
#define DLOG(...) do {} while (false)
#define DCHECK(...) do {} while (false)
#define RECOVERABLE_DCHECK(...) do {} while (false)
#define DASSERT(...) do {} while (false)
#define RECOVERABLE_DASSERT(...) do {} while (false)
#define DREQUIRE(...) do {} while (false)
#define RECOVERABLE_DREQUIRE(...) do {} while (false)
#else
#define DLOG LOG
#define DCHECK CHECK
#define RECOVERABLE_DCHECK RECOVERABLE_CHECK
#define DASSERT ASSERT
#define RECOVERABLE_DASSERT RECOVERABLE_ASSERT
#define DREQUIRE REQUIRE
#define RECOVERABLE_DREQUIRE RECOVERABLE_REQUIRE
#endif
......
......@@ -232,7 +232,7 @@ char* DoubleToBuffer(double value, char* buffer) {
// The snprintf should never overflow because the buffer is significantly
// larger than the precision we asked for.
DCHECK(snprintf_result > 0 && snprintf_result < kDoubleToBufferSize);
DASSERT(snprintf_result > 0 && snprintf_result < kDoubleToBufferSize);
// We need to make parsed_value volatile in order to force the compiler to
// write it out to the stack. Otherwise, it may keep the value in a
......@@ -246,7 +246,7 @@ char* DoubleToBuffer(double value, char* buffer) {
snprintf(buffer, kDoubleToBufferSize, "%.*g", DBL_DIG+2, value);
// Should never overflow; see above.
DCHECK(snprintf_result > 0 && snprintf_result < kDoubleToBufferSize);
DASSERT(snprintf_result > 0 && snprintf_result < kDoubleToBufferSize);
}
DelocalizeRadix(buffer);
......@@ -288,7 +288,7 @@ char* FloatToBuffer(float value, char* buffer) {
// The snprintf should never overflow because the buffer is significantly
// larger than the precision we asked for.
DCHECK(snprintf_result > 0 && snprintf_result < kFloatToBufferSize);
DASSERT(snprintf_result > 0 && snprintf_result < kFloatToBufferSize);
float parsed_value;
if (!safe_strtof(buffer, &parsed_value) || parsed_value != value) {
......@@ -296,7 +296,7 @@ char* FloatToBuffer(float value, char* buffer) {
snprintf(buffer, kFloatToBufferSize, "%.*g", FLT_DIG+2, value);
// Should never overflow; see above.
DCHECK(snprintf_result > 0 && snprintf_result < kFloatToBufferSize);
DASSERT(snprintf_result > 0 && snprintf_result < kFloatToBufferSize);
}
DelocalizeRadix(buffer);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment