From 6cd1de4d6a1d50ef78d6878136efacda94f38a39 Mon Sep 17 00:00:00 2001 From: Denis Biryukov Date: Tue, 29 Oct 2024 18:12:23 +0100 Subject: [PATCH 1/4] implement loaned take --- docs/api.rst | 19 ++++- include/zenoh-pico/api/macros.h | 93 +++++++++++++++++++++---- include/zenoh-pico/api/olv_macros.h | 31 +++++---- include/zenoh-pico/api/primitives.h | 2 + include/zenoh-pico/collections/intmap.h | 7 ++ include/zenoh-pico/collections/vec.h | 7 +- include/zenoh-pico/net/reply.h | 2 +- include/zenoh-pico/protocol/core.h | 2 + src/api/api.c | 42 ++++++++--- src/net/reply.c | 7 +- src/net/sample.c | 7 +- src/protocol/core.c | 5 ++ src/protocol/keyexpr.c | 5 +- src/session/query.c | 6 +- src/session/utils.c | 5 ++ zenohpico.pc | 2 +- 16 files changed, 187 insertions(+), 55 deletions(-) diff --git a/docs/api.rst b/docs/api.rst index b76f7a040..28e2e9fb7 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -62,7 +62,7 @@ See details at :ref:`owned_types_concept` .. c:function:: z_loaned_slice_t * z_view_slice_loan_mut(z_view_slice_t * slice) .. c:function:: const z_loaned_slice_t * z_slice_loan(const z_owned_slice_t * slice) .. c:function:: z_loaned_slice_t * z_slice_loan_mut(z_owned_slice_t * slice) - +.. c:function:: z_result_t z_slice_loaned_take(z_owned_slice_t *dst, z_loaned_slice_t *src) String ------ @@ -108,7 +108,7 @@ See details at :ref:`owned_types_concept` .. c:function:: z_loaned_string_t * z_view_string_loan_mut(z_view_string_t * string) .. c:function:: const z_loaned_string_t * z_string_loan(const z_owned_string_t * string) .. c:function:: z_loaned_string_t * z_string_loan_mut(z_owned_string_t * string) - +.. c:function:: z_result_t z_string_loaned_take(z_owned_string_t *dst, z_loaned_string_t *src) String Array ------------ @@ -142,6 +142,7 @@ See details at :ref:`owned_types_concept` .. c:function:: void z_string_array_clone(z_owned_string_array_t * dst, const z_loaned_string_array_t * string_array) .. c:function:: const z_loaned_string_array_t * z_string_array_loan(const z_owned_string_array_t * string_array) .. c:function:: z_loaned_string_array_t * z_string_array_loan_mut(z_owned_string_array_t * string_array) +.. c:function:: z_result_t z_string_array_loaned_take(z_owned_string_array_t *dst, z_loaned_string_array_t *src) Common @@ -205,6 +206,7 @@ See details at :ref:`owned_types_concept` .. c:function:: z_loaned_keyexpr_t * z_view_keyexpr_loan_mut(z_view_keyexpr_t * keyexpr) .. c:function:: const z_loaned_keyexpr_t * z_keyexpr_loan(const z_owned_keyexpr_t * keyexpr) .. c:function:: z_loaned_keyexpr_t * z_keyexpr_loan_mut(z_owned_keyexpr_t * keyexpr) +.. c:function:: z_result_t z_keyexpr_loaned_take(z_owned_keyexpr_t *dst, z_loaned_keyexpr_t *src) Payload ------- @@ -261,6 +263,7 @@ See details at :ref:`owned_types_concept` .. c:function:: void z_bytes_clone(z_owned_bytes_t * dst, const z_loaned_bytes_t * bytes) .. c:function:: const z_loaned_bytes_t * z_bytes_loan(const z_owned_bytes_t * bytes) .. c:function:: z_loaned_bytes_t * z_bytes_loan_mut(z_owned_bytes_t * bytes) +.. c:function:: z_result_t z_bytes_loaned_take(z_owned_bytes_t *dst, z_loaned_bytes_t *src) .. c:function:: void z_bytes_writer_drop(z_moved_bytes_writer_t * bytes_writer) .. c:function:: void z_bytes_writer_clone(z_owned_bytes_writer_t * dst, const z_loaned_bytes_writer_t * bytes_writer) @@ -300,6 +303,7 @@ See details at :ref:`owned_types_concept` .. c:function:: void z_encoding_clone(z_owned_encoding_t * dst, const z_loaned_encoding_t * encoding) .. c:function:: const z_loaned_encoding_t * z_encoding_loan(const z_owned_encoding_t * encoding) .. c:function:: z_loaned_encoding_t * z_encoding_loan_mut(z_owned_encoding_t * encoding) +.. c:function:: z_result_t z_encoding_loaned_take(z_owned_encoding_t *dst, z_loaned_encoding_t *src) Predefined Encodings @@ -385,7 +389,8 @@ See details at :ref:`owned_types_concept` .. c:function:: void z_reply_err_drop(z_moved_reply_err_t * reply_err) .. c:function:: void z_reply_err_clone(z_owned_reply_err_t * dst, const z_loaned_reply_err_t * reply_err) .. c:function:: const z_loaned_reply_err_t * z_reply_err_loan(const z_owned_reply_err_t * reply_err) - +.. c:function:: z_loaned_reply_err_t * z_reply_err_loan_mut(z_owned_reply_err_t * reply_err) +.. c:function:: z_result_t z_reply_err_loaned_take(z_owned_reply_err_t *dst, z_loaned_reply_err_t *src) Sample ------ @@ -424,6 +429,8 @@ See details at :ref:`owned_types_concept` .. c:function:: void z_sample_drop(z_moved_sample_t * sample) .. c:function:: void z_sample_clone(z_owned_sample_t * dst, const z_loaned_sample_t * sample) .. c:function:: const z_loaned_sample_t * z_sample_loan(const z_owned_sample_t * sample) +.. c:function:: z_loaned_sample_t * z_sample_loan_mut(z_owned_sample_t * sample) +.. c:function:: z_result_t z_sample_loaned_take(z_owned_sample_t *dst, z_loaned_sample_t *src) Timestamp @@ -1103,6 +1110,8 @@ See details at :ref:`owned_types_concept` .. c:function:: void z_query_drop(z_moved_query_t * query) .. c:function:: void z_query_clone(z_owned_query_t * dst, const z_loaned_query_t * query) .. c:function:: const z_loaned_query_t * z_query_loan(const z_owned_query_t * query) +.. c:function:: z_loaned_query_t * z_query_loan_mut(z_owned_query_t * query) +.. c:function:: z_result_t z_query_loaned_take(z_owned_query_t *dst, z_loaned_query_t *src) Query ===== @@ -1149,6 +1158,8 @@ See details at :ref:`owned_types_concept` .. c:function:: void z_reply_drop(z_moved_reply_t * reply) .. c:function:: void z_reply_clone(z_owned_reply_t * dst, const z_loaned_reply_t * reply) .. c:function:: const z_loaned_reply_t * z_reply_loan(const z_owned_reply_t * reply) +.. c:function:: z_loaned_reply_t * z_reply_loan_mut(z_owned_reply_t * reply) +.. c:function:: z_result_t z_reply_loaned_take(z_owned_reply_t *dst, z_loaned_reply_t *src) Scouting @@ -1187,6 +1198,8 @@ See details at :ref:`owned_types_concept` .. c:function:: void z_hello_drop(z_moved_hello_t * hello) .. c:function:: void z_hello_clone(z_owned_hello_t * dst, const z_loaned_hello_t * hello) .. c:function:: const z_loaned_hello_t * z_hello_loan(const z_owned_hello_t * hello) +.. c:function:: z_loaned_hello_t * z_hello_loan(z_owned_hello_t * hello) +.. c:function:: z_result_t z_hello_loaned_take(z_owned_hello_t *dst, z_loaned_hello_t *src) Serialization diff --git a/include/zenoh-pico/api/macros.h b/include/zenoh-pico/api/macros.h index ca17781d0..9a47f6ab7 100644 --- a/include/zenoh-pico/api/macros.h +++ b/include/zenoh-pico/api/macros.h @@ -321,7 +321,32 @@ z_owned_slice_t* : z_slice_clone, \ z_owned_string_array_t* : z_string_array_clone, \ z_owned_config_t* : z_config_clone \ - )(x, y) + )(dst, src) + +/** + * Defines a generic function for moving of the ``z_owned_X_t`` types. + * + * Parameters: + * dst: The take destination. + * src: The instance to take contents from. + * + * Returns: + * `0` in case of success, negative error code otherwise. + */ +#define z_loaned_take(dst, src) _Generic((dst), \ + z_owned_keyexpr_t* : z_keyexpr_loaned_take, \ + z_owned_query_t* : z_query_loaned_take, \ + z_owned_sample_t* : z_sample_loaned_take, \ + z_owned_bytes_t* : z_bytes_loaned_take, \ + z_owned_encoding_t* : z_encoding_loaned_take, \ + z_owned_reply_err_t* : z_reply_err_loaned_take, \ + z_owned_reply_t* : z_reply_loaned_take, \ + z_owned_hello_t* : z_hello_loaned_take, \ + z_owned_string_t* : z_string_loaned_take, \ + z_owned_slice_t* : z_slice_loaned_take, \ + z_owned_string_array_t* : z_string_array_loaned_take, \ + z_owned_config_t* : z_config_loaned_take \ + )(dst, src) /** * Defines a generic function for making null object of any of the ``z_owned_X_t`` types. @@ -709,22 +734,64 @@ inline void z_take(z_owned_bytes_writer_t* this_, z_moved_bytes_writer_t* v) { z inline void z_take(ze_owned_serializer_t* this_, ze_moved_serializer_t* v) { ze_serializer_take(this_, v); } // z_clone definition -inline z_result_t z_clone(z_owned_bytes_t* dst, z_loaned_bytes_t* this_) { return z_bytes_clone(dst, this_); } -inline z_result_t z_clone(z_owned_config_t* dst, z_loaned_config_t* this_) { return z_config_clone(dst, this_); } -inline z_result_t z_clone(z_owned_encoding_t* dst, z_loaned_encoding_t* this_) { return z_encoding_clone(dst, this_); } -inline z_result_t z_clone(z_owned_keyexpr_t* dst, z_loaned_keyexpr_t* this_) { return z_keyexpr_clone(dst, this_); } -inline z_result_t z_clone(z_owned_query_t* dst, z_loaned_query_t* this_) { return z_query_clone(dst, this_); } -inline z_result_t z_clone(z_owned_reply_t* dst, z_loaned_reply_t* this_) { return z_reply_clone(dst, this_); } -inline z_result_t z_clone(z_owned_reply_err_t* dst, z_loaned_reply_err_t* this_) { +inline z_result_t z_clone(z_owned_bytes_t* dst, const z_loaned_bytes_t* this_) { return z_bytes_clone(dst, this_); } +inline z_result_t z_clone(z_owned_config_t* dst, const z_loaned_config_t* this_) { return z_config_clone(dst, this_); } +inline z_result_t z_clone(z_owned_encoding_t* dst, const const z_loaned_encoding_t* this_) { + return z_encoding_clone(dst, this_); +} +inline z_result_t z_clone(z_owned_keyexpr_t* dst, const z_loaned_keyexpr_t* this_) { + return z_keyexpr_clone(dst, this_); +} +inline z_result_t z_clone(z_owned_query_t* dst, const z_loaned_query_t* this_) { return z_query_clone(dst, this_); } +inline z_result_t z_clone(z_owned_reply_t* dst, const z_loaned_reply_t* this_) { return z_reply_clone(dst, this_); } +inline z_result_t z_clone(z_owned_reply_err_t* dst, const z_loaned_reply_err_t* this_) { return z_reply_err_clone(dst, this_); } -inline z_result_t z_clone(z_owned_sample_t* dst, z_loaned_sample_t* this_) { return z_sample_clone(dst, this_); } -inline z_result_t z_clone(z_owned_slice_t* dst, z_loaned_slice_t* this_) { return z_slice_clone(dst, this_); } -inline z_result_t z_clone(z_owned_string_t* dst, z_loaned_string_t* this_) { return z_string_clone(dst, this_); } -inline z_result_t z_clone(z_owned_string_array_t* dst, z_loaned_string_array_t* this_) { +inline z_result_t z_clone(z_owned_sample_t* dst, const z_loaned_sample_t* this_) { return z_sample_clone(dst, this_); } +inline z_result_t z_clone(z_owned_slice_t* dst, const z_loaned_slice_t* this_) { return z_slice_clone(dst, this_); } +inline z_result_t z_clone(z_owned_string_t* dst, const z_loaned_string_t* this_) { return z_string_clone(dst, this_); } +inline z_result_t z_clone(z_owned_string_array_t* dst, const z_loaned_string_array_t* this_) { return z_string_array_clone(dst, this_); } -inline z_result_t z_clone(z_owned_hello_t* dst, z_loaned_hello_t* this_) { return z_hello_clone(dst, this_); } +inline z_result_t z_clone(z_owned_hello_t* dst, const z_loaned_hello_t* this_) { return z_hello_clone(dst, this_); } + +// z_loaned_take definition +inline z_result_t z_loaned_take(z_owned_bytes_t* dst, z_loaned_bytes_t* this_) { + return z_bytes_loaned_take(dst, this_); +} +inline z_result_t z_loaned_take(z_owned_config_t* dst, z_loaned_config_t* this_) { + return z_config_loaned_take(dst, this_); +} +inline z_result_t z_loaned_take(z_owned_encoding_t* dst, z_loaned_encoding_t* this_) { + return z_encoding_loaned_take(dst, this_); +} +inline z_result_t z_loaned_take(z_owned_keyexpr_t* dst, z_loaned_keyexpr_t* this_) { + return z_keyexpr_loaned_take(dst, this_); +} +inline z_result_t z_loaned_take(z_owned_query_t* dst, z_loaned_query_t* this_) { + return z_query_loaned_take(dst, this_); +} +inline z_result_t z_loaned_take(z_owned_reply_t* dst, z_loaned_reply_t* this_) { + return z_reply_loaned_take(dst, this_); +} +inline z_result_t z_loaned_take(z_owned_reply_err_t* dst, z_loaned_reply_err_t* this_) { + return z_reply_err_loaned_take(dst, this_); +} +inline z_result_t z_loaned_take(z_owned_sample_t* dst, z_loaned_sample_t* this_) { + return z_sample_loaned_take(dst, this_); +} +inline z_result_t z_loaned_take(z_owned_slice_t* dst, z_loaned_slice_t* this_) { + return z_slice_loaned_take(dst, this_); +} +inline z_result_t z_loaned_take(z_owned_string_t* dst, z_loaned_string_t* this_) { + return z_string_loaned_take(dst, this_); +} +inline z_result_t z_loaned_take(z_owned_string_array_t* dst, z_loaned_string_array_t* this_) { + return z_string_array_loaned_take(dst, this_); +} +inline z_result_t z_loaned_take(z_owned_hello_t* dst, z_loaned_hello_t* this_) { + return z_hello_loaned_take(dst, this_); +} template struct z_loaned_to_owned_type_t {}; diff --git a/include/zenoh-pico/api/olv_macros.h b/include/zenoh-pico/api/olv_macros.h index ffa82285c..7c61804f2 100644 --- a/include/zenoh-pico/api/olv_macros.h +++ b/include/zenoh-pico/api/olv_macros.h @@ -68,9 +68,10 @@ void prefix##_##name##_take(prefix##_owned_##name##_t *obj, prefix##_moved_##name##_t *src); \ void prefix##_##name##_drop(prefix##_moved_##name##_t *obj); -#define _Z_OWNED_FUNCTIONS_DEF_PREFIX(prefix, name) \ - _Z_OWNED_FUNCTIONS_NO_COPY_DEF_PREFIX(prefix, name) \ - z_result_t prefix##_##name##_clone(prefix##_owned_##name##_t *obj, const prefix##_loaned_##name##_t *src); +#define _Z_OWNED_FUNCTIONS_DEF_PREFIX(prefix, name) \ + _Z_OWNED_FUNCTIONS_NO_COPY_DEF_PREFIX(prefix, name) \ + z_result_t prefix##_##name##_clone(prefix##_owned_##name##_t *obj, const prefix##_loaned_##name##_t *src); \ + z_result_t prefix##_##name##_take_loaned(prefix##_owned_##name##_t *dst, prefix##_loaned_##name##_t *src); #define _Z_OWNED_FUNCTIONS_NO_COPY_DEF(name) _Z_OWNED_FUNCTIONS_NO_COPY_DEF_PREFIX(z, name) #define _Z_OWNED_FUNCTIONS_DEF(name) _Z_OWNED_FUNCTIONS_DEF_PREFIX(z, name) @@ -117,15 +118,21 @@ if (obj != NULL) f_drop((&obj->_this._val)); \ } -#define _Z_OWNED_FUNCTIONS_VALUE_IMPL_PREFIX_INNER(prefix, type, name, f_check, f_null, f_copy, f_drop, attribute) \ - _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_IMPL_PREFIX_INNER(prefix, type, name, f_check, f_null, f_drop, attribute) \ - attribute prefix##_result_t prefix##_##name##_clone(prefix##_owned_##name##_t *obj, \ - const prefix##_loaned_##name##_t *src) { \ - return f_copy((&obj->_val), src); \ +#define _Z_OWNED_FUNCTIONS_VALUE_IMPL_PREFIX_INNER(prefix, type, name, f_check, f_null, f_copy, f_move, f_drop, \ + attribute) \ + _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_IMPL_PREFIX_INNER(prefix, type, name, f_check, f_null, f_drop, attribute) \ + attribute z_result_t prefix##_##name##_clone(prefix##_owned_##name##_t *obj, \ + const prefix##_loaned_##name##_t *src) { \ + return f_copy((&obj->_val), src); \ + } \ + attribute z_result_t prefix##_##name##_take_loaned(prefix##_owned_##name##_t *obj, \ + prefix##_loaned_##name##_t *src) { \ + f_move((&obj->_val), src); \ + return _Z_RES_OK; \ } -#define _Z_OWNED_FUNCTIONS_VALUE_IMP_PREFIX(prefix, type, name, f_check, f_null, f_copy, f_drop) \ - _Z_OWNED_FUNCTIONS_VALUE_IMPL_PREFIX_INNER(z, type, name, f_check, f_null, f_copy, f_drop, _ZP_NOTHING) +#define _Z_OWNED_FUNCTIONS_VALUE_IMP_PREFIX(prefix, type, name, f_check, f_null, f_copy, f_move, f_drop) \ + _Z_OWNED_FUNCTIONS_VALUE_IMPL_PREFIX_INNER(z, type, name, f_check, f_null, f_copy, f_move, f_drop, _ZP_NOTHING) #define _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_IMPL_PREFIX(prefix, type, name, f_check, f_null, f_drop) \ _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_IMPL_PREFIX_INNER(prefix, type, name, f_check, f_null, f_drop, _ZP_NOTHING) @@ -133,8 +140,8 @@ #define _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_IMPL(type, name, f_check, f_null, f_drop) \ _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_IMPL_PREFIX(z, type, name, f_check, f_null, f_drop) -#define _Z_OWNED_FUNCTIONS_VALUE_IMPL(type, name, f_check, f_null, f_copy, f_drop) \ - _Z_OWNED_FUNCTIONS_VALUE_IMP_PREFIX(z, type, name, f_check, f_null, f_copy, f_drop) +#define _Z_OWNED_FUNCTIONS_VALUE_IMPL(type, name, f_check, f_null, f_copy, f_move, f_drop) \ + _Z_OWNED_FUNCTIONS_VALUE_IMP_PREFIX(z, type, name, f_check, f_null, f_copy, f_move, f_drop) #define _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_INLINE_IMPL(type, name, f_check, f_null, f_drop) \ _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_IMPL_PREFIX_INNER(z, type, name, f_check, f_null, f_drop, static inline) diff --git a/include/zenoh-pico/api/primitives.h b/include/zenoh-pico/api/primitives.h index 0ad1a5d6a..6c10996f1 100644 --- a/include/zenoh-pico/api/primitives.h +++ b/include/zenoh-pico/api/primitives.h @@ -1804,6 +1804,8 @@ void z_query_reply_options_default(z_query_reply_options_t *options); z_result_t z_query_reply(const z_loaned_query_t *query, const z_loaned_keyexpr_t *keyexpr, z_moved_bytes_t *payload, const z_query_reply_options_t *options); +z_result_t z_query_loaned_take(z_owned_query_t *dst, z_loaned_query_t *src); + /** * Builds a :c:type:`z_query_reply_del_options_t` with default values. * diff --git a/include/zenoh-pico/collections/intmap.h b/include/zenoh-pico/collections/intmap.h index 136cf9772..9a586e30e 100644 --- a/include/zenoh-pico/collections/intmap.h +++ b/include/zenoh-pico/collections/intmap.h @@ -70,6 +70,10 @@ _z_int_void_map_t _z_int_void_map_clone(const _z_int_void_map_t *src, z_element_ void _z_int_void_map_clear(_z_int_void_map_t *map, z_element_free_f f); void _z_int_void_map_free(_z_int_void_map_t **map, z_element_free_f f); +static inline void _z_int_void_map_move(_z_int_void_map_t *dst, _z_int_void_map_t *src) { + *dst = *src; + *src = _z_int_void_map_make(src->_capacity); +} #define _Z_INT_MAP_DEFINE(name, type) \ typedef _z_int_void_map_entry_t name##_intmap_entry_t; \ @@ -115,6 +119,9 @@ void _z_int_void_map_free(_z_int_void_map_t **map, z_element_free_f f); } \ static inline void name##_intmap_free(name##_intmap_t **m) { \ _z_int_void_map_free(m, name##_intmap_entry_elem_free); \ + } \ + static inline void name##_intmap_move(name##_intmap_t *dst, name##_intmap_t *src) { \ + _z_int_void_map_move(dst, src); \ } #ifdef __cplusplus diff --git a/include/zenoh-pico/collections/vec.h b/include/zenoh-pico/collections/vec.h index d89acd93c..c63973793 100644 --- a/include/zenoh-pico/collections/vec.h +++ b/include/zenoh-pico/collections/vec.h @@ -80,6 +80,10 @@ typedef struct { _z_svec_t _z_svec_make(size_t capacity, size_t element_size); bool _z_svec_copy(_z_svec_t *dst, const _z_svec_t *src, z_element_copy_f copy, size_t element_size); +static inline void _z_svec_move(_z_svec_t *dst, _z_svec_t *src) { + *dst = *src; + *src = _z_svec_make(0, 0); +} size_t _z_svec_len(const _z_svec_t *v); bool _z_svec_is_empty(const _z_svec_t *v); @@ -116,7 +120,8 @@ void _z_svec_release(_z_svec_t *v); } \ static inline void name##_svec_reset(name##_svec_t *v) { _z_svec_reset(v, name##_elem_clear, sizeof(type)); } \ static inline void name##_svec_clear(name##_svec_t *v) { _z_svec_clear(v, name##_elem_clear, sizeof(type)); } \ - static inline void name##_svec_free(name##_svec_t **v) { _z_svec_free(v, name##_elem_clear, sizeof(type)); } + static inline void name##_svec_free(name##_svec_t **v) { _z_svec_free(v, name##_elem_clear, sizeof(type)); } \ + static inline void name##_svec_move(name##_svec_t *dst, name##_svec_t *src) { _z_svec_move(dst, src); } #ifdef __cplusplus } diff --git a/include/zenoh-pico/net/reply.h b/include/zenoh-pico/net/reply.h index df2a2742e..b195338df 100644 --- a/include/zenoh-pico/net/reply.h +++ b/include/zenoh-pico/net/reply.h @@ -80,7 +80,7 @@ typedef struct _z_reply_t { _z_reply_data_t data; } _z_reply_t; -_z_reply_t _z_reply_move(_z_reply_t *src_reply); +void _z_reply_move(_z_reply_t *dst, _z_reply_t *src); _z_reply_t _z_reply_null(void); void _z_reply_clear(_z_reply_t *src); diff --git a/include/zenoh-pico/protocol/core.h b/include/zenoh-pico/protocol/core.h index 40dd8355e..41b34f728 100644 --- a/include/zenoh-pico/protocol/core.h +++ b/include/zenoh-pico/protocol/core.h @@ -73,6 +73,7 @@ typedef struct { _z_timestamp_t _z_timestamp_duplicate(const _z_timestamp_t *tstamp); _z_timestamp_t _z_timestamp_null(void); void _z_timestamp_clear(_z_timestamp_t *tstamp); +void _z_timestamp_move(_z_timestamp_t *dst, _z_timestamp_t *src); bool _z_timestamp_check(const _z_timestamp_t *stamp); uint64_t _z_timestamp_ntp64_from_time(uint32_t seconds, uint32_t nanos); @@ -192,6 +193,7 @@ void _z_hello_clear(_z_hello_t *src); void _z_hello_free(_z_hello_t **hello); z_result_t _z_hello_copy(_z_hello_t *dst, const _z_hello_t *src); _z_hello_t _z_hello_null(void); +void _z_hello_move(_z_hello_t *dst, _z_hello_t *src); bool _z_hello_check(const _z_hello_t *hello); _Z_ELEM_DEFINE(_z_hello, _z_hello_t, _z_noop_size, _z_hello_clear, _z_noop_copy) diff --git a/src/api/api.c b/src/api/api.c index c76a9b32e..1f2d54d98 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -213,7 +213,7 @@ z_result_t zp_config_insert(z_loaned_config_t *config, uint8_t key, const char * } _Z_OWNED_FUNCTIONS_VALUE_IMPL(_z_encoding_t, encoding, _z_encoding_check, _z_encoding_null, _z_encoding_copy, - _z_encoding_clear) + _z_encoding_move, _z_encoding_clear) bool z_encoding_equals(const z_loaned_encoding_t *left, const z_loaned_encoding_t *right) { return left->id == right->id && _z_string_equals(&left->schema, &right->schema); @@ -464,22 +464,26 @@ z_result_t _z_config_copy(_z_config_t *dst, const _z_config_t *src) { return _Z_RES_OK; } void _z_config_drop(_z_config_t *config) { _z_str_intmap_clear(config); } -_Z_OWNED_FUNCTIONS_VALUE_IMPL(_z_config_t, config, _z_config_check, _z_config_null, _z_config_copy, _z_config_drop) +_Z_OWNED_FUNCTIONS_VALUE_IMPL(_z_config_t, config, _z_config_check, _z_config_null, _z_config_copy, _z_str_intmap_move, + _z_config_drop) -_Z_OWNED_FUNCTIONS_VALUE_IMPL(_z_string_t, string, _z_string_check, _z_string_null, _z_string_copy, _z_string_clear) +_Z_OWNED_FUNCTIONS_VALUE_IMPL(_z_string_t, string, _z_string_check, _z_string_null, _z_string_copy, _z_string_move, + _z_string_clear) bool _z_value_check(const _z_value_t *value) { return _z_encoding_check(&value->encoding) || _z_bytes_check(&value->payload); } -_Z_OWNED_FUNCTIONS_VALUE_IMPL(_z_value_t, reply_err, _z_value_check, _z_value_null, _z_value_copy, _z_value_clear) +_Z_OWNED_FUNCTIONS_VALUE_IMPL(_z_value_t, reply_err, _z_value_check, _z_value_null, _z_value_copy, _z_value_move, + _z_value_clear) _Z_OWNED_FUNCTIONS_VALUE_IMPL(_z_keyexpr_t, keyexpr, _z_keyexpr_check, _z_keyexpr_null, _z_keyexpr_copy, - _z_keyexpr_clear) + _z_keyexpr_move, _z_keyexpr_clear) _Z_VIEW_FUNCTIONS_IMPL(_z_keyexpr_t, keyexpr, _z_keyexpr_check, _z_keyexpr_null) _Z_VIEW_FUNCTIONS_IMPL(_z_string_t, string, _z_string_check, _z_string_null) _Z_VIEW_FUNCTIONS_IMPL(_z_slice_t, slice, _z_slice_check, _z_slice_empty) -_Z_OWNED_FUNCTIONS_VALUE_IMPL(_z_hello_t, hello, _z_hello_check, _z_hello_null, _z_hello_copy, _z_hello_clear) +_Z_OWNED_FUNCTIONS_VALUE_IMPL(_z_hello_t, hello, _z_hello_check, _z_hello_null, _z_hello_copy, _z_hello_move, + _z_hello_clear) z_id_t z_hello_zid(const z_loaned_hello_t *hello) { return hello->_zid; } @@ -519,9 +523,11 @@ z_result_t _z_string_array_copy(_z_string_svec_t *dst, const _z_string_svec_t *s return dst->_len == src->_len ? _Z_RES_OK : _Z_ERR_SYSTEM_OUT_OF_MEMORY; } _Z_OWNED_FUNCTIONS_VALUE_IMPL(_z_string_svec_t, string_array, _z_string_array_check, _z_string_array_null, - _z_string_array_copy, _z_string_svec_clear) -_Z_OWNED_FUNCTIONS_VALUE_IMPL(_z_slice_t, slice, _z_slice_check, _z_slice_empty, _z_slice_copy, _z_slice_clear) -_Z_OWNED_FUNCTIONS_VALUE_IMPL(_z_bytes_t, bytes, _z_bytes_check, _z_bytes_null, _z_bytes_copy, _z_bytes_drop) + _z_string_array_copy, _z_string_svec_move, _z_string_svec_clear) +_Z_OWNED_FUNCTIONS_VALUE_IMPL(_z_slice_t, slice, _z_slice_check, _z_slice_empty, _z_slice_copy, _z_slice_move, + _z_slice_clear) +_Z_OWNED_FUNCTIONS_VALUE_IMPL(_z_bytes_t, bytes, _z_bytes_check, _z_bytes_null, _z_bytes_copy, _z_bytes_move, + _z_bytes_drop) _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_IMPL(_z_bytes_writer_t, bytes_writer, _z_bytes_writer_check, _z_bytes_writer_empty, _z_bytes_writer_clear) @@ -546,7 +552,8 @@ static _z_encoding_t _z_encoding_from_owned(const z_owned_encoding_t *encoding) } #endif -_Z_OWNED_FUNCTIONS_VALUE_IMPL(_z_sample_t, sample, _z_sample_check, _z_sample_null, _z_sample_copy, _z_sample_clear) +_Z_OWNED_FUNCTIONS_VALUE_IMPL(_z_sample_t, sample, _z_sample_check, _z_sample_null, _z_sample_copy, _z_sample_move, + _z_sample_clear) _Z_OWNED_FUNCTIONS_RC_IMPL(session) _Z_OWNED_FUNCTIONS_CLOSURE_IMPL(closure_sample, _z_closure_sample_callback_t, z_closure_drop_callback_t) @@ -1020,7 +1027,8 @@ bool _z_reply_check(const _z_reply_t *reply) { } return false; } -_Z_OWNED_FUNCTIONS_VALUE_IMPL(_z_reply_t, reply, _z_reply_check, _z_reply_null, _z_reply_copy, _z_reply_clear) +_Z_OWNED_FUNCTIONS_VALUE_IMPL(_z_reply_t, reply, _z_reply_check, _z_reply_null, _z_reply_copy, _z_reply_move, + _z_reply_clear) void z_get_options_default(z_get_options_t *options) { options->target = z_query_target_default(); @@ -1102,6 +1110,18 @@ bool z_reply_replier_id(const z_loaned_reply_t *reply, z_id_t *out_id) { #if Z_FEATURE_QUERYABLE == 1 _Z_OWNED_FUNCTIONS_RC_IMPL(query) +z_result_t z_query_loaned_take(z_owned_query_t *dst, z_loaned_query_t *src) { + dst->_rc = *src; + _z_query_t q = _z_query_null(); + *src = _z_query_rc_new_from_val(&q); + if (_Z_RC_IS_NULL(src)) { + *src = dst->_rc; // reset src to its original value + z_internal_query_null(dst); + return _Z_ERR_SYSTEM_OUT_OF_MEMORY; + } + return _Z_RES_OK; +} + void _z_queryable_drop(_z_queryable_t *queryable) { _z_undeclare_queryable(queryable); _z_queryable_clear(queryable); diff --git a/src/net/reply.c b/src/net/reply.c index b9038af2e..651971878 100644 --- a/src/net/reply.c +++ b/src/net/reply.c @@ -59,10 +59,9 @@ z_result_t _z_reply_data_copy(_z_reply_data_t *dst, const _z_reply_data_t *src) return _Z_RES_OK; } -_z_reply_t _z_reply_move(_z_reply_t *src_reply) { - _z_reply_t reply = *src_reply; - *src_reply = _z_reply_null(); - return reply; +void _z_reply_move(_z_reply_t *dst, _z_reply_t *src) { + *dst = *src; + *src = _z_reply_null(); } void _z_reply_clear(_z_reply_t *reply) { _z_reply_data_clear(&reply->data); } diff --git a/src/net/sample.c b/src/net/sample.c index 6248f57e5..a9877f30a 100644 --- a/src/net/sample.c +++ b/src/net/sample.c @@ -39,9 +39,10 @@ void _z_sample_move(_z_sample_t *dst, _z_sample_t *src) { _z_bytes_move(&dst->payload, &src->payload); _z_encoding_move(&dst->encoding, &src->encoding); _z_bytes_move(&dst->attachment, &src->attachment); - - dst->timestamp.time = src->timestamp.time; // FIXME: call the z_timestamp_move - dst->timestamp.id = src->timestamp.id; // FIXME: call the z_timestamp_move + _z_timestamp_move(&dst->timestamp, &src->timestamp); + dst->qos = src->qos; + dst->reliability = src->reliability; + dst->kind = src->kind; } void _z_sample_clear(_z_sample_t *sample) { diff --git a/src/protocol/core.c b/src/protocol/core.c index ed0479cc5..b95ab0e25 100644 --- a/src/protocol/core.c +++ b/src/protocol/core.c @@ -105,6 +105,11 @@ _z_hello_t _z_hello_null(void) { return (_z_hello_t){._zid = _z_id_empty(), ._version = 0, ._whatami = 0x0, ._locators = _z_string_svec_make(0)}; } +void _z_hello_move(_z_hello_t *dst, _z_hello_t *src) { + *dst = *src; + *src = _z_hello_null(); +} + void _z_value_move(_z_value_t *dst, _z_value_t *src) { _z_encoding_move(&dst->encoding, &src->encoding); _z_bytes_move(&dst->payload, &src->payload); diff --git a/src/protocol/keyexpr.c b/src/protocol/keyexpr.c index a097b2c40..c61eb9755 100644 --- a/src/protocol/keyexpr.c +++ b/src/protocol/keyexpr.c @@ -72,9 +72,8 @@ _z_keyexpr_t _z_keyexpr_steal(_Z_MOVE(_z_keyexpr_t) src) { } void _z_keyexpr_move(_z_keyexpr_t *dst, _z_keyexpr_t *src) { - dst->_id = src->_id; - dst->_mapping = src->_mapping; - _z_string_move(&dst->_suffix, &src->_suffix); + *dst = *src; + *src = _z_keyexpr_null(); } void _z_keyexpr_clear(_z_keyexpr_t *rk) { diff --git a/src/session/query.c b/src/session/query.c index 9515f47d3..6bd871e1a 100644 --- a/src/session/query.c +++ b/src/session/query.c @@ -166,7 +166,7 @@ z_result_t _z_trigger_query_reply_partial(_z_session_t *zn, const _z_zint_t id, // Trigger the user callback if ((ret == _Z_RES_OK) && (pen_qry->_consolidation != Z_CONSOLIDATION_MODE_LATEST)) { _z_reply_t cb_reply = _z_reply_null(); - cb_reply = _z_reply_move(&reply); + _z_reply_move(&cb_reply, &reply); pen_qry->_callback(&cb_reply, pen_qry->_arg); _z_reply_clear(&cb_reply); return ret; @@ -197,7 +197,7 @@ z_result_t _z_trigger_query_reply_err(_z_session_t *zn, _z_zint_t id, _z_msg_err // Trigger the user callback if (ret == _Z_RES_OK) { _z_reply_t cb_reply = _z_reply_null(); - cb_reply = _z_reply_move(&reply); + _z_reply_move(&cb_reply, &reply); pen_qry->_callback(&cb_reply, pen_qry->_arg); _z_reply_clear(&cb_reply); } @@ -226,7 +226,7 @@ z_result_t _z_trigger_query_reply_final(_z_session_t *zn, _z_zint_t id) { // Trigger the query handler _z_reply_t cb_reply = _z_reply_null(); - cb_reply = _z_reply_move(&pen_rep->_reply); + _z_reply_move(&cb_reply, &pen_rep->_reply); pen_qry->_callback(&cb_reply, pen_qry->_arg); pen_qry->_pending_replies = _z_pending_reply_list_pop(pen_qry->_pending_replies, NULL); _z_reply_clear(&cb_reply); diff --git a/src/session/utils.c b/src/session/utils.c index d82f9d84c..ea1ebb2f8 100644 --- a/src/session/utils.c +++ b/src/session/utils.c @@ -38,6 +38,11 @@ void _z_timestamp_clear(_z_timestamp_t *tstamp) { tstamp->time = 0; } +void _z_timestamp_move(_z_timestamp_t *dst, _z_timestamp_t *src) { + *dst = *src; + _z_timestamp_clear(src); +} + bool _z_timestamp_check(const _z_timestamp_t *stamp) { return _z_id_check(stamp->id); } z_result_t _z_session_generate_zid(_z_id_t *bs, uint8_t size) { diff --git a/zenohpico.pc b/zenohpico.pc index 1e3b39ae2..9ca8475b0 100644 --- a/zenohpico.pc +++ b/zenohpico.pc @@ -3,6 +3,6 @@ prefix=/usr/local Name: zenohpico Description: URL: -Version: 1.0.20241018dev +Version: 1.0.0.0 Cflags: -I${prefix}/include Libs: -L${prefix}/lib -lzenohpico From 0b2dac9d226ea0a4550d9c53d8d25338555ead9a Mon Sep 17 00:00:00 2001 From: Denis Biryukov Date: Wed, 30 Oct 2024 10:54:08 +0100 Subject: [PATCH 2/4] add empty gravestone values for bytes_writer and serializer --- docs/api.rst | 11 ++++ include/zenoh-pico/api/handlers.h | 52 ++++++++--------- include/zenoh-pico/api/macros.h | 8 +++ include/zenoh-pico/api/olv_macros.h | 88 +++++++++++++++++------------ include/zenoh-pico/api/primitives.h | 8 +-- src/api/api.c | 14 ++--- src/api/serialization.c | 5 +- 7 files changed, 113 insertions(+), 73 deletions(-) diff --git a/docs/api.rst b/docs/api.rst index 28e2e9fb7..48b6bf9b7 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -269,6 +269,7 @@ See details at :ref:`owned_types_concept` .. c:function:: void z_bytes_writer_clone(z_owned_bytes_writer_t * dst, const z_loaned_bytes_writer_t * bytes_writer) .. c:function:: const z_loaned_bytes_writer_t * z_bytes_writer_loan(const z_owned_bytes_writer_t * bytes_writer) .. c:function:: z_loaned_bytes_writer_t * z_bytes_writer_loan_mut(z_owned_bytes_writer_t * bytes_writer) +.. c:function:: z_result_t z_bytes_writer_loaned_take(z_owned_bytes_writer_t *dst, z_loaned_bytes_writer_t *src) Encoding -------- @@ -1283,6 +1284,16 @@ Functions .. autocfunction:: serialization.h::ze_serialize_str .. autocfunction:: serialization.h::ze_serialize_substr +Ownership Functions +^^^^^^^^^^^^^^^^^^^ + +See details at :ref:`owned_types_concept` + +.. c:function:: void ze_serializer_drop(ze_moved_serializer_t * serializer) +.. c:function:: void ze_serializer_clone(ze_owned_serializer_t * dst, const ze_loaned_serializer_t * serializer) +.. c:function:: const ze_loaned_serializer_t * ze_serializer_loan(const ze_owned_serializer_t * serializer) +.. c:function:: ze_loaned_serializer_t * ze_serializer_loan_mut(ze_owned_serializer_t * serializer) +.. c:function:: z_result_t ze_serializer_loaned_take(ze_owned_serializer_t *dst, ze_loaned_serializer_t *src) Others ====== diff --git a/include/zenoh-pico/api/handlers.h b/include/zenoh-pico/api/handlers.h index c3342302a..973173e9d 100644 --- a/include/zenoh-pico/api/handlers.h +++ b/include/zenoh-pico/api/handlers.h @@ -109,8 +109,8 @@ extern "C" { return h; \ } \ \ - _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_INLINE_IMPL(handler_type, handler_name, _z_##handler_name##_check, \ - _z_##handler_name##_null, _z_##handler_name##_clear) \ + _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_NO_MOVE_INLINE_IMPL(handler_type, handler_name, _z_##handler_name##_check, \ + _z_##handler_name##_null, _z_##handler_name##_clear) \ \ static inline z_result_t handler_new_f_name(callback_type *callback, z_owned_##handler_name##_t *handler, \ size_t capacity) { \ @@ -145,30 +145,30 @@ extern "C" { /* elem_drop_f */ z_##item_name##_drop, \ /* elem_null */ z_internal_##item_name##_null) -#define _Z_CHANNEL_DUMMY_IMPL(handler_type, handler_name, item_name) \ - _Z_OWNED_TYPE_VALUE(handler_type, handler_name) \ - static inline void _z_##handler_name##_clear(handler_type *handler) { _ZP_UNUSED(handler); } \ - static inline bool _z_##handler_name##_check(const handler_type *handler) { \ - _ZP_UNUSED(handler); \ - return false; \ - } \ - static inline handler_type _z_##handler_name##_null(void) { \ - handler_type h = {0}; \ - return h; \ - } \ - _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_INLINE_IMPL(handler_type, handler_name, _z_##handler_name##_check, \ - _z_##handler_name##_null, _z_##handler_name##_clear) \ - static inline z_result_t z_##handler_name##_try_recv(const z_loaned_##handler_name##_t *handler, \ - z_owned_##item_name##_t *e) { \ - _ZP_UNUSED(handler); \ - _ZP_UNUSED(e); \ - return Z_CHANNEL_DISCONNECTED; \ - } \ - static inline z_result_t z_##handler_name##_recv(const z_loaned_##handler_name##_t *handler, \ - z_owned_##item_name##_t *e) { \ - _ZP_UNUSED(handler); \ - _ZP_UNUSED(e); \ - return Z_CHANNEL_DISCONNECTED; \ +#define _Z_CHANNEL_DUMMY_IMPL(handler_type, handler_name, item_name) \ + _Z_OWNED_TYPE_VALUE(handler_type, handler_name) \ + static inline void _z_##handler_name##_clear(handler_type *handler) { _ZP_UNUSED(handler); } \ + static inline bool _z_##handler_name##_check(const handler_type *handler) { \ + _ZP_UNUSED(handler); \ + return false; \ + } \ + static inline handler_type _z_##handler_name##_null(void) { \ + handler_type h = {0}; \ + return h; \ + } \ + _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_NO_MOVE_INLINE_IMPL(handler_type, handler_name, _z_##handler_name##_check, \ + _z_##handler_name##_null, _z_##handler_name##_clear) \ + static inline z_result_t z_##handler_name##_try_recv(const z_loaned_##handler_name##_t *handler, \ + z_owned_##item_name##_t *e) { \ + _ZP_UNUSED(handler); \ + _ZP_UNUSED(e); \ + return Z_CHANNEL_DISCONNECTED; \ + } \ + static inline z_result_t z_##handler_name##_recv(const z_loaned_##handler_name##_t *handler, \ + z_owned_##item_name##_t *e) { \ + _ZP_UNUSED(handler); \ + _ZP_UNUSED(e); \ + return Z_CHANNEL_DISCONNECTED; \ } #define _Z_CHANNEL_DEFINE_DUMMY(item_name, kind_name) \ diff --git a/include/zenoh-pico/api/macros.h b/include/zenoh-pico/api/macros.h index 9a47f6ab7..6002bb4e0 100644 --- a/include/zenoh-pico/api/macros.h +++ b/include/zenoh-pico/api/macros.h @@ -346,6 +346,8 @@ z_owned_slice_t* : z_slice_loaned_take, \ z_owned_string_array_t* : z_string_array_loaned_take, \ z_owned_config_t* : z_config_loaned_take \ + z_owned_bytes_writer_t* : z_bytes_writer_loaned_take, \ + ze_owned_serializer_t* : ze_serializer_loaned_take, \ )(dst, src) /** @@ -792,6 +794,12 @@ inline z_result_t z_loaned_take(z_owned_string_array_t* dst, z_loaned_string_arr inline z_result_t z_loaned_take(z_owned_hello_t* dst, z_loaned_hello_t* this_) { return z_hello_loaned_take(dst, this_); } +inline z_result_t z_loaned_take(z_owned_bytes_writer_t* dst, z_loaned_bytes_writer_t* this_) { + return z_bytes_writer_loaned_take(dst, this_); +} +inline z_result_t z_loaned_take(ze_owned_serializer_t* dst, ze_loaned_serializer_t* this_) { + return ze_serializer_loaned_take(dst, this_); +} template struct z_loaned_to_owned_type_t {}; diff --git a/include/zenoh-pico/api/olv_macros.h b/include/zenoh-pico/api/olv_macros.h index 7c61804f2..0435a3687 100644 --- a/include/zenoh-pico/api/olv_macros.h +++ b/include/zenoh-pico/api/olv_macros.h @@ -59,7 +59,7 @@ type _val; \ } z_view_##name##_t; -#define _Z_OWNED_FUNCTIONS_NO_COPY_DEF_PREFIX(prefix, name) \ +#define _Z_OWNED_FUNCTIONS_NO_COPY_NO_MOVE_DEF_PREFIX(prefix, name) \ void prefix##_internal_##name##_null(prefix##_owned_##name##_t *obj); \ bool prefix##_internal_##name##_check(const prefix##_owned_##name##_t *obj); \ const prefix##_loaned_##name##_t *prefix##_##name##_loan(const prefix##_owned_##name##_t *obj); \ @@ -68,11 +68,15 @@ void prefix##_##name##_take(prefix##_owned_##name##_t *obj, prefix##_moved_##name##_t *src); \ void prefix##_##name##_drop(prefix##_moved_##name##_t *obj); -#define _Z_OWNED_FUNCTIONS_DEF_PREFIX(prefix, name) \ - _Z_OWNED_FUNCTIONS_NO_COPY_DEF_PREFIX(prefix, name) \ - z_result_t prefix##_##name##_clone(prefix##_owned_##name##_t *obj, const prefix##_loaned_##name##_t *src); \ +#define _Z_OWNED_FUNCTIONS_NO_COPY_DEF_PREFIX(prefix, name) \ + _Z_OWNED_FUNCTIONS_NO_COPY_NO_MOVE_DEF_PREFIX(prefix, name) \ z_result_t prefix##_##name##_take_loaned(prefix##_owned_##name##_t *dst, prefix##_loaned_##name##_t *src); +#define _Z_OWNED_FUNCTIONS_DEF_PREFIX(prefix, name) \ + _Z_OWNED_FUNCTIONS_NO_COPY_DEF_PREFIX(prefix, name) \ + z_result_t prefix##_##name##_clone(prefix##_owned_##name##_t *obj, const prefix##_loaned_##name##_t *src); + +#define _Z_OWNED_FUNCTIONS_NO_COPY_NO_MOVE_DEF(name) _Z_OWNED_FUNCTIONS_NO_COPY_NO_MOVE_DEF_PREFIX(z, name) #define _Z_OWNED_FUNCTIONS_NO_COPY_DEF(name) _Z_OWNED_FUNCTIONS_NO_COPY_DEF_PREFIX(z, name) #define _Z_OWNED_FUNCTIONS_DEF(name) _Z_OWNED_FUNCTIONS_DEF_PREFIX(z, name) @@ -102,49 +106,63 @@ #define _Z_OWNED_FUNCTIONS_IMPL_MOVE_TAKE(name) _Z_OWNED_FUNCTIONS_IMPL_MOVE_TAKE_PREFIX_INNER(z, name, _ZP_NOTHING) -#define _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_IMPL_PREFIX_INNER(prefix, type, name, f_check, f_null, f_drop, attribute) \ - attribute void prefix##_internal_##name##_null(prefix##_owned_##name##_t *obj) { obj->_val = f_null(); } \ - _Z_OWNED_FUNCTIONS_IMPL_MOVE_TAKE_PREFIX_INNER(prefix, name, attribute) \ - attribute bool prefix##_internal_##name##_check(const prefix##_owned_##name##_t *obj) { \ - return f_check((&obj->_val)); \ - } \ - attribute const prefix##_loaned_##name##_t *prefix##_##name##_loan(const prefix##_owned_##name##_t *obj) { \ - return &obj->_val; \ - } \ - attribute prefix##_loaned_##name##_t *prefix##_##name##_loan_mut(prefix##_owned_##name##_t *obj) { \ - return &obj->_val; \ - } \ - attribute void prefix##_##name##_drop(prefix##_moved_##name##_t *obj) { \ - if (obj != NULL) f_drop((&obj->_this._val)); \ +#define _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_NO_MOVE_IMPL_PREFIX_INNER(prefix, type, name, f_check, f_null, f_drop, \ + attribute) \ + attribute void prefix##_internal_##name##_null(prefix##_owned_##name##_t *obj) { obj->_val = f_null(); } \ + _Z_OWNED_FUNCTIONS_IMPL_MOVE_TAKE_PREFIX_INNER(prefix, name, attribute) \ + attribute bool prefix##_internal_##name##_check(const prefix##_owned_##name##_t *obj) { \ + return f_check((&obj->_val)); \ + } \ + attribute const prefix##_loaned_##name##_t *prefix##_##name##_loan(const prefix##_owned_##name##_t *obj) { \ + return &obj->_val; \ + } \ + attribute prefix##_loaned_##name##_t *prefix##_##name##_loan_mut(prefix##_owned_##name##_t *obj) { \ + return &obj->_val; \ + } \ + attribute void prefix##_##name##_drop(prefix##_moved_##name##_t *obj) { \ + if (obj != NULL) f_drop((&obj->_this._val)); \ } -#define _Z_OWNED_FUNCTIONS_VALUE_IMPL_PREFIX_INNER(prefix, type, name, f_check, f_null, f_copy, f_move, f_drop, \ - attribute) \ - _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_IMPL_PREFIX_INNER(prefix, type, name, f_check, f_null, f_drop, attribute) \ - attribute z_result_t prefix##_##name##_clone(prefix##_owned_##name##_t *obj, \ - const prefix##_loaned_##name##_t *src) { \ - return f_copy((&obj->_val), src); \ - } \ - attribute z_result_t prefix##_##name##_take_loaned(prefix##_owned_##name##_t *obj, \ - prefix##_loaned_##name##_t *src) { \ - f_move((&obj->_val), src); \ - return _Z_RES_OK; \ +#define _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_IMPL_PREFIX_INNER(prefix, type, name, f_check, f_null, f_move, f_drop, \ + attribute) \ + _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_NO_MOVE_IMPL_PREFIX_INNER(prefix, type, name, f_check, f_null, f_drop, attribute) \ + attribute z_result_t prefix##_##name##_take_loaned(prefix##_owned_##name##_t *obj, \ + prefix##_loaned_##name##_t *src) { \ + f_move((&obj->_val), src); \ + return _Z_RES_OK; \ + } + +#define _Z_OWNED_FUNCTIONS_VALUE_IMPL_PREFIX_INNER(prefix, type, name, f_check, f_null, f_copy, f_move, f_drop, \ + attribute) \ + _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_IMPL_PREFIX_INNER(prefix, type, name, f_check, f_null, f_move, f_drop, attribute) \ + attribute z_result_t prefix##_##name##_clone(prefix##_owned_##name##_t *obj, \ + const prefix##_loaned_##name##_t *src) { \ + return f_copy((&obj->_val), src); \ } #define _Z_OWNED_FUNCTIONS_VALUE_IMP_PREFIX(prefix, type, name, f_check, f_null, f_copy, f_move, f_drop) \ _Z_OWNED_FUNCTIONS_VALUE_IMPL_PREFIX_INNER(z, type, name, f_check, f_null, f_copy, f_move, f_drop, _ZP_NOTHING) -#define _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_IMPL_PREFIX(prefix, type, name, f_check, f_null, f_drop) \ - _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_IMPL_PREFIX_INNER(prefix, type, name, f_check, f_null, f_drop, _ZP_NOTHING) +#define _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_NO_MOVE_IMPL_PREFIX(prefix, type, name, f_check, f_null, f_drop) \ + _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_NO_MOVE_IMPL_PREFIX_INNER(prefix, type, name, f_check, f_null, f_drop, _ZP_NOTHING) + +#define _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_IMPL_PREFIX(prefix, type, name, f_check, f_null, f_move, f_drop) \ + _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_IMPL_PREFIX_INNER(prefix, type, name, f_check, f_null, f_move, f_drop, _ZP_NOTHING) -#define _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_IMPL(type, name, f_check, f_null, f_drop) \ - _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_IMPL_PREFIX(z, type, name, f_check, f_null, f_drop) +#define _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_NO_MOVE_IMPL(type, name, f_check, f_null, f_drop) \ + _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_NO_MOVE_IMPL_PREFIX(z, type, name, f_check, f_null, f_drop) + +#define _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_IMPL(type, name, f_check, f_null, f_move, f_drop) \ + _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_IMPL_PREFIX(z, type, name, f_check, f_null, f_move, f_drop) #define _Z_OWNED_FUNCTIONS_VALUE_IMPL(type, name, f_check, f_null, f_copy, f_move, f_drop) \ _Z_OWNED_FUNCTIONS_VALUE_IMP_PREFIX(z, type, name, f_check, f_null, f_copy, f_move, f_drop) -#define _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_INLINE_IMPL(type, name, f_check, f_null, f_drop) \ - _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_IMPL_PREFIX_INNER(z, type, name, f_check, f_null, f_drop, static inline) +#define _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_NO_MOVE_INLINE_IMPL(type, name, f_check, f_null, f_drop) \ + _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_NO_MOVE_IMPL_PREFIX_INNER(z, type, name, f_check, f_null, f_drop, static inline) + +#define _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_INLINE_IMPL(type, name, f_check, f_null, f_move, f_drop) \ + _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_IMPL_PREFIX_INNER(z, type, name, f_check, f_null, f_move, f_drop, static inline) #define _Z_OWNED_FUNCTIONS_RC_IMPL(name) \ _Z_OWNED_FUNCTIONS_IMPL_MOVE_TAKE(name) \ diff --git a/include/zenoh-pico/api/primitives.h b/include/zenoh-pico/api/primitives.h index 6c10996f1..239fe009d 100644 --- a/include/zenoh-pico/api/primitives.h +++ b/include/zenoh-pico/api/primitives.h @@ -1098,10 +1098,10 @@ void z_closure_zid_call(const z_loaned_closure_zid_t *closure, const z_id_t *id) _Z_OWNED_FUNCTIONS_DEF(string) _Z_OWNED_FUNCTIONS_DEF(keyexpr) _Z_OWNED_FUNCTIONS_DEF(config) -_Z_OWNED_FUNCTIONS_NO_COPY_DEF(session) -_Z_OWNED_FUNCTIONS_NO_COPY_DEF(subscriber) -_Z_OWNED_FUNCTIONS_NO_COPY_DEF(publisher) -_Z_OWNED_FUNCTIONS_NO_COPY_DEF(queryable) +_Z_OWNED_FUNCTIONS_NO_COPY_NO_MOVE_DEF(session) +_Z_OWNED_FUNCTIONS_NO_COPY_NO_MOVE_DEF(subscriber) +_Z_OWNED_FUNCTIONS_NO_COPY_NO_MOVE_DEF(publisher) +_Z_OWNED_FUNCTIONS_NO_COPY_NO_MOVE_DEF(queryable) _Z_OWNED_FUNCTIONS_DEF(hello) _Z_OWNED_FUNCTIONS_DEF(reply) _Z_OWNED_FUNCTIONS_DEF(string_array) diff --git a/src/api/api.c b/src/api/api.c index 1f2d54d98..7aba4a8f1 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -529,7 +529,7 @@ _Z_OWNED_FUNCTIONS_VALUE_IMPL(_z_slice_t, slice, _z_slice_check, _z_slice_empty, _Z_OWNED_FUNCTIONS_VALUE_IMPL(_z_bytes_t, bytes, _z_bytes_check, _z_bytes_null, _z_bytes_copy, _z_bytes_move, _z_bytes_drop) _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_IMPL(_z_bytes_writer_t, bytes_writer, _z_bytes_writer_check, _z_bytes_writer_empty, - _z_bytes_writer_clear) + _z_bytes_writer_move, _z_bytes_writer_clear) #if Z_FEATURE_PUBLICATION == 1 || Z_FEATURE_QUERYABLE == 1 || Z_FEATURE_QUERY == 1 // Convert a user owned bytes payload to an internal bytes payload, returning an empty one if value invalid @@ -790,8 +790,8 @@ void _z_publisher_drop(_z_publisher_t *pub) { _z_publisher_clear(pub); } -_Z_OWNED_FUNCTIONS_VALUE_NO_COPY_IMPL(_z_publisher_t, publisher, _z_publisher_check, _z_publisher_null, - _z_publisher_drop) +_Z_OWNED_FUNCTIONS_VALUE_NO_COPY_NO_MOVE_IMPL(_z_publisher_t, publisher, _z_publisher_check, _z_publisher_null, + _z_publisher_drop) void z_put_options_default(z_put_options_t *options) { options->congestion_control = Z_CONGESTION_CONTROL_DEFAULT; @@ -1127,8 +1127,8 @@ void _z_queryable_drop(_z_queryable_t *queryable) { _z_queryable_clear(queryable); } -_Z_OWNED_FUNCTIONS_VALUE_NO_COPY_IMPL(_z_queryable_t, queryable, _z_queryable_check, _z_queryable_null, - _z_queryable_drop) +_Z_OWNED_FUNCTIONS_VALUE_NO_COPY_NO_MOVE_IMPL(_z_queryable_t, queryable, _z_queryable_check, _z_queryable_null, + _z_queryable_drop) void z_queryable_options_default(z_queryable_options_t *options) { options->complete = _Z_QUERYABLE_COMPLETE_DEFAULT; } @@ -1346,8 +1346,8 @@ void _z_subscriber_drop(_z_subscriber_t *sub) { _z_subscriber_clear(sub); } -_Z_OWNED_FUNCTIONS_VALUE_NO_COPY_IMPL(_z_subscriber_t, subscriber, _z_subscriber_check, _z_subscriber_null, - _z_subscriber_drop) +_Z_OWNED_FUNCTIONS_VALUE_NO_COPY_NO_MOVE_IMPL(_z_subscriber_t, subscriber, _z_subscriber_check, _z_subscriber_null, + _z_subscriber_drop) void z_subscriber_options_default(z_subscriber_options_t *options) { options->__dummy = 0; } diff --git a/src/api/serialization.c b/src/api/serialization.c index c6b018593..ea0123df8 100644 --- a/src/api/serialization.c +++ b/src/api/serialization.c @@ -25,9 +25,12 @@ _ze_serializer_t _ze_serializer_empty(void) { } void _ze_serializer_clear(_ze_serializer_t *serializer) { _z_bytes_writer_clear(&serializer->_writer); } +void _ze_serializer_move(_ze_serializer_t *dst, _ze_serializer_t *src) { + _z_bytes_writer_move(&dst->_writer, &src->_writer); +} _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_IMPL_PREFIX(ze, _ze_serializer_t, serializer, _ze_serializer_check, - _ze_serializer_empty, _ze_serializer_clear) + _ze_serializer_empty, _ze_serializer_move, _ze_serializer_clear) z_result_t ze_serializer_empty(ze_owned_serializer_t *serializer) { serializer->_val._writer = _z_bytes_writer_empty(); From e954df67036a21e591c44ad0524216e6f1070404 Mon Sep 17 00:00:00 2001 From: Denis Biryukov Date: Wed, 30 Oct 2024 13:21:35 +0100 Subject: [PATCH 3/4] rename loaned_take -> take_loaned --- docs/api.rst | 26 ++++----- include/zenoh-pico/api/macros.h | 88 ++++++++++++++--------------- include/zenoh-pico/api/primitives.h | 2 +- src/api/api.c | 2 +- 4 files changed, 59 insertions(+), 59 deletions(-) diff --git a/docs/api.rst b/docs/api.rst index 48b6bf9b7..63c037bb2 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -62,7 +62,7 @@ See details at :ref:`owned_types_concept` .. c:function:: z_loaned_slice_t * z_view_slice_loan_mut(z_view_slice_t * slice) .. c:function:: const z_loaned_slice_t * z_slice_loan(const z_owned_slice_t * slice) .. c:function:: z_loaned_slice_t * z_slice_loan_mut(z_owned_slice_t * slice) -.. c:function:: z_result_t z_slice_loaned_take(z_owned_slice_t *dst, z_loaned_slice_t *src) +.. c:function:: z_result_t z_slice_take_loaned(z_owned_slice_t *dst, z_loaned_slice_t *src) String ------ @@ -108,7 +108,7 @@ See details at :ref:`owned_types_concept` .. c:function:: z_loaned_string_t * z_view_string_loan_mut(z_view_string_t * string) .. c:function:: const z_loaned_string_t * z_string_loan(const z_owned_string_t * string) .. c:function:: z_loaned_string_t * z_string_loan_mut(z_owned_string_t * string) -.. c:function:: z_result_t z_string_loaned_take(z_owned_string_t *dst, z_loaned_string_t *src) +.. c:function:: z_result_t z_string_take_loaned(z_owned_string_t *dst, z_loaned_string_t *src) String Array ------------ @@ -142,7 +142,7 @@ See details at :ref:`owned_types_concept` .. c:function:: void z_string_array_clone(z_owned_string_array_t * dst, const z_loaned_string_array_t * string_array) .. c:function:: const z_loaned_string_array_t * z_string_array_loan(const z_owned_string_array_t * string_array) .. c:function:: z_loaned_string_array_t * z_string_array_loan_mut(z_owned_string_array_t * string_array) -.. c:function:: z_result_t z_string_array_loaned_take(z_owned_string_array_t *dst, z_loaned_string_array_t *src) +.. c:function:: z_result_t z_string_array_take_loaned(z_owned_string_array_t *dst, z_loaned_string_array_t *src) Common @@ -206,7 +206,7 @@ See details at :ref:`owned_types_concept` .. c:function:: z_loaned_keyexpr_t * z_view_keyexpr_loan_mut(z_view_keyexpr_t * keyexpr) .. c:function:: const z_loaned_keyexpr_t * z_keyexpr_loan(const z_owned_keyexpr_t * keyexpr) .. c:function:: z_loaned_keyexpr_t * z_keyexpr_loan_mut(z_owned_keyexpr_t * keyexpr) -.. c:function:: z_result_t z_keyexpr_loaned_take(z_owned_keyexpr_t *dst, z_loaned_keyexpr_t *src) +.. c:function:: z_result_t z_keyexpr_take_loaned(z_owned_keyexpr_t *dst, z_loaned_keyexpr_t *src) Payload ------- @@ -263,13 +263,13 @@ See details at :ref:`owned_types_concept` .. c:function:: void z_bytes_clone(z_owned_bytes_t * dst, const z_loaned_bytes_t * bytes) .. c:function:: const z_loaned_bytes_t * z_bytes_loan(const z_owned_bytes_t * bytes) .. c:function:: z_loaned_bytes_t * z_bytes_loan_mut(z_owned_bytes_t * bytes) -.. c:function:: z_result_t z_bytes_loaned_take(z_owned_bytes_t *dst, z_loaned_bytes_t *src) +.. c:function:: z_result_t z_bytes_take_loaned(z_owned_bytes_t *dst, z_loaned_bytes_t *src) .. c:function:: void z_bytes_writer_drop(z_moved_bytes_writer_t * bytes_writer) .. c:function:: void z_bytes_writer_clone(z_owned_bytes_writer_t * dst, const z_loaned_bytes_writer_t * bytes_writer) .. c:function:: const z_loaned_bytes_writer_t * z_bytes_writer_loan(const z_owned_bytes_writer_t * bytes_writer) .. c:function:: z_loaned_bytes_writer_t * z_bytes_writer_loan_mut(z_owned_bytes_writer_t * bytes_writer) -.. c:function:: z_result_t z_bytes_writer_loaned_take(z_owned_bytes_writer_t *dst, z_loaned_bytes_writer_t *src) +.. c:function:: z_result_t z_bytes_writer_take_loaned(z_owned_bytes_writer_t *dst, z_loaned_bytes_writer_t *src) Encoding -------- @@ -304,7 +304,7 @@ See details at :ref:`owned_types_concept` .. c:function:: void z_encoding_clone(z_owned_encoding_t * dst, const z_loaned_encoding_t * encoding) .. c:function:: const z_loaned_encoding_t * z_encoding_loan(const z_owned_encoding_t * encoding) .. c:function:: z_loaned_encoding_t * z_encoding_loan_mut(z_owned_encoding_t * encoding) -.. c:function:: z_result_t z_encoding_loaned_take(z_owned_encoding_t *dst, z_loaned_encoding_t *src) +.. c:function:: z_result_t z_encoding_take_loaned(z_owned_encoding_t *dst, z_loaned_encoding_t *src) Predefined Encodings @@ -391,7 +391,7 @@ See details at :ref:`owned_types_concept` .. c:function:: void z_reply_err_clone(z_owned_reply_err_t * dst, const z_loaned_reply_err_t * reply_err) .. c:function:: const z_loaned_reply_err_t * z_reply_err_loan(const z_owned_reply_err_t * reply_err) .. c:function:: z_loaned_reply_err_t * z_reply_err_loan_mut(z_owned_reply_err_t * reply_err) -.. c:function:: z_result_t z_reply_err_loaned_take(z_owned_reply_err_t *dst, z_loaned_reply_err_t *src) +.. c:function:: z_result_t z_reply_err_take_loaned(z_owned_reply_err_t *dst, z_loaned_reply_err_t *src) Sample ------ @@ -431,7 +431,7 @@ See details at :ref:`owned_types_concept` .. c:function:: void z_sample_clone(z_owned_sample_t * dst, const z_loaned_sample_t * sample) .. c:function:: const z_loaned_sample_t * z_sample_loan(const z_owned_sample_t * sample) .. c:function:: z_loaned_sample_t * z_sample_loan_mut(z_owned_sample_t * sample) -.. c:function:: z_result_t z_sample_loaned_take(z_owned_sample_t *dst, z_loaned_sample_t *src) +.. c:function:: z_result_t z_sample_take_loaned(z_owned_sample_t *dst, z_loaned_sample_t *src) Timestamp @@ -1112,7 +1112,7 @@ See details at :ref:`owned_types_concept` .. c:function:: void z_query_clone(z_owned_query_t * dst, const z_loaned_query_t * query) .. c:function:: const z_loaned_query_t * z_query_loan(const z_owned_query_t * query) .. c:function:: z_loaned_query_t * z_query_loan_mut(z_owned_query_t * query) -.. c:function:: z_result_t z_query_loaned_take(z_owned_query_t *dst, z_loaned_query_t *src) +.. c:function:: z_result_t z_query_take_loaned(z_owned_query_t *dst, z_loaned_query_t *src) Query ===== @@ -1160,7 +1160,7 @@ See details at :ref:`owned_types_concept` .. c:function:: void z_reply_clone(z_owned_reply_t * dst, const z_loaned_reply_t * reply) .. c:function:: const z_loaned_reply_t * z_reply_loan(const z_owned_reply_t * reply) .. c:function:: z_loaned_reply_t * z_reply_loan_mut(z_owned_reply_t * reply) -.. c:function:: z_result_t z_reply_loaned_take(z_owned_reply_t *dst, z_loaned_reply_t *src) +.. c:function:: z_result_t z_reply_take_loaned(z_owned_reply_t *dst, z_loaned_reply_t *src) Scouting @@ -1200,7 +1200,7 @@ See details at :ref:`owned_types_concept` .. c:function:: void z_hello_clone(z_owned_hello_t * dst, const z_loaned_hello_t * hello) .. c:function:: const z_loaned_hello_t * z_hello_loan(const z_owned_hello_t * hello) .. c:function:: z_loaned_hello_t * z_hello_loan(z_owned_hello_t * hello) -.. c:function:: z_result_t z_hello_loaned_take(z_owned_hello_t *dst, z_loaned_hello_t *src) +.. c:function:: z_result_t z_hello_take_loaned(z_owned_hello_t *dst, z_loaned_hello_t *src) Serialization @@ -1293,7 +1293,7 @@ See details at :ref:`owned_types_concept` .. c:function:: void ze_serializer_clone(ze_owned_serializer_t * dst, const ze_loaned_serializer_t * serializer) .. c:function:: const ze_loaned_serializer_t * ze_serializer_loan(const ze_owned_serializer_t * serializer) .. c:function:: ze_loaned_serializer_t * ze_serializer_loan_mut(ze_owned_serializer_t * serializer) -.. c:function:: z_result_t ze_serializer_loaned_take(ze_owned_serializer_t *dst, ze_loaned_serializer_t *src) +.. c:function:: z_result_t ze_serializer_take_loaned(ze_owned_serializer_t *dst, ze_loaned_serializer_t *src) Others ====== diff --git a/include/zenoh-pico/api/macros.h b/include/zenoh-pico/api/macros.h index 6002bb4e0..cef9c2e51 100644 --- a/include/zenoh-pico/api/macros.h +++ b/include/zenoh-pico/api/macros.h @@ -333,21 +333,21 @@ * Returns: * `0` in case of success, negative error code otherwise. */ -#define z_loaned_take(dst, src) _Generic((dst), \ - z_owned_keyexpr_t* : z_keyexpr_loaned_take, \ - z_owned_query_t* : z_query_loaned_take, \ - z_owned_sample_t* : z_sample_loaned_take, \ - z_owned_bytes_t* : z_bytes_loaned_take, \ - z_owned_encoding_t* : z_encoding_loaned_take, \ - z_owned_reply_err_t* : z_reply_err_loaned_take, \ - z_owned_reply_t* : z_reply_loaned_take, \ - z_owned_hello_t* : z_hello_loaned_take, \ - z_owned_string_t* : z_string_loaned_take, \ - z_owned_slice_t* : z_slice_loaned_take, \ - z_owned_string_array_t* : z_string_array_loaned_take, \ - z_owned_config_t* : z_config_loaned_take \ - z_owned_bytes_writer_t* : z_bytes_writer_loaned_take, \ - ze_owned_serializer_t* : ze_serializer_loaned_take, \ +#define z_take_loaned(dst, src) _Generic((dst), \ + z_owned_keyexpr_t* : z_keyexpr_take_loaned, \ + z_owned_query_t* : z_query_take_loaned, \ + z_owned_sample_t* : z_sample_take_loaned, \ + z_owned_bytes_t* : z_bytes_take_loaned, \ + z_owned_encoding_t* : z_encoding_take_loaned, \ + z_owned_reply_err_t* : z_reply_err_take_loaned, \ + z_owned_reply_t* : z_reply_take_loaned, \ + z_owned_hello_t* : z_hello_take_loaned, \ + z_owned_string_t* : z_string_take_loaned, \ + z_owned_slice_t* : z_slice_take_loaned, \ + z_owned_string_array_t* : z_string_array_take_loaned, \ + z_owned_config_t* : z_config_take_loaned \ + z_owned_bytes_writer_t* : z_bytes_writer_take_loaned, \ + ze_owned_serializer_t* : ze_serializer_take_loaned, \ )(dst, src) /** @@ -757,48 +757,48 @@ inline z_result_t z_clone(z_owned_string_array_t* dst, const z_loaned_string_arr } inline z_result_t z_clone(z_owned_hello_t* dst, const z_loaned_hello_t* this_) { return z_hello_clone(dst, this_); } -// z_loaned_take definition -inline z_result_t z_loaned_take(z_owned_bytes_t* dst, z_loaned_bytes_t* this_) { - return z_bytes_loaned_take(dst, this_); +// z_take_loaned definition +inline z_result_t z_take_loaned(z_owned_bytes_t* dst, z_loaned_bytes_t* this_) { + return z_bytes_take_loaned(dst, this_); } -inline z_result_t z_loaned_take(z_owned_config_t* dst, z_loaned_config_t* this_) { - return z_config_loaned_take(dst, this_); +inline z_result_t z_take_loaned(z_owned_config_t* dst, z_loaned_config_t* this_) { + return z_config_take_loaned(dst, this_); } -inline z_result_t z_loaned_take(z_owned_encoding_t* dst, z_loaned_encoding_t* this_) { - return z_encoding_loaned_take(dst, this_); +inline z_result_t z_take_loaned(z_owned_encoding_t* dst, z_loaned_encoding_t* this_) { + return z_encoding_take_loaned(dst, this_); } -inline z_result_t z_loaned_take(z_owned_keyexpr_t* dst, z_loaned_keyexpr_t* this_) { - return z_keyexpr_loaned_take(dst, this_); +inline z_result_t z_take_loaned(z_owned_keyexpr_t* dst, z_loaned_keyexpr_t* this_) { + return z_keyexpr_take_loaned(dst, this_); } -inline z_result_t z_loaned_take(z_owned_query_t* dst, z_loaned_query_t* this_) { - return z_query_loaned_take(dst, this_); +inline z_result_t z_take_loaned(z_owned_query_t* dst, z_loaned_query_t* this_) { + return z_query_take_loaned(dst, this_); } -inline z_result_t z_loaned_take(z_owned_reply_t* dst, z_loaned_reply_t* this_) { - return z_reply_loaned_take(dst, this_); +inline z_result_t z_take_loaned(z_owned_reply_t* dst, z_loaned_reply_t* this_) { + return z_reply_take_loaned(dst, this_); } -inline z_result_t z_loaned_take(z_owned_reply_err_t* dst, z_loaned_reply_err_t* this_) { - return z_reply_err_loaned_take(dst, this_); +inline z_result_t z_take_loaned(z_owned_reply_err_t* dst, z_loaned_reply_err_t* this_) { + return z_reply_err_take_loaned(dst, this_); } -inline z_result_t z_loaned_take(z_owned_sample_t* dst, z_loaned_sample_t* this_) { - return z_sample_loaned_take(dst, this_); +inline z_result_t z_take_loaned(z_owned_sample_t* dst, z_loaned_sample_t* this_) { + return z_sample_take_loaned(dst, this_); } -inline z_result_t z_loaned_take(z_owned_slice_t* dst, z_loaned_slice_t* this_) { - return z_slice_loaned_take(dst, this_); +inline z_result_t z_take_loaned(z_owned_slice_t* dst, z_loaned_slice_t* this_) { + return z_slice_take_loaned(dst, this_); } -inline z_result_t z_loaned_take(z_owned_string_t* dst, z_loaned_string_t* this_) { - return z_string_loaned_take(dst, this_); +inline z_result_t z_take_loaned(z_owned_string_t* dst, z_loaned_string_t* this_) { + return z_string_take_loaned(dst, this_); } -inline z_result_t z_loaned_take(z_owned_string_array_t* dst, z_loaned_string_array_t* this_) { - return z_string_array_loaned_take(dst, this_); +inline z_result_t z_take_loaned(z_owned_string_array_t* dst, z_loaned_string_array_t* this_) { + return z_string_array_take_loaned(dst, this_); } -inline z_result_t z_loaned_take(z_owned_hello_t* dst, z_loaned_hello_t* this_) { - return z_hello_loaned_take(dst, this_); +inline z_result_t z_take_loaned(z_owned_hello_t* dst, z_loaned_hello_t* this_) { + return z_hello_take_loaned(dst, this_); } -inline z_result_t z_loaned_take(z_owned_bytes_writer_t* dst, z_loaned_bytes_writer_t* this_) { - return z_bytes_writer_loaned_take(dst, this_); +inline z_result_t z_take_loaned(z_owned_bytes_writer_t* dst, z_loaned_bytes_writer_t* this_) { + return z_bytes_writer_take_loaned(dst, this_); } -inline z_result_t z_loaned_take(ze_owned_serializer_t* dst, ze_loaned_serializer_t* this_) { - return ze_serializer_loaned_take(dst, this_); +inline z_result_t z_take_loaned(ze_owned_serializer_t* dst, ze_loaned_serializer_t* this_) { + return ze_serializer_take_loaned(dst, this_); } template diff --git a/include/zenoh-pico/api/primitives.h b/include/zenoh-pico/api/primitives.h index 239fe009d..2a37bdff6 100644 --- a/include/zenoh-pico/api/primitives.h +++ b/include/zenoh-pico/api/primitives.h @@ -1804,7 +1804,7 @@ void z_query_reply_options_default(z_query_reply_options_t *options); z_result_t z_query_reply(const z_loaned_query_t *query, const z_loaned_keyexpr_t *keyexpr, z_moved_bytes_t *payload, const z_query_reply_options_t *options); -z_result_t z_query_loaned_take(z_owned_query_t *dst, z_loaned_query_t *src); +z_result_t z_query_take_loaned(z_owned_query_t *dst, z_loaned_query_t *src); /** * Builds a :c:type:`z_query_reply_del_options_t` with default values. diff --git a/src/api/api.c b/src/api/api.c index 7aba4a8f1..2fa16d256 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -1110,7 +1110,7 @@ bool z_reply_replier_id(const z_loaned_reply_t *reply, z_id_t *out_id) { #if Z_FEATURE_QUERYABLE == 1 _Z_OWNED_FUNCTIONS_RC_IMPL(query) -z_result_t z_query_loaned_take(z_owned_query_t *dst, z_loaned_query_t *src) { +z_result_t z_query_take_loaned(z_owned_query_t *dst, z_loaned_query_t *src) { dst->_rc = *src; _z_query_t q = _z_query_null(); *src = _z_query_rc_new_from_val(&q); From 2950a79807bb990045266bd356ab1465251a2a6d Mon Sep 17 00:00:00 2001 From: Denis Biryukov Date: Mon, 4 Nov 2024 12:08:42 +0100 Subject: [PATCH 4/4] rename take_loaned -> take_from_loaned --- docs/api.rst | 26 ++++----- include/zenoh-pico/api/macros.h | 88 ++++++++++++++--------------- include/zenoh-pico/api/olv_macros.h | 6 +- include/zenoh-pico/api/primitives.h | 2 +- src/api/api.c | 2 +- 5 files changed, 62 insertions(+), 62 deletions(-) diff --git a/docs/api.rst b/docs/api.rst index 63c037bb2..1fc6cf6ac 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -62,7 +62,7 @@ See details at :ref:`owned_types_concept` .. c:function:: z_loaned_slice_t * z_view_slice_loan_mut(z_view_slice_t * slice) .. c:function:: const z_loaned_slice_t * z_slice_loan(const z_owned_slice_t * slice) .. c:function:: z_loaned_slice_t * z_slice_loan_mut(z_owned_slice_t * slice) -.. c:function:: z_result_t z_slice_take_loaned(z_owned_slice_t *dst, z_loaned_slice_t *src) +.. c:function:: z_result_t z_slice_take_from_loaned(z_owned_slice_t *dst, z_loaned_slice_t *src) String ------ @@ -108,7 +108,7 @@ See details at :ref:`owned_types_concept` .. c:function:: z_loaned_string_t * z_view_string_loan_mut(z_view_string_t * string) .. c:function:: const z_loaned_string_t * z_string_loan(const z_owned_string_t * string) .. c:function:: z_loaned_string_t * z_string_loan_mut(z_owned_string_t * string) -.. c:function:: z_result_t z_string_take_loaned(z_owned_string_t *dst, z_loaned_string_t *src) +.. c:function:: z_result_t z_string_take_from_loaned(z_owned_string_t *dst, z_loaned_string_t *src) String Array ------------ @@ -142,7 +142,7 @@ See details at :ref:`owned_types_concept` .. c:function:: void z_string_array_clone(z_owned_string_array_t * dst, const z_loaned_string_array_t * string_array) .. c:function:: const z_loaned_string_array_t * z_string_array_loan(const z_owned_string_array_t * string_array) .. c:function:: z_loaned_string_array_t * z_string_array_loan_mut(z_owned_string_array_t * string_array) -.. c:function:: z_result_t z_string_array_take_loaned(z_owned_string_array_t *dst, z_loaned_string_array_t *src) +.. c:function:: z_result_t z_string_array_take_from_loaned(z_owned_string_array_t *dst, z_loaned_string_array_t *src) Common @@ -206,7 +206,7 @@ See details at :ref:`owned_types_concept` .. c:function:: z_loaned_keyexpr_t * z_view_keyexpr_loan_mut(z_view_keyexpr_t * keyexpr) .. c:function:: const z_loaned_keyexpr_t * z_keyexpr_loan(const z_owned_keyexpr_t * keyexpr) .. c:function:: z_loaned_keyexpr_t * z_keyexpr_loan_mut(z_owned_keyexpr_t * keyexpr) -.. c:function:: z_result_t z_keyexpr_take_loaned(z_owned_keyexpr_t *dst, z_loaned_keyexpr_t *src) +.. c:function:: z_result_t z_keyexpr_take_from_loaned(z_owned_keyexpr_t *dst, z_loaned_keyexpr_t *src) Payload ------- @@ -263,13 +263,13 @@ See details at :ref:`owned_types_concept` .. c:function:: void z_bytes_clone(z_owned_bytes_t * dst, const z_loaned_bytes_t * bytes) .. c:function:: const z_loaned_bytes_t * z_bytes_loan(const z_owned_bytes_t * bytes) .. c:function:: z_loaned_bytes_t * z_bytes_loan_mut(z_owned_bytes_t * bytes) -.. c:function:: z_result_t z_bytes_take_loaned(z_owned_bytes_t *dst, z_loaned_bytes_t *src) +.. c:function:: z_result_t z_bytes_take_from_loaned(z_owned_bytes_t *dst, z_loaned_bytes_t *src) .. c:function:: void z_bytes_writer_drop(z_moved_bytes_writer_t * bytes_writer) .. c:function:: void z_bytes_writer_clone(z_owned_bytes_writer_t * dst, const z_loaned_bytes_writer_t * bytes_writer) .. c:function:: const z_loaned_bytes_writer_t * z_bytes_writer_loan(const z_owned_bytes_writer_t * bytes_writer) .. c:function:: z_loaned_bytes_writer_t * z_bytes_writer_loan_mut(z_owned_bytes_writer_t * bytes_writer) -.. c:function:: z_result_t z_bytes_writer_take_loaned(z_owned_bytes_writer_t *dst, z_loaned_bytes_writer_t *src) +.. c:function:: z_result_t z_bytes_writer_take_from_loaned(z_owned_bytes_writer_t *dst, z_loaned_bytes_writer_t *src) Encoding -------- @@ -304,7 +304,7 @@ See details at :ref:`owned_types_concept` .. c:function:: void z_encoding_clone(z_owned_encoding_t * dst, const z_loaned_encoding_t * encoding) .. c:function:: const z_loaned_encoding_t * z_encoding_loan(const z_owned_encoding_t * encoding) .. c:function:: z_loaned_encoding_t * z_encoding_loan_mut(z_owned_encoding_t * encoding) -.. c:function:: z_result_t z_encoding_take_loaned(z_owned_encoding_t *dst, z_loaned_encoding_t *src) +.. c:function:: z_result_t z_encoding_take_from_loaned(z_owned_encoding_t *dst, z_loaned_encoding_t *src) Predefined Encodings @@ -391,7 +391,7 @@ See details at :ref:`owned_types_concept` .. c:function:: void z_reply_err_clone(z_owned_reply_err_t * dst, const z_loaned_reply_err_t * reply_err) .. c:function:: const z_loaned_reply_err_t * z_reply_err_loan(const z_owned_reply_err_t * reply_err) .. c:function:: z_loaned_reply_err_t * z_reply_err_loan_mut(z_owned_reply_err_t * reply_err) -.. c:function:: z_result_t z_reply_err_take_loaned(z_owned_reply_err_t *dst, z_loaned_reply_err_t *src) +.. c:function:: z_result_t z_reply_err_take_from_loaned(z_owned_reply_err_t *dst, z_loaned_reply_err_t *src) Sample ------ @@ -431,7 +431,7 @@ See details at :ref:`owned_types_concept` .. c:function:: void z_sample_clone(z_owned_sample_t * dst, const z_loaned_sample_t * sample) .. c:function:: const z_loaned_sample_t * z_sample_loan(const z_owned_sample_t * sample) .. c:function:: z_loaned_sample_t * z_sample_loan_mut(z_owned_sample_t * sample) -.. c:function:: z_result_t z_sample_take_loaned(z_owned_sample_t *dst, z_loaned_sample_t *src) +.. c:function:: z_result_t z_sample_take_from_loaned(z_owned_sample_t *dst, z_loaned_sample_t *src) Timestamp @@ -1112,7 +1112,7 @@ See details at :ref:`owned_types_concept` .. c:function:: void z_query_clone(z_owned_query_t * dst, const z_loaned_query_t * query) .. c:function:: const z_loaned_query_t * z_query_loan(const z_owned_query_t * query) .. c:function:: z_loaned_query_t * z_query_loan_mut(z_owned_query_t * query) -.. c:function:: z_result_t z_query_take_loaned(z_owned_query_t *dst, z_loaned_query_t *src) +.. c:function:: z_result_t z_query_take_from_loaned(z_owned_query_t *dst, z_loaned_query_t *src) Query ===== @@ -1160,7 +1160,7 @@ See details at :ref:`owned_types_concept` .. c:function:: void z_reply_clone(z_owned_reply_t * dst, const z_loaned_reply_t * reply) .. c:function:: const z_loaned_reply_t * z_reply_loan(const z_owned_reply_t * reply) .. c:function:: z_loaned_reply_t * z_reply_loan_mut(z_owned_reply_t * reply) -.. c:function:: z_result_t z_reply_take_loaned(z_owned_reply_t *dst, z_loaned_reply_t *src) +.. c:function:: z_result_t z_reply_take_from_loaned(z_owned_reply_t *dst, z_loaned_reply_t *src) Scouting @@ -1200,7 +1200,7 @@ See details at :ref:`owned_types_concept` .. c:function:: void z_hello_clone(z_owned_hello_t * dst, const z_loaned_hello_t * hello) .. c:function:: const z_loaned_hello_t * z_hello_loan(const z_owned_hello_t * hello) .. c:function:: z_loaned_hello_t * z_hello_loan(z_owned_hello_t * hello) -.. c:function:: z_result_t z_hello_take_loaned(z_owned_hello_t *dst, z_loaned_hello_t *src) +.. c:function:: z_result_t z_hello_take_from_loaned(z_owned_hello_t *dst, z_loaned_hello_t *src) Serialization @@ -1293,7 +1293,7 @@ See details at :ref:`owned_types_concept` .. c:function:: void ze_serializer_clone(ze_owned_serializer_t * dst, const ze_loaned_serializer_t * serializer) .. c:function:: const ze_loaned_serializer_t * ze_serializer_loan(const ze_owned_serializer_t * serializer) .. c:function:: ze_loaned_serializer_t * ze_serializer_loan_mut(ze_owned_serializer_t * serializer) -.. c:function:: z_result_t ze_serializer_take_loaned(ze_owned_serializer_t *dst, ze_loaned_serializer_t *src) +.. c:function:: z_result_t ze_serializer_take_from_loaned(ze_owned_serializer_t *dst, ze_loaned_serializer_t *src) Others ====== diff --git a/include/zenoh-pico/api/macros.h b/include/zenoh-pico/api/macros.h index cef9c2e51..8d2660b7b 100644 --- a/include/zenoh-pico/api/macros.h +++ b/include/zenoh-pico/api/macros.h @@ -333,21 +333,21 @@ * Returns: * `0` in case of success, negative error code otherwise. */ -#define z_take_loaned(dst, src) _Generic((dst), \ - z_owned_keyexpr_t* : z_keyexpr_take_loaned, \ - z_owned_query_t* : z_query_take_loaned, \ - z_owned_sample_t* : z_sample_take_loaned, \ - z_owned_bytes_t* : z_bytes_take_loaned, \ - z_owned_encoding_t* : z_encoding_take_loaned, \ - z_owned_reply_err_t* : z_reply_err_take_loaned, \ - z_owned_reply_t* : z_reply_take_loaned, \ - z_owned_hello_t* : z_hello_take_loaned, \ - z_owned_string_t* : z_string_take_loaned, \ - z_owned_slice_t* : z_slice_take_loaned, \ - z_owned_string_array_t* : z_string_array_take_loaned, \ - z_owned_config_t* : z_config_take_loaned \ - z_owned_bytes_writer_t* : z_bytes_writer_take_loaned, \ - ze_owned_serializer_t* : ze_serializer_take_loaned, \ +#define z_take_from_loaned(dst, src) _Generic((dst), \ + z_owned_keyexpr_t* : z_keyexpr_take_from_loaned, \ + z_owned_query_t* : z_query_take_from_loaned, \ + z_owned_sample_t* : z_sample_take_from_loaned, \ + z_owned_bytes_t* : z_bytes_take_from_loaned, \ + z_owned_encoding_t* : z_encoding_take_from_loaned, \ + z_owned_reply_err_t* : z_reply_err_take_from_loaned, \ + z_owned_reply_t* : z_reply_take_from_loaned, \ + z_owned_hello_t* : z_hello_take_from_loaned, \ + z_owned_string_t* : z_string_take_from_loaned, \ + z_owned_slice_t* : z_slice_take_from_loaned, \ + z_owned_string_array_t* : z_string_array_take_from_loaned, \ + z_owned_config_t* : z_config_take_from_loaned \ + z_owned_bytes_writer_t* : z_bytes_writer_take_from_loaned, \ + ze_owned_serializer_t* : ze_serializer_take_from_loaned, \ )(dst, src) /** @@ -757,48 +757,48 @@ inline z_result_t z_clone(z_owned_string_array_t* dst, const z_loaned_string_arr } inline z_result_t z_clone(z_owned_hello_t* dst, const z_loaned_hello_t* this_) { return z_hello_clone(dst, this_); } -// z_take_loaned definition -inline z_result_t z_take_loaned(z_owned_bytes_t* dst, z_loaned_bytes_t* this_) { - return z_bytes_take_loaned(dst, this_); +// z_take_from_loaned definition +inline z_result_t z_take_from_loaned(z_owned_bytes_t* dst, z_loaned_bytes_t* this_) { + return z_bytes_take_from_loaned(dst, this_); } -inline z_result_t z_take_loaned(z_owned_config_t* dst, z_loaned_config_t* this_) { - return z_config_take_loaned(dst, this_); +inline z_result_t z_take_from_loaned(z_owned_config_t* dst, z_loaned_config_t* this_) { + return z_config_take_from_loaned(dst, this_); } -inline z_result_t z_take_loaned(z_owned_encoding_t* dst, z_loaned_encoding_t* this_) { - return z_encoding_take_loaned(dst, this_); +inline z_result_t z_take_from_loaned(z_owned_encoding_t* dst, z_loaned_encoding_t* this_) { + return z_encoding_take_from_loaned(dst, this_); } -inline z_result_t z_take_loaned(z_owned_keyexpr_t* dst, z_loaned_keyexpr_t* this_) { - return z_keyexpr_take_loaned(dst, this_); +inline z_result_t z_take_from_loaned(z_owned_keyexpr_t* dst, z_loaned_keyexpr_t* this_) { + return z_keyexpr_take_from_loaned(dst, this_); } -inline z_result_t z_take_loaned(z_owned_query_t* dst, z_loaned_query_t* this_) { - return z_query_take_loaned(dst, this_); +inline z_result_t z_take_from_loaned(z_owned_query_t* dst, z_loaned_query_t* this_) { + return z_query_take_from_loaned(dst, this_); } -inline z_result_t z_take_loaned(z_owned_reply_t* dst, z_loaned_reply_t* this_) { - return z_reply_take_loaned(dst, this_); +inline z_result_t z_take_from_loaned(z_owned_reply_t* dst, z_loaned_reply_t* this_) { + return z_reply_take_from_loaned(dst, this_); } -inline z_result_t z_take_loaned(z_owned_reply_err_t* dst, z_loaned_reply_err_t* this_) { - return z_reply_err_take_loaned(dst, this_); +inline z_result_t z_take_from_loaned(z_owned_reply_err_t* dst, z_loaned_reply_err_t* this_) { + return z_reply_err_take_from_loaned(dst, this_); } -inline z_result_t z_take_loaned(z_owned_sample_t* dst, z_loaned_sample_t* this_) { - return z_sample_take_loaned(dst, this_); +inline z_result_t z_take_from_loaned(z_owned_sample_t* dst, z_loaned_sample_t* this_) { + return z_sample_take_from_loaned(dst, this_); } -inline z_result_t z_take_loaned(z_owned_slice_t* dst, z_loaned_slice_t* this_) { - return z_slice_take_loaned(dst, this_); +inline z_result_t z_take_from_loaned(z_owned_slice_t* dst, z_loaned_slice_t* this_) { + return z_slice_take_from_loaned(dst, this_); } -inline z_result_t z_take_loaned(z_owned_string_t* dst, z_loaned_string_t* this_) { - return z_string_take_loaned(dst, this_); +inline z_result_t z_take_from_loaned(z_owned_string_t* dst, z_loaned_string_t* this_) { + return z_string_take_from_loaned(dst, this_); } -inline z_result_t z_take_loaned(z_owned_string_array_t* dst, z_loaned_string_array_t* this_) { - return z_string_array_take_loaned(dst, this_); +inline z_result_t z_take_from_loaned(z_owned_string_array_t* dst, z_loaned_string_array_t* this_) { + return z_string_array_take_from_loaned(dst, this_); } -inline z_result_t z_take_loaned(z_owned_hello_t* dst, z_loaned_hello_t* this_) { - return z_hello_take_loaned(dst, this_); +inline z_result_t z_take_from_loaned(z_owned_hello_t* dst, z_loaned_hello_t* this_) { + return z_hello_take_from_loaned(dst, this_); } -inline z_result_t z_take_loaned(z_owned_bytes_writer_t* dst, z_loaned_bytes_writer_t* this_) { - return z_bytes_writer_take_loaned(dst, this_); +inline z_result_t z_take_from_loaned(z_owned_bytes_writer_t* dst, z_loaned_bytes_writer_t* this_) { + return z_bytes_writer_take_from_loaned(dst, this_); } -inline z_result_t z_take_loaned(ze_owned_serializer_t* dst, ze_loaned_serializer_t* this_) { - return ze_serializer_take_loaned(dst, this_); +inline z_result_t z_take_from_loaned(ze_owned_serializer_t* dst, ze_loaned_serializer_t* this_) { + return ze_serializer_take_from_loaned(dst, this_); } template diff --git a/include/zenoh-pico/api/olv_macros.h b/include/zenoh-pico/api/olv_macros.h index 0435a3687..df6990666 100644 --- a/include/zenoh-pico/api/olv_macros.h +++ b/include/zenoh-pico/api/olv_macros.h @@ -70,7 +70,7 @@ #define _Z_OWNED_FUNCTIONS_NO_COPY_DEF_PREFIX(prefix, name) \ _Z_OWNED_FUNCTIONS_NO_COPY_NO_MOVE_DEF_PREFIX(prefix, name) \ - z_result_t prefix##_##name##_take_loaned(prefix##_owned_##name##_t *dst, prefix##_loaned_##name##_t *src); + z_result_t prefix##_##name##_take_from_loaned(prefix##_owned_##name##_t *dst, prefix##_loaned_##name##_t *src); #define _Z_OWNED_FUNCTIONS_DEF_PREFIX(prefix, name) \ _Z_OWNED_FUNCTIONS_NO_COPY_DEF_PREFIX(prefix, name) \ @@ -126,8 +126,8 @@ #define _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_IMPL_PREFIX_INNER(prefix, type, name, f_check, f_null, f_move, f_drop, \ attribute) \ _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_NO_MOVE_IMPL_PREFIX_INNER(prefix, type, name, f_check, f_null, f_drop, attribute) \ - attribute z_result_t prefix##_##name##_take_loaned(prefix##_owned_##name##_t *obj, \ - prefix##_loaned_##name##_t *src) { \ + attribute z_result_t prefix##_##name##_take_from_loaned(prefix##_owned_##name##_t *obj, \ + prefix##_loaned_##name##_t *src) { \ f_move((&obj->_val), src); \ return _Z_RES_OK; \ } diff --git a/include/zenoh-pico/api/primitives.h b/include/zenoh-pico/api/primitives.h index 2a37bdff6..f5d7de7d4 100644 --- a/include/zenoh-pico/api/primitives.h +++ b/include/zenoh-pico/api/primitives.h @@ -1804,7 +1804,7 @@ void z_query_reply_options_default(z_query_reply_options_t *options); z_result_t z_query_reply(const z_loaned_query_t *query, const z_loaned_keyexpr_t *keyexpr, z_moved_bytes_t *payload, const z_query_reply_options_t *options); -z_result_t z_query_take_loaned(z_owned_query_t *dst, z_loaned_query_t *src); +z_result_t z_query_take_from_loaned(z_owned_query_t *dst, z_loaned_query_t *src); /** * Builds a :c:type:`z_query_reply_del_options_t` with default values. diff --git a/src/api/api.c b/src/api/api.c index 2fa16d256..1986601c2 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -1110,7 +1110,7 @@ bool z_reply_replier_id(const z_loaned_reply_t *reply, z_id_t *out_id) { #if Z_FEATURE_QUERYABLE == 1 _Z_OWNED_FUNCTIONS_RC_IMPL(query) -z_result_t z_query_take_loaned(z_owned_query_t *dst, z_loaned_query_t *src) { +z_result_t z_query_take_from_loaned(z_owned_query_t *dst, z_loaned_query_t *src) { dst->_rc = *src; _z_query_t q = _z_query_null(); *src = _z_query_rc_new_from_val(&q);