Added -Wzero-as-null-pointer-constant, replaced NULL --> UAVCAN_NULLPTR. All changes are automatic, no manual edits to the library code.

This commit is contained in:
Pavel Kirienko
2016-07-29 15:39:24 +03:00
parent b6fa34fed5
commit 38a241a90a
69 changed files with 306 additions and 274 deletions
+12
View File
@@ -38,6 +38,18 @@
# endif
#endif
/**
* The library uses UAVCAN_NULLPTR instead of UAVCAN_NULLPTR and nullptr in order to allow the use of
* -Wzero-as-null-pointer-constant.
*/
#ifndef UAVCAN_NULLPTR
# if UAVCAN_CPP_VERSION >= UAVCAN_CPP11
# define UAVCAN_NULLPTR nullptr
# else
# define UAVCAN_NULLPTR NULL
# endif
#endif
/**
* By default, libuavcan enables all features if it detects that it is being built for a general-purpose
* target like Linux. Value of this macro influences other configuration options located below in this file.
+2 -2
View File
@@ -46,7 +46,7 @@ struct UAVCAN_EXPORT CanFrame
id(can_id),
dlc((data_len > MaxDataLen) ? MaxDataLen : data_len)
{
UAVCAN_ASSERT(can_data != NULL);
UAVCAN_ASSERT(can_data != UAVCAN_NULLPTR);
UAVCAN_ASSERT(data_len == dlc);
(void)copy(can_data, can_data + dlc, this->data);
}
@@ -232,7 +232,7 @@ public:
* The pending TX argument contains an array of pointers to CAN frames that the library wants to transmit
* next, per interface. This is intended to allow the driver to properly prioritize transmissions; many
* drivers will not need to use it. If a write flag for the given interface is set to one in the select mask
* structure, then the corresponding pointer is guaranteed to be valid (not NULL).
* structure, then the corresponding pointer is guaranteed to be valid (not UAVCAN_NULLPTR).
*
* @param [in,out] inout_masks Masks indicating which interfaces are needed/available for IO.
* @param [in] pending_tx Array of frames, per interface, that are likely to be transmitted next.
+4 -4
View File
@@ -153,15 +153,15 @@ PoolAllocator<PoolSize, BlockSize, RaiiSynchronizer>::PoolAllocator() :
// coverity[dead_error_line : FALSE]
free_list_[i].next = free_list_ + i + 1;
}
free_list_[NumBlocks - 1].next = NULL;
free_list_[NumBlocks - 1].next = UAVCAN_NULLPTR;
}
template <std::size_t PoolSize, uint8_t BlockSize, typename RaiiSynchronizer>
void* PoolAllocator<PoolSize, BlockSize, RaiiSynchronizer>::allocate(std::size_t size)
{
if (free_list_ == NULL || size > BlockSize)
if (free_list_ == UAVCAN_NULLPTR || size > BlockSize)
{
return NULL;
return UAVCAN_NULLPTR;
}
RaiiSynchronizer lock;
@@ -184,7 +184,7 @@ void* PoolAllocator<PoolSize, BlockSize, RaiiSynchronizer>::allocate(std::size_t
template <std::size_t PoolSize, uint8_t BlockSize, typename RaiiSynchronizer>
void PoolAllocator<PoolSize, BlockSize, RaiiSynchronizer>::deallocate(const void* ptr)
{
if (ptr == NULL)
if (ptr == UAVCAN_NULLPTR)
{
return;
}
@@ -75,7 +75,7 @@ public:
static_cast<uint32_t>(NumericTraits<uint16_t>::max())))),
num_reserved_blocks_(0),
num_allocated_blocks_(0),
reserve_(NULL)
reserve_(UAVCAN_NULLPTR)
{ }
/**
@@ -101,7 +101,7 @@ public:
{
if (size > BlockSize)
{
return NULL;
return UAVCAN_NULLPTR;
}
{
@@ -110,7 +110,7 @@ public:
Node* const p = reserve_;
if (UAVCAN_LIKELY(p != NULL))
if (UAVCAN_LIKELY(p != UAVCAN_NULLPTR))
{
reserve_ = reserve_->next;
num_allocated_blocks_++;
@@ -119,13 +119,13 @@ public:
if (num_reserved_blocks_ >= capacity_hard_limit_) // Hard limit reached, no further allocations
{
return NULL;
return UAVCAN_NULLPTR;
}
}
// Unlikely branch
void* const m = std::malloc(sizeof(Node));
if (m != NULL)
if (m != UAVCAN_NULLPTR)
{
RaiiSynchronizer lock;
(void)lock;
@@ -142,7 +142,7 @@ public:
*/
virtual void deallocate(const void* ptr)
{
if (ptr != NULL)
if (ptr != UAVCAN_NULLPTR)
{
RaiiSynchronizer lock;
(void)lock;
@@ -171,7 +171,7 @@ public:
*/
void shrink()
{
Node* p = NULL;
Node* p = UAVCAN_NULLPTR;
for (;;)
{
{
@@ -179,7 +179,7 @@ public:
(void)lock;
// Removing from reserve and updating the counter.
p = reserve_;
if (p != NULL)
if (p != UAVCAN_NULLPTR)
{
reserve_ = reserve_->next;
num_reserved_blocks_--;
+3 -3
View File
@@ -809,7 +809,7 @@ public:
*/
bool operator==(const char* ch) const
{
if (ch == NULL)
if (ch == UAVCAN_NULLPTR)
{
return false;
}
@@ -830,7 +830,7 @@ public:
StaticAssert<Base::IsStringLike>::check();
StaticAssert<IsDynamic>::check();
Base::clear();
if (ch == NULL)
if (ch == UAVCAN_NULLPTR)
{
handleFatalError("Array::operator=(const char*)");
}
@@ -849,7 +849,7 @@ public:
{
StaticAssert<Base::IsStringLike>::check();
StaticAssert<IsDynamic>::check();
if (ch == NULL)
if (ch == UAVCAN_NULLPTR)
{
handleFatalError("Array::operator+=(const char*)");
}
@@ -86,7 +86,7 @@ class UAVCAN_EXPORT GenericPublisher : public GenericPublisherBase
{
struct ZeroTransferBuffer : public StaticTransferBufferImpl
{
ZeroTransferBuffer() : StaticTransferBufferImpl(NULL, 0) { }
ZeroTransferBuffer() : StaticTransferBufferImpl(UAVCAN_NULLPTR, 0) { }
};
typedef typename Select<DataStruct::MaxBitLen == 0,
@@ -138,7 +138,7 @@ public:
int publish(const DataStruct& message, TransferType transfer_type, NodeID dst_node_id,
MonotonicTime blocking_deadline = MonotonicTime())
{
return genericPublish(message, transfer_type, dst_node_id, NULL, blocking_deadline);
return genericPublish(message, transfer_type, dst_node_id, UAVCAN_NULLPTR, blocking_deadline);
}
int publish(const DataStruct& message, TransferType transfer_type, NodeID dst_node_id, TransferID tid,
@@ -38,7 +38,7 @@ class UAVCAN_EXPORT ReceivedDataStructure : public DataType_
template <typename Ret, Ret(IncomingTransfer::*Fun) () const>
Ret safeget() const
{
if (_transfer_ == NULL)
if (_transfer_ == UAVCAN_NULLPTR)
{
return Ret();
}
@@ -47,13 +47,13 @@ class UAVCAN_EXPORT ReceivedDataStructure : public DataType_
protected:
ReceivedDataStructure()
: _transfer_(NULL)
: _transfer_(UAVCAN_NULLPTR)
{ }
ReceivedDataStructure(const IncomingTransfer* arg_transfer)
: _transfer_(arg_transfer)
{
UAVCAN_ASSERT(arg_transfer != NULL);
UAVCAN_ASSERT(arg_transfer != UAVCAN_NULLPTR);
}
public:
@@ -230,7 +230,7 @@ int GenericSubscriber<DataSpec, DataStruct, TransferListenerType>::checkInit()
GlobalDataTypeRegistry::instance().freeze();
const DataTypeDescriptor* const descr =
GlobalDataTypeRegistry::instance().find(DataTypeKind(DataSpec::DataTypeKind), DataSpec::getDataTypeFullName());
if (descr == NULL)
if (descr == UAVCAN_NULLPTR)
{
UAVCAN_TRACE("GenericSubscriber", "Type [%s] is not registered", DataSpec::getDataTypeFullName());
return -ErrUnknownDataType;
@@ -49,13 +49,13 @@ class UAVCAN_EXPORT GlobalDataTypeRegistry : Noncopyable
{
const DataTypeID id;
explicit EntryInsertionComparator(const Entry* dtd)
: id((dtd == NULL) ? DataTypeID() : dtd->descriptor.getID())
: id((dtd == UAVCAN_NULLPTR) ? DataTypeID() : dtd->descriptor.getID())
{
UAVCAN_ASSERT(dtd != NULL);
UAVCAN_ASSERT(dtd != UAVCAN_NULLPTR);
}
bool operator()(const Entry* entry) const
{
UAVCAN_ASSERT(entry != NULL);
UAVCAN_ASSERT(entry != UAVCAN_NULLPTR);
return entry->descriptor.getID() > id;
}
};
@@ -169,7 +169,7 @@ protected:
ServiceClientBase(INode& node)
: DeadlineHandler(node.getScheduler())
, data_type_descriptor_(NULL)
, data_type_descriptor_(UAVCAN_NULLPTR)
, request_timeout_(getDefaultRequestTimeout())
{ }
@@ -420,8 +420,8 @@ bool ServiceClient<DataType_, Callback_>::shouldAcceptFrame(const RxFrame& frame
{
UAVCAN_ASSERT(frame.getTransferType() == TransferTypeServiceResponse); // Other types filtered out by dispatcher
return NULL != call_registry_.find(CallStateMatchingPredicate(ServiceCallID(frame.getSrcNodeID(),
frame.getTransferID())));
return UAVCAN_NULLPTR != call_registry_.find(CallStateMatchingPredicate(ServiceCallID(frame.getSrcNodeID(),
frame.getTransferID())));
}
@@ -474,8 +474,8 @@ int ServiceClient<DataType_, Callback_>::addCallState(ServiceCallID call_id)
}
}
if (NULL == call_registry_.template emplace<INode&, ServiceClientBase&, ServiceCallID>(SubscriberType::getNode(),
*this, call_id))
if (UAVCAN_NULLPTR == call_registry_.template emplace<INode&, ServiceClientBase&,
ServiceCallID>(SubscriberType::getNode(), *this, call_id))
{
SubscriberType::stop();
return -ErrMemory;
@@ -527,7 +527,7 @@ int ServiceClient<DataType_, Callback_>::call(NodeID server_node_id, const Reque
* TODO move to init(), but this requires to somewhat refactor GenericSubscriber<> (remove TransferForwarder)
*/
TransferListenerWithFilter* const tl = SubscriberType::getTransferListener();
if (tl == NULL)
if (tl == UAVCAN_NULLPTR)
{
UAVCAN_ASSERT(0); // Must have been created
cancelCall(out_call_id);
@@ -570,14 +570,14 @@ void ServiceClient<DataType_, Callback_>::cancelAllCalls()
template <typename DataType_, typename Callback_>
bool ServiceClient<DataType_, Callback_>::hasPendingCallToServer(NodeID server_node_id) const
{
return NULL != call_registry_.find(ServerSearchPredicate(server_node_id));
return UAVCAN_NULLPTR != call_registry_.find(ServerSearchPredicate(server_node_id));
}
template <typename DataType_, typename Callback_>
ServiceCallID ServiceClient<DataType_, Callback_>::getCallIDByIndex(unsigned index) const
{
const CallState* const id = call_registry_.getByIndex(index);
return (id == NULL) ? ServiceCallID() : id->getCallID();
return (id == UAVCAN_NULLPTR) ? ServiceCallID() : id->getCallID();
}
}
@@ -39,7 +39,7 @@ class UAVCAN_EXPORT DataTypeInfoProvider : Noncopyable
/*
* Asking the Global Data Type Registry for the matching type descriptor, either by name or by ID
*/
const DataTypeDescriptor* desc = NULL;
const DataTypeDescriptor* desc = UAVCAN_NULLPTR;
if (request.name.empty())
{
@@ -62,7 +62,7 @@ class UAVCAN_EXPORT DataTypeInfoProvider : Noncopyable
desc = GlobalDataTypeRegistry::instance().find(request.name.c_str());
}
if (desc == NULL)
if (desc == UAVCAN_NULLPTR)
{
UAVCAN_TRACE("DataTypeInfoProvider",
"Cannot process GetDataTypeInfo for nonexistent type: dtid=%i dtk=%i name='%s'",
@@ -108,7 +108,7 @@ class Server : public AbstractServer
return;
}
const int res = storage_.add(node_id, (unique_id_or_null == NULL) ? UniqueID() : *unique_id_or_null);
const int res = storage_.add(node_id, (unique_id_or_null == UAVCAN_NULLPTR) ? UniqueID() : *unique_id_or_null);
if (res < 0)
{
tracer_.onEvent(TraceError, res);
@@ -84,7 +84,7 @@ private:
return &servers_[i];
}
}
return NULL;
return UAVCAN_NULLPTR;
}
virtual void handleTimerEvent(const TimerEvent&)
@@ -338,7 +338,7 @@ public:
Log::Index getServerNextIndex(NodeID server_node_id) const
{
const Server* const s = findServer(server_node_id);
if (s != NULL)
if (s != UAVCAN_NULLPTR)
{
return s->next_index;
}
@@ -349,7 +349,7 @@ public:
void incrementServerNextIndexBy(NodeID server_node_id, Log::Index increment)
{
Server* const s = findServer(server_node_id);
if (s != NULL)
if (s != UAVCAN_NULLPTR)
{
s->next_index = Log::Index(s->next_index + increment);
}
@@ -362,7 +362,7 @@ public:
void decrementServerNextIndex(NodeID server_node_id)
{
Server* const s = findServer(server_node_id);
if (s != NULL)
if (s != UAVCAN_NULLPTR)
{
s->next_index--;
}
@@ -378,7 +378,7 @@ public:
Log::Index getServerMatchIndex(NodeID server_node_id) const
{
const Server* const s = findServer(server_node_id);
if (s != NULL)
if (s != UAVCAN_NULLPTR)
{
return s->match_index;
}
@@ -389,7 +389,7 @@ public:
void setServerMatchIndex(NodeID server_node_id, Log::Index match_index)
{
Server* const s = findServer(server_node_id);
if (s != NULL)
if (s != UAVCAN_NULLPTR)
{
s->match_index = match_index;
}
@@ -285,7 +285,7 @@ public:
const Entry* getEntryAtIndex(Index index) const
{
UAVCAN_ASSERT(last_index_ < Capacity);
return (index <= last_index_) ? &entries_[index] : NULL;
return (index <= last_index_) ? &entries_[index] : UAVCAN_NULLPTR;
}
Index getLastIndex() const { return last_index_; }
@@ -63,7 +63,7 @@ public:
}
const Entry* const last_entry = log_.getEntryAtIndex(log_.getLastIndex());
if (last_entry == NULL)
if (last_entry == UAVCAN_NULLPTR)
{
UAVCAN_ASSERT(0);
return -ErrLogic;
@@ -143,9 +143,10 @@ private:
UAVCAN_ASSERT(commit_index_ <= persistent_state_.getLog().getLastIndex());
// Term
UAVCAN_ASSERT(persistent_state_.getLog().getEntryAtIndex(persistent_state_.getLog().getLastIndex()) != NULL);
UAVCAN_ASSERT(persistent_state_.getLog().getEntryAtIndex(persistent_state_.getLog().getLastIndex())->term
<= persistent_state_.getCurrentTerm());
UAVCAN_ASSERT(persistent_state_.getLog().getEntryAtIndex(persistent_state_.getLog().getLastIndex()) !=
UAVCAN_NULLPTR);
UAVCAN_ASSERT(persistent_state_.getLog().getEntryAtIndex(persistent_state_.getLog().getLastIndex())->term <=
persistent_state_.getCurrentTerm());
// Elections
UAVCAN_ASSERT(server_state_ != ServerStateCandidate || !request_vote_client_.hasPendingCalls() ||
@@ -281,7 +282,7 @@ private:
req.prev_log_index = Log::Index(cluster_.getServerNextIndex(node_id) - 1U);
const Entry* const entry = persistent_state_.getLog().getEntryAtIndex(req.prev_log_index);
if (entry == NULL)
if (entry == UAVCAN_NULLPTR)
{
UAVCAN_ASSERT(0);
handlePersistentStateUpdateError(-ErrLogic);
@@ -470,7 +471,7 @@ private:
* Reject the request if the assumed log index does not exist on the local node.
*/
const Entry* const prev_entry = persistent_state_.getLog().getEntryAtIndex(request.prev_log_index);
if (prev_entry == NULL)
if (prev_entry == UAVCAN_NULLPTR)
{
response.setResponseEnabled(true);
return;
@@ -880,7 +881,7 @@ public:
for (int index = static_cast<int>(persistent_state_.getLog().getLastIndex()); index >= 0; index--)
{
const Entry* const entry = persistent_state_.getLog().getEntryAtIndex(Log::Index(index));
UAVCAN_ASSERT(entry != NULL);
UAVCAN_ASSERT(entry != UAVCAN_NULLPTR);
const LogEntryInfo info(*entry, Log::Index(index) <= commit_index_);
if (predicate(info))
{
@@ -154,7 +154,7 @@ class UAVCAN_EXPORT Server : public AbstractServer
return;
}
const UniqueID uid = (unique_id_or_null == NULL) ? UniqueID() : *unique_id_or_null;
const UniqueID uid = (unique_id_or_null == UAVCAN_NULLPTR) ? UniqueID() : *unique_id_or_null;
if (raft_core_.isLeader())
{
@@ -327,8 +327,8 @@ struct StateReport
, num_unknown_nodes (s.getNodeDiscoverer().getNumUnknownNodes())
{
const Entry* const e = s.getRaftCore().getPersistentState().getLog().getEntryAtIndex(last_log_index);
UAVCAN_ASSERT(e != NULL);
if (e != NULL)
UAVCAN_ASSERT(e != UAVCAN_NULLPTR);
if (e != UAVCAN_NULLPTR)
{
last_log_term = e->term;
}
@@ -54,7 +54,7 @@ public:
* This method will be called when a new node responds to GetNodeInfo request.
* If this method fails to register the node, the node will be queried again later and this method will be
* invoked again.
* Unique ID will be NULL if the node is assumed to not implement the GetNodeInfo service.
* Unique ID will be UAVCAN_NULLPTR if the node is assumed to not implement the GetNodeInfo service.
*/
virtual void handleNewNodeDiscovery(const UniqueID* unique_id_or_null, NodeID node_id) = 0;
@@ -123,7 +123,7 @@ class NodeDiscoverer : TimerBase
{
// This essentially means that we pick first available node. Remember that the map is unordered.
const NodeMap::KVPair* const pair = node_map_.getByIndex(0);
return (pair == NULL) ? NodeID() : pair->key;
return (pair == UAVCAN_NULLPTR) ? NodeID() : pair->key;
}
bool needToQuery(NodeID node_id)
@@ -190,7 +190,7 @@ class NodeDiscoverer : TimerBase
void finalizeNodeDiscovery(const UniqueID* unique_id_or_null, NodeID node_id)
{
trace(TraceDiscoveryNodeFinalized, node_id.get() | ((unique_id_or_null == NULL) ? 0U : 0x100U));
trace(TraceDiscoveryNodeFinalized, node_id.get() | ((unique_id_or_null == UAVCAN_NULLPTR) ? 0U : 0x100U));
removeNode(node_id);
/*
* It is paramount to check if the server is still interested to receive this data.
@@ -216,7 +216,7 @@ class NodeDiscoverer : TimerBase
trace(TraceDiscoveryGetNodeInfoFailure, result.getCallID().server_node_id.get());
NodeData* const data = node_map_.access(result.getCallID().server_node_id);
if (data == NULL)
if (data == UAVCAN_NULLPTR)
{
return; // Probably it is a known node now
}
@@ -227,7 +227,7 @@ class NodeDiscoverer : TimerBase
data->num_get_node_info_attempts++;
if (data->num_get_node_info_attempts >= MaxAttemptsToGetNodeInfo)
{
finalizeNodeDiscovery(NULL, result.getCallID().server_node_id);
finalizeNodeDiscovery(UAVCAN_NULLPTR, result.getCallID().server_node_id);
// Warning: data pointer is invalidated now
}
}
@@ -272,18 +272,18 @@ class NodeDiscoverer : TimerBase
}
NodeData* data = node_map_.access(msg.getSrcNodeID());
if (data == NULL)
if (data == UAVCAN_NULLPTR)
{
trace(TraceDiscoveryNewNodeFound, msg.getSrcNodeID().get());
data = node_map_.insert(msg.getSrcNodeID(), NodeData());
if (data == NULL)
if (data == UAVCAN_NULLPTR)
{
getNode().registerInternalFailure("NodeDiscoverer OOM");
return;
}
}
UAVCAN_ASSERT(data != NULL);
UAVCAN_ASSERT(data != UAVCAN_NULLPTR);
if (msg.uptime_sec < data->last_seen_uptime)
{
@@ -28,8 +28,8 @@ public:
: owner_(owner)
, is_node_id_taken_(is_node_id_taken)
{
UAVCAN_ASSERT(owner_ != NULL);
UAVCAN_ASSERT(is_node_id_taken_ != NULL);
UAVCAN_ASSERT(owner_ != UAVCAN_NULLPTR);
UAVCAN_ASSERT(is_node_id_taken_ != UAVCAN_NULLPTR);
}
/**
@@ -123,11 +123,11 @@ public:
#endif
#if UAVCAN_CPP_VERSION >= UAVCAN_CPP11
const unsigned long long x = std::strtoull(val.c_str(), NULL, 10);
const unsigned long long x = std::strtoull(val.c_str(), UAVCAN_NULLPTR, 10);
#else
// There was no strtoull() before C++11, so we need to resort to strtoul()
StaticAssert<(sizeof(unsigned long) >= sizeof(uint32_t))>::check();
const unsigned long x = std::strtoul(val.c_str(), NULL, 10);
const unsigned long x = std::strtoul(val.c_str(), UAVCAN_NULLPTR, 10);
#endif
#if UAVCAN_CPP_VERSION >= UAVCAN_CPP11
@@ -226,7 +226,7 @@ class FirmwareUpdateTrigger : public INodeInfoListener,
void trySetPendingNode(const NodeID node_id, const FirmwareFilePath& path)
{
if (NULL != pending_nodes_.insert(node_id, path))
if (UAVCAN_NULLPTR != pending_nodes_.insert(node_id, path))
{
if (!TimerBase::isRunning())
{
@@ -285,7 +285,7 @@ class FirmwareUpdateTrigger : public INodeInfoListener,
}
FirmwareFilePath* const old_path = pending_nodes_.access(result.getCallID().server_node_id);
if (old_path == NULL)
if (old_path == UAVCAN_NULLPTR)
{
// The entry has been removed, assuming that it's not needed anymore
return;
@@ -304,7 +304,7 @@ class FirmwareUpdateTrigger : public INodeInfoListener,
}
else
{
UAVCAN_ASSERT(old_path != NULL);
UAVCAN_ASSERT(old_path != UAVCAN_NULLPTR);
UAVCAN_ASSERT(TimerBase::isRunning());
// We won't have to call trySetPendingNode(), because we'll directly update the old path via the pointer
@@ -336,7 +336,7 @@ class FirmwareUpdateTrigger : public INodeInfoListener,
}
FirmwareFilePath* const path = pending_nodes_.access(node_id);
if (path == NULL)
if (path == UAVCAN_NULLPTR)
{
UAVCAN_ASSERT(0); // pickNextNodeID() returned a node ID that is not present in the map
return;
@@ -367,7 +367,7 @@ public:
: TimerBase(node)
, begin_fw_update_client_(node)
, checker_(checker)
, node_info_retriever_(NULL)
, node_info_retriever_(UAVCAN_NULLPTR)
, pending_nodes_(node.getAllocator())
, request_interval_(MonotonicDuration::fromMSec(DefaultRequestIntervalMs))
, last_queried_node_id_(0)
@@ -375,7 +375,7 @@ public:
~FirmwareUpdateTrigger()
{
if (node_info_retriever_ != NULL)
if (node_info_retriever_ != UAVCAN_NULLPTR)
{
node_info_retriever_->removeListener(this);
}
@@ -129,7 +129,7 @@ class UAVCAN_EXPORT GlobalTimeSyncMaster : protected LoopbackFrameListenerBase
const MonotonicTime otr_deadline = node_.getMonotonicTime() + max_transfer_interval;
TransferID* const tid_ptr =
node_.getDispatcher().getOutgoingTransferRegistry().accessOrCreate(otr_key, otr_deadline);
if (tid_ptr == NULL)
if (tid_ptr == UAVCAN_NULLPTR)
{
return -ErrMemory;
}
@@ -161,7 +161,7 @@ public:
// Data type ID
const DataTypeDescriptor* const desc =
GlobalDataTypeRegistry::instance().find(DataTypeKindMessage, protocol::GlobalTimeSync::getDataTypeFullName());
if (desc == NULL)
if (desc == UAVCAN_NULLPTR)
{
return -ErrUnknownDataType;
}
+2 -2
View File
@@ -76,13 +76,13 @@ private:
LogLevel getExternalSinkLevel() const
{
return (external_sink_ == NULL) ? getLogLevelAboveAll() : external_sink_->getLogLevel();
return (external_sink_ == UAVCAN_NULLPTR) ? getLogLevelAboveAll() : external_sink_->getLogLevel();
}
public:
explicit Logger(INode& node)
: logmsg_pub_(node)
, external_sink_(NULL)
, external_sink_(UAVCAN_NULLPTR)
{
level_ = protocol::debug::LogLevel::ERROR;
setTxTimeout(MonotonicDuration::fromMSec(DefaultTxTimeoutMs));
@@ -131,7 +131,7 @@ private:
bool operator()(INodeInfoListener* key)
{
UAVCAN_ASSERT(key != NULL);
UAVCAN_ASSERT(key != UAVCAN_NULLPTR);
key->handleNodeInfoRetrieved(node_id, node_info);
return false;
}
@@ -150,7 +150,7 @@ private:
bool operator()(INodeInfoListener* key)
{
UAVCAN_ASSERT(key != NULL);
UAVCAN_ASSERT(key != UAVCAN_NULLPTR);
(key->*method)(event);
return false;
}
@@ -385,10 +385,10 @@ public:
*/
int addListener(INodeInfoListener* listener)
{
if (listener != NULL)
if (listener != UAVCAN_NULLPTR)
{
removeListener(listener);
return (NULL == listeners_.emplace(listener)) ? -ErrMemory : 0;
return (UAVCAN_NULLPTR == listeners_.emplace(listener)) ? -ErrMemory : 0;
}
else
{
@@ -402,7 +402,7 @@ public:
*/
void removeListener(INodeInfoListener* listener)
{
if (listener != NULL)
if (listener != UAVCAN_NULLPTR)
{
listeners_.removeAll(listener);
}
@@ -90,7 +90,7 @@ class UAVCAN_EXPORT ParamServer
void handleGetSet(const protocol::param::GetSet::Request& in, protocol::param::GetSet::Response& out)
{
UAVCAN_ASSERT(manager_ != NULL);
UAVCAN_ASSERT(manager_ != UAVCAN_NULLPTR);
// Recover the name from index
if (in.name.empty())
@@ -131,7 +131,7 @@ class UAVCAN_EXPORT ParamServer
void handleExecuteOpcode(const protocol::param::ExecuteOpcode::Request& in,
protocol::param::ExecuteOpcode::Response& out)
{
UAVCAN_ASSERT(manager_ != NULL);
UAVCAN_ASSERT(manager_ != UAVCAN_NULLPTR);
if (in.opcode == protocol::param::ExecuteOpcode::Request::OPCODE_SAVE)
{
@@ -152,7 +152,7 @@ public:
explicit ParamServer(INode& node)
: get_set_srv_(node)
, save_erase_srv_(node)
, manager_(NULL)
, manager_(UAVCAN_NULLPTR)
{ }
/**
@@ -161,7 +161,7 @@ public:
*/
int start(IParamManager* manager)
{
if (manager == NULL)
if (manager == UAVCAN_NULLPTR)
{
return -ErrInvalidParam;
}
@@ -67,7 +67,7 @@ class UAVCAN_EXPORT RestartRequestServer : Noncopyable
public:
explicit RestartRequestServer(INode& node)
: srv_(node)
, handler_(NULL)
, handler_(UAVCAN_NULLPTR)
{ }
/**
@@ -138,7 +138,7 @@ public:
, sysclock_(sysclock)
, outgoing_transfer_reg_(allocator)
#if !UAVCAN_TINY
, rx_listener_(NULL)
, rx_listener_(UAVCAN_NULLPTR)
#endif
, self_node_id_(NodeID::Broadcast) // Default
, self_node_id_is_set_(false)
@@ -207,10 +207,10 @@ public:
LoopbackFrameListenerRegistry& getLoopbackFrameListenerRegistry() { return loopback_listeners_; }
IRxFrameListener* getRxFrameListener() const { return rx_listener_; }
void removeRxFrameListener() { rx_listener_ = NULL; }
void removeRxFrameListener() { rx_listener_ = UAVCAN_NULLPTR; }
void installRxFrameListener(IRxFrameListener* listener)
{
UAVCAN_ASSERT(listener != NULL);
UAVCAN_ASSERT(listener != UAVCAN_NULLPTR);
rx_listener_ = listener;
}
#endif
@@ -180,7 +180,7 @@ public:
TransferListenerWithFilter(TransferPerfCounter& perf, const DataTypeDescriptor& data_type,
uint16_t max_buffer_size, IPoolAllocator& allocator)
: TransferListener(perf, data_type, max_buffer_size, allocator)
, filter_(NULL)
, filter_(UAVCAN_NULLPTR)
{ }
void installAcceptanceFilter(const ITransferAcceptanceFilter* acceptance_filter)
+1 -1
View File
@@ -77,7 +77,7 @@ struct HasIsCloseMethod
template <typename U, typename R> static NotApplicable test(...);
enum { Result = sizeof(test<This, Rhs>(NULL)) };
enum { Result = sizeof(test<This, Rhs>(UAVCAN_NULLPTR)) };
};
/// First stage: bool L::isClose(R)
@@ -60,13 +60,13 @@ class UAVCAN_EXPORT LazyConstructor
public:
LazyConstructor()
: ptr_(NULL)
: ptr_(UAVCAN_NULLPTR)
{
fill(data_.pool, data_.pool + sizeof(T), uint8_t(0));
}
LazyConstructor(const LazyConstructor<T>& rhs) // Implicit
: ptr_(NULL)
: ptr_(UAVCAN_NULLPTR)
{
fill(data_.pool, data_.pool + sizeof(T), uint8_t(0));
if (rhs)
@@ -87,7 +87,7 @@ public:
return *this;
}
bool isConstructed() const { return ptr_ != NULL; }
bool isConstructed() const { return ptr_ != UAVCAN_NULLPTR; }
operator T*() const { return ptr_; }
@@ -103,7 +103,7 @@ public:
{
ptr_->~T();
}
ptr_ = NULL;
ptr_ = UAVCAN_NULLPTR;
fill(data_.pool, data_.pool + sizeof(T), uint8_t(0));
}
@@ -22,7 +22,7 @@ class UAVCAN_EXPORT LinkedListNode
protected:
LinkedListNode()
: next_(NULL)
: next_(UAVCAN_NULLPTR)
{ }
~LinkedListNode() { }
@@ -46,11 +46,11 @@ class UAVCAN_EXPORT LinkedListRoot
public:
LinkedListRoot()
: root_(NULL)
: root_(UAVCAN_NULLPTR)
{ }
T* get() const { return root_; }
bool isEmpty() const { return get() == NULL; }
bool isEmpty() const { return get() == UAVCAN_NULLPTR; }
/**
* Complexity: O(N)
@@ -100,7 +100,7 @@ unsigned LinkedListRoot<T>::getLength() const
template <typename T>
void LinkedListRoot<T>::insert(T* node)
{
if (node == NULL)
if (node == UAVCAN_NULLPTR)
{
UAVCAN_ASSERT(0);
return;
@@ -114,7 +114,7 @@ template <typename T>
template <typename Predicate>
void LinkedListRoot<T>::insertBefore(T* node, Predicate predicate)
{
if (node == NULL)
if (node == UAVCAN_NULLPTR)
{
UAVCAN_ASSERT(0);
return;
@@ -122,7 +122,7 @@ void LinkedListRoot<T>::insertBefore(T* node, Predicate predicate)
remove(node);
if (root_ == NULL || predicate(root_))
if (root_ == UAVCAN_NULLPTR || predicate(root_))
{
node->setNextListNode(root_);
root_ = node;
@@ -146,7 +146,7 @@ void LinkedListRoot<T>::insertBefore(T* node, Predicate predicate)
template <typename T>
void LinkedListRoot<T>::remove(const T* node)
{
if (root_ == NULL || node == NULL)
if (root_ == UAVCAN_NULLPTR || node == UAVCAN_NULLPTR)
{
return;
}
+15 -15
View File
@@ -66,20 +66,20 @@ private:
static KVGroup* instantiate(IPoolAllocator& allocator)
{
void* const praw = allocator.allocate(sizeof(KVGroup));
if (praw == NULL)
if (praw == UAVCAN_NULLPTR)
{
return NULL;
return UAVCAN_NULLPTR;
}
return new (praw) KVGroup();
}
static void destroy(KVGroup*& obj, IPoolAllocator& allocator)
{
if (obj != NULL)
if (obj != UAVCAN_NULLPTR)
{
obj->~KVGroup();
allocator.deallocate(obj);
obj = NULL;
obj = UAVCAN_NULLPTR;
}
}
@@ -92,7 +92,7 @@ private:
return kvs + i;
}
}
return NULL;
return UAVCAN_NULLPTR;
}
};
@@ -167,7 +167,7 @@ public:
/**
* Complexity is O(1).
*/
bool isEmpty() const { return find(YesPredicate()) == NULL; }
bool isEmpty() const { return find(YesPredicate()) == UAVCAN_NULLPTR; }
/**
* Complexity is O(N).
@@ -193,7 +193,7 @@ typename Map<Key, Value>::KVPair* Map<Key, Value>::findKey(const Key& key)
}
p = p->getNextListNode();
}
return NULL;
return UAVCAN_NULLPTR;
}
template <typename Key, typename Value>
@@ -226,7 +226,7 @@ Value* Map<Key, Value>::access(const Key& key)
{
UAVCAN_ASSERT(!(key == Key()));
KVPair* const kv = findKey(key);
return kv ? &kv->value : NULL;
return kv ? &kv->value : UAVCAN_NULLPTR;
}
template <typename Key, typename Value>
@@ -243,9 +243,9 @@ Value* Map<Key, Value>::insert(const Key& key, const Value& value)
}
KVGroup* const kvg = KVGroup::instantiate(allocator_);
if (kvg == NULL)
if (kvg == UAVCAN_NULLPTR)
{
return NULL;
return UAVCAN_NULLPTR;
}
list_.insert(kvg);
kvg->kvs[0] = KVPair(key, value);
@@ -271,7 +271,7 @@ void Map<Key, Value>::removeAllWhere(Predicate predicate)
unsigned num_removed = 0;
KVGroup* p = list_.get();
while (p != NULL)
while (p != UAVCAN_NULLPTR)
{
KVGroup* const next_group = p->getNextListNode();
@@ -302,7 +302,7 @@ template <typename Predicate>
const Key* Map<Key, Value>::find(Predicate predicate) const
{
KVGroup* p = list_.get();
while (p != NULL)
while (p != UAVCAN_NULLPTR)
{
KVGroup* const next_group = p->getNextListNode();
@@ -320,7 +320,7 @@ const Key* Map<Key, Value>::find(Predicate predicate) const
p = next_group;
}
return NULL;
return UAVCAN_NULLPTR;
}
template <typename Key, typename Value>
@@ -334,7 +334,7 @@ typename Map<Key, Value>::KVPair* Map<Key, Value>::getByIndex(unsigned index)
{
// Slowly crawling through the dynamic storage
KVGroup* p = list_.get();
while (p != NULL)
while (p != UAVCAN_NULLPTR)
{
KVGroup* const next_group = p->getNextListNode();
@@ -354,7 +354,7 @@ typename Map<Key, Value>::KVPair* Map<Key, Value>::getByIndex(unsigned index)
p = next_group;
}
return NULL;
return UAVCAN_NULLPTR;
}
template <typename Key, typename Value>
+29 -29
View File
@@ -49,21 +49,21 @@ class UAVCAN_EXPORT Multiset : Noncopyable
#endif
Item()
: ptr(NULL)
: ptr(UAVCAN_NULLPTR)
{
fill_n(pool, sizeof(pool), static_cast<unsigned char>(0));
}
~Item() { destroy(); }
bool isConstructed() const { return ptr != NULL; }
bool isConstructed() const { return ptr != UAVCAN_NULLPTR; }
void destroy()
{
if (ptr != NULL)
if (ptr != UAVCAN_NULLPTR)
{
ptr->~T();
ptr = NULL;
ptr = UAVCAN_NULLPTR;
fill_n(pool, sizeof(pool), static_cast<unsigned char>(0));
}
}
@@ -85,20 +85,20 @@ private:
static Chunk* instantiate(IPoolAllocator& allocator)
{
void* const praw = allocator.allocate(sizeof(Chunk));
if (praw == NULL)
if (praw == UAVCAN_NULLPTR)
{
return NULL;
return UAVCAN_NULLPTR;
}
return new (praw) Chunk();
}
static void destroy(Chunk*& obj, IPoolAllocator& allocator)
{
if (obj != NULL)
if (obj != UAVCAN_NULLPTR)
{
obj->~Chunk();
allocator.deallocate(obj);
obj = NULL;
obj = UAVCAN_NULLPTR;
}
}
@@ -111,7 +111,7 @@ private:
return items + i;
}
}
return NULL;
return UAVCAN_NULLPTR;
}
};
@@ -199,17 +199,17 @@ public:
/**
* Creates one item in-place and returns a pointer to it.
* If creation fails due to lack of memory, NULL will be returned.
* If creation fails due to lack of memory, UAVCAN_NULLPTR will be returned.
* Complexity is O(N).
*/
T* emplace()
{
Item* const item = findOrCreateFreeSlot();
if (item == NULL)
if (item == UAVCAN_NULLPTR)
{
return NULL;
return UAVCAN_NULLPTR;
}
UAVCAN_ASSERT(item->ptr == NULL);
UAVCAN_ASSERT(item->ptr == UAVCAN_NULLPTR);
item->ptr = new (item->pool) T();
return item->ptr;
}
@@ -218,11 +218,11 @@ public:
T* emplace(P1 p1)
{
Item* const item = findOrCreateFreeSlot();
if (item == NULL)
if (item == UAVCAN_NULLPTR)
{
return NULL;
return UAVCAN_NULLPTR;
}
UAVCAN_ASSERT(item->ptr == NULL);
UAVCAN_ASSERT(item->ptr == UAVCAN_NULLPTR);
item->ptr = new (item->pool) T(p1);
return item->ptr;
}
@@ -231,11 +231,11 @@ public:
T* emplace(P1 p1, P2 p2)
{
Item* const item = findOrCreateFreeSlot();
if (item == NULL)
if (item == UAVCAN_NULLPTR)
{
return NULL;
return UAVCAN_NULLPTR;
}
UAVCAN_ASSERT(item->ptr == NULL);
UAVCAN_ASSERT(item->ptr == UAVCAN_NULLPTR);
item->ptr = new (item->pool) T(p1, p2);
return item->ptr;
}
@@ -244,11 +244,11 @@ public:
T* emplace(P1 p1, P2 p2, P3 p3)
{
Item* const item = findOrCreateFreeSlot();
if (item == NULL)
if (item == UAVCAN_NULLPTR)
{
return NULL;
return UAVCAN_NULLPTR;
}
UAVCAN_ASSERT(item->ptr == NULL);
UAVCAN_ASSERT(item->ptr == UAVCAN_NULLPTR);
item->ptr = new (item->pool) T(p1, p2, p3);
return item->ptr;
}
@@ -324,7 +324,7 @@ public:
/**
* Complexity is O(1).
*/
bool isEmpty() const { return find(YesPredicate()) == NULL; }
bool isEmpty() const { return find(YesPredicate()) == UAVCAN_NULLPTR; }
/**
* Counts number of items stored.
@@ -347,7 +347,7 @@ typename Multiset<T>::Item* Multiset<T>::findOrCreateFreeSlot()
while (p)
{
Item* const dyn = p->findFreeSlot();
if (dyn != NULL)
if (dyn != UAVCAN_NULLPTR)
{
return dyn;
}
@@ -357,9 +357,9 @@ typename Multiset<T>::Item* Multiset<T>::findOrCreateFreeSlot()
// Create new chunk
Chunk* const chunk = Chunk::instantiate(allocator_);
if (chunk == NULL)
if (chunk == UAVCAN_NULLPTR)
{
return NULL;
return UAVCAN_NULLPTR;
}
list_.insert(chunk);
return &chunk->items[0];
@@ -397,7 +397,7 @@ void Multiset<T>::removeWhere(Predicate predicate, const RemoveStrategy strategy
unsigned num_removed = 0;
Chunk* p = list_.get();
while (p != NULL)
while (p != UAVCAN_NULLPTR)
{
Chunk* const next_chunk = p->getNextListNode(); // For the case if the current entry gets modified
@@ -437,7 +437,7 @@ template <typename Predicate>
T* Multiset<T>::find(Predicate predicate)
{
Chunk* p = list_.get();
while (p != NULL)
while (p != UAVCAN_NULLPTR)
{
Chunk* const next_chunk = p->getNextListNode(); // For the case if the current entry gets modified
@@ -454,7 +454,7 @@ T* Multiset<T>::find(Predicate predicate)
p = next_chunk;
}
return NULL;
return UAVCAN_NULLPTR;
}
template <typename T>