From e184e5c16184f2642e013ef1f44d4504baf734ed Mon Sep 17 00:00:00 2001 From: Dejan Pangercic Date: Tue, 24 Oct 2017 17:39:35 -0700 Subject: [PATCH 1/4] pointers are checked for null --- rmw_fastrtps_cpp/src/rmw_wait.cpp | 147 +++++++++++++++++------------- 1 file changed, 86 insertions(+), 61 deletions(-) diff --git a/rmw_fastrtps_cpp/src/rmw_wait.cpp b/rmw_fastrtps_cpp/src/rmw_wait.cpp index 2af01bbe2..94e1f867f 100644 --- a/rmw_fastrtps_cpp/src/rmw_wait.cpp +++ b/rmw_fastrtps_cpp/src/rmw_wait.cpp @@ -31,28 +31,34 @@ check_waitset_for_data( const rmw_services_t * services, const rmw_clients_t * clients) { - for (size_t i = 0; i < subscriptions->subscriber_count; ++i) { - void * data = subscriptions->subscribers[i]; - CustomSubscriberInfo * custom_subscriber_info = static_cast(data); - // Short circuiting out of this function is possible - if (custom_subscriber_info && custom_subscriber_info->listener_->hasData()) { - return true; + if (subscriptions) { + for (size_t i = 0; i < subscriptions->subscriber_count; ++i) { + void * data = subscriptions->subscribers[i]; + CustomSubscriberInfo * custom_subscriber_info = static_cast(data); + // Short circuiting out of this function is possible + if (custom_subscriber_info && custom_subscriber_info->listener_->hasData()) { + return true; + } } } - for (size_t i = 0; i < clients->client_count; ++i) { - void * data = clients->clients[i]; - CustomClientInfo * custom_client_info = static_cast(data); - if (custom_client_info && custom_client_info->listener_->hasData()) { - return true; + if (clients) { + for (size_t i = 0; i < clients->client_count; ++i) { + void * data = clients->clients[i]; + CustomClientInfo * custom_client_info = static_cast(data); + if (custom_client_info && custom_client_info->listener_->hasData()) { + return true; + } } } - for (size_t i = 0; i < services->service_count; ++i) { - void * data = services->services[i]; - CustomServiceInfo * custom_service_info = static_cast(data); - if (custom_service_info && custom_service_info->listener_->hasData()) { - return true; + if (services) { + for (size_t i = 0; i < services->service_count; ++i) { + void * data = services->services[i]; + CustomServiceInfo * custom_service_info = static_cast(data); + if (custom_service_info && custom_service_info->listener_->hasData()) { + return true; + } } } @@ -99,22 +105,28 @@ rmw_wait( return RMW_RET_ERROR; } - for (size_t i = 0; i < subscriptions->subscriber_count; ++i) { - void * data = subscriptions->subscribers[i]; - CustomSubscriberInfo * custom_subscriber_info = static_cast(data); - custom_subscriber_info->listener_->attachCondition(conditionMutex, conditionVariable); + if (subscriptions) { + for (size_t i = 0; i < subscriptions->subscriber_count; ++i) { + void * data = subscriptions->subscribers[i]; + CustomSubscriberInfo * custom_subscriber_info = static_cast(data); + custom_subscriber_info->listener_->attachCondition(conditionMutex, conditionVariable); + } } - for (size_t i = 0; i < clients->client_count; ++i) { - void * data = clients->clients[i]; - CustomClientInfo * custom_client_info = static_cast(data); - custom_client_info->listener_->attachCondition(conditionMutex, conditionVariable); + if (clients) { + for (size_t i = 0; i < clients->client_count; ++i) { + void * data = clients->clients[i]; + CustomClientInfo * custom_client_info = static_cast(data); + custom_client_info->listener_->attachCondition(conditionMutex, conditionVariable); + } } - for (size_t i = 0; i < services->service_count; ++i) { - void * data = services->services[i]; - CustomServiceInfo * custom_service_info = static_cast(data); - custom_service_info->listener_->attachCondition(conditionMutex, conditionVariable); + if (services) { + for (size_t i = 0; i < services->service_count; ++i) { + void * data = services->services[i]; + CustomServiceInfo * custom_service_info = static_cast(data); + custom_service_info->listener_->attachCondition(conditionMutex, conditionVariable); + } } if (guard_conditions) { @@ -137,27 +149,33 @@ rmw_wait( bool hasToWait = (wait_timeout && (wait_timeout->sec > 0 || wait_timeout->nsec > 0)) || !wait_timeout; - for (size_t i = 0; hasToWait && i < subscriptions->subscriber_count; ++i) { - void * data = subscriptions->subscribers[i]; - CustomSubscriberInfo * custom_subscriber_info = static_cast(data); - if (custom_subscriber_info->listener_->hasData()) { - hasToWait = false; + if (subscriptions) { + for (size_t i = 0; hasToWait && i < subscriptions->subscriber_count; ++i) { + void * data = subscriptions->subscribers[i]; + CustomSubscriberInfo * custom_subscriber_info = static_cast(data); + if (custom_subscriber_info->listener_->hasData()) { + hasToWait = false; + } } } - for (size_t i = 0; hasToWait && i < clients->client_count; ++i) { - void * data = clients->clients[i]; - CustomClientInfo * custom_client_info = static_cast(data); - if (custom_client_info->listener_->hasData()) { - hasToWait = false; + if (clients) { + for (size_t i = 0; hasToWait && i < clients->client_count; ++i) { + void * data = clients->clients[i]; + CustomClientInfo * custom_client_info = static_cast(data); + if (custom_client_info->listener_->hasData()) { + hasToWait = false; + } } } - for (size_t i = 0; hasToWait && i < services->service_count; ++i) { - void * data = services->services[i]; - CustomServiceInfo * custom_service_info = static_cast(data); - if (custom_service_info->listener_->hasData()) { - hasToWait = false; + if (services) { + for (size_t i = 0; hasToWait && i < services->service_count; ++i) { + void * data = services->services[i]; + CustomServiceInfo * custom_service_info = static_cast(data); + if (custom_service_info->listener_->hasData()) { + hasToWait = false; + } } } @@ -202,30 +220,37 @@ rmw_wait( timeout = true; } - for (size_t i = 0; i < subscriptions->subscriber_count; ++i) { - void * data = subscriptions->subscribers[i]; - CustomSubscriberInfo * custom_subscriber_info = static_cast(data); - custom_subscriber_info->listener_->detachCondition(); - if (!custom_subscriber_info->listener_->hasData()) { - subscriptions->subscribers[i] = 0; + if (subscriptions) { + for (size_t i = 0; i < subscriptions->subscriber_count; ++i) { + void * data = subscriptions->subscribers[i]; + CustomSubscriberInfo * custom_subscriber_info = static_cast(data); + custom_subscriber_info->listener_->detachCondition(); + if (!custom_subscriber_info->listener_->hasData()) { + subscriptions->subscribers[i] = 0; + } } } - for (size_t i = 0; i < clients->client_count; ++i) { - void * data = clients->clients[i]; - CustomClientInfo * custom_client_info = static_cast(data); - custom_client_info->listener_->detachCondition(); - if (!custom_client_info->listener_->hasData()) { - clients->clients[i] = 0; + if (clients) { + for (size_t i = 0; i < clients->client_count; ++i) { + void * data = clients->clients[i]; + CustomClientInfo * custom_client_info = static_cast(data); + custom_client_info->listener_->detachCondition(); + if (!custom_client_info->listener_->hasData()) { + clients->clients[i] = 0; + } } } - for (size_t i = 0; i < services->service_count; ++i) { - void * data = services->services[i]; - CustomServiceInfo * custom_service_info = static_cast(data); - custom_service_info->listener_->detachCondition(); - if (!custom_service_info->listener_->hasData()) { - services->services[i] = 0; + + if (services) { + for (size_t i = 0; i < services->service_count; ++i) { + void * data = services->services[i]; + CustomServiceInfo * custom_service_info = static_cast(data); + custom_service_info->listener_->detachCondition(); + if (!custom_service_info->listener_->hasData()) { + services->services[i] = 0; + } } } From 3e5edb3316e2aee325e9354549e54c999a89bca9 Mon Sep 17 00:00:00 2001 From: jwang11 Date: Thu, 26 Oct 2017 19:45:36 -0700 Subject: [PATCH 2/4] use auto deduction and nullptr to keep coding style consistent (#162) This commit use auto to deduce complex TYPE and replace NULL with nullptr. It helps to keep coding style consistent across the project --- .../rmw_fastrtps_cpp/TypeSupport_impl.hpp | 38 +++++++++---------- .../rmw_fastrtps_cpp/custom_client_info.hpp | 10 ++--- .../rmw_fastrtps_cpp/custom_service_info.hpp | 10 ++--- .../custom_subscriber_info.hpp | 10 ++--- .../src/client_service_common.cpp | 4 +- .../src/client_service_common.hpp | 4 +- rmw_fastrtps_cpp/src/get_client.cpp | 12 +++--- rmw_fastrtps_cpp/src/get_participant.cpp | 6 +-- rmw_fastrtps_cpp/src/get_publisher.cpp | 6 +-- rmw_fastrtps_cpp/src/get_service.cpp | 12 +++--- rmw_fastrtps_cpp/src/get_subscriber.cpp | 6 +-- rmw_fastrtps_cpp/src/rmw_client.cpp | 22 +++++------ rmw_fastrtps_cpp/src/rmw_count.cpp | 2 +- .../src/rmw_get_gid_for_publisher.cpp | 2 +- rmw_fastrtps_cpp/src/rmw_node.cpp | 20 +++++----- rmw_fastrtps_cpp/src/rmw_node_names.cpp | 2 +- rmw_fastrtps_cpp/src/rmw_publish.cpp | 2 +- rmw_fastrtps_cpp/src/rmw_publisher.cpp | 24 ++++++------ rmw_fastrtps_cpp/src/rmw_request.cpp | 4 +- rmw_fastrtps_cpp/src/rmw_response.cpp | 4 +- rmw_fastrtps_cpp/src/rmw_service.cpp | 18 ++++----- .../src/rmw_service_names_and_types.cpp | 2 +- .../src/rmw_service_server_is_available.cpp | 2 +- rmw_fastrtps_cpp/src/rmw_subscription.cpp | 22 +++++------ .../src/rmw_topic_names_and_types.cpp | 3 +- .../src/rmw_trigger_guard_condition.cpp | 2 +- rmw_fastrtps_cpp/src/rmw_wait.cpp | 23 ++++++----- rmw_fastrtps_cpp/src/rmw_waitset.cpp | 2 +- .../src/types/guard_condition.hpp | 8 ++-- 29 files changed, 139 insertions(+), 143 deletions(-) diff --git a/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/TypeSupport_impl.hpp b/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/TypeSupport_impl.hpp index f22dd8019..bfbfff517 100644 --- a/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/TypeSupport_impl.hpp +++ b/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/TypeSupport_impl.hpp @@ -69,7 +69,7 @@ rosidl_generator_c__void__Array__init( if (!array) { return false; } - void * data = NULL; + void * data = nullptr; if (size) { data = static_cast(calloc(size, member_size)); if (!data) { @@ -94,7 +94,7 @@ rosidl_generator_c__void__Array__fini(rosidl_generator_c__void__Array * array) assert(array->capacity > 0); // finalize all array elements free(array->data); - array->data = NULL; + array->data = nullptr; array->size = 0; array->capacity = 0; } else { @@ -186,7 +186,7 @@ static size_t calculateMaxAlign(const MembersType * members) break; case ::rosidl_typesupport_introspection_cpp::ROS_TYPE_MESSAGE: { - const MembersType * sub_members = (const MembersType *)member.members_->data; + auto sub_members = (const MembersType *)member.members_->data; alignment = calculateMaxAlign(sub_members); } break; @@ -269,7 +269,7 @@ size_t get_array_size_and_assign_field( size_t sub_members_size, size_t max_align) { - std::vector * vector = reinterpret_cast *>(field); + auto vector = reinterpret_cast *>(field); void * ptr = reinterpret_cast(sub_members_size); size_t vsize = vector->size() / reinterpret_cast(align_(max_align, ptr)); if (member->is_upper_bound_ && vsize > member->array_size_) { @@ -286,8 +286,7 @@ size_t get_array_size_and_assign_field( void * & subros_message, size_t, size_t) { - rosidl_generator_c__void__Array * tmparray = - static_cast(field); + auto tmparray = static_cast(field); if (member->is_upper_bound_ && tmparray->size > member->array_size_) { throw std::runtime_error("vector overcomes the maximum length"); } @@ -362,7 +361,7 @@ bool TypeSupport::serializeROSmessage( break; case ::rosidl_typesupport_introspection_cpp::ROS_TYPE_MESSAGE: { - const MembersType * sub_members = (const MembersType *)member->members_->data; + auto sub_members = (const MembersType *)member->members_->data; serializeROSmessage(ser, sub_members, field); } break; @@ -411,7 +410,7 @@ bool TypeSupport::serializeROSmessage( break; case ::rosidl_typesupport_introspection_cpp::ROS_TYPE_MESSAGE: { - const MembersType * sub_members = + auto sub_members = static_cast(member->members_->data); void * subros_message = nullptr; size_t array_size = 0; @@ -455,7 +454,7 @@ void deserialize_array( if (member->array_size_ && !member->is_upper_bound_) { deser.deserializeArray(static_cast(field), member->array_size_); } else { - std::vector & vector = *reinterpret_cast *>(field); + auto & vector = *reinterpret_cast *>(field); if (call_new) { new(&vector) std::vector; } @@ -533,7 +532,7 @@ inline size_t get_submessage_array_deserialize( uint32_t vsize = 0; // Deserialize length deser >> vsize; - std::vector * vector = reinterpret_cast *>(field); + auto vector = reinterpret_cast *>(field); if (call_new) { new(vector) std::vector; } @@ -556,8 +555,7 @@ inline size_t get_submessage_array_deserialize( // Deserialize length uint32_t vsize = 0; deser >> vsize; - rosidl_generator_c__void__Array * tmparray = - static_cast(field); + auto tmparray = static_cast(field); rosidl_generator_c__void__Array__init(tmparray, vsize, sub_members_size); subros_message = reinterpret_cast(tmparray->data); return vsize; @@ -618,7 +616,7 @@ bool TypeSupport::deserializeROSmessage( break; case ::rosidl_typesupport_introspection_cpp::ROS_TYPE_MESSAGE: { - const MembersType * sub_members = (const MembersType *)member->members_->data; + auto sub_members = (const MembersType *)member->members_->data; deserializeROSmessage(deser, sub_members, field, call_new); } break; @@ -667,7 +665,7 @@ bool TypeSupport::deserializeROSmessage( break; case ::rosidl_typesupport_introspection_cpp::ROS_TYPE_MESSAGE: { - const MembersType * sub_members = (const MembersType *)member->members_->data; + auto sub_members = (const MembersType *)member->members_->data; void * subros_message = nullptr; size_t array_size = 0; size_t sub_members_size = sub_members->size_of_; @@ -748,8 +746,7 @@ size_t TypeSupport::calculateMaxSerializedSize( break; case ::rosidl_typesupport_introspection_cpp::ROS_TYPE_MESSAGE: { - const MembersType * sub_members = - static_cast(member->members_->data); + auto sub_members = static_cast(member->members_->data); current_alignment += calculateMaxSerializedSize(sub_members, current_alignment); } break; @@ -800,8 +797,7 @@ size_t TypeSupport::calculateMaxSerializedSize( break; case ::rosidl_typesupport_introspection_cpp::ROS_TYPE_MESSAGE: { - const MembersType * sub_members = - static_cast(member->members_->data); + auto sub_members = static_cast(member->members_->data); for (size_t index = 0; index < array_size; ++index) { current_alignment += calculateMaxSerializedSize(sub_members, current_alignment); } @@ -871,7 +867,7 @@ bool TypeSupport::serialize( assert(data); assert(payload); - eprosima::fastcdr::Cdr * ser = static_cast(data); + auto ser = static_cast(data); if (payload->max_size >= ser->getSerializedDataLength()) { payload->length = static_cast(ser->getSerializedDataLength()); payload->encapsulation = ser->endianness() == @@ -889,7 +885,7 @@ bool TypeSupport::deserialize(SerializedPayload_t * payload, void * assert(data); assert(payload); - eprosima::fastcdr::FastBuffer * buffer = static_cast(data); + auto buffer = static_cast(data); buffer->resize(payload->length); memcpy(buffer->getBuffer(), payload->data, payload->length); return true; @@ -900,7 +896,7 @@ std::function TypeSupport::getSerializedSizeProvider(vo { assert(data); - eprosima::fastcdr::Cdr * ser = static_cast(data); + auto ser = static_cast(data); return [ser]() -> uint32_t {return static_cast(ser->getSerializedDataLength());}; } diff --git a/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/custom_client_info.hpp b/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/custom_client_info.hpp index 8452fedaf..ea91da2b7 100644 --- a/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/custom_client_info.hpp +++ b/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/custom_client_info.hpp @@ -54,7 +54,7 @@ class ClientListener : public eprosima::fastrtps::SubscriberListener public: explicit ClientListener(CustomClientInfo * info) : info_(info), list_has_data_(false), - conditionMutex_(NULL), conditionVariable_(NULL) {} + conditionMutex_(nullptr), conditionVariable_(nullptr) {} void @@ -73,7 +73,7 @@ class ClientListener : public eprosima::fastrtps::SubscriberListener if (info_->writer_guid_ == response.sample_identity_.writer_guid()) { std::lock_guard lock(internalMutex_); - if (conditionMutex_ != NULL) { + if (conditionMutex_ != nullptr) { std::unique_lock clock(*conditionMutex_); list.push_back(response); // the change to list_has_data_ needs to be mutually exclusive with @@ -97,7 +97,7 @@ class ClientListener : public eprosima::fastrtps::SubscriberListener std::lock_guard lock(internalMutex_); CustomClientResponse response; - if (conditionMutex_ != NULL) { + if (conditionMutex_ != nullptr) { std::unique_lock clock(*conditionMutex_); if (!list.empty()) { response = list.front(); @@ -127,8 +127,8 @@ class ClientListener : public eprosima::fastrtps::SubscriberListener detachCondition() { std::lock_guard lock(internalMutex_); - conditionMutex_ = NULL; - conditionVariable_ = NULL; + conditionMutex_ = nullptr; + conditionVariable_ = nullptr; } bool diff --git a/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/custom_service_info.hpp b/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/custom_service_info.hpp index 5fc2e6058..935ff5ec9 100644 --- a/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/custom_service_info.hpp +++ b/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/custom_service_info.hpp @@ -54,7 +54,7 @@ class ServiceListener : public eprosima::fastrtps::SubscriberListener public: explicit ServiceListener(CustomServiceInfo * info) : info_(info), list_has_data_(false), - conditionMutex_(NULL), conditionVariable_(NULL) + conditionMutex_(nullptr), conditionVariable_(nullptr) { (void)info_; } @@ -75,7 +75,7 @@ class ServiceListener : public eprosima::fastrtps::SubscriberListener std::lock_guard lock(internalMutex_); - if (conditionMutex_ != NULL) { + if (conditionMutex_ != nullptr) { std::unique_lock clock(*conditionMutex_); list.push_back(request); // the change to list_has_data_ needs to be mutually exclusive with @@ -98,7 +98,7 @@ class ServiceListener : public eprosima::fastrtps::SubscriberListener std::lock_guard lock(internalMutex_); CustomServiceRequest request; - if (conditionMutex_ != NULL) { + if (conditionMutex_ != nullptr) { std::unique_lock clock(*conditionMutex_); if (!list.empty()) { request = list.front(); @@ -128,8 +128,8 @@ class ServiceListener : public eprosima::fastrtps::SubscriberListener detachCondition() { std::lock_guard lock(internalMutex_); - conditionMutex_ = NULL; - conditionVariable_ = NULL; + conditionMutex_ = nullptr; + conditionVariable_ = nullptr; } bool diff --git a/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/custom_subscriber_info.hpp b/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/custom_subscriber_info.hpp index 00329a0eb..1558ee073 100644 --- a/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/custom_subscriber_info.hpp +++ b/rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/custom_subscriber_info.hpp @@ -38,7 +38,7 @@ class SubListener : public eprosima::fastrtps::SubscriberListener public: explicit SubListener(CustomSubscriberInfo * info) : data_(0), - conditionMutex_(NULL), conditionVariable_(NULL) + conditionMutex_(nullptr), conditionVariable_(nullptr) { // Field is not used right now (void)info; @@ -58,7 +58,7 @@ class SubListener : public eprosima::fastrtps::SubscriberListener (void)sub; std::lock_guard lock(internalMutex_); - if (conditionMutex_ != NULL) { + if (conditionMutex_ != nullptr) { std::unique_lock clock(*conditionMutex_); // the change to data_ needs to be mutually exclusive with rmw_wait() // which checks hasData() and decides if wait() needs to be called @@ -82,8 +82,8 @@ class SubListener : public eprosima::fastrtps::SubscriberListener detachCondition() { std::lock_guard lock(internalMutex_); - conditionMutex_ = NULL; - conditionVariable_ = NULL; + conditionMutex_ = nullptr; + conditionVariable_ = nullptr; } bool @@ -97,7 +97,7 @@ class SubListener : public eprosima::fastrtps::SubscriberListener { std::lock_guard lock(internalMutex_); - if (conditionMutex_ != NULL) { + if (conditionMutex_ != nullptr) { std::unique_lock clock(*conditionMutex_); --data_; } else { diff --git a/rmw_fastrtps_cpp/src/client_service_common.cpp b/rmw_fastrtps_cpp/src/client_service_common.cpp index ebcfa533b..6535f7fde 100644 --- a/rmw_fastrtps_cpp/src/client_service_common.cpp +++ b/rmw_fastrtps_cpp/src/client_service_common.cpp @@ -27,7 +27,7 @@ get_request_ptr(const void * untyped_service_members, const char * typesupport) untyped_service_members); } RMW_SET_ERROR_MSG("Unknown typesupport identifier"); - return NULL; + return nullptr; } const void * @@ -41,5 +41,5 @@ get_response_ptr(const void * untyped_service_members, const char * typesupport) untyped_service_members); } RMW_SET_ERROR_MSG("Unknown typesupport identifier"); - return NULL; + return nullptr; } diff --git a/rmw_fastrtps_cpp/src/client_service_common.hpp b/rmw_fastrtps_cpp/src/client_service_common.hpp index 638a2b5c3..f7878b2a4 100644 --- a/rmw_fastrtps_cpp/src/client_service_common.hpp +++ b/rmw_fastrtps_cpp/src/client_service_common.hpp @@ -23,7 +23,7 @@ const void * get_request_ptr(const void * untyped_service_members) auto service_members = static_cast(untyped_service_members); if (!service_members) { RMW_SET_ERROR_MSG("service members handle is null"); - return NULL; + return nullptr; } return service_members->request_members_; } @@ -36,7 +36,7 @@ const void * get_response_ptr(const void * untyped_service_members) auto service_members = static_cast(untyped_service_members); if (!service_members) { RMW_SET_ERROR_MSG("service members handle is null"); - return NULL; + return nullptr; } return service_members->response_members_; } diff --git a/rmw_fastrtps_cpp/src/get_client.cpp b/rmw_fastrtps_cpp/src/get_client.cpp index 301f17ce3..175c9e301 100644 --- a/rmw_fastrtps_cpp/src/get_client.cpp +++ b/rmw_fastrtps_cpp/src/get_client.cpp @@ -24,12 +24,12 @@ eprosima::fastrtps::Publisher * get_request_publisher(rmw_client_t * client) { if (!client) { - return NULL; + return nullptr; } if (client->implementation_identifier != eprosima_fastrtps_identifier) { - return NULL; + return nullptr; } - CustomClientInfo * impl = static_cast(client->data); + auto impl = static_cast(client->data); return impl->request_publisher_; } @@ -37,12 +37,12 @@ eprosima::fastrtps::Subscriber * get_response_subscriber(rmw_client_t * client) { if (!client) { - return NULL; + return nullptr; } if (client->implementation_identifier != eprosima_fastrtps_identifier) { - return NULL; + return nullptr; } - CustomClientInfo * impl = static_cast(client->data); + auto impl = static_cast(client->data); return impl->response_subscriber_; } diff --git a/rmw_fastrtps_cpp/src/get_participant.cpp b/rmw_fastrtps_cpp/src/get_participant.cpp index 36f8d6e42..f20d46932 100644 --- a/rmw_fastrtps_cpp/src/get_participant.cpp +++ b/rmw_fastrtps_cpp/src/get_participant.cpp @@ -24,12 +24,12 @@ eprosima::fastrtps::Participant * get_participant(rmw_node_t * node) { if (!node) { - return NULL; + return nullptr; } if (node->implementation_identifier != eprosima_fastrtps_identifier) { - return NULL; + return nullptr; } - CustomParticipantInfo * impl = static_cast(node->data); + auto impl = static_cast(node->data); return impl->participant; } diff --git a/rmw_fastrtps_cpp/src/get_publisher.cpp b/rmw_fastrtps_cpp/src/get_publisher.cpp index fb5c6a60a..3a2cf0ea3 100644 --- a/rmw_fastrtps_cpp/src/get_publisher.cpp +++ b/rmw_fastrtps_cpp/src/get_publisher.cpp @@ -24,12 +24,12 @@ eprosima::fastrtps::Publisher * get_publisher(rmw_publisher_t * publisher) { if (!publisher) { - return NULL; + return nullptr; } if (publisher->implementation_identifier != eprosima_fastrtps_identifier) { - return NULL; + return nullptr; } - CustomPublisherInfo * impl = static_cast(publisher->data); + auto impl = static_cast(publisher->data); return impl->publisher_; } diff --git a/rmw_fastrtps_cpp/src/get_service.cpp b/rmw_fastrtps_cpp/src/get_service.cpp index 2d533a1a5..1af63baff 100644 --- a/rmw_fastrtps_cpp/src/get_service.cpp +++ b/rmw_fastrtps_cpp/src/get_service.cpp @@ -24,12 +24,12 @@ eprosima::fastrtps::Subscriber * get_request_subscriber(rmw_service_t * service) { if (!service) { - return NULL; + return nullptr; } if (service->implementation_identifier != eprosima_fastrtps_identifier) { - return NULL; + return nullptr; } - CustomServiceInfo * impl = static_cast(service->data); + auto impl = static_cast(service->data); return impl->request_subscriber_; } @@ -37,12 +37,12 @@ eprosima::fastrtps::Publisher * get_response_publisher(rmw_service_t * service) { if (!service) { - return NULL; + return nullptr; } if (service->implementation_identifier != eprosima_fastrtps_identifier) { - return NULL; + return nullptr; } - CustomServiceInfo * impl = static_cast(service->data); + auto impl = static_cast(service->data); return impl->response_publisher_; } diff --git a/rmw_fastrtps_cpp/src/get_subscriber.cpp b/rmw_fastrtps_cpp/src/get_subscriber.cpp index 62f85ee19..8bec35177 100644 --- a/rmw_fastrtps_cpp/src/get_subscriber.cpp +++ b/rmw_fastrtps_cpp/src/get_subscriber.cpp @@ -24,12 +24,12 @@ eprosima::fastrtps::Subscriber * get_subscriber(rmw_subscription_t * subscription) { if (!subscription) { - return NULL; + return nullptr; } if (subscription->implementation_identifier != eprosima_fastrtps_identifier) { - return NULL; + return nullptr; } - CustomSubscriberInfo * impl = static_cast(subscription->data); + auto impl = static_cast(subscription->data); return impl->subscriber_; } diff --git a/rmw_fastrtps_cpp/src/rmw_client.cpp b/rmw_fastrtps_cpp/src/rmw_client.cpp index af8b115a2..d2e0b5971 100644 --- a/rmw_fastrtps_cpp/src/rmw_client.cpp +++ b/rmw_fastrtps_cpp/src/rmw_client.cpp @@ -42,34 +42,34 @@ rmw_create_client( { if (!node) { RMW_SET_ERROR_MSG("node handle is null"); - return NULL; + return nullptr; } if (node->implementation_identifier != eprosima_fastrtps_identifier) { RMW_SET_ERROR_MSG("node handle not from this implementation"); - return NULL; + return nullptr; } if (!service_name || strlen(service_name) == 0) { RMW_SET_ERROR_MSG("client topic is null or empty string"); - return NULL; + return nullptr; } if (!qos_policies) { RMW_SET_ERROR_MSG("qos_profile is null"); - return NULL; + return nullptr; } - const CustomParticipantInfo * impl = static_cast(node->data); + auto impl = static_cast(node->data); if (!impl) { RMW_SET_ERROR_MSG("node impl is null"); - return NULL; + return nullptr; } Participant * participant = impl->participant; if (!participant) { RMW_SET_ERROR_MSG("participant handle is null"); - return NULL; + return nullptr; } const rosidl_service_type_support_t * type_support = get_service_typesupport_handle( @@ -79,7 +79,7 @@ rmw_create_client( type_supports, rosidl_typesupport_introspection_cpp::typesupport_identifier); if (!type_support) { RMW_SET_ERROR_MSG("type support not from this implementation"); - return NULL; + return nullptr; } } @@ -182,7 +182,7 @@ rmw_create_client( goto fail; } info->request_publisher_ = - Domain::createPublisher(participant, publisherParam, NULL); + Domain::createPublisher(participant, publisherParam, nullptr); if (!info->request_publisher_) { RMW_SET_ERROR_MSG("create_publisher() could not create publisher"); goto fail; @@ -241,7 +241,7 @@ rmw_create_client( } rmw_client_free(rmw_client); - return NULL; + return nullptr; } rmw_ret_t @@ -257,7 +257,7 @@ rmw_destroy_client(rmw_node_t * node, rmw_client_t * client) return RMW_RET_ERROR; } - CustomClientInfo * info = static_cast(client->data); + auto info = static_cast(client->data); if (info != nullptr) { if (info->response_subscriber_ != nullptr) { Domain::removeSubscriber(info->response_subscriber_); diff --git a/rmw_fastrtps_cpp/src/rmw_count.cpp b/rmw_fastrtps_cpp/src/rmw_count.cpp index 47c721e4f..6c684fe1c 100644 --- a/rmw_fastrtps_cpp/src/rmw_count.cpp +++ b/rmw_fastrtps_cpp/src/rmw_count.cpp @@ -46,7 +46,7 @@ rmw_count_publishers( return RMW_RET_ERROR; } - CustomParticipantInfo * impl = static_cast(node->data); + auto impl = static_cast(node->data); std::map> unfiltered_topics; WriterInfo * slave_target = impl->secondaryPubListener; diff --git a/rmw_fastrtps_cpp/src/rmw_get_gid_for_publisher.cpp b/rmw_fastrtps_cpp/src/rmw_get_gid_for_publisher.cpp index ced05cf05..7bf074082 100644 --- a/rmw_fastrtps_cpp/src/rmw_get_gid_for_publisher.cpp +++ b/rmw_fastrtps_cpp/src/rmw_get_gid_for_publisher.cpp @@ -39,7 +39,7 @@ rmw_get_gid_for_publisher(const rmw_publisher_t * publisher, rmw_gid_t * gid) return RMW_RET_ERROR; } - const CustomPublisherInfo * info = static_cast(publisher->data); + auto info = static_cast(publisher->data); if (!info) { RMW_SET_ERROR_MSG("publisher info handle is null"); diff --git a/rmw_fastrtps_cpp/src/rmw_node.cpp b/rmw_fastrtps_cpp/src/rmw_node.cpp index 09153b064..1a6499c42 100644 --- a/rmw_fastrtps_cpp/src/rmw_node.cpp +++ b/rmw_fastrtps_cpp/src/rmw_node.cpp @@ -56,12 +56,12 @@ create_node( { if (!name) { RMW_SET_ERROR_MSG("name is null"); - return NULL; + return nullptr; } if (!namespace_) { RMW_SET_ERROR_MSG("namespace_ is null"); - return NULL; + return nullptr; } eprosima::fastrtps::Log::SetVerbosity(eprosima::fastrtps::Log::Error); @@ -77,7 +77,7 @@ create_node( Participant * participant = Domain::createParticipant(participantAttrs); if (!participant) { RMW_SET_ERROR_MSG("create_node() could not create participant"); - return NULL; + return nullptr; } graph_guard_condition = rmw_create_guard_condition(); @@ -155,7 +155,7 @@ create_node( if (participant) { Domain::removeParticipant(participant); } - return NULL; + return nullptr; } bool @@ -188,7 +188,7 @@ rmw_create_node( { if (!name) { RMW_SET_ERROR_MSG("name is null"); - return NULL; + return nullptr; } if (!security_options) { RMW_SET_ERROR_MSG("security_options is null"); @@ -228,13 +228,13 @@ rmw_create_node( participantAttrs.rtps.properties = property_policy; } else if (security_options->enforce_security) { RMW_SET_ERROR_MSG("couldn't find all security files!"); - return NULL; + return nullptr; } #else RMW_SET_ERROR_MSG( "This Fast-RTPS version doesn't have the security libraries\n" "Please compile Fast-RTPS using the -DSECURITY=ON CMake option"); - return NULL; + return nullptr; #endif } return create_node(name, namespace_, participantAttrs); @@ -254,7 +254,7 @@ rmw_destroy_node(rmw_node_t * node) return RMW_RET_ERROR; } - CustomParticipantInfo * impl = static_cast(node->data); + auto impl = static_cast(node->data); if (!impl) { RMW_SET_ERROR_MSG("node impl is null"); return RMW_RET_ERROR; @@ -296,10 +296,10 @@ rmw_destroy_node(rmw_node_t * node) const rmw_guard_condition_t * rmw_node_get_graph_guard_condition(const rmw_node_t * node) { - CustomParticipantInfo * impl = static_cast(node->data); + auto impl = static_cast(node->data); if (!impl) { RMW_SET_ERROR_MSG("node impl is null"); - return NULL; + return nullptr; } return impl->graph_guard_condition; } diff --git a/rmw_fastrtps_cpp/src/rmw_node_names.cpp b/rmw_fastrtps_cpp/src/rmw_node_names.cpp index 8ae891e85..b99468263 100644 --- a/rmw_fastrtps_cpp/src/rmw_node_names.cpp +++ b/rmw_fastrtps_cpp/src/rmw_node_names.cpp @@ -50,7 +50,7 @@ rmw_get_node_names( return RMW_RET_ERROR; } - CustomParticipantInfo * impl = static_cast(node->data); + auto impl = static_cast(node->data); Participant * participant = impl->participant; auto participant_names = participant->getParticipantNames(); diff --git a/rmw_fastrtps_cpp/src/rmw_publish.cpp b/rmw_fastrtps_cpp/src/rmw_publish.cpp index 000a3e663..b65d3485b 100644 --- a/rmw_fastrtps_cpp/src/rmw_publish.cpp +++ b/rmw_fastrtps_cpp/src/rmw_publish.cpp @@ -37,7 +37,7 @@ rmw_publish(const rmw_publisher_t * publisher, const void * ros_message) return RMW_RET_ERROR; } - CustomPublisherInfo * info = static_cast(publisher->data); + auto info = static_cast(publisher->data); assert(info); eprosima::fastcdr::FastBuffer buffer; diff --git a/rmw_fastrtps_cpp/src/rmw_publisher.cpp b/rmw_fastrtps_cpp/src/rmw_publisher.cpp index 60846a70e..7b7ab92eb 100644 --- a/rmw_fastrtps_cpp/src/rmw_publisher.cpp +++ b/rmw_fastrtps_cpp/src/rmw_publisher.cpp @@ -36,34 +36,34 @@ rmw_create_publisher( { if (!node) { RMW_SET_ERROR_MSG("node handle is null"); - return NULL; + return nullptr; } if (node->implementation_identifier != eprosima_fastrtps_identifier) { RMW_SET_ERROR_MSG("node handle not from this implementation"); - return NULL; + return nullptr; } if (!topic_name || strlen(topic_name) == 0) { RMW_SET_ERROR_MSG("publisher topic is null or empty string"); - return NULL; + return nullptr; } if (!qos_policies) { RMW_SET_ERROR_MSG("qos_profile is null"); - return NULL; + return nullptr; } - const CustomParticipantInfo * impl = static_cast(node->data); + auto impl = static_cast(node->data); if (!impl) { RMW_SET_ERROR_MSG("node impl is null"); - return NULL; + return nullptr; } Participant * participant = impl->participant; if (!participant) { RMW_SET_ERROR_MSG("participant handle is null"); - return NULL; + return nullptr; } const rosidl_message_type_support_t * type_support = get_message_typesupport_handle( @@ -73,7 +73,7 @@ rmw_create_publisher( type_supports, rosidl_typesupport_introspection_cpp::typesupport_identifier); if (!type_support) { RMW_SET_ERROR_MSG("type support not from this implementation"); - return NULL; + return nullptr; } } @@ -139,7 +139,7 @@ rmw_create_publisher( goto fail; } - info->publisher_ = Domain::createPublisher(participant, publisherParam, NULL); + info->publisher_ = Domain::createPublisher(participant, publisherParam, nullptr); if (!info->publisher_) { RMW_SET_ERROR_MSG("create_publisher() could not create publisher"); @@ -181,7 +181,7 @@ rmw_create_publisher( rmw_publisher_free(rmw_publisher); } - return NULL; + return nullptr; } rmw_ret_t @@ -207,13 +207,13 @@ rmw_destroy_publisher(rmw_node_t * node, rmw_publisher_t * publisher) return RMW_RET_ERROR; } - CustomPublisherInfo * info = static_cast(publisher->data); + auto info = static_cast(publisher->data); if (info != nullptr) { if (info->publisher_ != nullptr) { Domain::removePublisher(info->publisher_); } if (info->type_support_ != nullptr) { - CustomParticipantInfo * impl = static_cast(node->data); + auto impl = static_cast(node->data); if (!impl) { RMW_SET_ERROR_MSG("node impl is null"); return RMW_RET_ERROR; diff --git a/rmw_fastrtps_cpp/src/rmw_request.cpp b/rmw_fastrtps_cpp/src/rmw_request.cpp index 0642a88e7..8a2ef2ea3 100644 --- a/rmw_fastrtps_cpp/src/rmw_request.cpp +++ b/rmw_fastrtps_cpp/src/rmw_request.cpp @@ -47,7 +47,7 @@ rmw_send_request( return RMW_RET_ERROR; } - CustomClientInfo * info = static_cast(client->data); + auto info = static_cast(client->data); assert(info); eprosima::fastcdr::FastBuffer buffer; @@ -92,7 +92,7 @@ rmw_take_request( return RMW_RET_ERROR; } - CustomServiceInfo * info = static_cast(service->data); + auto info = static_cast(service->data); assert(info); CustomServiceRequest request = info->listener_->getRequest(); diff --git a/rmw_fastrtps_cpp/src/rmw_response.cpp b/rmw_fastrtps_cpp/src/rmw_response.cpp index 4dc2b0195..7c57dec9b 100644 --- a/rmw_fastrtps_cpp/src/rmw_response.cpp +++ b/rmw_fastrtps_cpp/src/rmw_response.cpp @@ -47,7 +47,7 @@ rmw_take_response( return RMW_RET_ERROR; } - CustomClientInfo * info = static_cast(client->data); + auto info = static_cast(client->data); assert(info); CustomClientResponse response = info->listener_->getResponse(); @@ -84,7 +84,7 @@ rmw_send_response( return RMW_RET_ERROR; } - CustomServiceInfo * info = static_cast(service->data); + auto info = static_cast(service->data); assert(info); eprosima::fastcdr::FastBuffer buffer; diff --git a/rmw_fastrtps_cpp/src/rmw_service.cpp b/rmw_fastrtps_cpp/src/rmw_service.cpp index 1edfbc19e..0c85110f8 100644 --- a/rmw_fastrtps_cpp/src/rmw_service.cpp +++ b/rmw_fastrtps_cpp/src/rmw_service.cpp @@ -52,34 +52,34 @@ rmw_create_service( { if (!node) { RMW_SET_ERROR_MSG("node handle is null"); - return NULL; + return nullptr; } if (node->implementation_identifier != eprosima_fastrtps_identifier) { RMW_SET_ERROR_MSG("node handle not from this implementation"); - return NULL; + return nullptr; } if (!service_name || strlen(service_name) == 0) { RMW_SET_ERROR_MSG("service topic is null or empty string"); - return NULL; + return nullptr; } if (!qos_policies) { RMW_SET_ERROR_MSG("qos_profile is null"); - return NULL; + return nullptr; } const CustomParticipantInfo * impl = static_cast(node->data); if (!impl) { RMW_SET_ERROR_MSG("node impl is null"); - return NULL; + return nullptr; } Participant * participant = impl->participant; if (!participant) { RMW_SET_ERROR_MSG("participant handle is null"); - return NULL; + return nullptr; } const rosidl_service_type_support_t * type_support = get_service_typesupport_handle( @@ -89,7 +89,7 @@ rmw_create_service( type_supports, rosidl_typesupport_introspection_cpp::typesupport_identifier); if (!type_support) { RMW_SET_ERROR_MSG("type support not from this implementation"); - return NULL; + return nullptr; } } @@ -192,7 +192,7 @@ rmw_create_service( goto fail; } info->response_publisher_ = - Domain::createPublisher(participant, publisherParam, NULL); + Domain::createPublisher(participant, publisherParam, nullptr); if (!info->response_publisher_) { RMW_SET_ERROR_MSG("create_publisher() could not create publisher"); goto fail; @@ -243,7 +243,7 @@ rmw_create_service( } rmw_service_free(rmw_service); - return NULL; + return nullptr; } rmw_ret_t diff --git a/rmw_fastrtps_cpp/src/rmw_service_names_and_types.cpp b/rmw_fastrtps_cpp/src/rmw_service_names_and_types.cpp index b1f9b738f..2994a183d 100644 --- a/rmw_fastrtps_cpp/src/rmw_service_names_and_types.cpp +++ b/rmw_fastrtps_cpp/src/rmw_service_names_and_types.cpp @@ -56,7 +56,7 @@ rmw_get_service_names_and_types( return RMW_RET_ERROR; } - CustomParticipantInfo * impl = static_cast(node->data); + auto impl = static_cast(node->data); // Access the slave Listeners, which are the ones that have the topicnamesandtypes member // Get info from publisher and subscriber diff --git a/rmw_fastrtps_cpp/src/rmw_service_server_is_available.cpp b/rmw_fastrtps_cpp/src/rmw_service_server_is_available.cpp index 2a0028882..d2f686538 100644 --- a/rmw_fastrtps_cpp/src/rmw_service_server_is_available.cpp +++ b/rmw_fastrtps_cpp/src/rmw_service_server_is_available.cpp @@ -56,7 +56,7 @@ rmw_service_server_is_available( return RMW_RET_ERROR; } - CustomClientInfo * client_info = static_cast(client->data); + auto client_info = static_cast(client->data); if (!client_info) { RMW_SET_ERROR_MSG("client info handle is null"); return RMW_RET_ERROR; diff --git a/rmw_fastrtps_cpp/src/rmw_subscription.cpp b/rmw_fastrtps_cpp/src/rmw_subscription.cpp index 76b74673a..28b9c54a6 100644 --- a/rmw_fastrtps_cpp/src/rmw_subscription.cpp +++ b/rmw_fastrtps_cpp/src/rmw_subscription.cpp @@ -40,34 +40,34 @@ rmw_create_subscription( { if (!node) { RMW_SET_ERROR_MSG("node handle is null"); - return NULL; + return nullptr; } if (node->implementation_identifier != eprosima_fastrtps_identifier) { RMW_SET_ERROR_MSG("node handle not from this implementation"); - return NULL; + return nullptr; } if (!topic_name || strlen(topic_name) == 0) { RMW_SET_ERROR_MSG("subscription topic is null or empty string"); - return NULL; + return nullptr; } if (!qos_policies) { RMW_SET_ERROR_MSG("qos_profile is null"); - return NULL; + return nullptr; } - const CustomParticipantInfo * impl = static_cast(node->data); + auto impl = static_cast(node->data); if (!impl) { RMW_SET_ERROR_MSG("node impl is null"); - return NULL; + return nullptr; } Participant * participant = impl->participant; if (!participant) { RMW_SET_ERROR_MSG("participant handle is null"); - return NULL; + return nullptr; } const rosidl_message_type_support_t * type_support = get_message_typesupport_handle( @@ -77,7 +77,7 @@ rmw_create_subscription( type_supports, rosidl_typesupport_introspection_cpp::typesupport_identifier); if (!type_support) { RMW_SET_ERROR_MSG("type support not from this implementation"); - return NULL; + return nullptr; } } @@ -166,7 +166,7 @@ rmw_create_subscription( rmw_subscription_free(rmw_subscription); } - return NULL; + return nullptr; } rmw_ret_t @@ -192,7 +192,7 @@ rmw_destroy_subscription(rmw_node_t * node, rmw_subscription_t * subscription) return RMW_RET_ERROR; } - CustomSubscriberInfo * info = static_cast(subscription->data); + auto info = static_cast(subscription->data); if (info != nullptr) { if (info->subscriber_ != nullptr) { @@ -202,7 +202,7 @@ rmw_destroy_subscription(rmw_node_t * node, rmw_subscription_t * subscription) delete info->listener_; } if (info->type_support_ != nullptr) { - CustomParticipantInfo * impl = static_cast(node->data); + auto impl = static_cast(node->data); if (!impl) { RMW_SET_ERROR_MSG("node impl is null"); return RMW_RET_ERROR; diff --git a/rmw_fastrtps_cpp/src/rmw_topic_names_and_types.cpp b/rmw_fastrtps_cpp/src/rmw_topic_names_and_types.cpp index aad486747..3d8befec7 100644 --- a/rmw_fastrtps_cpp/src/rmw_topic_names_and_types.cpp +++ b/rmw_fastrtps_cpp/src/rmw_topic_names_and_types.cpp @@ -52,6 +52,7 @@ rmw_get_topic_names_and_types( RMW_SET_ERROR_MSG_ALLOC("null node handle", *allocator) return RMW_RET_INVALID_ARGUMENT; } + rmw_ret_t ret = rmw_names_and_types_check_zero(topic_names_and_types); if (ret != RMW_RET_OK) { return ret; @@ -63,7 +64,7 @@ rmw_get_topic_names_and_types( return RMW_RET_ERROR; } - CustomParticipantInfo * impl = static_cast(node->data); + auto impl = static_cast(node->data); // Access the slave Listeners, which are the ones that have the topicnamesandtypes member // Get info from publisher and subscriber diff --git a/rmw_fastrtps_cpp/src/rmw_trigger_guard_condition.cpp b/rmw_fastrtps_cpp/src/rmw_trigger_guard_condition.cpp index 8dfe9aab6..e842bb855 100644 --- a/rmw_fastrtps_cpp/src/rmw_trigger_guard_condition.cpp +++ b/rmw_fastrtps_cpp/src/rmw_trigger_guard_condition.cpp @@ -32,7 +32,7 @@ rmw_trigger_guard_condition(const rmw_guard_condition_t * guard_condition_handle return RMW_RET_ERROR; } - GuardCondition * guard_condition = static_cast(guard_condition_handle->data); + auto guard_condition = static_cast(guard_condition_handle->data); guard_condition->trigger(); return RMW_RET_OK; } diff --git a/rmw_fastrtps_cpp/src/rmw_wait.cpp b/rmw_fastrtps_cpp/src/rmw_wait.cpp index 94e1f867f..0cbb441c3 100644 --- a/rmw_fastrtps_cpp/src/rmw_wait.cpp +++ b/rmw_fastrtps_cpp/src/rmw_wait.cpp @@ -34,7 +34,7 @@ check_waitset_for_data( if (subscriptions) { for (size_t i = 0; i < subscriptions->subscriber_count; ++i) { void * data = subscriptions->subscribers[i]; - CustomSubscriberInfo * custom_subscriber_info = static_cast(data); + auto custom_subscriber_info = static_cast(data); // Short circuiting out of this function is possible if (custom_subscriber_info && custom_subscriber_info->listener_->hasData()) { return true; @@ -65,7 +65,7 @@ check_waitset_for_data( if (guard_conditions) { for (size_t i = 0; i < guard_conditions->guard_condition_count; ++i) { void * data = guard_conditions->guard_conditions[i]; - GuardCondition * guard_condition = static_cast(data); + auto guard_condition = static_cast(data); if (guard_condition && guard_condition->hasTriggered()) { return true; } @@ -108,7 +108,7 @@ rmw_wait( if (subscriptions) { for (size_t i = 0; i < subscriptions->subscriber_count; ++i) { void * data = subscriptions->subscribers[i]; - CustomSubscriberInfo * custom_subscriber_info = static_cast(data); + auto custom_subscriber_info = static_cast(data); custom_subscriber_info->listener_->attachCondition(conditionMutex, conditionVariable); } } @@ -124,7 +124,7 @@ rmw_wait( if (services) { for (size_t i = 0; i < services->service_count; ++i) { void * data = services->services[i]; - CustomServiceInfo * custom_service_info = static_cast(data); + auto custom_service_info = static_cast(data); custom_service_info->listener_->attachCondition(conditionMutex, conditionVariable); } } @@ -132,7 +132,7 @@ rmw_wait( if (guard_conditions) { for (size_t i = 0; i < guard_conditions->guard_condition_count; ++i) { void * data = guard_conditions->guard_conditions[i]; - GuardCondition * guard_condition = static_cast(data); + auto guard_condition = static_cast(data); guard_condition->attachCondition(conditionMutex, conditionVariable); } } @@ -152,7 +152,7 @@ rmw_wait( if (subscriptions) { for (size_t i = 0; hasToWait && i < subscriptions->subscriber_count; ++i) { void * data = subscriptions->subscribers[i]; - CustomSubscriberInfo * custom_subscriber_info = static_cast(data); + auto custom_subscriber_info = static_cast(data); if (custom_subscriber_info->listener_->hasData()) { hasToWait = false; } @@ -172,7 +172,7 @@ rmw_wait( if (services) { for (size_t i = 0; hasToWait && i < services->service_count; ++i) { void * data = services->services[i]; - CustomServiceInfo * custom_service_info = static_cast(data); + auto custom_service_info = static_cast(data); if (custom_service_info->listener_->hasData()) { hasToWait = false; } @@ -182,7 +182,7 @@ rmw_wait( if (guard_conditions) { for (size_t i = 0; hasToWait && i < guard_conditions->guard_condition_count; ++i) { void * data = guard_conditions->guard_conditions[i]; - GuardCondition * guard_condition = static_cast(data); + auto guard_condition = static_cast(data); if (guard_condition->hasTriggered()) { hasToWait = false; } @@ -223,7 +223,7 @@ rmw_wait( if (subscriptions) { for (size_t i = 0; i < subscriptions->subscriber_count; ++i) { void * data = subscriptions->subscribers[i]; - CustomSubscriberInfo * custom_subscriber_info = static_cast(data); + auto custom_subscriber_info = static_cast(data); custom_subscriber_info->listener_->detachCondition(); if (!custom_subscriber_info->listener_->hasData()) { subscriptions->subscribers[i] = 0; @@ -242,11 +242,10 @@ rmw_wait( } } - if (services) { for (size_t i = 0; i < services->service_count; ++i) { void * data = services->services[i]; - CustomServiceInfo * custom_service_info = static_cast(data); + auto custom_service_info = static_cast(data); custom_service_info->listener_->detachCondition(); if (!custom_service_info->listener_->hasData()) { services->services[i] = 0; @@ -257,7 +256,7 @@ rmw_wait( if (guard_conditions) { for (size_t i = 0; i < guard_conditions->guard_condition_count; ++i) { void * data = guard_conditions->guard_conditions[i]; - GuardCondition * guard_condition = static_cast(data); + auto guard_condition = static_cast(data); guard_condition->detachCondition(); if (!guard_condition->getHasTriggered()) { guard_conditions->guard_conditions[i] = 0; diff --git a/rmw_fastrtps_cpp/src/rmw_waitset.cpp b/rmw_fastrtps_cpp/src/rmw_waitset.cpp index c61692e6b..478bd1818 100644 --- a/rmw_fastrtps_cpp/src/rmw_waitset.cpp +++ b/rmw_fastrtps_cpp/src/rmw_waitset.cpp @@ -71,7 +71,7 @@ rmw_destroy_waitset(rmw_waitset_t * waitset) return RMW_RET_ERROR) auto result = RMW_RET_OK; - CustomWaitsetInfo * waitset_info = static_cast(waitset->data); + auto waitset_info = static_cast(waitset->data); if (!waitset_info) { RMW_SET_ERROR_MSG("waitset info is null"); return RMW_RET_ERROR; diff --git a/rmw_fastrtps_cpp/src/types/guard_condition.hpp b/rmw_fastrtps_cpp/src/types/guard_condition.hpp index 8f78a7e0f..6ae157726 100644 --- a/rmw_fastrtps_cpp/src/types/guard_condition.hpp +++ b/rmw_fastrtps_cpp/src/types/guard_condition.hpp @@ -27,14 +27,14 @@ class GuardCondition public: GuardCondition() : hasTriggered_(false), - conditionMutex_(NULL), conditionVariable_(NULL) {} + conditionMutex_(nullptr), conditionVariable_(nullptr) {} void trigger() { std::lock_guard lock(internalMutex_); - if (conditionMutex_ != NULL) { + if (conditionMutex_ != nullptr) { std::unique_lock clock(*conditionMutex_); // the change to hasTriggered_ needs to be mutually exclusive with // rmw_wait() which checks hasTriggered() and decides if wait() needs to @@ -59,8 +59,8 @@ class GuardCondition detachCondition() { std::lock_guard lock(internalMutex_); - conditionMutex_ = NULL; - conditionVariable_ = NULL; + conditionMutex_ = nullptr; + conditionVariable_ = nullptr; } bool From 048ead9cf52c65ed31d86299a4eaa5d184375898 Mon Sep 17 00:00:00 2001 From: Denise Eng Date: Thu, 26 Oct 2017 11:40:17 -0400 Subject: [PATCH 3/4] Remove string allocation in the count of subscribers and publishers --- rmw_fastrtps_cpp/src/rmw_count.cpp | 56 +++++++----------------------- 1 file changed, 12 insertions(+), 44 deletions(-) diff --git a/rmw_fastrtps_cpp/src/rmw_count.cpp b/rmw_fastrtps_cpp/src/rmw_count.cpp index 47c721e4f..7768317f5 100644 --- a/rmw_fastrtps_cpp/src/rmw_count.cpp +++ b/rmw_fastrtps_cpp/src/rmw_count.cpp @@ -48,37 +48,21 @@ rmw_count_publishers( CustomParticipantInfo * impl = static_cast(node->data); - std::map> unfiltered_topics; WriterInfo * slave_target = impl->secondaryPubListener; slave_target->mapmutex.lock(); + *count = 0; for (auto it : slave_target->topicNtypes) { - for (auto & itt : it.second) { - // truncate the ROS specific prefix - auto topic_fqdn = _demangle_if_ros_topic(it.first); - unfiltered_topics[topic_fqdn].push_back(itt); + auto topic_fqdn = _demangle_if_ros_topic(it.first); + if (topic_fqdn == topic_name) { + *count += it.second.size(); } } slave_target->mapmutex.unlock(); - // get count - auto it = unfiltered_topics.find(topic_name); - if (it == unfiltered_topics.end()) { - *count = 0; - } else { - *count = it->second.size(); - } - - RCUTILS_LOG_DEBUG_NAMED( - "rmw_fastrtps_cpp", - "looking for subscriber topic: %s", topic_name) - for (auto it : unfiltered_topics) { - RCUTILS_LOG_DEBUG_NAMED( - "rmw_fastrtps_cpp", - "available topic: %s", it.first.c_str()) - } RCUTILS_LOG_DEBUG_NAMED( "rmw_fastrtps_cpp", - "number of matches: %zu", *count) + "looking for subscriber topic: %s, number of matches: %zu", + topic_name, *count) return RMW_RET_OK; } @@ -103,37 +87,21 @@ rmw_count_subscribers( CustomParticipantInfo * impl = static_cast(node->data); - std::map> unfiltered_topics; ReaderInfo * slave_target = impl->secondarySubListener; + *count = 0; slave_target->mapmutex.lock(); for (auto it : slave_target->topicNtypes) { - for (auto & itt : it.second) { - // truncate the ROS specific prefix - auto topic_fqdn = _demangle_if_ros_topic(it.first); - unfiltered_topics[topic_fqdn].push_back(itt); + auto topic_fqdn = _demangle_if_ros_topic(it.first); + if (topic_fqdn == topic_name) { + *count += it.second.size(); } } slave_target->mapmutex.unlock(); - // get_count - auto it = unfiltered_topics.find(topic_name); - if (it == unfiltered_topics.end()) { - *count = 0; - } else { - *count = it->second.size(); - } - - RCUTILS_LOG_DEBUG_NAMED( - "rmw_fastrtps_cpp", - "looking for subscriber topic: %s", topic_name) - for (auto it : unfiltered_topics) { - RCUTILS_LOG_DEBUG_NAMED( - "rmw_fastrtps_cpp", - "available topic: %s", it.first.c_str()) - } RCUTILS_LOG_DEBUG_NAMED( "rmw_fastrtps_cpp", - "number of matches: %zu", *count) + "looking for subscriber topic: %s, number of matches: %zu", + topic_name, *count) return RMW_RET_OK; } From 4e22c3ec493c26fcda0c620ab7f0f17149a24008 Mon Sep 17 00:00:00 2001 From: Ethan Gao <16472154+gaoethan@users.noreply.github.com> Date: Fri, 27 Oct 2017 23:46:57 +0800 Subject: [PATCH 4/4] Fix rmw_fastrtps dead code (#163) * * Fix rmw_fastrtps dead code Dead code in API rmw_create_subscription() becasue the condition "rmw_subscription" cannot be true in the "fail" clauses, the execution cannot reach this statement: rmw_subscription_free(rmw_subscription); finally, the "rmw_subscribtion" is free by rmw_destroy_subscription() when it's not a nullptr Dead code in API rmw_create_publisher() because the condition "rmw_publisher" cannot be true in the "fail" clauses, the execution cannot reach this statement: rmw_publisher_free(rmw_publisher); finally, the "rmw_publisher" is free by rmw_destroy_publisher() when it's not a nullptr Signed-off-by: Ethan Gao * * Add memory allocation checking for topic name this memory allocation checking avoids the unintended behaviour which derives from unknown memory free issue at rmw_destroy_publisher Signed-off-by: Ethan Gao * publiser -> publisher Signed-off-by: Chris Lalancette * tweak the log information more accurate Signed-off-by: Ethan Gao --- rmw_fastrtps_cpp/src/rmw_publisher.cpp | 6 ++++++ rmw_fastrtps_cpp/src/rmw_subscription.cpp | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/rmw_fastrtps_cpp/src/rmw_publisher.cpp b/rmw_fastrtps_cpp/src/rmw_publisher.cpp index 7b7ab92eb..e50aef3df 100644 --- a/rmw_fastrtps_cpp/src/rmw_publisher.cpp +++ b/rmw_fastrtps_cpp/src/rmw_publisher.cpp @@ -168,6 +168,12 @@ rmw_create_publisher( rmw_publisher->implementation_identifier = eprosima_fastrtps_identifier; rmw_publisher->data = info; rmw_publisher->topic_name = reinterpret_cast(rmw_allocate(strlen(topic_name) + 1)); + + if (!rmw_publisher->topic_name) { + RMW_SET_ERROR_MSG("failed to allocate memory for publisher topic name"); + goto fail; + } + memcpy(const_cast(rmw_publisher->topic_name), topic_name, strlen(topic_name) + 1); return rmw_publisher; diff --git a/rmw_fastrtps_cpp/src/rmw_subscription.cpp b/rmw_fastrtps_cpp/src/rmw_subscription.cpp index 28b9c54a6..7c222865c 100644 --- a/rmw_fastrtps_cpp/src/rmw_subscription.cpp +++ b/rmw_fastrtps_cpp/src/rmw_subscription.cpp @@ -150,6 +150,12 @@ rmw_create_subscription( rmw_subscription->data = info; rmw_subscription->topic_name = reinterpret_cast(rmw_allocate(strlen(topic_name) + 1)); + + if (!rmw_subscription->topic_name) { + RMW_SET_ERROR_MSG("failed to allocate memory for subscription topic name"); + goto fail; + } + memcpy(const_cast(rmw_subscription->topic_name), topic_name, strlen(topic_name) + 1); return rmw_subscription;