cpp-common/bt2: remove redundant assertions
authorSimon Marchi <simon.marchi@efficios.com>
Wed, 13 Mar 2024 15:04:07 +0000 (11:04 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Tue, 26 Mar 2024 18:56:36 +0000 (14:56 -0400)
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 <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12052
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
src/cpp-common/bt2/borrowed-object-iterator.hpp
src/cpp-common/bt2/field-class.hpp
src/cpp-common/bt2/field-path.hpp
src/cpp-common/bt2/field.hpp
src/cpp-common/bt2/message.hpp
src/cpp-common/bt2/optional-borrowed-object.hpp
src/cpp-common/bt2/self-component-port.hpp
src/cpp-common/bt2/self-message-iterator.hpp
src/cpp-common/bt2/shared-object.hpp
src/cpp-common/bt2/value.hpp

index 46e68c161f60d8e2019beb05ca48af9c03bcf1c5..3602a4e9101910e861e8132c86f01f9e7718a29a 100644 (file)
@@ -73,7 +73,6 @@ public:
 
     Object operator*() const noexcept
     {
-        BT_ASSERT_DBG(_mIdx < _mContainer.length());
         return _mContainer[_mIdx];
     }
 
index c6c4d690ff7870e93b26ee6bc4852630991c3d9c..857c33a718335514caad8ad78d26936c188f103a 100644 (file)
@@ -2551,21 +2551,18 @@ struct TypeDescr<ConstVariantWithSignedIntegerSelectorFieldClass> :
 template <typename LibObjT>
 CommonBitArrayFieldClass<LibObjT> CommonFieldClass<LibObjT>::asBitArray() const noexcept
 {
-    BT_ASSERT_DBG(this->isBitArray());
     return CommonBitArrayFieldClass<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonIntegerFieldClass<LibObjT> CommonFieldClass<LibObjT>::asInteger() const noexcept
 {
-    BT_ASSERT_DBG(this->isInteger());
     return CommonIntegerFieldClass<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonBaseEnumerationFieldClass<LibObjT> CommonFieldClass<LibObjT>::asEnumeration() const noexcept
 {
-    BT_ASSERT_DBG(this->isEnumeration());
     return CommonBaseEnumerationFieldClass<LibObjT> {this->libObjPtr()};
 }
 
@@ -2590,21 +2587,18 @@ CommonFieldClass<LibObjT>::asSignedEnumeration() const noexcept
 template <typename LibObjT>
 CommonStructureFieldClass<LibObjT> CommonFieldClass<LibObjT>::asStructure() const noexcept
 {
-    BT_ASSERT_DBG(this->isStructure());
     return CommonStructureFieldClass<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonArrayFieldClass<LibObjT> CommonFieldClass<LibObjT>::asArray() const noexcept
 {
-    BT_ASSERT_DBG(this->isArray());
     return CommonArrayFieldClass<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonStaticArrayFieldClass<LibObjT> CommonFieldClass<LibObjT>::asStaticArray() const noexcept
 {
-    BT_ASSERT_DBG(this->isStaticArray());
     return CommonStaticArrayFieldClass<LibObjT> {this->libObjPtr()};
 }
 
@@ -2612,14 +2606,12 @@ template <typename LibObjT>
 CommonDynamicArrayWithLengthFieldClass<LibObjT>
 CommonFieldClass<LibObjT>::asDynamicArrayWithLength() const noexcept
 {
-    BT_ASSERT_DBG(this->isDynamicArrayWithLength());
     return CommonDynamicArrayWithLengthFieldClass<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonOptionFieldClass<LibObjT> CommonFieldClass<LibObjT>::asOption() const noexcept
 {
-    BT_ASSERT_DBG(this->isOption());
     return CommonOptionFieldClass<LibObjT> {this->libObjPtr()};
 }
 
@@ -2627,7 +2619,6 @@ template <typename LibObjT>
 CommonOptionWithSelectorFieldClass<LibObjT>
 CommonFieldClass<LibObjT>::asOptionWithSelector() const noexcept
 {
-    BT_ASSERT_DBG(this->isOptionWithSelector());
     return CommonOptionWithSelectorFieldClass<LibObjT> {this->libObjPtr()};
 }
 
@@ -2635,7 +2626,6 @@ template <typename LibObjT>
 CommonOptionWithBoolSelectorFieldClass<LibObjT>
 CommonFieldClass<LibObjT>::asOptionWithBoolSelector() const noexcept
 {
-    BT_ASSERT_DBG(this->isOptionWithBoolSelector());
     return CommonOptionWithBoolSelectorFieldClass<LibObjT> {this->libObjPtr()};
 }
 
@@ -2660,7 +2650,6 @@ CommonFieldClass<LibObjT>::asOptionWithSignedIntegerSelector() const noexcept
 template <typename LibObjT>
 CommonVariantFieldClass<LibObjT> CommonFieldClass<LibObjT>::asVariant() const noexcept
 {
-    BT_ASSERT_DBG(this->isVariant());
     return CommonVariantFieldClass<LibObjT> {this->libObjPtr()};
 }
 
@@ -2668,7 +2657,6 @@ template <typename LibObjT>
 CommonVariantWithoutSelectorFieldClass<LibObjT>
 CommonFieldClass<LibObjT>::asVariantWithoutSelector() const noexcept
 {
-    BT_ASSERT_DBG(this->isVariantWithoutSelector());
     return CommonVariantWithoutSelectorFieldClass<LibObjT> {this->libObjPtr()};
 }
 
@@ -2676,7 +2664,6 @@ template <typename LibObjT>
 CommonVariantWithSelectorFieldClass<LibObjT>
 CommonFieldClass<LibObjT>::asVariantWithSelector() const noexcept
 {
-    BT_ASSERT_DBG(this->isVariantWithSelector());
     return CommonVariantWithSelectorFieldClass<LibObjT> {this->libObjPtr()};
 }
 
index 2d4af443a3e5b0e9d6d8c495c1e6c4af455bb240..fc087593b881ecbaef878ccdea4642c4c3884de4 100644 (file)
@@ -82,7 +82,6 @@ public:
 
 inline ConstIndexFieldPathItem ConstFieldPathItem::asIndex() const noexcept
 {
-    BT_ASSERT_DBG(this->isIndex());
     return ConstIndexFieldPathItem {this->libObjPtr()};
 }
 
index 427cdd51017b7b79af64251b6cbbfac256e72703..6853510eb0cf55ddfc4536d93a0500540a01b1e6 100644 (file)
@@ -1537,98 +1537,84 @@ struct TypeDescr<ConstVariantField> : public VariantFieldTypeDescr
 template <typename LibObjT>
 CommonBoolField<LibObjT> CommonField<LibObjT>::asBool() const noexcept
 {
-    BT_ASSERT_DBG(this->isBool());
     return CommonBoolField<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonBitArrayField<LibObjT> CommonField<LibObjT>::asBitArray() const noexcept
 {
-    BT_ASSERT_DBG(this->isBitArray());
     return CommonBitArrayField<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonUnsignedIntegerField<LibObjT> CommonField<LibObjT>::asUnsignedInteger() const noexcept
 {
-    BT_ASSERT_DBG(this->isUnsignedInteger());
     return CommonUnsignedIntegerField<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonSignedIntegerField<LibObjT> CommonField<LibObjT>::asSignedInteger() const noexcept
 {
-    BT_ASSERT_DBG(this->isSignedInteger());
     return CommonSignedIntegerField<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonUnsignedEnumerationField<LibObjT> CommonField<LibObjT>::asUnsignedEnumeration() const noexcept
 {
-    BT_ASSERT_DBG(this->isUnsignedEnumeration());
     return CommonUnsignedEnumerationField<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonSignedEnumerationField<LibObjT> CommonField<LibObjT>::asSignedEnumeration() const noexcept
 {
-    BT_ASSERT_DBG(this->isSignedEnumeration());
     return CommonSignedEnumerationField<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonSinglePrecisionRealField<LibObjT> CommonField<LibObjT>::asSinglePrecisionReal() const noexcept
 {
-    BT_ASSERT_DBG(this->isSinglePrecisionReal());
     return CommonSinglePrecisionRealField<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonDoublePrecisionRealField<LibObjT> CommonField<LibObjT>::asDoublePrecisionReal() const noexcept
 {
-    BT_ASSERT_DBG(this->isDoublePrecisionReal());
     return CommonDoublePrecisionRealField<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonStringField<LibObjT> CommonField<LibObjT>::asString() const noexcept
 {
-    BT_ASSERT_DBG(this->isString());
     return CommonStringField<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonStructureField<LibObjT> CommonField<LibObjT>::asStructure() const noexcept
 {
-    BT_ASSERT_DBG(this->isStructure());
     return CommonStructureField<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonArrayField<LibObjT> CommonField<LibObjT>::asArray() const noexcept
 {
-    BT_ASSERT_DBG(this->isArray());
     return CommonArrayField<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonDynamicArrayField<LibObjT> CommonField<LibObjT>::asDynamicArray() const noexcept
 {
-    BT_ASSERT_DBG(this->isDynamicArray());
     return CommonDynamicArrayField<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonOptionField<LibObjT> CommonField<LibObjT>::asOption() const noexcept
 {
-    BT_ASSERT_DBG(this->isOption());
     return CommonOptionField<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonVariantField<LibObjT> CommonField<LibObjT>::asVariant() const noexcept
 {
-    BT_ASSERT_DBG(this->isVariant());
     return CommonVariantField<LibObjT> {this->libObjPtr()};
 }
 
index a0259c0edbc55dd7839fdada5c75d7ee48018484..3f9d74183e53f7e1d66e399d4f4d3e9c279c49ae 100644 (file)
@@ -1094,49 +1094,42 @@ struct TypeDescr<ConstMessageIteratorInactivityMessage> :
 template <typename LibObjT>
 CommonStreamBeginningMessage<LibObjT> CommonMessage<LibObjT>::asStreamBeginning() const noexcept
 {
-    BT_ASSERT_DBG(this->isStreamBeginning());
     return CommonStreamBeginningMessage<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonStreamEndMessage<LibObjT> CommonMessage<LibObjT>::asStreamEnd() const noexcept
 {
-    BT_ASSERT_DBG(this->isStreamEnd());
     return CommonStreamEndMessage<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonPacketBeginningMessage<LibObjT> CommonMessage<LibObjT>::asPacketBeginning() const noexcept
 {
-    BT_ASSERT_DBG(this->isPacketBeginning());
     return CommonPacketBeginningMessage<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonPacketEndMessage<LibObjT> CommonMessage<LibObjT>::asPacketEnd() const noexcept
 {
-    BT_ASSERT_DBG(this->isPacketEnd());
     return CommonPacketEndMessage<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonEventMessage<LibObjT> CommonMessage<LibObjT>::asEvent() const noexcept
 {
-    BT_ASSERT_DBG(this->isEvent());
     return CommonEventMessage<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonDiscardedEventsMessage<LibObjT> CommonMessage<LibObjT>::asDiscardedEvents() const noexcept
 {
-    BT_ASSERT_DBG(this->isDiscardedEvents());
     return CommonDiscardedEventsMessage<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonDiscardedPacketsMessage<LibObjT> CommonMessage<LibObjT>::asDiscardedPackets() const noexcept
 {
-    BT_ASSERT_DBG(this->isDiscardedPackets());
     return CommonDiscardedPacketsMessage<LibObjT> {this->libObjPtr()};
 }
 
@@ -1144,7 +1137,6 @@ template <typename LibObjT>
 CommonMessageIteratorInactivityMessage<LibObjT>
 CommonMessage<LibObjT>::asMessageIteratorInactivity() const noexcept
 {
-    BT_ASSERT_DBG(this->isMessageIteratorInactivity());
     return CommonMessageIteratorInactivityMessage<LibObjT> {this->libObjPtr()};
 }
 
index 100abf4def965da8b4ccc25ea4d1c46a58c1ab82..941a87b1e96f0525eb9cfd5db7064ff87e5d5c0e 100644 (file)
@@ -9,8 +9,6 @@
 
 #include <type_traits>
 
-#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};
     }
 
index 5b34abfd1d3fbf486c552bd632e960d0f4a0186e..2cd056afb1f4343dbe367d4f99c102b4de39f8a3 100644 (file)
@@ -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 {};
index 4460fe27e79c422cc90f9f222147a4c48d96ae2b..e52f08e6727951f398bfa01362140dbab6f518c2 100644 (file)
@@ -9,7 +9,6 @@
 
 #include <babeltrace2/babeltrace.h>
 
-#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 {};
index 406172d80577b929ea0a8745e6544425fd6a7791..124cff48b49086ce16ede66647eecfdfa01a694b 100644 (file)
@@ -9,8 +9,6 @@
 
 #include <utility>
 
-#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<ObjT> 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();
index 14ae5a2b3b7f325dde5be3c6582fde908506fc3f..7388c3403a7558c0e94fefcd8527a2fdac80c249 100644 (file)
@@ -1426,49 +1426,42 @@ CommonNullValue<LibObjT> CommonValue<LibObjT>::asNull() const noexcept
 template <typename LibObjT>
 CommonBoolValue<LibObjT> CommonValue<LibObjT>::asBool() const noexcept
 {
-    BT_ASSERT_DBG(this->isBool());
     return CommonBoolValue<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonSignedIntegerValue<LibObjT> CommonValue<LibObjT>::asSignedInteger() const noexcept
 {
-    BT_ASSERT_DBG(this->isSignedInteger());
     return CommonSignedIntegerValue<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonUnsignedIntegerValue<LibObjT> CommonValue<LibObjT>::asUnsignedInteger() const noexcept
 {
-    BT_ASSERT_DBG(this->isUnsignedInteger());
     return CommonUnsignedIntegerValue<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonRealValue<LibObjT> CommonValue<LibObjT>::asReal() const noexcept
 {
-    BT_ASSERT_DBG(this->isReal());
     return CommonRealValue<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonStringValue<LibObjT> CommonValue<LibObjT>::asString() const noexcept
 {
-    BT_ASSERT_DBG(this->isString());
     return CommonStringValue<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonArrayValue<LibObjT> CommonValue<LibObjT>::asArray() const noexcept
 {
-    BT_ASSERT_DBG(this->isArray());
     return CommonArrayValue<LibObjT> {this->libObjPtr()};
 }
 
 template <typename LibObjT>
 CommonMapValue<LibObjT> CommonValue<LibObjT>::asMap() const noexcept
 {
-    BT_ASSERT_DBG(this->isMap());
     return CommonMapValue<LibObjT> {this->libObjPtr()};
 }
 
This page took 0.032137 seconds and 4 git commands to generate.