Commit 20272ec5 authored by Kenton Varda's avatar Kenton Varda

PRECOND -> REQUIRE

parent 5b65179c
...@@ -181,7 +181,7 @@ struct UseScratch { ...@@ -181,7 +181,7 @@ struct UseScratch {
word* words; word* words;
ScratchSpace() { ScratchSpace() {
PRECOND(scratchCounter < 6, "Too many scratch spaces needed at once."); REQUIRE(scratchCounter < 6, "Too many scratch spaces needed at once.");
words = scratchSpace + scratchCounter++ * SCRATCH_SIZE; words = scratchSpace + scratchCounter++ * SCRATCH_SIZE;
} }
~ScratchSpace() { ~ScratchSpace() {
......
...@@ -76,7 +76,7 @@ public: ...@@ -76,7 +76,7 @@ public:
inline const char operator[](uint index) const { return bytes[index]; } inline const char operator[](uint index) const { return bytes[index]; }
inline Reader slice(uint start, uint end) const { inline Reader slice(uint start, uint end) const {
KJ_INLINE_DPRECOND(start <= end && end <= size_, "Out-of-bounds slice."); KJ_IREQUIRE(start <= end && end <= size_, "Out-of-bounds slice.");
return Reader(bytes + start, end - start); return Reader(bytes + start, end - start);
} }
...@@ -121,13 +121,13 @@ public: ...@@ -121,13 +121,13 @@ public:
inline Reader(const char* text): Data::Reader(text, strlen(text)) {} inline Reader(const char* text): Data::Reader(text, strlen(text)) {}
inline Reader(char* text): Data::Reader(text, strlen(text)) {} inline Reader(char* text): Data::Reader(text, strlen(text)) {}
inline Reader(const char* text, uint size): Data::Reader(text, size) { inline Reader(const char* text, uint size): Data::Reader(text, size) {
KJ_INLINE_DPRECOND(text[size] == '\0', "Text must be NUL-terminated."); KJ_IREQUIRE(text[size] == '\0', "Text must be NUL-terminated.");
} }
template <typename T> template <typename T>
inline Reader(const T& other): Data::Reader(other.c_str(), other.size()) { inline Reader(const T& other): Data::Reader(other.c_str(), other.size()) {
// Primarily intended for converting from std::string. // Primarily intended for converting from std::string.
KJ_INLINE_DPRECOND(data()[size()] == '\0', "Text must be NUL-terminated."); KJ_IREQUIRE(data()[size()] == '\0', "Text must be NUL-terminated.");
} }
inline const char* c_str() const { return data(); } inline const char* c_str() const { return data(); }
...@@ -164,7 +164,7 @@ public: ...@@ -164,7 +164,7 @@ public:
inline char& operator[](uint index) const { return bytes[index]; } inline char& operator[](uint index) const { return bytes[index]; }
inline Builder slice(uint start, uint end) const { inline Builder slice(uint start, uint end) const {
KJ_INLINE_DPRECOND(start <= end && end <= size_, "Out-of-bounds slice."); KJ_IREQUIRE(start <= end && end <= size_, "Out-of-bounds slice.");
return Builder(bytes + start, end - start); return Builder(bytes + start, end - start);
} }
...@@ -183,7 +183,7 @@ public: ...@@ -183,7 +183,7 @@ public:
template <typename T> template <typename T>
inline void copyFrom(const T& other) const { inline void copyFrom(const T& other) const {
KJ_INLINE_DPRECOND(size() == other.size(), "Sizes must match to copy."); KJ_IREQUIRE(size() == other.size(), "Sizes must match to copy.");
memcpy(bytes, other.data(), other.size()); memcpy(bytes, other.data(), other.size());
} }
inline void copyFrom(const void* other) const { inline void copyFrom(const void* other) const {
......
...@@ -217,7 +217,7 @@ Text::Reader getUnqualifiedName(Schema schema) { ...@@ -217,7 +217,7 @@ Text::Reader getUnqualifiedName(Schema schema) {
return nested.getName(); return nested.getName();
} }
} }
FAIL_PRECOND("A schema Node's supposed scope did not contain the node as a NestedNode."); FAIL_REQUIRE("A schema Node's supposed scope did not contain the node as a NestedNode.");
return "(?)"; return "(?)";
} }
...@@ -365,22 +365,22 @@ TextBlob genValue(schema::Type::Reader type, schema::Value::Reader value, Schema ...@@ -365,22 +365,22 @@ TextBlob genValue(schema::Type::Reader type, schema::Value::Reader value, Schema
case schema::Value::Body::TEXT_VALUE: return text(DynamicValue::Reader(body.getTextValue())); case schema::Value::Body::TEXT_VALUE: return text(DynamicValue::Reader(body.getTextValue()));
case schema::Value::Body::DATA_VALUE: return text(DynamicValue::Reader(body.getDataValue())); case schema::Value::Body::DATA_VALUE: return text(DynamicValue::Reader(body.getDataValue()));
case schema::Value::Body::LIST_VALUE: { case schema::Value::Body::LIST_VALUE: {
PRECOND(type.getBody().which() == schema::Type::Body::LIST_TYPE, "type/value mismatch"); REQUIRE(type.getBody().which() == schema::Type::Body::LIST_TYPE, "type/value mismatch");
auto value = body.getListValue<DynamicList>( auto value = body.getListValue<DynamicList>(
ListSchema::of(type.getBody().getListType(), scope)); ListSchema::of(type.getBody().getListType(), scope));
return text(value); return text(value);
} }
case schema::Value::Body::ENUM_VALUE: { case schema::Value::Body::ENUM_VALUE: {
PRECOND(type.getBody().which() == schema::Type::Body::ENUM_TYPE, "type/value mismatch"); REQUIRE(type.getBody().which() == schema::Type::Body::ENUM_TYPE, "type/value mismatch");
auto enumNode = scope.getDependency(type.getBody().getEnumType()).asEnum().getProto(); auto enumNode = scope.getDependency(type.getBody().getEnumType()).asEnum().getProto();
auto enumType = enumNode.getBody().getEnumNode(); auto enumType = enumNode.getBody().getEnumNode();
auto enumerants = enumType.getEnumerants(); auto enumerants = enumType.getEnumerants();
PRECOND(body.getEnumValue() < enumerants.size(), REQUIRE(body.getEnumValue() < enumerants.size(),
"Enum value out-of-range.", body.getEnumValue(), enumNode.getDisplayName()); "Enum value out-of-range.", body.getEnumValue(), enumNode.getDisplayName());
return text(enumerants[body.getEnumValue()].getName()); return text(enumerants[body.getEnumValue()].getName());
} }
case schema::Value::Body::STRUCT_VALUE: { case schema::Value::Body::STRUCT_VALUE: {
PRECOND(type.getBody().which() == schema::Type::Body::STRUCT_TYPE, "type/value mismatch"); REQUIRE(type.getBody().which() == schema::Type::Body::STRUCT_TYPE, "type/value mismatch");
auto value = body.getStructValue<DynamicStruct>( auto value = body.getStructValue<DynamicStruct>(
scope.getDependency(type.getBody().getStructType()).asStruct()); scope.getDependency(type.getBody().getStructType()).asStruct());
return text(value); return text(value);
...@@ -400,7 +400,7 @@ TextBlob genAnnotation(schema::Annotation::Reader annotation, ...@@ -400,7 +400,7 @@ TextBlob genAnnotation(schema::Annotation::Reader annotation,
const char* prefix = " ", const char* suffix = "") { const char* prefix = " ", const char* suffix = "") {
auto decl = schemaLoader.get(annotation.getId()); auto decl = schemaLoader.get(annotation.getId());
auto body = decl.getProto().getBody(); auto body = decl.getProto().getBody();
PRECOND(body.which() == schema::Node::Body::ANNOTATION_NODE); REQUIRE(body.which() == schema::Node::Body::ANNOTATION_NODE);
auto annDecl = body.getAnnotationNode(); auto annDecl = body.getAnnotationNode();
return text(prefix, "$", nodeName(decl, scope), "(", return text(prefix, "$", nodeName(decl, scope), "(",
...@@ -468,12 +468,12 @@ TextBlob genDecl(Schema schema, Text::Reader name, uint64_t scopeId, Indent inde ...@@ -468,12 +468,12 @@ TextBlob genDecl(Schema schema, Text::Reader name, uint64_t scopeId, Indent inde
auto proto = schema.getProto(); auto proto = schema.getProto();
if (proto.getScopeId() != scopeId) { if (proto.getScopeId() != scopeId) {
// This appears to be an alias for something declared elsewhere. // This appears to be an alias for something declared elsewhere.
FAIL_PRECOND("Aliases not implemented."); FAIL_REQUIRE("Aliases not implemented.");
} }
switch (proto.getBody().which()) { switch (proto.getBody().which()) {
case schema::Node::Body::FILE_NODE: case schema::Node::Body::FILE_NODE:
FAIL_PRECOND("Encountered nested file node."); FAIL_REQUIRE("Encountered nested file node.");
break; break;
case schema::Node::Body::STRUCT_NODE: { case schema::Node::Body::STRUCT_NODE: {
auto body = proto.getBody().getStructNode(); auto body = proto.getBody().getStructNode();
...@@ -578,7 +578,7 @@ TextBlob genNestedDecls(Schema schema, Indent indent) { ...@@ -578,7 +578,7 @@ TextBlob genNestedDecls(Schema schema, Indent indent) {
TextBlob genFile(Schema file) { TextBlob genFile(Schema file) {
auto proto = file.getProto(); auto proto = file.getProto();
auto body = proto.getBody(); auto body = proto.getBody();
PRECOND(body.which() == schema::Node::Body::FILE_NODE, "Expected a file node.", REQUIRE(body.which() == schema::Node::Body::FILE_NODE, "Expected a file node.",
(uint)body.which()); (uint)body.which());
return text( return text(
......
This diff is collapsed.
...@@ -102,12 +102,12 @@ struct WirePointer { ...@@ -102,12 +102,12 @@ struct WirePointer {
} }
KJ_ALWAYS_INLINE(WordCount farPositionInSegment() const) { KJ_ALWAYS_INLINE(WordCount farPositionInSegment() const) {
DPRECOND(kind() == FAR, DREQUIRE(kind() == FAR,
"positionInSegment() should only be called on FAR pointers."); "positionInSegment() should only be called on FAR pointers.");
return (offsetAndKind.get() >> 3) * WORDS; return (offsetAndKind.get() >> 3) * WORDS;
} }
KJ_ALWAYS_INLINE(bool isDoubleFar() const) { KJ_ALWAYS_INLINE(bool isDoubleFar() const) {
DPRECOND(kind() == FAR, DREQUIRE(kind() == FAR,
"isDoubleFar() should only be called on FAR pointers."); "isDoubleFar() should only be called on FAR pointers.");
return (offsetAndKind.get() >> 2) & 1; return (offsetAndKind.get() >> 2) & 1;
} }
...@@ -155,12 +155,12 @@ struct WirePointer { ...@@ -155,12 +155,12 @@ struct WirePointer {
} }
KJ_ALWAYS_INLINE(void set(FieldSize es, ElementCount ec)) { KJ_ALWAYS_INLINE(void set(FieldSize es, ElementCount ec)) {
DPRECOND(ec < (1 << 29) * ELEMENTS, "Lists are limited to 2**29 elements."); DREQUIRE(ec < (1 << 29) * ELEMENTS, "Lists are limited to 2**29 elements.");
elementSizeAndCount.set(((ec / ELEMENTS) << 3) | static_cast<int>(es)); elementSizeAndCount.set(((ec / ELEMENTS) << 3) | static_cast<int>(es));
} }
KJ_ALWAYS_INLINE(void setInlineComposite(WordCount wc)) { KJ_ALWAYS_INLINE(void setInlineComposite(WordCount wc)) {
DPRECOND(wc < (1 << 29) * WORDS, "Inline composite lists are limited to 2**29 words."); DREQUIRE(wc < (1 << 29) * WORDS, "Inline composite lists are limited to 2**29 words.");
elementSizeAndCount.set(((wc / WORDS) << 3) | elementSizeAndCount.set(((wc / WORDS) << 3) |
static_cast<int>(FieldSize::INLINE_COMPOSITE)); static_cast<int>(FieldSize::INLINE_COMPOSITE));
} }
...@@ -656,7 +656,7 @@ struct WireHelpers { ...@@ -656,7 +656,7 @@ struct WireHelpers {
break; break;
} }
default: default:
FAIL_PRECOND("Copy source message contained unexpected kind."); FAIL_REQUIRE("Copy source message contained unexpected kind.");
break; break;
} }
...@@ -796,7 +796,7 @@ struct WireHelpers { ...@@ -796,7 +796,7 @@ struct WireHelpers {
static KJ_ALWAYS_INLINE(ListBuilder initListPointer( static KJ_ALWAYS_INLINE(ListBuilder initListPointer(
WirePointer* ref, SegmentBuilder* segment, ElementCount elementCount, WirePointer* ref, SegmentBuilder* segment, ElementCount elementCount,
FieldSize elementSize)) { FieldSize elementSize)) {
DPRECOND(elementSize != FieldSize::INLINE_COMPOSITE, DREQUIRE(elementSize != FieldSize::INLINE_COMPOSITE,
"Should have called initStructListPointer() instead."); "Should have called initStructListPointer() instead.");
BitCount dataSize = dataBitsPerElement(elementSize) * ELEMENTS; BitCount dataSize = dataBitsPerElement(elementSize) * ELEMENTS;
...@@ -848,7 +848,7 @@ struct WireHelpers { ...@@ -848,7 +848,7 @@ struct WireHelpers {
static KJ_ALWAYS_INLINE(ListBuilder getWritableListPointer( static KJ_ALWAYS_INLINE(ListBuilder getWritableListPointer(
WirePointer* origRef, SegmentBuilder* origSegment, FieldSize elementSize, WirePointer* origRef, SegmentBuilder* origSegment, FieldSize elementSize,
const word* defaultValue)) { const word* defaultValue)) {
DPRECOND(elementSize != FieldSize::INLINE_COMPOSITE, DREQUIRE(elementSize != FieldSize::INLINE_COMPOSITE,
"Use getStructList{Element,Field}() for structs."); "Use getStructList{Element,Field}() for structs.");
if (origRef->isNull()) { if (origRef->isNull()) {
...@@ -886,7 +886,7 @@ struct WireHelpers { ...@@ -886,7 +886,7 @@ struct WireHelpers {
// Read the tag to get the actual element count. // Read the tag to get the actual element count.
WirePointer* tag = reinterpret_cast<WirePointer*>(ptr); WirePointer* tag = reinterpret_cast<WirePointer*>(ptr);
PRECOND(tag->kind() == WirePointer::STRUCT, REQUIRE(tag->kind() == WirePointer::STRUCT,
"INLINE_COMPOSITE list with non-STRUCT elements not supported."); "INLINE_COMPOSITE list with non-STRUCT elements not supported.");
ptr += POINTER_SIZE_IN_WORDS; ptr += POINTER_SIZE_IN_WORDS;
...@@ -1226,9 +1226,9 @@ struct WireHelpers { ...@@ -1226,9 +1226,9 @@ struct WireHelpers {
} else { } else {
word* ptr = followFars(ref, segment); word* ptr = followFars(ref, segment);
PRECOND(ref->kind() == WirePointer::LIST, REQUIRE(ref->kind() == WirePointer::LIST,
"Called getText{Field,Element}() but existing pointer is not a list."); "Called getText{Field,Element}() but existing pointer is not a list.");
PRECOND(ref->listRef.elementSize() == FieldSize::BYTE, REQUIRE(ref->listRef.elementSize() == FieldSize::BYTE,
"Called getText{Field,Element}() but existing list pointer is not byte-sized."); "Called getText{Field,Element}() but existing list pointer is not byte-sized.");
// Subtract 1 from the size for the NUL terminator. // Subtract 1 from the size for the NUL terminator.
...@@ -1263,9 +1263,9 @@ struct WireHelpers { ...@@ -1263,9 +1263,9 @@ struct WireHelpers {
} else { } else {
word* ptr = followFars(ref, segment); word* ptr = followFars(ref, segment);
PRECOND(ref->kind() == WirePointer::LIST, REQUIRE(ref->kind() == WirePointer::LIST,
"Called getData{Field,Element}() but existing pointer is not a list."); "Called getData{Field,Element}() but existing pointer is not a list.");
PRECOND(ref->listRef.elementSize() == FieldSize::BYTE, REQUIRE(ref->listRef.elementSize() == FieldSize::BYTE,
"Called getData{Field,Element}() but existing list pointer is not byte-sized."); "Called getData{Field,Element}() but existing list pointer is not byte-sized.");
return Data::Builder(reinterpret_cast<char*>(ptr), ref->listRef.elementCount() / ELEMENTS); return Data::Builder(reinterpret_cast<char*>(ptr), ref->listRef.elementCount() / ELEMENTS);
...@@ -1291,7 +1291,7 @@ struct WireHelpers { ...@@ -1291,7 +1291,7 @@ struct WireHelpers {
if (ref->listRef.elementSize() == FieldSize::INLINE_COMPOSITE) { if (ref->listRef.elementSize() == FieldSize::INLINE_COMPOSITE) {
// Read the tag to get the actual element count. // Read the tag to get the actual element count.
WirePointer* tag = reinterpret_cast<WirePointer*>(ptr); WirePointer* tag = reinterpret_cast<WirePointer*>(ptr);
PRECOND(tag->kind() == WirePointer::STRUCT, REQUIRE(tag->kind() == WirePointer::STRUCT,
"INLINE_COMPOSITE list with non-STRUCT elements not supported."); "INLINE_COMPOSITE list with non-STRUCT elements not supported.");
// First list element is at tag + 1 pointer. // First list element is at tag + 1 pointer.
...@@ -1951,7 +1951,7 @@ ObjectReader StructReader::getObjectField( ...@@ -1951,7 +1951,7 @@ ObjectReader StructReader::getObjectField(
} }
const word* StructReader::getUncheckedPointer(WirePointerCount ptrIndex) const { const word* StructReader::getUncheckedPointer(WirePointerCount ptrIndex) const {
PRECOND(segment == nullptr, "getUncheckedPointer() only allowed on unchecked messages."); REQUIRE(segment == nullptr, "getUncheckedPointer() only allowed on unchecked messages.");
return reinterpret_cast<const word*>(pointers + ptrIndex); return reinterpret_cast<const word*>(pointers + ptrIndex);
} }
......
...@@ -146,10 +146,10 @@ MallocMessageBuilder::MallocMessageBuilder( ...@@ -146,10 +146,10 @@ MallocMessageBuilder::MallocMessageBuilder(
kj::ArrayPtr<word> firstSegment, AllocationStrategy allocationStrategy) kj::ArrayPtr<word> firstSegment, AllocationStrategy allocationStrategy)
: nextSize(firstSegment.size()), allocationStrategy(allocationStrategy), : nextSize(firstSegment.size()), allocationStrategy(allocationStrategy),
ownFirstSegment(false), returnedFirstSegment(false), firstSegment(firstSegment.begin()) { ownFirstSegment(false), returnedFirstSegment(false), firstSegment(firstSegment.begin()) {
PRECOND(firstSegment.size() > 0, "First segment size must be non-zero."); REQUIRE(firstSegment.size() > 0, "First segment size must be non-zero.");
// Checking just the first word should catch most cases of failing to zero the segment. // Checking just the first word should catch most cases of failing to zero the segment.
PRECOND(*reinterpret_cast<uint64_t*>(firstSegment.begin()) == 0, REQUIRE(*reinterpret_cast<uint64_t*>(firstSegment.begin()) == 0,
"First segment must be zeroed."); "First segment must be zeroed.");
} }
...@@ -218,12 +218,12 @@ FlatMessageBuilder::FlatMessageBuilder(kj::ArrayPtr<word> array): array(array), ...@@ -218,12 +218,12 @@ FlatMessageBuilder::FlatMessageBuilder(kj::ArrayPtr<word> array): array(array),
FlatMessageBuilder::~FlatMessageBuilder() {} FlatMessageBuilder::~FlatMessageBuilder() {}
void FlatMessageBuilder::requireFilled() { void FlatMessageBuilder::requireFilled() {
PRECOND(getSegmentsForOutput()[0].end() == array.end(), REQUIRE(getSegmentsForOutput()[0].end() == array.end(),
"FlatMessageBuilder's buffer was too large."); "FlatMessageBuilder's buffer was too large.");
} }
kj::ArrayPtr<word> FlatMessageBuilder::allocateSegment(uint minimumSize) { kj::ArrayPtr<word> FlatMessageBuilder::allocateSegment(uint minimumSize) {
PRECOND(!allocated, "FlatMessageBuilder's buffer was not large enough."); REQUIRE(!allocated, "FlatMessageBuilder's buffer was not large enough.");
allocated = true; allocated = true;
return array; return array;
} }
......
...@@ -447,7 +447,7 @@ public: ...@@ -447,7 +447,7 @@ public:
CONTEXT("checking compatibility with previously-loaded node of the same id", CONTEXT("checking compatibility with previously-loaded node of the same id",
existingNode.getDisplayName()); existingNode.getDisplayName());
DPRECOND(existingNode.getId() == replacement.getId()); DREQUIRE(existingNode.getId() == replacement.getId());
nodeName = existingNode.getDisplayName(); nodeName = existingNode.getDisplayName();
compatibility = EQUIVALENT; compatibility = EQUIVALENT;
...@@ -1026,7 +1026,7 @@ internal::RawSchema* SchemaLoader::Impl::loadNative(const internal::RawSchema* n ...@@ -1026,7 +1026,7 @@ internal::RawSchema* SchemaLoader::Impl::loadNative(const internal::RawSchema* n
if (slot == nullptr) { if (slot == nullptr) {
slot = allocate<internal::RawSchema>(); slot = allocate<internal::RawSchema>();
} else if (slot->canCastTo != nullptr) { } else if (slot->canCastTo != nullptr) {
PRECOND(slot->canCastTo == nativeSchema, REQUIRE(slot->canCastTo == nativeSchema,
"two different compiled-in type have the same type ID", "two different compiled-in type have the same type ID",
reader.getId(), reader.getDisplayName(), reader.getId(), reader.getDisplayName(),
readMessageUnchecked<schema::Node>(slot->canCastTo->encodedNode).getDisplayName()); readMessageUnchecked<schema::Node>(slot->canCastTo->encodedNode).getDisplayName());
...@@ -1079,7 +1079,7 @@ internal::RawSchema* SchemaLoader::Impl::loadEmpty( ...@@ -1079,7 +1079,7 @@ internal::RawSchema* SchemaLoader::Impl::loadEmpty(
case schema::Node::Body::FILE_NODE: case schema::Node::Body::FILE_NODE:
case schema::Node::Body::CONST_NODE: case schema::Node::Body::CONST_NODE:
case schema::Node::Body::ANNOTATION_NODE: case schema::Node::Body::ANNOTATION_NODE:
FAIL_PRECOND("Not a type."); FAIL_REQUIRE("Not a type.");
break; break;
} }
...@@ -1111,7 +1111,7 @@ SchemaLoader::~SchemaLoader() {} ...@@ -1111,7 +1111,7 @@ SchemaLoader::~SchemaLoader() {}
Schema SchemaLoader::get(uint64_t id) const { Schema SchemaLoader::get(uint64_t id) const {
internal::RawSchema* raw = impl->tryGet(id); internal::RawSchema* raw = impl->tryGet(id);
PRECOND(raw != nullptr, "no schema node loaded for id", id); REQUIRE(raw != nullptr, "no schema node loaded for id", id);
return Schema(raw); return Schema(raw);
} }
......
...@@ -51,33 +51,33 @@ Schema Schema::getDependency(uint64_t id) const { ...@@ -51,33 +51,33 @@ Schema Schema::getDependency(uint64_t id) const {
} }
} }
FAIL_PRECOND("Requested ID not found in dependency table.", id); FAIL_REQUIRE("Requested ID not found in dependency table.", id);
return Schema(); return Schema();
} }
StructSchema Schema::asStruct() const { StructSchema Schema::asStruct() const {
PRECOND(getProto().getBody().which() == schema::Node::Body::STRUCT_NODE, REQUIRE(getProto().getBody().which() == schema::Node::Body::STRUCT_NODE,
"Tried to use non-struct schema as a struct.", "Tried to use non-struct schema as a struct.",
getProto().getDisplayName()); getProto().getDisplayName());
return StructSchema(raw); return StructSchema(raw);
} }
EnumSchema Schema::asEnum() const { EnumSchema Schema::asEnum() const {
PRECOND(getProto().getBody().which() == schema::Node::Body::ENUM_NODE, REQUIRE(getProto().getBody().which() == schema::Node::Body::ENUM_NODE,
"Tried to use non-enum schema as an enum.", "Tried to use non-enum schema as an enum.",
getProto().getDisplayName()); getProto().getDisplayName());
return EnumSchema(raw); return EnumSchema(raw);
} }
InterfaceSchema Schema::asInterface() const { InterfaceSchema Schema::asInterface() const {
PRECOND(getProto().getBody().which() == schema::Node::Body::INTERFACE_NODE, REQUIRE(getProto().getBody().which() == schema::Node::Body::INTERFACE_NODE,
"Tried to use non-interface schema as an interface.", "Tried to use non-interface schema as an interface.",
getProto().getDisplayName()); getProto().getDisplayName());
return InterfaceSchema(raw); return InterfaceSchema(raw);
} }
void Schema::requireUsableAs(const internal::RawSchema* expected) { void Schema::requireUsableAs(const internal::RawSchema* expected) {
PRECOND(raw == expected || REQUIRE(raw == expected ||
(raw != nullptr && expected != nullptr && raw->canCastTo == expected), (raw != nullptr && expected != nullptr && raw->canCastTo == expected),
"This schema is not compatible with the requested native type."); "This schema is not compatible with the requested native type.");
} }
...@@ -132,7 +132,7 @@ StructSchema::Member StructSchema::getMemberByName(Text::Reader name) const { ...@@ -132,7 +132,7 @@ StructSchema::Member StructSchema::getMemberByName(Text::Reader name) const {
KJ_IF_MAYBE(member, findMemberByName(name)) { KJ_IF_MAYBE(member, findMemberByName(name)) {
return *member; return *member;
} else { } else {
FAIL_PRECOND("struct has no such member", name); FAIL_REQUIRE("struct has no such member", name);
} }
} }
...@@ -142,7 +142,7 @@ kj::Maybe<StructSchema::Union> StructSchema::Member::getContainingUnion() const ...@@ -142,7 +142,7 @@ kj::Maybe<StructSchema::Union> StructSchema::Member::getContainingUnion() const
} }
StructSchema::Union StructSchema::Member::asUnion() const { StructSchema::Union StructSchema::Member::asUnion() const {
PRECOND(proto.getBody().which() == schema::StructNode::Member::Body::UNION_MEMBER, REQUIRE(proto.getBody().which() == schema::StructNode::Member::Body::UNION_MEMBER,
"Tried to use non-union struct member as a union.", "Tried to use non-union struct member as a union.",
parent.getProto().getDisplayName(), proto.getName()); parent.getProto().getDisplayName(), proto.getName());
return Union(*this); return Union(*this);
...@@ -160,7 +160,7 @@ StructSchema::Member StructSchema::Union::getMemberByName(Text::Reader name) con ...@@ -160,7 +160,7 @@ StructSchema::Member StructSchema::Union::getMemberByName(Text::Reader name) con
KJ_IF_MAYBE(member, findMemberByName(name)) { KJ_IF_MAYBE(member, findMemberByName(name)) {
return *member; return *member;
} else { } else {
FAIL_PRECOND("union has no such member", name); FAIL_REQUIRE("union has no such member", name);
} }
} }
...@@ -178,7 +178,7 @@ EnumSchema::Enumerant EnumSchema::getEnumerantByName(Text::Reader name) const { ...@@ -178,7 +178,7 @@ EnumSchema::Enumerant EnumSchema::getEnumerantByName(Text::Reader name) const {
KJ_IF_MAYBE(enumerant, findEnumerantByName(name)) { KJ_IF_MAYBE(enumerant, findEnumerantByName(name)) {
return *enumerant; return *enumerant;
} else { } else {
FAIL_PRECOND("enum has no such enumerant", name); FAIL_REQUIRE("enum has no such enumerant", name);
} }
} }
...@@ -196,7 +196,7 @@ InterfaceSchema::Method InterfaceSchema::getMethodByName(Text::Reader name) cons ...@@ -196,7 +196,7 @@ InterfaceSchema::Method InterfaceSchema::getMethodByName(Text::Reader name) cons
KJ_IF_MAYBE(method, findMethodByName(name)) { KJ_IF_MAYBE(method, findMethodByName(name)) {
return *method; return *method;
} else { } else {
FAIL_PRECOND("interface has no such method", name); FAIL_REQUIRE("interface has no such method", name);
} }
} }
...@@ -224,11 +224,11 @@ ListSchema ListSchema::of(schema::Type::Body::Which primitiveType) { ...@@ -224,11 +224,11 @@ ListSchema ListSchema::of(schema::Type::Body::Which primitiveType) {
case schema::Type::Body::ENUM_TYPE: case schema::Type::Body::ENUM_TYPE:
case schema::Type::Body::INTERFACE_TYPE: case schema::Type::Body::INTERFACE_TYPE:
case schema::Type::Body::LIST_TYPE: case schema::Type::Body::LIST_TYPE:
FAIL_PRECOND("Must use one of the other ListSchema::of() overloads for complex types."); FAIL_REQUIRE("Must use one of the other ListSchema::of() overloads for complex types.");
break; break;
case schema::Type::Body::OBJECT_TYPE: case schema::Type::Body::OBJECT_TYPE:
FAIL_PRECOND("List(Object) not supported."); FAIL_REQUIRE("List(Object) not supported.");
break; break;
} }
...@@ -267,7 +267,7 @@ ListSchema ListSchema::of(schema::Type::Reader elementType, Schema context) { ...@@ -267,7 +267,7 @@ ListSchema ListSchema::of(schema::Type::Reader elementType, Schema context) {
return of(of(body.getListType(), context)); return of(of(body.getListType(), context));
case schema::Type::Body::OBJECT_TYPE: case schema::Type::Body::OBJECT_TYPE:
FAIL_PRECOND("List(Object) not supported."); FAIL_REQUIRE("List(Object) not supported.");
return ListSchema(); return ListSchema();
} }
...@@ -276,31 +276,31 @@ ListSchema ListSchema::of(schema::Type::Reader elementType, Schema context) { ...@@ -276,31 +276,31 @@ ListSchema ListSchema::of(schema::Type::Reader elementType, Schema context) {
} }
StructSchema ListSchema::getStructElementType() const { StructSchema ListSchema::getStructElementType() const {
PRECOND(nestingDepth == 0 && elementType == schema::Type::Body::STRUCT_TYPE, REQUIRE(nestingDepth == 0 && elementType == schema::Type::Body::STRUCT_TYPE,
"ListSchema::getStructElementType(): The elements are not structs."); "ListSchema::getStructElementType(): The elements are not structs.");
return elementSchema.asStruct(); return elementSchema.asStruct();
} }
EnumSchema ListSchema::getEnumElementType() const { EnumSchema ListSchema::getEnumElementType() const {
PRECOND(nestingDepth == 0 && elementType == schema::Type::Body::ENUM_TYPE, REQUIRE(nestingDepth == 0 && elementType == schema::Type::Body::ENUM_TYPE,
"ListSchema::getEnumElementType(): The elements are not enums."); "ListSchema::getEnumElementType(): The elements are not enums.");
return elementSchema.asEnum(); return elementSchema.asEnum();
} }
InterfaceSchema ListSchema::getInterfaceElementType() const { InterfaceSchema ListSchema::getInterfaceElementType() const {
PRECOND(nestingDepth == 0 && elementType == schema::Type::Body::INTERFACE_TYPE, REQUIRE(nestingDepth == 0 && elementType == schema::Type::Body::INTERFACE_TYPE,
"ListSchema::getInterfaceElementType(): The elements are not interfaces."); "ListSchema::getInterfaceElementType(): The elements are not interfaces.");
return elementSchema.asInterface(); return elementSchema.asInterface();
} }
ListSchema ListSchema::getListElementType() const { ListSchema ListSchema::getListElementType() const {
PRECOND(nestingDepth > 0, REQUIRE(nestingDepth > 0,
"ListSchema::getListElementType(): The elements are not lists."); "ListSchema::getListElementType(): The elements are not lists.");
return ListSchema(elementType, nestingDepth - 1, elementSchema); return ListSchema(elementType, nestingDepth - 1, elementSchema);
} }
void ListSchema::requireUsableAs(ListSchema expected) { void ListSchema::requireUsableAs(ListSchema expected) {
PRECOND(elementType == expected.elementType && nestingDepth == expected.nestingDepth, REQUIRE(elementType == expected.elementType && nestingDepth == expected.nestingDepth,
"This schema is not compatible with the requested native type."); "This schema is not compatible with the requested native type.");
elementSchema.requireUsableAs(expected.elementSchema.raw); elementSchema.requireUsableAs(expected.elementSchema.raw);
} }
......
...@@ -39,8 +39,8 @@ size_t PackedInputStream::read(void* dst, size_t minBytes, size_t maxBytes) { ...@@ -39,8 +39,8 @@ size_t PackedInputStream::read(void* dst, size_t minBytes, size_t maxBytes) {
return 0; return 0;
} }
DPRECOND(minBytes % sizeof(word) == 0, "PackedInputStream reads must be word-aligned."); DREQUIRE(minBytes % sizeof(word) == 0, "PackedInputStream reads must be word-aligned.");
DPRECOND(maxBytes % sizeof(word) == 0, "PackedInputStream reads must be word-aligned."); DREQUIRE(maxBytes % sizeof(word) == 0, "PackedInputStream reads must be word-aligned.");
uint8_t* __restrict__ out = reinterpret_cast<uint8_t*>(dst); uint8_t* __restrict__ out = reinterpret_cast<uint8_t*>(dst);
uint8_t* const outEnd = reinterpret_cast<uint8_t*>(dst) + maxBytes; uint8_t* const outEnd = reinterpret_cast<uint8_t*>(dst) + maxBytes;
...@@ -190,7 +190,7 @@ void PackedInputStream::skip(size_t bytes) { ...@@ -190,7 +190,7 @@ void PackedInputStream::skip(size_t bytes) {
return; return;
} }
DPRECOND(bytes % sizeof(word) == 0, "PackedInputStream reads must be word-aligned."); DREQUIRE(bytes % sizeof(word) == 0, "PackedInputStream reads must be word-aligned.");
kj::ArrayPtr<const byte> buffer = inner.getReadBuffer(); kj::ArrayPtr<const byte> buffer = inner.getReadBuffer();
const uint8_t* __restrict__ in = reinterpret_cast<const uint8_t*>(buffer.begin()); const uint8_t* __restrict__ in = reinterpret_cast<const uint8_t*>(buffer.begin());
......
...@@ -88,7 +88,7 @@ kj::ArrayPtr<const word> FlatArrayMessageReader::getSegment(uint id) { ...@@ -88,7 +88,7 @@ kj::ArrayPtr<const word> FlatArrayMessageReader::getSegment(uint id) {
} }
kj::Array<word> messageToFlatArray(kj::ArrayPtr<const kj::ArrayPtr<const word>> segments) { kj::Array<word> messageToFlatArray(kj::ArrayPtr<const kj::ArrayPtr<const word>> segments) {
PRECOND(segments.size() > 0, "Tried to serialize uninitialized message."); REQUIRE(segments.size() > 0, "Tried to serialize uninitialized message.");
size_t totalSize = segments.size() / 2 + 1; size_t totalSize = segments.size() / 2 + 1;
...@@ -237,7 +237,7 @@ kj::ArrayPtr<const word> InputStreamMessageReader::getSegment(uint id) { ...@@ -237,7 +237,7 @@ kj::ArrayPtr<const word> InputStreamMessageReader::getSegment(uint id) {
// ------------------------------------------------------------------- // -------------------------------------------------------------------
void writeMessage(kj::OutputStream& output, kj::ArrayPtr<const kj::ArrayPtr<const word>> segments) { void writeMessage(kj::OutputStream& output, kj::ArrayPtr<const kj::ArrayPtr<const word>> segments) {
PRECOND(segments.size() > 0, "Tried to serialize uninitialized message."); REQUIRE(segments.size() > 0, "Tried to serialize uninitialized message.");
internal::WireValue<uint32_t> table[(segments.size() + 2) & ~size_t(1)]; internal::WireValue<uint32_t> table[(segments.size() + 2) & ~size_t(1)];
......
...@@ -94,7 +94,7 @@ public: ...@@ -94,7 +94,7 @@ public:
inline size_t size() const { return size_; } inline size_t size() const { return size_; }
inline T& operator[](size_t index) const { inline T& operator[](size_t index) const {
KJ_INLINE_DPRECOND(index < size_, "Out-of-bounds Array access."); KJ_IREQUIRE(index < size_, "Out-of-bounds Array access.");
return ptr[index]; return ptr[index];
} }
...@@ -108,11 +108,11 @@ public: ...@@ -108,11 +108,11 @@ public:
inline T& back() { return *(ptr + size_ - 1); } inline T& back() { return *(ptr + size_ - 1); }
inline ArrayPtr<T> slice(size_t start, size_t end) { inline ArrayPtr<T> slice(size_t start, size_t end) {
KJ_INLINE_DPRECOND(start <= end && end <= size_, "Out-of-bounds Array::slice()."); KJ_IREQUIRE(start <= end && end <= size_, "Out-of-bounds Array::slice().");
return ArrayPtr<T>(ptr + start, end - start); return ArrayPtr<T>(ptr + start, end - start);
} }
inline ArrayPtr<const T> slice(size_t start, size_t end) const { inline ArrayPtr<const T> slice(size_t start, size_t end) const {
KJ_INLINE_DPRECOND(start <= end && end <= size_, "Out-of-bounds Array::slice()."); KJ_IREQUIRE(start <= end && end <= size_, "Out-of-bounds Array::slice().");
return ArrayPtr<const T>(ptr + start, end - start); return ArrayPtr<const T>(ptr + start, end - start);
} }
...@@ -235,7 +235,7 @@ public: ...@@ -235,7 +235,7 @@ public:
inline size_t size() const { return pos - ptr; } inline size_t size() const { return pos - ptr; }
inline size_t capacity() const { return endPtr - ptr; } inline size_t capacity() const { return endPtr - ptr; }
inline T& operator[](size_t index) const { inline T& operator[](size_t index) const {
KJ_INLINE_DPRECOND(index < pos - ptr, "Out-of-bounds Array access."); KJ_IREQUIRE(index < pos - ptr, "Out-of-bounds Array access.");
return ptr[index]; return ptr[index];
} }
...@@ -266,7 +266,7 @@ public: ...@@ -266,7 +266,7 @@ public:
template <typename... Params> template <typename... Params>
void add(Params&&... params) { void add(Params&&... params) {
KJ_INLINE_DPRECOND(pos < endPtr, "Added too many elements to ArrayBuilder."); KJ_IREQUIRE(pos < endPtr, "Added too many elements to ArrayBuilder.");
ctor(*pos, kj::fwd<Params>(params)...); ctor(*pos, kj::fwd<Params>(params)...);
++pos; ++pos;
} }
...@@ -286,7 +286,7 @@ public: ...@@ -286,7 +286,7 @@ public:
// arbitrary disposers with ArrayBuilder in the future, and anyway this check might catch bugs. // arbitrary disposers with ArrayBuilder in the future, and anyway this check might catch bugs.
// Probably we should just create a new Vector-like data structure if we want to allow building // Probably we should just create a new Vector-like data structure if we want to allow building
// of arrays without knowing the final size in advance. // of arrays without knowing the final size in advance.
KJ_INLINE_DPRECOND(pos == endPtr, "ArrayBuilder::finish() called prematurely."); KJ_IREQUIRE(pos == endPtr, "ArrayBuilder::finish() called prematurely.");
Array<T> result(reinterpret_cast<T*>(ptr), pos - ptr, internal::HeapArrayDisposer::instance); Array<T> result(reinterpret_cast<T*>(ptr), pos - ptr, internal::HeapArrayDisposer::instance);
ptr = nullptr; ptr = nullptr;
pos = nullptr; pos = nullptr;
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
namespace kj { namespace kj {
namespace internal { namespace internal {
void inlinePreconditionFailure(const char* file, int line, const char* expectation, void inlineRequireFailure(const char* file, int line, const char* expectation,
const char* macroArgs, const char* message) { const char* macroArgs, const char* message) {
if (message == nullptr) { if (message == nullptr) {
Log::fatalFault(file, line, Exception::Nature::PRECONDITION, expectation, macroArgs); Log::fatalFault(file, line, Exception::Nature::PRECONDITION, expectation, macroArgs);
......
...@@ -113,24 +113,22 @@ typedef unsigned char byte; ...@@ -113,24 +113,22 @@ typedef unsigned char byte;
namespace internal { namespace internal {
void inlinePreconditionFailure( void inlineRequireFailure(
const char* file, int line, const char* expectation, const char* macroArgs, const char* file, int line, const char* expectation, const char* macroArgs,
const char* message = nullptr) KJ_NORETURN; const char* message = nullptr) KJ_NORETURN;
} // namespace internal } // namespace internal
#define KJ_INLINE_PRECOND(condition, ...) \ #ifdef NDEBUG
if (KJ_EXPECT_TRUE(condition)); else ::kj::internal::inlinePreconditionFailure( \ #define KJ_IREQUIRE(condition, ...)
#else
#define KJ_IREQUIRE(condition, ...) \
if (KJ_EXPECT_TRUE(condition)); else ::kj::internal::inlineRequireFailure( \
__FILE__, __LINE__, #condition, #__VA_ARGS__, ##__VA_ARGS__) __FILE__, __LINE__, #condition, #__VA_ARGS__, ##__VA_ARGS__)
// Version of PRECOND() which is safe to use in headers that are #included by users. Used to check // Version of REQUIRE() which is safe to use in headers that are #included by users. Used to check
// preconditions inside inline methods. KJ_INLINE_DPRECOND is particularly useful in that // preconditions inside inline methods. KJ_INLINE_DPRECOND is particularly useful in that
// it will be enabled depending on whether the application is compiled in debug mode rather than // it will be enabled depending on whether the application is compiled in debug mode rather than
// whether libkj is. // whether libkj is.
#ifdef NDEBUG
#define KJ_INLINE_DPRECOND(...)
#else
#define KJ_INLINE_DPRECOND KJ_INLINE_PRECOND
#endif #endif
// #define KJ_STACK_ARRAY(type, name, size, minStack, maxStack) // #define KJ_STACK_ARRAY(type, name, size, minStack, maxStack)
...@@ -501,7 +499,7 @@ public: ...@@ -501,7 +499,7 @@ public:
inline size_t size() const { return size_; } inline size_t size() const { return size_; }
inline T& operator[](size_t index) const { inline T& operator[](size_t index) const {
KJ_INLINE_DPRECOND(index < size_, "Out-of-bounds ArrayPtr access."); KJ_IREQUIRE(index < size_, "Out-of-bounds ArrayPtr access.");
return ptr[index]; return ptr[index];
} }
...@@ -511,7 +509,7 @@ public: ...@@ -511,7 +509,7 @@ public:
inline T& back() const { return *(ptr + size_ - 1); } inline T& back() const { return *(ptr + size_ - 1); }
inline ArrayPtr slice(size_t start, size_t end) const { inline ArrayPtr slice(size_t start, size_t end) const {
KJ_INLINE_DPRECOND(start <= end && end <= size_, "Out-of-bounds ArrayPtr::slice()."); KJ_IREQUIRE(start <= end && end <= size_, "Out-of-bounds ArrayPtr::slice().");
return ArrayPtr(ptr + start, end - start); return ArrayPtr(ptr + start, end - start);
} }
...@@ -578,8 +576,7 @@ To downcast(From* from) { ...@@ -578,8 +576,7 @@ To downcast(From* from) {
} }
#if !KJ_NO_RTTI #if !KJ_NO_RTTI
KJ_INLINE_DPRECOND( KJ_IREQUIRE(from == nullptr || dynamic_cast<To>(from) != nullptr,
from == nullptr || dynamic_cast<To>(from) != nullptr,
"Value cannot be downcast() to requested type."); "Value cannot be downcast() to requested type.");
#endif #endif
......
...@@ -174,7 +174,7 @@ void ExceptionCallback::logMessage(StringPtr text) { ...@@ -174,7 +174,7 @@ void ExceptionCallback::logMessage(StringPtr text) {
} }
void ExceptionCallback::useProcessWide() { void ExceptionCallback::useProcessWide() {
RECOVERABLE_PRECOND(globalCallback == nullptr, RECOVERABLE_REQUIRE(globalCallback == nullptr,
"Can't register multiple global ExceptionCallbacks at once.") { "Can't register multiple global ExceptionCallbacks at once.") {
return; return;
} }
......
...@@ -217,7 +217,7 @@ void ArrayOutputStream::write(const void* src, size_t size) { ...@@ -217,7 +217,7 @@ void ArrayOutputStream::write(const void* src, size_t size) {
// Oh goody, the caller wrote directly into our buffer. // Oh goody, the caller wrote directly into our buffer.
fillPos += size; fillPos += size;
} else { } else {
PRECOND(size <= (size_t)(array.end() - fillPos), REQUIRE(size <= (size_t)(array.end() - fillPos),
"ArrayOutputStream's backing array was not large enough for the data written."); "ArrayOutputStream's backing array was not large enough for the data written.");
memcpy(fillPos, src, size); memcpy(fillPos, src, size);
fillPos += size; fillPos += size;
......
...@@ -123,7 +123,7 @@ TEST(Logging, Log) { ...@@ -123,7 +123,7 @@ TEST(Logging, Log) {
"1 == 2; i = 123; hi; str = foo\n", mockCallback.text); "1 == 2; i = 123; hi; str = foo\n", mockCallback.text);
mockCallback.text.clear(); mockCallback.text.clear();
EXPECT_THROW(PRECOND(1 == 2, i, "hi", str), MockException); line = __LINE__; EXPECT_THROW(REQUIRE(1 == 2, i, "hi", str), MockException); line = __LINE__;
EXPECT_EQ("fatal exception: " + fileLine(__FILE__, line) + ": precondition not met: expected " EXPECT_EQ("fatal exception: " + fileLine(__FILE__, line) + ": precondition not met: expected "
"1 == 2; i = 123; hi; str = foo\n", mockCallback.text); "1 == 2; i = 123; hi; str = foo\n", mockCallback.text);
mockCallback.text.clear(); mockCallback.text.clear();
......
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
// are disabled. This macro should be used to check for bugs in the surrounding code and its // 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. // dependencies, but NOT to check for invalid input.
// //
// * `PRECOND(condition, ...)`: Like `CHECK` but used to check preconditions -- i.e. to validate // * `REQUIRE(condition, ...)`: Like `CHECK` but used to check preconditions -- e.g. to validate
// parameters passed from a caller. A failure indicates that the caller is buggy. // parameters passed from a caller. A failure indicates that the caller is buggy.
// //
// * `RECOVERABLE_CHECK(condition, ...) { ... }`: Like `CHECK` except that if exceptions are // * `RECOVERABLE_CHECK(condition, ...) { ... }`: Like `CHECK` except that if exceptions are
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
// do whatever it can to fill in dummy values so that the code can continue executing, even if // 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. // this means the eventual output will be garbage.
// //
// * `RECOVERABLE_PRECOND(condition, ...) { ... }`: Like `RECOVERABLE_CHECK` and `PRECOND`. // * `RECOVERABLE_REQUIRE(condition, ...) { ... }`: Like `RECOVERABLE_CHECK` and `REQUIRE`.
// //
// * `VALIDATE_INPUT(condition, ...) { ... }`: Like `RECOVERABLE_PRECOND` but used to validate // * `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 // input that may have come from the user or some other untrusted source. Recoverability is
...@@ -228,14 +228,14 @@ ArrayPtr<const char> KJ_STRINGIFY(Log::Severity severity); ...@@ -228,14 +228,14 @@ ArrayPtr<const char> KJ_STRINGIFY(Log::Severity severity);
#define CHECK(...) FAULT(LOCAL_BUG, __VA_ARGS__) #define CHECK(...) FAULT(LOCAL_BUG, __VA_ARGS__)
#define RECOVERABLE_CHECK(...) RECOVERABLE_FAULT(LOCAL_BUG, __VA_ARGS__) #define RECOVERABLE_CHECK(...) RECOVERABLE_FAULT(LOCAL_BUG, __VA_ARGS__)
#define PRECOND(...) FAULT(PRECONDITION, __VA_ARGS__) #define REQUIRE(...) FAULT(PRECONDITION, __VA_ARGS__)
#define RECOVERABLE_PRECOND(...) RECOVERABLE_FAULT(PRECONDITION, __VA_ARGS__) #define RECOVERABLE_REQUIRE(...) RECOVERABLE_FAULT(PRECONDITION, __VA_ARGS__)
#define VALIDATE_INPUT(...) RECOVERABLE_FAULT(INPUT, __VA_ARGS__) #define VALIDATE_INPUT(...) RECOVERABLE_FAULT(INPUT, __VA_ARGS__)
#define FAIL_CHECK(...) CHECK(false, ##__VA_ARGS__) #define FAIL_CHECK(...) CHECK(false, ##__VA_ARGS__)
#define FAIL_RECOVERABLE_CHECK(...) RECOVERABLE_CHECK(false, ##__VA_ARGS__) #define FAIL_RECOVERABLE_CHECK(...) RECOVERABLE_CHECK(false, ##__VA_ARGS__)
#define FAIL_PRECOND(...) PRECOND(false, ##__VA_ARGS__) #define FAIL_REQUIRE(...) REQUIRE(false, ##__VA_ARGS__)
#define FAIL_RECOVERABLE_PRECOND(...) RECOVERABLE_PRECOND(false, ##__VA_ARGS__) #define FAIL_RECOVERABLE_REQUIRE(...) RECOVERABLE_REQUIRE(false, ##__VA_ARGS__)
#define FAIL_VALIDATE_INPUT(...) VALIDATE_INPUT(false, ##__VA_ARGS__) #define FAIL_VALIDATE_INPUT(...) VALIDATE_INPUT(false, ##__VA_ARGS__)
#define SYSCALL(call, ...) \ #define SYSCALL(call, ...) \
...@@ -274,14 +274,14 @@ ArrayPtr<const char> KJ_STRINGIFY(Log::Severity severity); ...@@ -274,14 +274,14 @@ ArrayPtr<const char> KJ_STRINGIFY(Log::Severity severity);
#define DLOG(...) do {} while (false) #define DLOG(...) do {} while (false)
#define DCHECK(...) do {} while (false) #define DCHECK(...) do {} while (false)
#define RECOVERABLE_DCHECK(...) do {} while (false) #define RECOVERABLE_DCHECK(...) do {} while (false)
#define DPRECOND(...) do {} while (false) #define DREQUIRE(...) do {} while (false)
#define RECOVERABLE_DPRECOND(...) do {} while (false) #define RECOVERABLE_DREQUIRE(...) do {} while (false)
#else #else
#define DLOG LOG #define DLOG LOG
#define DCHECK CHECK #define DCHECK CHECK
#define RECOVERABLE_DCHECK RECOVERABLE_CHECK #define RECOVERABLE_DCHECK RECOVERABLE_CHECK
#define DPRECOND PRECOND #define DREQUIRE REQUIRE
#define RECOVERABLE_DPRECOND RECOVERABLE_PRECOND #define RECOVERABLE_DREQUIRE RECOVERABLE_REQUIRE
#endif #endif
template <typename... Params> template <typename... Params>
......
...@@ -365,7 +365,7 @@ inline const char* String::end() const { return content == nullptr ? nullptr : c ...@@ -365,7 +365,7 @@ inline const char* String::end() const { return content == nullptr ? nullptr : c
inline String::String(char* value, size_t size, const ArrayDisposer& disposer) inline String::String(char* value, size_t size, const ArrayDisposer& disposer)
: content(value, size + 1, disposer) { : content(value, size + 1, disposer) {
KJ_INLINE_DPRECOND(value[size] == '\0', "String must be NUL-terminated."); KJ_IREQUIRE(value[size] == '\0', "String must be NUL-terminated.");
} }
inline String heapString(const char* value) { inline String heapString(const char* value) {
......
...@@ -309,7 +309,7 @@ inline {{unionFullName}}::Which {{unionFullName}}::Builder::which() { ...@@ -309,7 +309,7 @@ inline {{unionFullName}}::Which {{unionFullName}}::Builder::which() {
{{#fieldIsPrimitive}} {{#fieldIsPrimitive}}
inline {{fieldType}} {{typeFullName}}::Reader::get{{fieldTitleCase}}() { inline {{fieldType}} {{typeFullName}}::Reader::get{{fieldTitleCase}}() {
{{#fieldUnion}} {{#fieldUnion}}
KJ_INLINE_DPRECOND(which() == {{unionTitleCase}}::{{fieldUpperCase}}, KJ_IREQUIRE(which() == {{unionTitleCase}}::{{fieldUpperCase}},
"Must check which() before get()ing a union member."); "Must check which() before get()ing a union member.");
{{/fieldUnion}} {{/fieldUnion}}
return _reader.getDataField<{{fieldType}}>( return _reader.getDataField<{{fieldType}}>(
...@@ -318,7 +318,7 @@ inline {{fieldType}} {{typeFullName}}::Reader::get{{fieldTitleCase}}() { ...@@ -318,7 +318,7 @@ inline {{fieldType}} {{typeFullName}}::Reader::get{{fieldTitleCase}}() {
inline {{fieldType}} {{typeFullName}}::Builder::get{{fieldTitleCase}}() { inline {{fieldType}} {{typeFullName}}::Builder::get{{fieldTitleCase}}() {
{{#fieldUnion}} {{#fieldUnion}}
KJ_INLINE_DPRECOND(which() == {{unionTitleCase}}::{{fieldUpperCase}}, KJ_IREQUIRE(which() == {{unionTitleCase}}::{{fieldUpperCase}},
"Must check which() before get()ing a union member."); "Must check which() before get()ing a union member.");
{{/fieldUnion}} {{/fieldUnion}}
return _builder.getDataField<{{fieldType}}>( return _builder.getDataField<{{fieldType}}>(
...@@ -346,7 +346,7 @@ inline bool {{typeFullName}}::Builder::has{{fieldTitleCase}}() { ...@@ -346,7 +346,7 @@ inline bool {{typeFullName}}::Builder::has{{fieldTitleCase}}() {
{{^fieldIsGenericObject}} {{^fieldIsGenericObject}}
inline {{fieldType}}::Reader {{typeFullName}}::Reader::get{{fieldTitleCase}}() { inline {{fieldType}}::Reader {{typeFullName}}::Reader::get{{fieldTitleCase}}() {
{{#fieldUnion}} {{#fieldUnion}}
KJ_INLINE_DPRECOND(which() == {{unionTitleCase}}::{{fieldUpperCase}}, KJ_IREQUIRE(which() == {{unionTitleCase}}::{{fieldUpperCase}},
"Must check which() before get()ing a union member."); "Must check which() before get()ing a union member.");
{{/fieldUnion}} {{/fieldUnion}}
return ::capnproto::internal::PointerHelpers<{{fieldType}}>::get( return ::capnproto::internal::PointerHelpers<{{fieldType}}>::get(
...@@ -356,7 +356,7 @@ inline {{fieldType}}::Reader {{typeFullName}}::Reader::get{{fieldTitleCase}}() { ...@@ -356,7 +356,7 @@ inline {{fieldType}}::Reader {{typeFullName}}::Reader::get{{fieldTitleCase}}() {
inline {{fieldType}}::Builder {{typeFullName}}::Builder::get{{fieldTitleCase}}() { inline {{fieldType}}::Builder {{typeFullName}}::Builder::get{{fieldTitleCase}}() {
{{#fieldUnion}} {{#fieldUnion}}
KJ_INLINE_DPRECOND(which() == {{unionTitleCase}}::{{fieldUpperCase}}, KJ_IREQUIRE(which() == {{unionTitleCase}}::{{fieldUpperCase}},
"Must check which() before get()ing a union member."); "Must check which() before get()ing a union member.");
{{/fieldUnion}} {{/fieldUnion}}
return ::capnproto::internal::PointerHelpers<{{fieldType}}>::get( return ::capnproto::internal::PointerHelpers<{{fieldType}}>::get(
...@@ -413,7 +413,7 @@ inline {{fieldType}}::Builder {{typeFullName}}::Builder::init{{fieldTitleCase}}( ...@@ -413,7 +413,7 @@ inline {{fieldType}}::Builder {{typeFullName}}::Builder::init{{fieldTitleCase}}(
template <typename T> template <typename T>
inline typename T::Reader {{typeFullName}}::Reader::get{{fieldTitleCase}}() { inline typename T::Reader {{typeFullName}}::Reader::get{{fieldTitleCase}}() {
{{#fieldUnion}} {{#fieldUnion}}
KJ_INLINE_DPRECOND(which() == {{unionTitleCase}}::{{fieldUpperCase}}, KJ_IREQUIRE(which() == {{unionTitleCase}}::{{fieldUpperCase}},
"Must check which() before get()ing a union member."); "Must check which() before get()ing a union member.");
{{/fieldUnion}} {{/fieldUnion}}
return ::capnproto::internal::PointerHelpers<T>::get( return ::capnproto::internal::PointerHelpers<T>::get(
...@@ -423,7 +423,7 @@ inline typename T::Reader {{typeFullName}}::Reader::get{{fieldTitleCase}}() { ...@@ -423,7 +423,7 @@ inline typename T::Reader {{typeFullName}}::Reader::get{{fieldTitleCase}}() {
template <typename T> template <typename T>
inline typename T::Builder {{typeFullName}}::Builder::get{{fieldTitleCase}}() { inline typename T::Builder {{typeFullName}}::Builder::get{{fieldTitleCase}}() {
{{#fieldUnion}} {{#fieldUnion}}
KJ_INLINE_DPRECOND(which() == {{unionTitleCase}}::{{fieldUpperCase}}, KJ_IREQUIRE(which() == {{unionTitleCase}}::{{fieldUpperCase}},
"Must check which() before get()ing a union member."); "Must check which() before get()ing a union member.");
{{/fieldUnion}} {{/fieldUnion}}
return ::capnproto::internal::PointerHelpers<T>::get( return ::capnproto::internal::PointerHelpers<T>::get(
...@@ -433,7 +433,7 @@ inline typename T::Builder {{typeFullName}}::Builder::get{{fieldTitleCase}}() { ...@@ -433,7 +433,7 @@ inline typename T::Builder {{typeFullName}}::Builder::get{{fieldTitleCase}}() {
template <typename T, typename Param> template <typename T, typename Param>
inline typename T::Reader {{typeFullName}}::Reader::get{{fieldTitleCase}}(Param&& param) { inline typename T::Reader {{typeFullName}}::Reader::get{{fieldTitleCase}}(Param&& param) {
{{#fieldUnion}} {{#fieldUnion}}
KJ_INLINE_DPRECOND(which() == {{unionTitleCase}}::{{fieldUpperCase}}, KJ_IREQUIRE(which() == {{unionTitleCase}}::{{fieldUpperCase}},
"Must check which() before get()ing a union member."); "Must check which() before get()ing a union member.");
{{/fieldUnion}} {{/fieldUnion}}
return ::capnproto::internal::PointerHelpers<T>::getDynamic( return ::capnproto::internal::PointerHelpers<T>::getDynamic(
...@@ -443,7 +443,7 @@ inline typename T::Reader {{typeFullName}}::Reader::get{{fieldTitleCase}}(Param& ...@@ -443,7 +443,7 @@ inline typename T::Reader {{typeFullName}}::Reader::get{{fieldTitleCase}}(Param&
template <typename T, typename Param> template <typename T, typename Param>
inline typename T::Builder {{typeFullName}}::Builder::get{{fieldTitleCase}}(Param&& param) { inline typename T::Builder {{typeFullName}}::Builder::get{{fieldTitleCase}}(Param&& param) {
{{#fieldUnion}} {{#fieldUnion}}
KJ_INLINE_DPRECOND(which() == {{unionTitleCase}}::{{fieldUpperCase}}, KJ_IREQUIRE(which() == {{unionTitleCase}}::{{fieldUpperCase}},
"Must check which() before get()ing a union member."); "Must check which() before get()ing a union member.");
{{/fieldUnion}} {{/fieldUnion}}
return ::capnproto::internal::PointerHelpers<T>::getDynamic( return ::capnproto::internal::PointerHelpers<T>::getDynamic(
......
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