From bd6e66fd0c3012ad6bcb03cdb3fb687767fb6ccf Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Wed, 13 Mar 2024 11:04:07 -0400 Subject: [PATCH] cpp-common/bt2: remove redundant assertions Remove some redundant BT_ASSERT and BT_ASSERT_DBG. - Most `as*()` methods call a constructor that does the exact same check. Some exceptions are field class types that have signed and unsigned variants, where the base class' assertion does not check the signedness. Another one is `CommonNullValue::asNull`, where the `CommonNullValue` constructor does not take a lib object pointer, so does not do a check. - Things that end up constructing a `BorrowedObject` don't need to do a null pointer check, as `BorrowedObject`'s constructor does one. - `BorrowedObjectIterator::operator*` does not need an assertion on the length, as `operator[]` of the container is expected to do it (either directly, or rely on the preconditions in the lib). Change-Id: I6f11680628607eee11164a2e9d3f9de7fc7468cb Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/12052 Reviewed-by: Philippe Proulx --- src/cpp-common/bt2/borrowed-object-iterator.hpp | 1 - src/cpp-common/bt2/field-class.hpp | 13 ------------- src/cpp-common/bt2/field-path.hpp | 1 - src/cpp-common/bt2/field.hpp | 14 -------------- src/cpp-common/bt2/message.hpp | 8 -------- src/cpp-common/bt2/optional-borrowed-object.hpp | 3 --- src/cpp-common/bt2/self-component-port.hpp | 2 -- src/cpp-common/bt2/self-message-iterator.hpp | 2 -- src/cpp-common/bt2/shared-object.hpp | 6 ------ src/cpp-common/bt2/value.hpp | 7 ------- 10 files changed, 57 deletions(-) diff --git a/src/cpp-common/bt2/borrowed-object-iterator.hpp b/src/cpp-common/bt2/borrowed-object-iterator.hpp index 46e68c16..3602a4e9 100644 --- a/src/cpp-common/bt2/borrowed-object-iterator.hpp +++ b/src/cpp-common/bt2/borrowed-object-iterator.hpp @@ -73,7 +73,6 @@ public: Object operator*() const noexcept { - BT_ASSERT_DBG(_mIdx < _mContainer.length()); return _mContainer[_mIdx]; } diff --git a/src/cpp-common/bt2/field-class.hpp b/src/cpp-common/bt2/field-class.hpp index c6c4d690..857c33a7 100644 --- a/src/cpp-common/bt2/field-class.hpp +++ b/src/cpp-common/bt2/field-class.hpp @@ -2551,21 +2551,18 @@ struct TypeDescr : template CommonBitArrayFieldClass CommonFieldClass::asBitArray() const noexcept { - BT_ASSERT_DBG(this->isBitArray()); return CommonBitArrayFieldClass {this->libObjPtr()}; } template CommonIntegerFieldClass CommonFieldClass::asInteger() const noexcept { - BT_ASSERT_DBG(this->isInteger()); return CommonIntegerFieldClass {this->libObjPtr()}; } template CommonBaseEnumerationFieldClass CommonFieldClass::asEnumeration() const noexcept { - BT_ASSERT_DBG(this->isEnumeration()); return CommonBaseEnumerationFieldClass {this->libObjPtr()}; } @@ -2590,21 +2587,18 @@ CommonFieldClass::asSignedEnumeration() const noexcept template CommonStructureFieldClass CommonFieldClass::asStructure() const noexcept { - BT_ASSERT_DBG(this->isStructure()); return CommonStructureFieldClass {this->libObjPtr()}; } template CommonArrayFieldClass CommonFieldClass::asArray() const noexcept { - BT_ASSERT_DBG(this->isArray()); return CommonArrayFieldClass {this->libObjPtr()}; } template CommonStaticArrayFieldClass CommonFieldClass::asStaticArray() const noexcept { - BT_ASSERT_DBG(this->isStaticArray()); return CommonStaticArrayFieldClass {this->libObjPtr()}; } @@ -2612,14 +2606,12 @@ template CommonDynamicArrayWithLengthFieldClass CommonFieldClass::asDynamicArrayWithLength() const noexcept { - BT_ASSERT_DBG(this->isDynamicArrayWithLength()); return CommonDynamicArrayWithLengthFieldClass {this->libObjPtr()}; } template CommonOptionFieldClass CommonFieldClass::asOption() const noexcept { - BT_ASSERT_DBG(this->isOption()); return CommonOptionFieldClass {this->libObjPtr()}; } @@ -2627,7 +2619,6 @@ template CommonOptionWithSelectorFieldClass CommonFieldClass::asOptionWithSelector() const noexcept { - BT_ASSERT_DBG(this->isOptionWithSelector()); return CommonOptionWithSelectorFieldClass {this->libObjPtr()}; } @@ -2635,7 +2626,6 @@ template CommonOptionWithBoolSelectorFieldClass CommonFieldClass::asOptionWithBoolSelector() const noexcept { - BT_ASSERT_DBG(this->isOptionWithBoolSelector()); return CommonOptionWithBoolSelectorFieldClass {this->libObjPtr()}; } @@ -2660,7 +2650,6 @@ CommonFieldClass::asOptionWithSignedIntegerSelector() const noexcept template CommonVariantFieldClass CommonFieldClass::asVariant() const noexcept { - BT_ASSERT_DBG(this->isVariant()); return CommonVariantFieldClass {this->libObjPtr()}; } @@ -2668,7 +2657,6 @@ template CommonVariantWithoutSelectorFieldClass CommonFieldClass::asVariantWithoutSelector() const noexcept { - BT_ASSERT_DBG(this->isVariantWithoutSelector()); return CommonVariantWithoutSelectorFieldClass {this->libObjPtr()}; } @@ -2676,7 +2664,6 @@ template CommonVariantWithSelectorFieldClass CommonFieldClass::asVariantWithSelector() const noexcept { - BT_ASSERT_DBG(this->isVariantWithSelector()); return CommonVariantWithSelectorFieldClass {this->libObjPtr()}; } diff --git a/src/cpp-common/bt2/field-path.hpp b/src/cpp-common/bt2/field-path.hpp index 2d4af443..fc087593 100644 --- a/src/cpp-common/bt2/field-path.hpp +++ b/src/cpp-common/bt2/field-path.hpp @@ -82,7 +82,6 @@ public: inline ConstIndexFieldPathItem ConstFieldPathItem::asIndex() const noexcept { - BT_ASSERT_DBG(this->isIndex()); return ConstIndexFieldPathItem {this->libObjPtr()}; } diff --git a/src/cpp-common/bt2/field.hpp b/src/cpp-common/bt2/field.hpp index 427cdd51..6853510e 100644 --- a/src/cpp-common/bt2/field.hpp +++ b/src/cpp-common/bt2/field.hpp @@ -1537,98 +1537,84 @@ struct TypeDescr : public VariantFieldTypeDescr template CommonBoolField CommonField::asBool() const noexcept { - BT_ASSERT_DBG(this->isBool()); return CommonBoolField {this->libObjPtr()}; } template CommonBitArrayField CommonField::asBitArray() const noexcept { - BT_ASSERT_DBG(this->isBitArray()); return CommonBitArrayField {this->libObjPtr()}; } template CommonUnsignedIntegerField CommonField::asUnsignedInteger() const noexcept { - BT_ASSERT_DBG(this->isUnsignedInteger()); return CommonUnsignedIntegerField {this->libObjPtr()}; } template CommonSignedIntegerField CommonField::asSignedInteger() const noexcept { - BT_ASSERT_DBG(this->isSignedInteger()); return CommonSignedIntegerField {this->libObjPtr()}; } template CommonUnsignedEnumerationField CommonField::asUnsignedEnumeration() const noexcept { - BT_ASSERT_DBG(this->isUnsignedEnumeration()); return CommonUnsignedEnumerationField {this->libObjPtr()}; } template CommonSignedEnumerationField CommonField::asSignedEnumeration() const noexcept { - BT_ASSERT_DBG(this->isSignedEnumeration()); return CommonSignedEnumerationField {this->libObjPtr()}; } template CommonSinglePrecisionRealField CommonField::asSinglePrecisionReal() const noexcept { - BT_ASSERT_DBG(this->isSinglePrecisionReal()); return CommonSinglePrecisionRealField {this->libObjPtr()}; } template CommonDoublePrecisionRealField CommonField::asDoublePrecisionReal() const noexcept { - BT_ASSERT_DBG(this->isDoublePrecisionReal()); return CommonDoublePrecisionRealField {this->libObjPtr()}; } template CommonStringField CommonField::asString() const noexcept { - BT_ASSERT_DBG(this->isString()); return CommonStringField {this->libObjPtr()}; } template CommonStructureField CommonField::asStructure() const noexcept { - BT_ASSERT_DBG(this->isStructure()); return CommonStructureField {this->libObjPtr()}; } template CommonArrayField CommonField::asArray() const noexcept { - BT_ASSERT_DBG(this->isArray()); return CommonArrayField {this->libObjPtr()}; } template CommonDynamicArrayField CommonField::asDynamicArray() const noexcept { - BT_ASSERT_DBG(this->isDynamicArray()); return CommonDynamicArrayField {this->libObjPtr()}; } template CommonOptionField CommonField::asOption() const noexcept { - BT_ASSERT_DBG(this->isOption()); return CommonOptionField {this->libObjPtr()}; } template CommonVariantField CommonField::asVariant() const noexcept { - BT_ASSERT_DBG(this->isVariant()); return CommonVariantField {this->libObjPtr()}; } diff --git a/src/cpp-common/bt2/message.hpp b/src/cpp-common/bt2/message.hpp index a0259c0e..3f9d7418 100644 --- a/src/cpp-common/bt2/message.hpp +++ b/src/cpp-common/bt2/message.hpp @@ -1094,49 +1094,42 @@ struct TypeDescr : template CommonStreamBeginningMessage CommonMessage::asStreamBeginning() const noexcept { - BT_ASSERT_DBG(this->isStreamBeginning()); return CommonStreamBeginningMessage {this->libObjPtr()}; } template CommonStreamEndMessage CommonMessage::asStreamEnd() const noexcept { - BT_ASSERT_DBG(this->isStreamEnd()); return CommonStreamEndMessage {this->libObjPtr()}; } template CommonPacketBeginningMessage CommonMessage::asPacketBeginning() const noexcept { - BT_ASSERT_DBG(this->isPacketBeginning()); return CommonPacketBeginningMessage {this->libObjPtr()}; } template CommonPacketEndMessage CommonMessage::asPacketEnd() const noexcept { - BT_ASSERT_DBG(this->isPacketEnd()); return CommonPacketEndMessage {this->libObjPtr()}; } template CommonEventMessage CommonMessage::asEvent() const noexcept { - BT_ASSERT_DBG(this->isEvent()); return CommonEventMessage {this->libObjPtr()}; } template CommonDiscardedEventsMessage CommonMessage::asDiscardedEvents() const noexcept { - BT_ASSERT_DBG(this->isDiscardedEvents()); return CommonDiscardedEventsMessage {this->libObjPtr()}; } template CommonDiscardedPacketsMessage CommonMessage::asDiscardedPackets() const noexcept { - BT_ASSERT_DBG(this->isDiscardedPackets()); return CommonDiscardedPacketsMessage {this->libObjPtr()}; } @@ -1144,7 +1137,6 @@ template CommonMessageIteratorInactivityMessage CommonMessage::asMessageIteratorInactivity() const noexcept { - BT_ASSERT_DBG(this->isMessageIteratorInactivity()); return CommonMessageIteratorInactivityMessage {this->libObjPtr()}; } diff --git a/src/cpp-common/bt2/optional-borrowed-object.hpp b/src/cpp-common/bt2/optional-borrowed-object.hpp index 100abf4d..941a87b1 100644 --- a/src/cpp-common/bt2/optional-borrowed-object.hpp +++ b/src/cpp-common/bt2/optional-borrowed-object.hpp @@ -9,8 +9,6 @@ #include -#include "common/assert.h" - #include "borrowed-object-proxy.hpp" namespace bt2 { @@ -147,7 +145,6 @@ public: ObjT object() const noexcept { - BT_ASSERT_DBG(_mLibObjPtr); return ObjT {_mLibObjPtr}; } diff --git a/src/cpp-common/bt2/self-component-port.hpp b/src/cpp-common/bt2/self-component-port.hpp index 5b34abfd..2cd056af 100644 --- a/src/cpp-common/bt2/self-component-port.hpp +++ b/src/cpp-common/bt2/self-component-port.hpp @@ -13,7 +13,6 @@ #include "logging.hpp" -#include "common/assert.h" #include "cpp-common/bt2c/c-string-view.hpp" #include "borrowed-object-iterator.hpp" @@ -688,7 +687,6 @@ SelfSinkComponent::createMessageIterator(const InputPorts::Port port) const switch (status) { case BT_MESSAGE_ITERATOR_CREATE_FROM_SINK_COMPONENT_STATUS_OK: - BT_ASSERT(libMsgIterPtr); return MessageIterator::Shared::createWithoutRef(libMsgIterPtr); case BT_MESSAGE_ITERATOR_CREATE_FROM_SINK_COMPONENT_STATUS_MEMORY_ERROR: throw MemoryError {}; diff --git a/src/cpp-common/bt2/self-message-iterator.hpp b/src/cpp-common/bt2/self-message-iterator.hpp index 4460fe27..e52f08e6 100644 --- a/src/cpp-common/bt2/self-message-iterator.hpp +++ b/src/cpp-common/bt2/self-message-iterator.hpp @@ -9,7 +9,6 @@ #include -#include "common/assert.h" #include "common/common.h" #include "borrowed-object.hpp" @@ -34,7 +33,6 @@ public: switch (status) { case BT_MESSAGE_ITERATOR_CREATE_FROM_MESSAGE_ITERATOR_STATUS_OK: - BT_ASSERT(libMsgIterPtr); return MessageIterator::Shared::createWithoutRef(libMsgIterPtr); case BT_MESSAGE_ITERATOR_CREATE_FROM_MESSAGE_ITERATOR_STATUS_MEMORY_ERROR: throw MemoryError {}; diff --git a/src/cpp-common/bt2/shared-object.hpp b/src/cpp-common/bt2/shared-object.hpp index 406172d8..124cff48 100644 --- a/src/cpp-common/bt2/shared-object.hpp +++ b/src/cpp-common/bt2/shared-object.hpp @@ -9,8 +9,6 @@ #include -#include "common/assert.h" - #include "optional-borrowed-object.hpp" namespace bt2 { @@ -235,13 +233,11 @@ public: ObjT operator*() const noexcept { - BT_ASSERT_DBG(_mObj); return *_mObj; } BorrowedObjectProxy operator->() const noexcept { - BT_ASSERT_DBG(_mObj); return _mObj.operator->(); } @@ -270,8 +266,6 @@ public: */ ObjT release() noexcept { - BT_ASSERT_DBG(_mObj); - const auto obj = *_mObj; this->_reset(); diff --git a/src/cpp-common/bt2/value.hpp b/src/cpp-common/bt2/value.hpp index 14ae5a2b..7388c340 100644 --- a/src/cpp-common/bt2/value.hpp +++ b/src/cpp-common/bt2/value.hpp @@ -1426,49 +1426,42 @@ CommonNullValue CommonValue::asNull() const noexcept template CommonBoolValue CommonValue::asBool() const noexcept { - BT_ASSERT_DBG(this->isBool()); return CommonBoolValue {this->libObjPtr()}; } template CommonSignedIntegerValue CommonValue::asSignedInteger() const noexcept { - BT_ASSERT_DBG(this->isSignedInteger()); return CommonSignedIntegerValue {this->libObjPtr()}; } template CommonUnsignedIntegerValue CommonValue::asUnsignedInteger() const noexcept { - BT_ASSERT_DBG(this->isUnsignedInteger()); return CommonUnsignedIntegerValue {this->libObjPtr()}; } template CommonRealValue CommonValue::asReal() const noexcept { - BT_ASSERT_DBG(this->isReal()); return CommonRealValue {this->libObjPtr()}; } template CommonStringValue CommonValue::asString() const noexcept { - BT_ASSERT_DBG(this->isString()); return CommonStringValue {this->libObjPtr()}; } template CommonArrayValue CommonValue::asArray() const noexcept { - BT_ASSERT_DBG(this->isArray()); return CommonArrayValue {this->libObjPtr()}; } template CommonMapValue CommonValue::asMap() const noexcept { - BT_ASSERT_DBG(this->isMap()); return CommonMapValue {this->libObjPtr()}; } -- 2.34.1