From 686dec18c6e578c09389dc2e3ba3e54d269d9225 Mon Sep 17 00:00:00 2001 From: Steven Palma Date: Tue, 13 Aug 2024 17:09:22 +0200 Subject: [PATCH 1/2] Replaced ament_vendor with ExternalProject --- zenoh_c_vendor/CMakeLists.txt | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/zenoh_c_vendor/CMakeLists.txt b/zenoh_c_vendor/CMakeLists.txt index 943ebb1d..0aea2753 100644 --- a/zenoh_c_vendor/CMakeLists.txt +++ b/zenoh_c_vendor/CMakeLists.txt @@ -8,7 +8,7 @@ if(NOT CMAKE_CXX_STANDARD) endif() find_package(ament_cmake REQUIRED) -find_package(ament_cmake_vendor_package REQUIRED) +# find_package(ament_cmake_vendor_package REQUIRED) # Disable default features and enable only the most useful ones. This reduces build time and footprint. # For a complete list of features see: https://github.com/eclipse-zenoh/zenoh/blob/main/zenoh/Cargo.toml @@ -23,11 +23,25 @@ set(ZENOHC_CARGO_FLAGS "--no-default-features$--features=shared-memor # - https://github.com/eclipse-zenoh/zenoh/pull/1022 (fix empty messages received if payload >btach size) # - https://github.com/eclipse-zenoh/zenoh-c/pull/358 (fix debian packaging issue: https://github.com/jspricke/ros-deb-builder-action/issues/49) # - https://github.com/eclipse-zenoh/zenoh/pull/1150 (fix deadlock issue https://github.com/ros2/rmw_zenoh/issues/182) -ament_vendor(zenoh_c_vendor - VCS_URL https://github.com/eclipse-zenoh/zenoh-c - VCS_VERSION dev/1.0.0 - CMAKE_ARGS - "-DZENOHC_CARGO_FLAGS=${ZENOHC_CARGO_FLAGS}" +# ament_vendor(zenoh_c_vendor +# VCS_URL https://github.com/eclipse-zenoh/zenoh-c +# VCS_VERSION dev/1.0.0 +# CMAKE_ARGS +# "-DZENOHC_CARGO_FLAGS=${ZENOHC_CARGO_FLAGS}" +# ) + +include(ExternalProject) +set(ZENOHC_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}) +ExternalProject_Add(zenohc + PREFIX ${CMAKE_BINARY_DIR}/zenohc + GIT_REPOSITORY https://github.com/eclipse-zenoh/zenoh-c.git + GIT_TAG dev/1.0.0 + CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${ZENOHC_INSTALL_DIR} -DZENOHC_CARGO_FLAGS=${ZENOHC_CARGO_FLAGS} + BUILD_IN_SOURCE 1 +) +add_custom_target(zenoh_c_vendor ALL + DEPENDS zenohc ) +list(APPEND CMAKE_PREFIX_PATH ${ZENOHC_INSTALL_DIR}) -ament_package() +ament_package() \ No newline at end of file From aace581c78e900ed1cc4036ad483d03a6730aef4 Mon Sep 17 00:00:00 2001 From: yuanyuyuan Date: Sun, 18 Aug 2024 22:18:54 +0800 Subject: [PATCH 2/2] fix: segmentation fault due to the unallocated query memory --- rmw_zenoh_cpp/src/detail/rmw_data_types.cpp | 6 +++--- rmw_zenoh_cpp/src/detail/rmw_data_types.hpp | 2 +- rmw_zenoh_cpp/src/rmw_init.cpp | 2 -- rmw_zenoh_cpp/src/rmw_zenoh.cpp | 21 +++++++-------------- 4 files changed, 11 insertions(+), 20 deletions(-) diff --git a/rmw_zenoh_cpp/src/detail/rmw_data_types.cpp b/rmw_zenoh_cpp/src/detail/rmw_data_types.cpp index d39084ae..0d288964 100644 --- a/rmw_zenoh_cpp/src/detail/rmw_data_types.cpp +++ b/rmw_zenoh_cpp/src/detail/rmw_data_types.cpp @@ -465,15 +465,15 @@ void sub_data_handler(const z_loaned_sample_t *sample, void *data) { ///============================================================================= ZenohQuery::ZenohQuery(const z_loaned_query_t *query) { - z_query_clone(query_, query); + z_query_clone(&query_, query); } ///============================================================================= -ZenohQuery::~ZenohQuery() { z_drop(z_move(*query_)); } +ZenohQuery::~ZenohQuery() { z_drop(z_move(query_)); } ///============================================================================= const z_loaned_query_t *ZenohQuery::get_query() const { - return z_query_loan(query_); + return z_query_loan(&query_); } //============================================================================== diff --git a/rmw_zenoh_cpp/src/detail/rmw_data_types.hpp b/rmw_zenoh_cpp/src/detail/rmw_data_types.hpp index 0b314d35..b6744971 100644 --- a/rmw_zenoh_cpp/src/detail/rmw_data_types.hpp +++ b/rmw_zenoh_cpp/src/detail/rmw_data_types.hpp @@ -216,7 +216,7 @@ class ZenohQuery final const z_loaned_query_t * get_query() const; private: - z_owned_query_t * query_{nullptr}; + z_owned_query_t query_; }; ///============================================================================= diff --git a/rmw_zenoh_cpp/src/rmw_init.cpp b/rmw_zenoh_cpp/src/rmw_init.cpp index 66f67b67..2a8f8772 100644 --- a/rmw_zenoh_cpp/src/rmw_init.cpp +++ b/rmw_zenoh_cpp/src/rmw_init.cpp @@ -386,8 +386,6 @@ rmw_ret_t rmw_init(const rmw_init_options_t *options, rmw_context_t *context) { free_shm_provider.cancel(); restore_context.cancel(); - - return RMW_RET_OK; } diff --git a/rmw_zenoh_cpp/src/rmw_zenoh.cpp b/rmw_zenoh_cpp/src/rmw_zenoh.cpp index 26689c5f..662ff494 100644 --- a/rmw_zenoh_cpp/src/rmw_zenoh.cpp +++ b/rmw_zenoh_cpp/src/rmw_zenoh.cpp @@ -1416,17 +1416,14 @@ rmw_subscription_t *rmw_create_subscription( sub_options.reliability = Z_RELIABILITY_RELIABLE; } - ; - - ze_owned_querying_subscriber_t *sub = - &std::get(sub_data->sub); - ze_declare_querying_subscriber(sub, z_loan(context_impl->session), + ze_owned_querying_subscriber_t sub; + if (ze_declare_querying_subscriber(&sub, z_loan(context_impl->session), z_loan(keyexpr), z_move(callback), - &sub_options); - if (!z_check(*sub)) { + &sub_options)) { RMW_SET_ERROR_MSG("unable to create zenoh subscription"); return nullptr; } + sub_data->sub = sub; } else { // Create a regular subscriber for all other durability settings. z_subscriber_options_t sub_options; @@ -1435,13 +1432,12 @@ rmw_subscription_t *rmw_create_subscription( sub_options.reliability = Z_RELIABILITY_RELIABLE; } - z_owned_subscriber_t *sub = &std::get(sub_data->sub); - z_declare_subscriber(sub, z_loan(context_impl->session), z_loan(keyexpr), - z_move(callback), &sub_options); - if (!z_check(*sub)) { + z_owned_subscriber_t sub; + if(z_declare_subscriber(&sub, z_loan(context_impl->session), z_loan(keyexpr), z_move(callback), &sub_options)) { RMW_SET_ERROR_MSG("unable to create zenoh subscription"); return nullptr; } + sub_data->sub = sub; } auto undeclare_z_sub = rcpputils::make_scope_exit([sub_data]() { @@ -2374,9 +2370,6 @@ rmw_ret_t rmw_send_request(const rmw_client_t *client, const void *ros_request, z_owned_closure_reply_t callback; z_closure(&callback, rmw_zenoh_cpp::client_data_handler, NULL, client_data); - - // TODO(yuyuan): z_owned_closure_reply_t zn_closure_reply is replaced with a - // moved callback z_get(z_loan(context_impl->session), z_loan(client_data->keyexpr), "", z_move(callback), &opts);