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