diff --git a/include/zenoh/api/base.hxx b/include/zenoh/api/base.hxx index aa6eb892..d96b1545 100644 --- a/include/zenoh/api/base.hxx +++ b/include/zenoh/api/base.hxx @@ -18,6 +18,7 @@ #include #include +#include "../detail/availability_checks.hxx" #include "../zenohc.hxx" namespace zenoh { @@ -72,8 +73,12 @@ class Owned { Owned& operator=(Owned&& v) { if (this != &v) { ::z_drop(::z_move(this->_0)); - _0 = v._0; - ::z_internal_null(&v._0); + if constexpr (detail::is_take_from_loaned_available_v) { + ::z_take_from_loaned(&this->_0, ::z_loan_mut(v._0)); + } else { + _0 = v._0; + ::z_internal_null(&v._0); + } } return *this; } @@ -84,16 +89,16 @@ class Owned { explicit Owned(OwnedType* pv) { if (pv != nullptr) { - _0 = *pv; - ::z_internal_null(pv); - } else + if constexpr (detail::is_take_from_loaned_available_v) { + ::z_take_from_loaned(&this->_0, ::z_loan_mut(*pv)); + } else { + _0 = *pv; + ::z_internal_null(pv); + } + } else { ::z_internal_null(&this->_0); + } } }; -namespace detail { -struct null_object_t {}; -inline constexpr null_object_t null_object{}; -} // namespace detail - } // namespace zenoh diff --git a/include/zenoh/api/interop.hxx b/include/zenoh/api/interop.hxx index 811fb432..24d18d68 100644 --- a/include/zenoh/api/interop.hxx +++ b/include/zenoh/api/interop.hxx @@ -17,27 +17,6 @@ #include "base.hxx" -namespace zenoh::detail { -template -struct is_loan_available : std::false_type {}; - -template -struct is_loan_available()))>> : std::true_type {}; - -template -inline constexpr bool is_loan_available_v = is_loan_available::value; - -template -struct is_loan_mut_available : std::false_type {}; - -template -struct is_loan_mut_available()))>> : std::true_type {}; - -template -inline constexpr bool is_loan_mut_available_v = is_loan_mut_available::value; - -} // namespace zenoh::detail - namespace zenoh::interop { /// @brief Get zenoh-c representation of trivially copyable zenoh-cpp object. diff --git a/include/zenoh/detail/availability_checks.hxx b/include/zenoh/detail/availability_checks.hxx new file mode 100644 index 00000000..f86f74bb --- /dev/null +++ b/include/zenoh/detail/availability_checks.hxx @@ -0,0 +1,54 @@ +// +// Copyright (c) 2024 ZettaScale Technology +// +// This program and the accompanying materials are made available under the +// terms of the Eclipse Public License 2.0 which is available at +// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 +// which is available at https://www.apache.org/licenses/LICENSE-2.0. +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// +// Contributors: +// ZettaScale Zenoh Team, +#pragma once + +#include +#include + +#include "../zenohc.hxx" + +// namespace zenoh::detail +namespace zenoh::detail { +template +struct is_loan_available : std::false_type {}; + +template +struct is_loan_available()))>> : std::true_type {}; + +template +inline constexpr bool is_loan_available_v = is_loan_available::value; + +template +struct is_loan_mut_available : std::false_type {}; + +template +struct is_loan_mut_available()))>> : std::true_type {}; + +template +inline constexpr bool is_loan_mut_available_v = is_loan_mut_available::value; + +template +struct is_take_from_loaned_available : std::false_type {}; + +template +struct is_take_from_loaned_available< + T, std::void_t(), std::declval::type*>()))>> : std::true_type {}; + +template +inline constexpr bool is_take_from_loaned_available_v = is_take_from_loaned_available::value; + +struct null_object_t {}; +inline constexpr null_object_t null_object{}; + +} // namespace zenoh::detail diff --git a/scripts/build_standalone_examples.sh b/scripts/build_standalone_examples.sh index 2b84e5d6..4826c91e 100755 --- a/scripts/build_standalone_examples.sh +++ b/scripts/build_standalone_examples.sh @@ -15,7 +15,7 @@ absolute_install_location=$(cd $1; pwd) bash $SCRIPT_DIR/build_local.sh $SCRIPT_DIR/../examples/simple/zenohc $absolute_install_location -if [ "$BUILD_PICO" == "ON" ]; then +if [ "$BUILD_PICO" == "ON" ] || [ "$BUILD_PICO" == "TRUE" ] || [ "$BUILD_PICO" == "1" ]; then #build examples requiring zenoh-pico bash $SCRIPT_DIR/build_local.sh $SCRIPT_DIR/../examples/simple/universal $absolute_install_location bash $SCRIPT_DIR/build_local.sh $SCRIPT_DIR/../examples/simple/zenohpico $absolute_install_location diff --git a/scripts/install_from_git.sh b/scripts/install_from_git.sh index e235c3f3..fa140417 100755 --- a/scripts/install_from_git.sh +++ b/scripts/install_from_git.sh @@ -20,7 +20,7 @@ if [ "$#" -ge 3 ]; then USE_SHARED_MEMORY=$3 fi -if [ "$USE_UNSTABLE" == "TRUE" ]; then +if [ "$USE_UNSTABLE" == "TRUE" ] || [ "$USE_UNSTABLE" == "ON" ] || [ "$USE_UNSTABLE" == "1" ]; then USE_UNSTABLE_PICO="1" fi @@ -36,7 +36,7 @@ mkdir -p $1 absolute_install_location=$(cd $1; pwd) #build zenoh-c bash $SCRIPT_DIR/install_local.sh $SCRIPT_DIR/../zenoh-c $absolute_install_location -DZENOHC_BUILD_WITH_UNSTABLE_API=$USE_UNSTABLE -DZENOHC_BUILD_WITH_SHARED_MEMORY=$USE_SHARED_MEMORY -if [ "$BUILD_PICO" == "ON" ]; then +if [ "$BUILD_PICO" == "ON" ] || [ "$BUILD_PICO" == "TRUE" ] || [ "$BUILD_PICO" == "1" ]; then #build zenoh-pico bash $SCRIPT_DIR/install_local.sh $SCRIPT_DIR/../zenoh-pico $absolute_install_location -DZ_FEATURE_UNSTABLE_API=$USE_UNSTABLE_PICO fi diff --git a/tests/universal/details.cxx b/tests/universal/details.cxx new file mode 100644 index 00000000..34a65f1c --- /dev/null +++ b/tests/universal/details.cxx @@ -0,0 +1,25 @@ +// +// Copyright (c) 2025 ZettaScale Technology +// +// This program and the accompanying materials are made available under the +// terms of the Eclipse Public License 2.0 which is available at +// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 +// which is available at https://www.apache.org/licenses/LICENSE-2.0. +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// +// Contributors: +// ZettaScale Zenoh Team, +// + +#include "zenoh.hxx" + +using namespace zenoh; + +static_assert(detail::is_take_from_loaned_available_v<::z_owned_session_t> == false); +static_assert(detail::is_take_from_loaned_available_v<::z_owned_hello_t>); +static_assert(detail::is_take_from_loaned_available_v<::z_owned_sample_t>); +static_assert(detail::is_take_from_loaned_available_v<::z_owned_reply_t>); +static_assert(detail::is_take_from_loaned_available_v<::z_owned_query_t>); + +int main() { return 0; } \ No newline at end of file diff --git a/zenoh-c b/zenoh-c index 26149368..af53af34 160000 --- a/zenoh-c +++ b/zenoh-c @@ -1 +1 @@ -Subproject commit 261493682c7dc54db3a07079315e009a2e7c1573 +Subproject commit af53af345cf7263b13954b4553b654c1d9c5cfb5 diff --git a/zenoh-pico b/zenoh-pico index 5d7a4902..1238f04f 160000 --- a/zenoh-pico +++ b/zenoh-pico @@ -1 +1 @@ -Subproject commit 5d7a4902d23a69e28cfe0499140dc5d4fb1c3a3e +Subproject commit 1238f04f5fd14161b6d0009b067a1f4a8a3a2acf