From: g0dil Date: Thu, 6 May 2010 12:23:29 +0000 (+0000) Subject: Add 'comment' argument to SENF_ASSERT X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=a1c37005ec4c281f6a76c07070a943cd1e36b6af;p=senf.git Add 'comment' argument to SENF_ASSERT git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1625 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/senf/PPI/Connectors.cc b/senf/PPI/Connectors.cc index bdcf581..0813b41 100644 --- a/senf/PPI/Connectors.cc +++ b/senf/PPI/Connectors.cc @@ -42,19 +42,19 @@ prefix_ void senf::ppi::connector::Connector::connect(Connector & target) { // The connector is not registered -> route() or noroute() statement missing - SENF_ASSERT( module_ && + SENF_ASSERT( module_, "senf::ppi::connector::Connector::connect(): (source) " "Missing route() or noroute()" ); // The connector is already connected - SENF_ASSERT( ! peer_ && + SENF_ASSERT( ! peer_, "senf::ppi::connector::Connector::connect(): (source) " "duplicate connection" ); // The target connector is not registered -> route() or noroute() statement missing - SENF_ASSERT( target.module_ && + SENF_ASSERT( target.module_, "senf::ppi::connector::Connector::connect(): (target) " "Missing route() or noroute()" ); // The target connector is already connected - SENF_ASSERT( ! target.peer_ && + SENF_ASSERT( ! target.peer_, "senf::ppi::connector::Connector::connect(): (target) " "duplicate connection" ); if (! (packetTypeID() == typeid(void) || @@ -167,7 +167,7 @@ namespace { prefix_ void senf::ppi::connector::Connector::disconnect() { // Cannot disconnected a non-connected connector - SENF_ASSERT( peer_ && + SENF_ASSERT( peer_, "senf::ppi::connector::Connector::disconnect(): Not connected" ); Connector & peer (*peer_); diff --git a/senf/PPI/Connectors.cci b/senf/PPI/Connectors.cci index cebc539..986a2a4 100644 --- a/senf/PPI/Connectors.cci +++ b/senf/PPI/Connectors.cci @@ -38,7 +38,7 @@ prefix_ senf::ppi::connector::Connector & senf::ppi::connector::Connector::peer( const { // The connector is not connected - SENF_ASSERT(peer_ && "senf::ppi::connect() call missing"); + SENF_ASSERT(peer_, "senf::ppi::connect() call missing"); return *peer_; } @@ -47,7 +47,7 @@ prefix_ senf::ppi::module::Module & senf::ppi::connector::Connector::module() { // The connector is not registered in the module -> probably a route() or noroute() statement is // missing. - SENF_ASSERT(module_ && "Connector not registered: Missing route() or noroute()"); + SENF_ASSERT(module_, "Connector not registered: Missing route() or noroute()"); return *module_; } @@ -192,7 +192,7 @@ prefix_ senf::ppi::connector::PassiveConnector::PassiveConnector() prefix_ void senf::ppi::connector::PassiveConnector::emit() { // No event callback has been registered (onRequest() call missing) - SENF_ASSERT(callback_ && "senf::ppi::connector::PassiveConnector: missing onRequest()"); + SENF_ASSERT(callback_, "senf::ppi::connector::PassiveConnector: missing onRequest()"); if (!throttled()) callback_(); else @@ -263,7 +263,7 @@ prefix_ senf::Packet senf::ppi::connector::InputConnector::peek() const { // Cannot peek() head of empty queue - SENF_ASSERT( ! queue_.empty() && + SENF_ASSERT( ! queue_.empty(), "senf::ppi::connector::InputConnector: cannot call peek() on empty queue" ); return queue_.back(); } diff --git a/senf/PPI/DebugModules.cc b/senf/PPI/DebugModules.cc index 0da4b61..cc7e1da 100644 --- a/senf/PPI/DebugModules.cc +++ b/senf/PPI/DebugModules.cc @@ -37,7 +37,7 @@ prefix_ void senf::ppi::module::debug::PassiveSource::request() { - SENF_ASSERT( ! packets_.empty() && + SENF_ASSERT( ! packets_.empty(), "senf::ppi::module::debug::PassiveSource::request(): " "Requesting packet from empty source." ); output(packets_.front()); diff --git a/senf/PPI/EventManager.cc b/senf/PPI/EventManager.cc index 60a56ca..ca2a598 100644 --- a/senf/PPI/EventManager.cc +++ b/senf/PPI/EventManager.cc @@ -56,7 +56,8 @@ prefix_ void senf::ppi::EventManager::destroyEvent(EventDescriptor & event) SENF_ASSERT( std::find_if(registrations_.begin(), registrations_.end(), l::bind(&detail::EventBindingBase::descriptor_,_1) == &event) - == registrations_.end()); + == registrations_.end(), + "Internal failure: registrations still active while destroying event ??"); } ///////////////////////////////cc.e//////////////////////////////////////// diff --git a/senf/PPI/Events.cc b/senf/PPI/Events.cc index 546bd13..c866a86 100644 --- a/senf/PPI/Events.cc +++ b/senf/PPI/Events.cc @@ -58,7 +58,7 @@ prefix_ void senf::ppi::EventDescriptor::notifyUnthrottle() prefix_ void senf::ppi::EventDescriptor::enabled(bool v) { - SENF_ASSERT(v_isRegistered() && "Module::registerEvent() call missing"); + SENF_ASSERT(v_isRegistered(), "Module::registerEvent() call missing"); if (throttled_ && v) return; if (v && ! enabled_) diff --git a/senf/PPI/Events.cti b/senf/PPI/Events.cti index 9478b8e..5c6bc97 100644 --- a/senf/PPI/Events.cti +++ b/senf/PPI/Events.cti @@ -59,7 +59,7 @@ template prefix_ senf::ppi::detail::EventBinding & senf::ppi::EventImplementationHelper::binding() { - SENF_ASSERT( static_cast(this)->binding_ && + SENF_ASSERT( static_cast(this)->binding_, "senf::ppi::EventImplementationHelper::binding(): Missing registerEvent()" ); return * static_cast(this)->binding_; } @@ -90,7 +90,7 @@ template prefix_ senf::ppi::detail::EventBinding & senf::ppi::EventImplementationHelper::binding() { - SENF_ASSERT( static_cast(this)->binding_ && + SENF_ASSERT( static_cast(this)->binding_, "senf::ppi::EventImplementationHelper::binding(): Missing registerEvent()" ); return * static_cast(this)->binding_; } diff --git a/senf/PPI/IOEvent.cc b/senf/PPI/IOEvent.cc index 3a38feb..afb7b73 100644 --- a/senf/PPI/IOEvent.cc +++ b/senf/PPI/IOEvent.cc @@ -59,7 +59,7 @@ prefix_ void senf::ppi::IOEvent::cb(int event) else if (event & Hup) throw HangupException(); else - SENF_ASSERT(false && "Internal failure in senf::ppi::IOEvent::cb(int)"); + SENF_ASSERT(false, "Internal failure: IOEvent::cb() called with invalid flag??"); } else { IOEventInfo info = { event }; callback(info); diff --git a/senf/PPI/Module.cci b/senf/PPI/Module.cci index b54093f..78b7be3 100644 --- a/senf/PPI/Module.cci +++ b/senf/PPI/Module.cci @@ -92,8 +92,10 @@ senf::ppi::module::Module::addRoute(std::auto_ptr route) prefix_ senf::ppi::module::Module::~Module() { - SENF_ASSERT(connectorRegistry_.empty()); - SENF_ASSERT(routes_.empty()); + SENF_ASSERT(connectorRegistry_.empty(), + "Internal failure: connectors still registered in Module destructor ??"); + SENF_ASSERT(routes_.empty(), + "internal failure: routes still registered in Module destructor ??"); moduleManager().unregisterModule(*this); } diff --git a/senf/PPI/Route.test.cc b/senf/PPI/Route.test.cc index 684c8c8..6d81ba1 100644 --- a/senf/PPI/Route.test.cc +++ b/senf/PPI/Route.test.cc @@ -209,7 +209,7 @@ namespace { } private: void request() { - SENF_ASSERT(input()); + SENF_ASSERT(input(), "TestSink called without packet"); } }; } diff --git a/senf/Packets/ArrayParser.cti b/senf/Packets/ArrayParser.cti index 012fbc2..da31433 100644 --- a/senf/Packets/ArrayParser.cti +++ b/senf/Packets/ArrayParser.cti @@ -70,7 +70,7 @@ senf::ArrayParser::operator[](difference_type i) const { // Access out of range element - SENF_ASSERT( i>=0 && i < difference_type(elements) ); + SENF_ASSERT( i>=0 && i < difference_type(elements), "Access to out-of-range array element" ); return begin()[i]; } diff --git a/senf/Packets/ListBParser.ct b/senf/Packets/ListBParser.ct index de8f2b0..03baab8 100644 --- a/senf/Packets/ListBParser.ct +++ b/senf/Packets/ListBParser.ct @@ -47,7 +47,7 @@ container_policy(parser_policy const & p) while (i!=e) { ElementParser p (i,selfp.state()); size_type sz (senf::bytes(p)); - SENF_ASSERT(sz); + SENF_ASSERT(sz, "Broken element parser: reports size of 0 bytes"); i = p.i(sz); ++ n_; } diff --git a/senf/Packets/ListNParser.ct b/senf/Packets/ListNParser.ct index 0ccd811..c45d1ec 100644 --- a/senf/Packets/ListNParser.ct +++ b/senf/Packets/ListNParser.ct @@ -47,7 +47,7 @@ senf::detail::ListNParser_Policy::setFromPosition(conta for (; d.n_; --d.n_, j += ElementParser(j,c.state()).bytes()) if (j==p) return; - SENF_ASSERT( false ); + SENF_ASSERT( false, "setFromPosition: position does not point to any list element" ); } template diff --git a/senf/Packets/ListParser.ct b/senf/Packets/ListParser.ct index 7ce53a3..901d2e0 100644 --- a/senf/Packets/ListParser.ct +++ b/senf/Packets/ListParser.ct @@ -51,7 +51,7 @@ prefix_ typename senf::ListParser::value_type senf::ListParser::back() const { - SENF_ASSERT( ! empty() ); + SENF_ASSERT( ! empty(), "back() called on empty list" ); container c(*this); typename container::iterator i (c.begin()), j; typename container::iterator const e (c.end()); @@ -67,7 +67,7 @@ prefix_ typename senf::ListParser_Container::value_type senf::ListParser_Container::back() const { - SENF_ASSERT( ! empty() ); + SENF_ASSERT( ! empty(), "back() called on empty list" ); iterator i (begin()), j; iterator const e (end()); for (j=i; i!=e; j=i, ++i) ; diff --git a/senf/Packets/ListParser.cti b/senf/Packets/ListParser.cti index 0aa24ea..20f32da 100644 --- a/senf/Packets/ListParser.cti +++ b/senf/Packets/ListParser.cti @@ -77,7 +77,7 @@ prefix_ typename senf::ListParser::value_type senf::ListParser::front() const { - SENF_ASSERT( ! empty() ); + SENF_ASSERT( ! empty(), "front() called on empty list" ); container c(*this); return *(c.begin()); } @@ -281,7 +281,7 @@ prefix_ typename senf::ListParser_Container::value_type senf::ListParser_Container::front() const { - SENF_ASSERT( ! empty() ); + SENF_ASSERT( ! empty(), "front() called on empty list" ); return *begin(); } diff --git a/senf/Packets/Packet.cci b/senf/Packets/Packet.cci index 862c04c..9773af8 100644 --- a/senf/Packets/Packet.cci +++ b/senf/Packets/Packet.cci @@ -41,7 +41,7 @@ prefix_ senf::Packet::Packet(PacketInterpreterBase::ptr packet) prefix_ senf::PacketInterpreterBase::ptr senf::Packet::ptr() const { - SENF_ASSERT(packet_); + SENF_ASSERT(packet_, "Invalid operation (dereferencing) on in-valid() Packet"); return packet_; } diff --git a/senf/Packets/PacketData.cci b/senf/Packets/PacketData.cci index 7cc1ace..747c794 100644 --- a/senf/Packets/PacketData.cci +++ b/senf/Packets/PacketData.cci @@ -38,21 +38,25 @@ prefix_ senf::detail::PacketImpl & senf::PacketData::impl() const { - SENF_ASSERT( impl_ ); + SENF_ASSERT( + impl_, + "Internal failure: PacketData (PacketInterpreter) instance not part of any Packet?"); return *impl_; } prefix_ senf::PacketData::iterator senf::PacketData::begin() const { - SENF_ASSERT(begin_ <= impl().size()); + SENF_ASSERT(begin_ <= impl().size(), + "Internal failure: PacketInterpreter range outside of data container"); return boost::next(impl().begin(),begin_); } prefix_ senf::PacketData::iterator senf::PacketData::end() const { - SENF_ASSERT(end_ <= impl().size()); + SENF_ASSERT(end_ <= impl().size(), + "Internal failure: PacketInterpreter range outside of data container"); return boost::next(impl().begin(),end_); } @@ -71,13 +75,13 @@ prefix_ bool senf::PacketData::empty() prefix_ senf::PacketData::byte senf::PacketData::operator[](size_type n) const { - SENF_ASSERT( n < size() ); + SENF_ASSERT( n < size(), "Access out of container range" ); return *( boost::next(begin(),n) ); } prefix_ senf::PacketData::byte & senf::PacketData::operator[](size_type n) { - SENF_ASSERT( n < size() ); + SENF_ASSERT( n < size(), "Access out of container range" ); return *( boost::next(begin(),n) ); } diff --git a/senf/Packets/PacketImpl.cci b/senf/Packets/PacketImpl.cci index d7a2ec3..34c3d1d 100644 --- a/senf/Packets/PacketImpl.cci +++ b/senf/Packets/PacketImpl.cci @@ -206,7 +206,7 @@ prefix_ void senf::detail::PacketImpl::dumpAnnotations(std::ostream & os) prefix_ void senf::detail::PacketImpl::release(refcount_t n) { - SENF_ASSERT(refcount_ >= n); + SENF_ASSERT(refcount_ >= n, "Internal failure: Releasing dead PacketImpl ??"); // uah ... we need to be extremely careful here. If refcount_ is n, we want to commit suicide, // however the destructor will remove all PacketInterpreters from the list and will thereby // decrement refcount -> only decrenebt refcount_ when *not* caling delete diff --git a/senf/Packets/PacketInterpreter.cci b/senf/Packets/PacketInterpreter.cci index 71bf36d..b5e84bb 100644 --- a/senf/Packets/PacketInterpreter.cci +++ b/senf/Packets/PacketInterpreter.cci @@ -164,14 +164,14 @@ prefix_ bool senf::PacketInterpreterBase::release() prefix_ void senf::PacketInterpreterBase::assignImpl(detail::PacketImpl * impl) { - SENF_ASSERT(!impl_); + SENF_ASSERT(!impl_, "Internal failure: PacketInterpreter added to two Packets"); impl_ = impl; impl_->add_ref(refcount()); } prefix_ void senf::PacketInterpreterBase::releaseImpl() { - SENF_ASSERT(impl_); + SENF_ASSERT(impl_, "Internal failure: release of lone PacketInterpreter"); refcount_t refc (refcount()); if (refc) { impl_->release(refc); diff --git a/senf/Packets/PacketRegistry.ct b/senf/Packets/PacketRegistry.ct index dad629e..6237734 100644 --- a/senf/Packets/PacketRegistry.ct +++ b/senf/Packets/PacketRegistry.ct @@ -103,9 +103,10 @@ template template prefix_ void senf::detail::PacketRegistryImpl::registerPacket(key_t key, int priority) { - bool ok (registry_.insert( - typename Entry::ptr(new EntryImpl(key,priority))).second); - SENF_ASSERT(ok && "Duplicate packet registration"); + SENF_ASSERT_EXPRESSION( + registry_.insert( + typename Entry::ptr(new EntryImpl(key,priority))).second, + "Duplicate packet registration"); } template diff --git a/senf/Packets/SafeIterator.cci b/senf/Packets/SafeIterator.cci index b703ede..1ef2af2 100644 --- a/senf/Packets/SafeIterator.cci +++ b/senf/Packets/SafeIterator.cci @@ -52,13 +52,13 @@ prefix_ senf::safe_data_iterator::safe_data_iterator(PacketParserBase const & p prefix_ senf::PacketData::iterator senf::safe_data_iterator::i() const { - SENF_ASSERT(data_); + SENF_ASSERT(data_, "Use/dereferencing of empty safe_data_iterator"); return boost::next(data_->begin(),i_); } prefix_ senf::safe_data_iterator & senf::safe_data_iterator::operator=(PacketData::iterator i) { - SENF_ASSERT(data_); + SENF_ASSERT(data_, "Use/dereferencing of empty safe_data_iterator"); i_ = std::distance(data_->begin(),i); return *this; } @@ -86,7 +86,7 @@ prefix_ bool senf::safe_data_iterator::boolean_test() prefix_ senf::PacketData & senf::safe_data_iterator::data() const { - SENF_ASSERT(data_); + SENF_ASSERT(data_, "Use/dereferencing of empty safe_data_iterator"); return *data_; } @@ -99,7 +99,7 @@ prefix_ senf::safe_data_iterator::value_type & senf::safe_data_iterator::derefer prefix_ bool senf::safe_data_iterator::equal(safe_data_iterator const & other) const { - SENF_ASSERT(data_ == other.data_); + SENF_ASSERT(data_ == other.data_, "Comparing iterators of two different containers is invalid"); return i_ == other.i_; } @@ -107,7 +107,7 @@ prefix_ senf::safe_data_iterator::difference_type senf::safe_data_iterator::distance_to(safe_data_iterator const & other) const { - SENF_ASSERT(data_ == other.data_); + SENF_ASSERT(data_ == other.data_, "Comparing iterators of two different containers is invalid"); return other.i_ - i_; } @@ -118,13 +118,13 @@ prefix_ void senf::safe_data_iterator::increment() prefix_ void senf::safe_data_iterator::decrement() { - SENF_ASSERT(i_>0); + SENF_ASSERT(i_>0, "Decrementing iterator before beginning of container" ); --i_; } prefix_ void senf::safe_data_iterator::advance(difference_type n) { - SENF_ASSERT( -n < difference_type(i_) ); + SENF_ASSERT( -n < difference_type(i_), "Moving iterator to before beginning of container" ); i_ += n; } diff --git a/senf/Packets/SafeIterator.cti b/senf/Packets/SafeIterator.cti index 0f551aa..7615630 100644 --- a/senf/Packets/SafeIterator.cti +++ b/senf/Packets/SafeIterator.cti @@ -55,7 +55,7 @@ template prefix_ Parser & senf::SafePacketParserWrapper::operator*() const { - SENF_ASSERT( i_ ); + SENF_ASSERT( i_, "Dereferencing empty SafePacketParserWrapper" ); parser_->i_ = PacketParserBase::data_iterator(i_); return *parser_; } @@ -64,7 +64,7 @@ template prefix_ Parser * senf::SafePacketParserWrapper::operator->() const { - SENF_ASSERT( i_ ); + SENF_ASSERT( i_, "Dereferencing empty SafePacketParserWrapper" ); parser_->i_ = PacketParserBase::data_iterator(i_); return & (*parser_); } diff --git a/senf/Packets/VariantParser.cti b/senf/Packets/VariantParser.cti index 5a582e6..6043bd5 100644 --- a/senf/Packets/VariantParser.cti +++ b/senf/Packets/VariantParser.cti @@ -79,7 +79,7 @@ prefix_ typename boost::mpl::at< senf::VariantParser::get() const { - SENF_ASSERT( variant() == N ); + SENF_ASSERT( variant() == N, "Access to non-active variant member" ); return typename boost::mpl::at >::type( AuxPolicy::adjust(i(), state()), state() ); } diff --git a/senf/Scheduler/ClockService.cc b/senf/Scheduler/ClockService.cc index 5a1fb6a..36ffdd4 100644 --- a/senf/Scheduler/ClockService.cc +++ b/senf/Scheduler/ClockService.cc @@ -57,7 +57,8 @@ senf::parseClockServiceInterval(console::ParseCommandInfo::TokensRange const & t scale = *match.first; unit = *boost::next(match.first); } else { - SENF_ASSERT( match.length() == 1); + SENF_ASSERT( match.length() == 1, + "Internal failure: RegEx match returns weird number of matches" ); unit = *match.first; } switch (scale) { diff --git a/senf/Scheduler/SignalEvent.cc b/senf/Scheduler/SignalEvent.cc index 140344b..989bcc7 100644 --- a/senf/Scheduler/SignalEvent.cc +++ b/senf/Scheduler/SignalEvent.cc @@ -110,10 +110,11 @@ prefix_ void senf::scheduler::detail::SignalDispatcher::signal(int events) i->setRunnable(); } -prefix_ void senf::scheduler::detail::SignalDispatcher::sigHandler(int signal, ::siginfo_t * siginfo, - void *) +prefix_ void senf::scheduler::detail::SignalDispatcher::sigHandler(int signal, + ::siginfo_t * siginfo, + void *) { - SENF_ASSERT( alive() ); + SENF_ASSERT( alive(), "Internal failure: Destroyed signal handler called" ); // The manpage says, si_signo is unused in linux so we set it here siginfo->si_signo = signal; // We can't do much on error anyway so we ignore errors here diff --git a/senf/Socket/FileHandle.cci b/senf/Socket/FileHandle.cci index 9de38d1..83dd47e 100644 --- a/senf/Socket/FileHandle.cci +++ b/senf/Socket/FileHandle.cci @@ -112,14 +112,14 @@ prefix_ bool senf::FileBody::waitOOBReadable(senf::ClockService::clock_type time prefix_ senf::FileBody & senf::FileHandle::body() { - SENF_ASSERT(body_); + SENF_ASSERT(body_, "dereferencing in-valid() FileHandle"); return *body_; } prefix_ senf::FileBody const & senf::FileHandle::body() const { - SENF_ASSERT(body_); + SENF_ASSERT(body_, "dereferencing in-valid() FileHandle"); return *body_; } diff --git a/senf/Socket/ProtocolClientSocketHandle.cti b/senf/Socket/ProtocolClientSocketHandle.cti index dd1dfdc..dc6b543 100644 --- a/senf/Socket/ProtocolClientSocketHandle.cti +++ b/senf/Socket/ProtocolClientSocketHandle.cti @@ -48,7 +48,8 @@ prefix_ senf::ProtocolClientSocketHandle::ProtocolClientSocketHa this->protocol().init_client(); } -#define BOOST_PP_ITERATION_PARAMS_1 (4, (1, 9, SENF_ABSOLUTE_INCLUDE_PATH(Socket/ProtocolClientSocketHandle.mpp), 2)) +#define BOOST_PP_ITERATION_PARAMS_1 \ + (4, (1, 9, SENF_ABSOLUTE_INCLUDE_PATH(Socket/ProtocolClientSocketHandle.mpp), 2)) #include BOOST_PP_ITERATE() template @@ -61,7 +62,8 @@ template prefix_ SocketProtocol & senf::ProtocolClientSocketHandle::protocol() { - SENF_ASSERT( dynamic_cast(&this->body().protocol()) ); + SENF_ASSERT( dynamic_cast(&this->body().protocol()), + "Internal failure: Incompatible protocol class fount it's way into this handle"); // Need dynamic_cast here, since senf::SocketProtocol is a // virtual base return dynamic_cast(this->body().protocol()); diff --git a/senf/Socket/ProtocolServerSocketHandle.cti b/senf/Socket/ProtocolServerSocketHandle.cti index 482a3f2..756d343 100644 --- a/senf/Socket/ProtocolServerSocketHandle.cti +++ b/senf/Socket/ProtocolServerSocketHandle.cti @@ -46,14 +46,16 @@ prefix_ senf::ProtocolServerSocketHandle::ProtocolServerSocketHa std::auto_ptr(new ProtocolSocketBody(true))) {} -#define BOOST_PP_ITERATION_PARAMS_1 (4, (1, 9, SENF_ABSOLUTE_INCLUDE_PATH(Socket/ProtocolServerSocketHandle.mpp), 2)) +#define BOOST_PP_ITERATION_PARAMS_1 \ + (4, (1, 9, SENF_ABSOLUTE_INCLUDE_PATH(Socket/ProtocolServerSocketHandle.mpp), 2)) #include BOOST_PP_ITERATE() template prefix_ SocketProtocol & senf::ProtocolServerSocketHandle::protocol() { - SENF_ASSERT( dynamic_cast(&this->body().protocol()) ); + SENF_ASSERT( dynamic_cast(&this->body().protocol()), + "Internal failure: Incompatible protocol class fount it's way into this handle"); // Need dynamic_cast here, since senf::SocketProtocol is a // virtual base return dynamic_cast(this->body().protocol()); diff --git a/senf/Socket/Protocols/INet/INetAddressing.cc b/senf/Socket/Protocols/INet/INetAddressing.cc index aead331..21d0d81 100644 --- a/senf/Socket/Protocols/INet/INetAddressing.cc +++ b/senf/Socket/Protocols/INet/INetAddressing.cc @@ -133,11 +133,8 @@ prefix_ std::string senf::INet6SocketAddress::iface() if (sockaddr_.sin6_scope_id == 0) return ""; char buffer[IFNAMSIZ]; -#ifdef SENF_DEBUG - SENF_ASSERT( if_indextoname(sockaddr_.sin6_scope_id,buffer) ); -#else - if_indextoname(sockaddr_.sin6_scope_id,buffer); -#endif + SENF_ASSERT_EXPRESSION(if_indextoname(sockaddr_.sin6_scope_id,buffer), + "Internal failure: Invalid interface index (how does it get here?)"); return std::string(buffer); } diff --git a/senf/Socket/SocketHandle.cti b/senf/Socket/SocketHandle.cti index ff93a02..63db515 100644 --- a/senf/Socket/SocketHandle.cti +++ b/senf/Socket/SocketHandle.cti @@ -44,7 +44,7 @@ prefix_ senf::SocketHandle::SocketHandle() template template prefix_ senf::SocketHandle::SocketHandle(SocketHandle other, - typename IsCompatible::type *) + typename IsCompatible::type *) : FileHandle(other) {} @@ -67,14 +67,16 @@ template prefix_ senf::SocketHandle::SocketHandle(FileHandle other, bool isChecked) : FileHandle(other) { - SENF_ASSERT( isChecked ); - SENF_ASSERT( ! valid() || dynamic_cast(&FileHandle::body()) ); + SENF_ASSERT( isChecked, "Inrernal failure: Wrong overload called !!" ); + SENF_ASSERT( ! valid() || dynamic_cast(&FileHandle::body()), + "Internal failure: Replacing or re-assigning non-empty incompatible handle"); } template prefix_ senf::SocketBody & senf::SocketHandle::body() { - SENF_ASSERT( dynamic_cast(&FileHandle::body()) ); + SENF_ASSERT( dynamic_cast(&FileHandle::body()), + "Internal failure: Invalid body found it's way into SocketHandle"); return static_cast(FileHandle::body()); } @@ -82,7 +84,8 @@ template prefix_ senf::SocketBody const & senf::SocketHandle::body() const { - SENF_ASSERT( dynamic_cast(&FileHandle::body()) ); + SENF_ASSERT( dynamic_cast(&FileHandle::body()), + "Internal failure: Invalid body found it's way into SocketHandle"); return static_cast(FileHandle::body()); } @@ -125,7 +128,8 @@ prefix_ Target senf::static_socket_cast(Source handle) boost::is_convertible::value && ( boost::is_convertible::value || boost::is_convertible::value ) )); - SENF_ASSERT( check_socket_cast(handle) ); + SENF_ASSERT( check_socket_cast(handle), + "Invalid static_socket_cast" ); return Target::cast_static(handle); } diff --git a/senf/Socket/SocketProtocol.cci b/senf/Socket/SocketProtocol.cci index 51fd4e2..da7889c 100644 --- a/senf/Socket/SocketProtocol.cci +++ b/senf/Socket/SocketProtocol.cci @@ -50,7 +50,7 @@ prefix_ int senf::SocketProtocol::fd() prefix_ void senf::SocketProtocol::fd(int fd) const { - SENF_ASSERT(! body().valid()); + SENF_ASSERT(! body().valid(), "Replacing filedescriptor of open FileHandle"); body().fd(fd); } diff --git a/senf/Utils/Console/Executor.cc b/senf/Utils/Console/Executor.cc index b9a2546..0ab942b 100644 --- a/senf/Utils/Console/Executor.cc +++ b/senf/Utils/Console/Executor.cc @@ -58,7 +58,7 @@ namespace { prefix_ senf::console::DirectoryNode & senf::console::Executor::cwd() const { - SENF_ASSERT( ! cwd_.empty() ); + SENF_ASSERT( ! cwd_.empty(), "Internal error: CWD history empty ?" ); while (cwd_.size()>1 && (cwd_.back().expired() || ! cwd_.back().lock()->active())) cwd_.pop_back(); return * cwd_.back().lock(); diff --git a/senf/Utils/Console/Node.cti b/senf/Utils/Console/Node.cti index a15d63e..ee7db3d 100644 --- a/senf/Utils/Console/Node.cti +++ b/senf/Utils/Console/Node.cti @@ -37,7 +37,7 @@ template prefix_ NodeType & senf::console::DirectoryNode::add(std::string const & name, boost::shared_ptr node) { - SENF_ASSERT( ! node->parent() ); + SENF_ASSERT( ! node->parent(), "Node can only be added to tree once" ); node->name(name); add(node); return *node; diff --git a/senf/Utils/Console/OverloadedCommand.cci b/senf/Utils/Console/OverloadedCommand.cci index 59de51c..5965021 100644 --- a/senf/Utils/Console/OverloadedCommand.cci +++ b/senf/Utils/Console/OverloadedCommand.cci @@ -119,7 +119,7 @@ prefix_ std::string senf::console::CommandOverload::doc() prefix_ senf::console::OverloadedCommandNode & senf::console::CommandOverload::node() const { - SENF_ASSERT( node_ ); + SENF_ASSERT( node_, "Overload not added to any node yet" ); return *node_; } diff --git a/senf/Utils/Console/Parse.cc b/senf/Utils/Console/Parse.cc index a2ace99..afae4fe 100644 --- a/senf/Utils/Console/Parse.cc +++ b/senf/Utils/Console/Parse.cc @@ -362,7 +362,7 @@ prefix_ Iterator senf::console::CommandParser::parseLoop(Iterator npb, Iterator throwParserError(ex); } // Otherwise the error handling in the parser is broken - SENF_ASSERT( result.hit ); + SENF_ASSERT( result.hit, "Internal parser failure (error handling broken?)" ); if (! info.empty()) try { cb(info); diff --git a/senf/Utils/Console/Parse.cci b/senf/Utils/Console/Parse.cci index 6818aee..3ac5ed4 100644 --- a/senf/Utils/Console/Parse.cci +++ b/senf/Utils/Console/Parse.cci @@ -329,7 +329,7 @@ senf::console::CheckedArgumentIteratorWrapper::operator++(int) prefix_ senf::console::CommandParser::Impl & senf::console::CommandParser::impl() { - SENF_ASSERT(impl_); + SENF_ASSERT(impl_, "Ineral error: PIMPL pointer NULL ??"); return *impl_; } diff --git a/senf/Utils/Console/ScopedDirectory.cti b/senf/Utils/Console/ScopedDirectory.cti index f5441d0..c4e287f 100644 --- a/senf/Utils/Console/ScopedDirectory.cti +++ b/senf/Utils/Console/ScopedDirectory.cti @@ -37,7 +37,7 @@ template prefix_ senf::console::ScopedDirectory::ScopedDirectory(Owner * owner) : owner_ (owner) { - SENF_ASSERT(owner_); + SENF_ASSERT(owner_, "ScopedDirectory owner is mandatory"); } template diff --git a/senf/Utils/Console/Traits.cc b/senf/Utils/Console/Traits.cc index 91c4f45..923e8ce 100644 --- a/senf/Utils/Console/Traits.cc +++ b/senf/Utils/Console/Traits.cc @@ -59,7 +59,7 @@ prefix_ long senf::console::detail::parseEnum(EnumTable const & table, prefix_ std::string senf::console::detail::formatEnum(EnumTable const & table, long value) { EnumTable::right_map::const_iterator i (table.right.find(value)); - SENF_ASSERT( i != table.right.end() ); + SENF_ASSERT( i != table.right.end(), "Invalid enum value" ); return i->second; } diff --git a/senf/Utils/Console/UDPServer.cc b/senf/Utils/Console/UDPServer.cc index d2db770..20b6cf5 100644 --- a/senf/Utils/Console/UDPServer.cc +++ b/senf/Utils/Console/UDPServer.cc @@ -70,7 +70,8 @@ prefix_ senf::console::UDPServer & senf::console::UDPServer::replies(bool enable prefix_ senf::console::UDPServer & senf::console::UDPServer::replies(senf::INet4SocketAddress const & address) { - SENF_ASSERT( handle_.local().family() == senf::INet4SocketAddress::addressFamily ); + SENF_ASSERT( handle_.local().family() == senf::INet4SocketAddress::addressFamily, + "Internal failure: INet6 address on INet4 socket ??" ); target_ = address; return *this; } @@ -78,7 +79,8 @@ senf::console::UDPServer::replies(senf::INet4SocketAddress const & address) prefix_ senf::console::UDPServer & senf::console::UDPServer::replies(senf::INet6SocketAddress const & address) { - SENF_ASSERT( handle_.local().family() == senf::INet6SocketAddress::addressFamily ); + SENF_ASSERT( handle_.local().family() == senf::INet6SocketAddress::addressFamily, + "Internal failure: INet4 address on INet6 socket ??" ); target_ = address; return *this; } diff --git a/senf/Utils/Termlib/Telnet.cc b/senf/Utils/Termlib/Telnet.cc index 6e09183..9efb101 100644 --- a/senf/Utils/Termlib/Telnet.cc +++ b/senf/Utils/Termlib/Telnet.cc @@ -57,7 +57,10 @@ prefix_ senf::term::BaseTelnetProtocol::BaseTelnetProtocol() requestTimeout_ (ClockService::milliseconds(DEFAULT_REQUEST_TIMEOUT_MS)), timeout_ ("senf::term::BaseTelnetProtocol::timeout", 0) { - SENF_ASSERT( false ); + SENF_ASSERT( false, + "Missing BaseTelnetProtocol constructor call in derived class " + "(BaseTelnetProtocol is a VIRTUAL base and MUST be constructed explicitly " + "in the most derived class." ); } prefix_ void senf::term::BaseTelnetProtocol::write(std::string const & s) diff --git a/senf/Utils/TypeIdValue.cci b/senf/Utils/TypeIdValue.cci index e11e44b..8ce9622 100644 --- a/senf/Utils/TypeIdValue.cci +++ b/senf/Utils/TypeIdValue.cci @@ -67,7 +67,8 @@ prefix_ std::string senf::TypeIdValue::prettyName() prefix_ std::type_info const & senf::TypeIdValue::id() const { - SENF_ASSERT(p_); + SENF_ASSERT( + p_, "Internal failure: Empty TypeIdValue should have p_ point to typeid(void) not 0"); return *p_; } diff --git a/senf/Utils/intrusive_refcount.cci b/senf/Utils/intrusive_refcount.cci index 99b23bc..69cb1f6 100644 --- a/senf/Utils/intrusive_refcount.cci +++ b/senf/Utils/intrusive_refcount.cci @@ -52,7 +52,7 @@ prefix_ void senf::intrusive_refcount_base::add_ref() prefix_ bool senf::intrusive_refcount_base::release() { - SENF_ASSERT(refcount_>0 && + SENF_ASSERT(refcount_>0, "senf::intrusive_refcount_base: Internal inconsistency: " "Calling release on dead object."); return --refcount_ == 0; diff --git a/senf/Utils/pool_alloc_mixin.cti b/senf/Utils/pool_alloc_mixin.cti index bb002d0..5e0550a 100644 --- a/senf/Utils/pool_alloc_mixin.cti +++ b/senf/Utils/pool_alloc_mixin.cti @@ -36,7 +36,7 @@ prefix_ void * senf::pool_alloc_mixin::operator new(size_t size) { // When deriving from Self you may not change the class's size without // inheriting from pool_alloc_mixin again. See pool_alloc_mixin documentation. - SENF_ASSERT( size <= sizeof(Self) && + SENF_ASSERT( size <= sizeof(Self), "senf::pool_alloc_mixin::operator new(): " "Bad object size. Missing pool_alloc_mixin base in derived class?" ); #ifdef SENF_DEBUG diff --git a/senf/Utils/senfassert.hh b/senf/Utils/senfassert.hh index d6f92e7..2a53803 100644 --- a/senf/Utils/senfassert.hh +++ b/senf/Utils/senfassert.hh @@ -33,12 +33,14 @@ #ifndef SENF_DEBUG -# define SENF_ASSERT(x) +# define SENF_ASSERT(x, comment) +# define SENF_ASSERT_EXPRESSION(expression, comment) expression #else # include -# define SENF_ASSERT(x) assert(x) +# define SENF_ASSERT(x, comment) assert((x) && comment) +# define SENF_ASSERT_EXPRESSION(expression, comment) assert((expression) && comment) #endif