Skip to content

Commit

Permalink
build: stop defining _DEBUG, rely only on NDEBUG instead
Browse files Browse the repository at this point in the history
NDEBUG is more standard on non-Microsoft platforms, and _DEBUG is
technically a reserved identifier.

Change-Id: I24c951032d50b37853dc1a38ac844b0be5ac8937
  • Loading branch information
Pesa committed Jan 15, 2024
1 parent 8a93284 commit 91c15c8
Show file tree
Hide file tree
Showing 16 changed files with 59 additions and 80 deletions.
2 changes: 1 addition & 1 deletion .waf-tools/default-compiler-flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def getGeneralFlags(self, conf):

def getDebugFlags(self, conf):
"""Get dict of CXXFLAGS, LINKFLAGS, and DEFINES that are needed only in debug mode"""
return {'CXXFLAGS': [], 'LINKFLAGS': [], 'DEFINES': ['_DEBUG']}
return {'CXXFLAGS': [], 'LINKFLAGS': [], 'DEFINES': []}

def getOptimizedFlags(self, conf):
"""Get dict of CXXFLAGS, LINKFLAGS, and DEFINES that are needed only in optimized mode"""
Expand Down
5 changes: 2 additions & 3 deletions daemon/face/datagram-transport.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2023, Regents of the University of California,
* Copyright (c) 2014-2024, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand Down Expand Up @@ -99,14 +99,13 @@ class DatagramTransport : public Transport

private:
std::array<uint8_t, ndn::MAX_NDN_PACKET_SIZE> m_receiveBuffer;
bool m_hasRecentlyReceived;
bool m_hasRecentlyReceived = false;
};


template<class T, class U>
DatagramTransport<T, U>::DatagramTransport(typename DatagramTransport::protocol::socket&& socket)
: m_socket(std::move(socket))
, m_hasRecentlyReceived(false)
{
boost::asio::socket_base::send_buffer_size sendBufferSizeOption;
boost::system::error_code error;
Expand Down
8 changes: 2 additions & 6 deletions daemon/face/ethernet-channel.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2023, Regents of the University of California,
* Copyright (c) 2014-2024, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand Down Expand Up @@ -40,13 +40,9 @@ NFD_LOG_INIT(EthernetChannel);
EthernetChannel::EthernetChannel(shared_ptr<const ndn::net::NetworkInterface> localEndpoint,
time::nanoseconds idleTimeout)
: m_localEndpoint(std::move(localEndpoint))
, m_isListening(false)
, m_socket(getGlobalIoService())
, m_pcap(m_localEndpoint->getName())
, m_idleFaceTimeout(idleTimeout)
#ifdef _DEBUG
, m_nDropped(0)
#endif
{
setUri(FaceUri::fromDev(m_localEndpoint->getName()));
NFD_LOG_CHAN_INFO("Creating channel");
Expand Down Expand Up @@ -137,7 +133,7 @@ EthernetChannel::handleRead(const boost::system::error_code& error,
}
}

#ifdef _DEBUG
#ifndef NDEBUG
size_t nDropped = m_pcap.getNDropped();
if (nDropped - m_nDropped > 0)
NFD_LOG_CHAN_DEBUG("Detected " << nDropped - m_nDropped << " dropped frame(s)");
Expand Down
10 changes: 5 additions & 5 deletions daemon/face/ethernet-channel.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2023, Regents of the University of California,
* Copyright (c) 2014-2024, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand Down Expand Up @@ -121,15 +121,15 @@ class EthernetChannel final : public Channel

private:
shared_ptr<const ndn::net::NetworkInterface> m_localEndpoint;
bool m_isListening;
bool m_isListening = false;
boost::asio::posix::stream_descriptor m_socket;
PcapHelper m_pcap;
std::map<ethernet::Address, shared_ptr<Face>> m_channelFaces;
const time::nanoseconds m_idleFaceTimeout; ///< Timeout for automatic closure of idle on-demand faces

#ifdef _DEBUG
/// number of frames dropped by the kernel, as reported by libpcap
size_t m_nDropped;
#ifndef NDEBUG
/// Number of frames dropped by the kernel, as reported by libpcap
size_t m_nDropped = 0;
#endif
};

Expand Down
4 changes: 2 additions & 2 deletions daemon/face/ethernet-protocol.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2022, Regents of the University of California,
* Copyright (c) 2014-2024, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand Down Expand Up @@ -43,7 +43,7 @@ checkFrameHeader(span<const uint8_t> packet, const Address& localAddr, const Add
if (ethertype != ETHERTYPE_NDN)
return {nullptr, "Received frame with wrong ethertype: " + to_string(ethertype)};

#ifdef _DEBUG
#ifndef NDEBUG
Address shost(eh->ether_shost);
if (shost == localAddr)
return {nullptr, "Received frame sent by this host"};
Expand Down
8 changes: 2 additions & 6 deletions daemon/face/ethernet-transport.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2023, Regents of the University of California,
* Copyright (c) 2014-2024, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand Down Expand Up @@ -43,10 +43,6 @@ EthernetTransport::EthernetTransport(const ndn::net::NetworkInterface& localEndp
, m_srcAddress(localEndpoint.getEthernetAddress())
, m_destAddress(remoteEndpoint)
, m_interfaceName(localEndpoint.getName())
, m_hasRecentlyReceived(false)
#ifdef _DEBUG
, m_nDropped(0)
#endif
{
try {
m_pcap.activate(DLT_EN10MB);
Expand Down Expand Up @@ -183,7 +179,7 @@ EthernetTransport::handleRead(const boost::system::error_code& error)
}
}

#ifdef _DEBUG
#ifndef NDEBUG
size_t nDropped = m_pcap.getNDropped();
if (nDropped - m_nDropped > 0)
NFD_LOG_FACE_DEBUG("Detected " << nDropped - m_nDropped << " dropped frame(s)");
Expand Down
10 changes: 5 additions & 5 deletions daemon/face/ethernet-transport.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2023, Regents of the University of California,
* Copyright (c) 2014-2024, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand Down Expand Up @@ -106,10 +106,10 @@ class EthernetTransport : public Transport
private:
signal::ScopedConnection m_netifStateChangedConn;
signal::ScopedConnection m_netifMtuChangedConn;
bool m_hasRecentlyReceived;
#ifdef _DEBUG
/// number of frames dropped by the kernel, as reported by libpcap
size_t m_nDropped;
bool m_hasRecentlyReceived = false;
#ifndef NDEBUG
/// Number of frames dropped by the kernel, as reported by libpcap
size_t m_nDropped = 0;
#endif
};

Expand Down
5 changes: 1 addition & 4 deletions daemon/face/generic-link-service.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2023, Regents of the University of California,
* Copyright (c) 2014-2024, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand Down Expand Up @@ -44,9 +44,6 @@ GenericLinkService::GenericLinkService(const GenericLinkService::Options& option
, m_fragmenter(m_options.fragmenterOptions, this)
, m_reassembler(m_options.reassemblerOptions, this)
, m_reliability(m_options.reliabilityOptions, this)
, m_lastSeqNo(-2)
, m_nextMarkTime(time::steady_clock::time_point::max())
, m_nMarkedSinceInMarkingState(0)
{
m_reassembler.beforeTimeout.connect([this] (auto&&...) { ++nReassemblyTimeouts; });
m_reliability.onDroppedInterest.connect([this] (const auto& i) { notifyDroppedInterest(i); });
Expand Down
10 changes: 5 additions & 5 deletions daemon/face/generic-link-service.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2022, Regents of the University of California,
* Copyright (c) 2014-2024, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand Down Expand Up @@ -308,13 +308,13 @@ class GenericLinkService NFD_FINAL_UNLESS_WITH_TESTS : public LinkService
LpFragmenter m_fragmenter;
LpReassembler m_reassembler;
LpReliability m_reliability;
lp::Sequence m_lastSeqNo;
lp::Sequence m_lastSeqNo = static_cast<lp::Sequence>(-2);

NFD_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
/// Time to mark next packet due to send queue congestion
time::steady_clock::time_point m_nextMarkTime;
/// number of marked packets in the current incident of congestion
size_t m_nMarkedSinceInMarkingState;
time::steady_clock::time_point m_nextMarkTime = time::steady_clock::time_point::max();
/// Number of marked packets in the current incident of congestion
size_t m_nMarkedSinceInMarkingState = 0;

friend LpReliability;
};
Expand Down
17 changes: 1 addition & 16 deletions daemon/face/lp-reliability.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2023, Regents of the University of California,
* Copyright (c) 2014-2024, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand Down Expand Up @@ -400,21 +400,6 @@ LpReliability::deleteUnackedFrag(UnackedFrags::iterator fragIt)
}
}

LpReliability::UnackedFrag::UnackedFrag(lp::Packet pkt)
: pkt(std::move(pkt))
, sendTime(time::steady_clock::now())
, retxCount(0)
, nGreaterSeqAcks(0)
{
}

LpReliability::NetPkt::NetPkt(lp::Packet&& pkt, bool isInterest)
: pkt(std::move(pkt))
, isInterest(isInterest)
, didRetx(false)
{
}

std::ostream&
operator<<(std::ostream& os, const FaceLogHelper<LpReliability>& flh)
{
Expand Down
23 changes: 15 additions & 8 deletions daemon/face/lp-reliability.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2022, Regents of the University of California,
* Copyright (c) 2014-2024, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand Down Expand Up @@ -174,14 +174,17 @@ class LpReliability : noncopyable
{
public:
explicit
UnackedFrag(lp::Packet pkt);
UnackedFrag(lp::Packet p)
: pkt(std::move(p))
{
}

public:
lp::Packet pkt;
scheduler::ScopedEventId rtoTimer;
time::steady_clock::time_point sendTime;
size_t retxCount;
size_t nGreaterSeqAcks; //!< number of Acks received for sequences greater than this fragment
time::steady_clock::time_point sendTime = time::steady_clock::now();
size_t retxCount = 0;
size_t nGreaterSeqAcks = 0; ///< Number of Acks received for sequences greater than this fragment
shared_ptr<NetPkt> netPkt;
};

Expand All @@ -191,17 +194,21 @@ class LpReliability : noncopyable
class NetPkt
{
public:
NetPkt(lp::Packet&& pkt, bool isInterest);
NetPkt(lp::Packet&& p, bool isInterest)
: pkt(std::move(p))
, isInterest(isInterest)
{
}

public:
std::vector<UnackedFrags::iterator> unackedFrags;
lp::Packet pkt;
bool isInterest;
bool didRetx;
bool didRetx = false;
};

Options m_options;
GenericLinkService* m_linkService;
GenericLinkService* m_linkService = nullptr;
UnackedFrags m_unackedFrags;
// An iterator that points to the first unacknowledged fragment in the current window. The window
// can wrap around so that the beginning of the window is at a TxSequence greater than other
Expand Down
8 changes: 3 additions & 5 deletions daemon/face/stream-transport.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2023, Regents of the University of California,
* Copyright (c) 2014-2024, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand Down Expand Up @@ -105,17 +105,15 @@ class StreamTransport : public Transport

private:
uint8_t m_receiveBuffer[ndn::MAX_NDN_PACKET_SIZE];
size_t m_receiveBufferSize;
size_t m_receiveBufferSize = 0;
std::queue<Block> m_sendQueue;
size_t m_sendQueueBytes;
size_t m_sendQueueBytes = 0;
};


template<class T>
StreamTransport<T>::StreamTransport(typename StreamTransport::protocol::socket&& socket)
: m_socket(std::move(socket))
, m_receiveBufferSize(0)
, m_sendQueueBytes(0)
{
// No queue capacity is set because there is no theoretical limit to the size of m_sendQueue.
// Therefore, protecting against send queue overflows is less critical than in other transport
Expand Down
17 changes: 9 additions & 8 deletions tests/core/ndebug.t.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2022, Regents of the University of California,
* Copyright (c) 2014-2024, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand Down Expand Up @@ -31,24 +31,25 @@ namespace nfd::tests {

BOOST_AUTO_TEST_SUITE(TestNdebug)

BOOST_AUTO_TEST_CASE(AssertFalse)
BOOST_AUTO_TEST_CASE(Assert)
{
#ifndef _DEBUG
BOOST_TEST(BOOST_IS_DEFINED(BOOST_ASSERT_IS_VOID) == BOOST_IS_DEFINED(NDEBUG));

#ifdef NDEBUG
// in release builds, assertion shouldn't execute
BOOST_ASSERT(false);
BOOST_VERIFY(false);
#endif
// Trivial check to avoid "test case did not check any assertions" message from Boost.Test
BOOST_CHECK(true);
}

BOOST_AUTO_TEST_CASE(SideEffect)
{
int a = 1;
BOOST_ASSERT((a = 2) > 0);
#ifdef _DEBUG
BOOST_CHECK_EQUAL(a, 2);
#ifdef NDEBUG
BOOST_TEST(a == 1);
#else
BOOST_CHECK_EQUAL(a, 1);
BOOST_TEST(a == 2);
#endif
}

Expand Down
4 changes: 2 additions & 2 deletions tests/other/cs-benchmark.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2022, Regents of the University of California,
* Copyright (c) 2014-2024, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand Down Expand Up @@ -39,7 +39,7 @@ class CsBenchmarkFixture
protected:
CsBenchmarkFixture()
{
#ifdef _DEBUG
#ifndef NDEBUG
std::cerr << "Benchmark compiled in debug mode is unreliable, please compile in release mode.\n";
#endif

Expand Down
4 changes: 2 additions & 2 deletions tests/other/face-benchmark.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2023, Regents of the University of California,
* Copyright (c) 2014-2024, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand Down Expand Up @@ -177,7 +177,7 @@ class FaceBenchmark
int
main(int argc, char** argv)
{
#ifdef _DEBUG
#ifndef NDEBUG
std::cerr << "Benchmark compiled in debug mode is unreliable, please compile in release mode.\n";
#endif

Expand Down
Loading

0 comments on commit 91c15c8

Please sign in to comment.