Skip to content

Commit

Permalink
restore assert -> RCUTILS_ASSERT and abort -> RCUTILS_BREAK
Browse files Browse the repository at this point in the history
Provide migration path #define and TODO for resolving once provided
upstream in ros2/rcutils#112
  • Loading branch information
tfoote committed Aug 6, 2018
1 parent 70b00b7 commit 58e437c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 23 deletions.
9 changes: 8 additions & 1 deletion include/message_filters/message_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@
#include <type_traits>
#include <memory>

#ifndef RCUTILS_ASSERT
// TODO(tfoote) remove this after it's implemented upstream
#define RCUTILS_ASSERT assert
#endif
// Uncomment below intead
//#include <rcutils/assert.h>

namespace message_filters
{
typedef std::map< std::string, std::string > M_string;
Expand Down Expand Up @@ -202,7 +209,7 @@ class MessageEvent
return message_copy_;
}

assert(create_);
RCUTILS_ASSERT(create_);
message_copy_ = create_();
*message_copy_ = *message_;

Expand Down
54 changes: 34 additions & 20 deletions include/message_filters/sync_policies/approximate_time.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@
#include <string>
#include <tuple>


#ifndef RCUTILS_ASSERT
// TODO(tfoote) remove this after it's implemented upstream
// https://github.com/ros2/rcutils/pull/112
#define RCUTILS_ASSERT assert
#endif
#ifndef RCUTILS_BREAK
#include <cassert>
// TODO(tfoote) remove this after it's implemented upstream
// https://github.com/ros2/rcutils/pull/112
#define RCUTILS_BREAK std::abort
#endif
// Uncomment below intead
//#include <rcutils/assert.h>

namespace message_filters
{
namespace sync_policies
Expand Down Expand Up @@ -105,7 +120,7 @@ struct ApproximateTime : public PolicyBase<M0, M1, M2, M3, M4, M5, M6, M7, M8>
, inter_message_lower_bounds_(9, rclcpp::Duration(0, 0))
, warned_about_incorrect_bound_(9, false)
{
assert(queue_size_ > 0); // The synchronizer will tend to drop many messages with a queue size of 1. At least 2 is recommended.
RCUTILS_ASSERT(queue_size_ > 0); // The synchronizer will tend to drop many messages with a queue size of 1. At least 2 is recommended.
}

ApproximateTime(const ApproximateTime& e)
Expand Down Expand Up @@ -149,7 +164,7 @@ struct ApproximateTime : public PolicyBase<M0, M1, M2, M3, M4, M5, M6, M7, M8>
}
std::deque<typename std::tuple_element<i, Events>::type>& deque = std::get<i>(deques_);
std::vector<typename std::tuple_element<i, Events>::type>& v = std::get<i>(past_);
assert(!deque.empty());
RCUTILS_ASSERT(!deque.empty());
const typename std::tuple_element<i, Messages>::type &msg = *(deque.back()).getMessage();
rclcpp::Time msg_time = mt::TimeStamp<typename std::tuple_element<i, Messages>::type>::value(msg);
rclcpp::Time previous_msg_time;
Expand Down Expand Up @@ -222,7 +237,7 @@ struct ApproximateTime : public PolicyBase<M0, M1, M2, M3, M4, M5, M6, M7, M8>
recover<7>();
recover<8>();
// Drop the oldest message in the offending topic
assert(!deque.empty());
RCUTILS_ASSERT(!deque.empty());
deque.pop_front();
has_dropped_messages_[i] = true;
if (pivot_ != NO_PIVOT)
Expand All @@ -239,19 +254,19 @@ struct ApproximateTime : public PolicyBase<M0, M1, M2, M3, M4, M5, M6, M7, M8>
void setAgePenalty(double age_penalty)
{
// For correctness we only need age_penalty > -1.0, but most likely a negative age_penalty is a mistake.
assert(age_penalty >= 0);
RCUTILS_ASSERT(age_penalty >= 0);
age_penalty_ = age_penalty;
}

void setInterMessageLowerBound(int i, rclcpp::Duration lower_bound) {
// For correctness we only need age_penalty > -1.0, but most likely a negative age_penalty is a mistake.
assert(lower_bound >= rclcpp::Duration(0,0));
RCUTILS_ASSERT(lower_bound >= rclcpp::Duration(0,0));
inter_message_lower_bounds_[i] = lower_bound;
}

void setMaxIntervalDuration(rclcpp::Duration max_interval_duration) {
// For correctness we only need age_penalty > -1.0, but most likely a negative age_penalty is a mistake.
assert(max_interval_duration >= rclcpp::Duration(0,0));
RCUTILS_ASSERT(max_interval_duration >= rclcpp::Duration(0,0));
max_interval_duration_ = max_interval_duration;
}

Expand All @@ -261,7 +276,7 @@ struct ApproximateTime : public PolicyBase<M0, M1, M2, M3, M4, M5, M6, M7, M8>
void dequeDeleteFront()
{
std::deque<typename std::tuple_element<i, Events>::type>& deque = std::get<i>(deques_);
assert(!deque.empty());
RCUTILS_ASSERT(!deque.empty());
deque.pop_front();
if (deque.empty())
{
Expand Down Expand Up @@ -302,7 +317,7 @@ struct ApproximateTime : public PolicyBase<M0, M1, M2, M3, M4, M5, M6, M7, M8>
dequeDeleteFront<8>();
break;
default:
std::abort();
RCUTILS_BREAK();
}
}

Expand All @@ -312,7 +327,7 @@ struct ApproximateTime : public PolicyBase<M0, M1, M2, M3, M4, M5, M6, M7, M8>
{
std::deque<typename std::tuple_element<i, Events>::type>& deque = std::get<i>(deques_);
std::vector<typename std::tuple_element<i, Events>::type>& vector = std::get<i>(past_);
assert(!deque.empty());
RCUTILS_ASSERT(!deque.empty());
vector.push_back(deque.front());
deque.pop_front();
if (deque.empty())
Expand Down Expand Up @@ -353,7 +368,7 @@ struct ApproximateTime : public PolicyBase<M0, M1, M2, M3, M4, M5, M6, M7, M8>
dequeMoveFrontToPast<8>();
break;
default:
std::abort();
RCUTILS_BREAK();
}
}

Expand Down Expand Up @@ -417,7 +432,7 @@ struct ApproximateTime : public PolicyBase<M0, M1, M2, M3, M4, M5, M6, M7, M8>

std::vector<typename std::tuple_element<i, Events>::type>& v = std::get<i>(past_);
std::deque<typename std::tuple_element<i, Events>::type>& q = std::get<i>(deques_);
assert(num_messages <= v.size());
RCUTILS_ASSERT(num_messages <= v.size());
while (num_messages > 0)
{
q.push_front(v.back());
Expand Down Expand Up @@ -471,7 +486,7 @@ struct ApproximateTime : public PolicyBase<M0, M1, M2, M3, M4, M5, M6, M7, M8>
v.pop_back();
}

assert(!q.empty());
RCUTILS_ASSERT(!q.empty());

q.pop_front();
if (!q.empty())
Expand Down Expand Up @@ -615,13 +630,13 @@ struct ApproximateTime : public PolicyBase<M0, M1, M2, M3, M4, M5, M6, M7, M8>
{
return rclcpp::Time(0,0); // Dummy return value
}
assert(pivot_ != NO_PIVOT);
RCUTILS_ASSERT(pivot_ != NO_PIVOT);

std::vector<typename std::tuple_element<i, Events>::type>& v = std::get<i>(past_);
std::deque<typename std::tuple_element<i, Events>::type>& q = std::get<i>(deques_);
if (q.empty())
{
assert(!v.empty()); // Because we have a candidate
RCUTILS_ASSERT(!v.empty()); // Because we have a candidate
rclcpp::Time last_msg_time = mt::TimeStamp<typename std::tuple_element<i, Messages>::type>::value(*(v.back()).getMessage());
rclcpp::Time msg_time_lower_bound = last_msg_time + inter_message_lower_bounds_[i];
if (msg_time_lower_bound > pivot_time_) // Take the max
Expand Down Expand Up @@ -662,7 +677,7 @@ struct ApproximateTime : public PolicyBase<M0, M1, M2, M3, M4, M5, M6, M7, M8>
virtual_times[6] = getVirtualTime<6>();
virtual_times[7] = getVirtualTime<7>();
virtual_times[8] = getVirtualTime<8>();

time = virtual_times[0];
index = 0;
for (int i = 0; i < RealTypeCount::value; i++)
Expand Down Expand Up @@ -745,7 +760,7 @@ struct ApproximateTime : public PolicyBase<M0, M1, M2, M3, M4, M5, M6, M7, M8>
}
}
// INVARIANT: we have a candidate and pivot
assert(pivot_ != NO_PIVOT);
RCUTILS_ASSERT(pivot_ != NO_PIVOT);
//printf("start_index == %d, pivot_ == %d\n", start_index, pivot_);
if (start_index == pivot_) // TODO: replace with start_time == pivot_time_
{
Expand Down Expand Up @@ -798,14 +813,14 @@ struct ApproximateTime : public PolicyBase<M0, M1, M2, M3, M4, M5, M6, M7, M8>
recover<7>(num_virtual_moves[7]);
recover<8>(num_virtual_moves[8]);
(void)num_non_empty_deques_before_virtual_search; // unused variable warning stopper
assert(num_non_empty_deques_before_virtual_search == num_non_empty_deques_);
RCUTILS_ASSERT(num_non_empty_deques_before_virtual_search == num_non_empty_deques_);
break;
}
// Note: we cannot reach this point with start_index == pivot_ since in that case we would
// have start_time == pivot_time, in which case the two tests above are the negation
// of each other, so that one must be true. Therefore the while loop always terminates.
assert(start_index != pivot_);
assert(start_time < pivot_time_);
RCUTILS_ASSERT(start_index != pivot_);
RCUTILS_ASSERT(start_time < pivot_time_);
dequeMoveFrontToPast(start_index);
num_virtual_moves[start_index]++;
} // while(1)
Expand Down Expand Up @@ -840,4 +855,3 @@ struct ApproximateTime : public PolicyBase<M0, M1, M2, M3, M4, M5, M6, M7, M8>
} // namespace message_filters

#endif // MESSAGE_FILTERS_SYNC_APPROXIMATE_TIME_H

3 changes: 1 addition & 2 deletions include/message_filters/sync_policies/exact_time.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
#include "message_filters/message_traits.h"

#include <rclcpp/rclcpp.hpp>
#include <cassert>
#include <deque>
#include <string>
#include <tuple>
Expand Down Expand Up @@ -102,7 +101,7 @@ struct ExactTime : public PolicyBase<M0, M1, M2, M3, M4, M5, M6, M7, M8>
template<int i>
void add(const typename std::tuple_element<i, Events>::type& evt)
{
assert(parent_);
RCUTILS_ASSERT(parent_);

namespace mt = message_filters::message_traits;

Expand Down

0 comments on commit 58e437c

Please sign in to comment.