Skip to content

Commit

Permalink
Loaned-take operation for taking value from loaned mutable reference (#…
Browse files Browse the repository at this point in the history
…901)

* implement loaned take

* add empty gravestone values for bytes_writer and serializer

* rename loaned_take -> take_loaned

* rename take_loaned -> take_from_loaned

* build fixes

* clang format

* build fix

* build fix

* unnecessary changes removed

* unnecessary change removed

---------

Co-authored-by: Denis Biryukov <denis.biryukov@zettascale.tech>
  • Loading branch information
milyin and DenisBiryukov91 authored Feb 24, 2025
1 parent 6223029 commit 0d10b49
Show file tree
Hide file tree
Showing 14 changed files with 271 additions and 108 deletions.
30 changes: 27 additions & 3 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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_from_loaned(z_owned_slice_t *dst, z_loaned_slice_t *src)
String
------
Expand Down Expand Up @@ -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_from_loaned(z_owned_string_t *dst, z_loaned_string_t *src)
String Array
------------
Expand Down Expand Up @@ -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_take_from_loaned(z_owned_string_array_t *dst, z_loaned_string_array_t *src)
Common
Expand Down Expand Up @@ -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_take_from_loaned(z_owned_keyexpr_t *dst, z_loaned_keyexpr_t *src)
Payload
-------
Expand Down Expand Up @@ -266,11 +268,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_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_from_loaned(z_owned_bytes_writer_t *dst, z_loaned_bytes_writer_t *src)
Encoding
--------
Expand Down Expand Up @@ -305,6 +309,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_from_loaned(z_owned_encoding_t *dst, z_loaned_encoding_t *src)
Predefined Encodings
Expand Down Expand Up @@ -390,7 +395,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_take_from_loaned(z_owned_reply_err_t *dst, z_loaned_reply_err_t *src)
Sample
------
Expand Down Expand Up @@ -429,6 +435,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_take_from_loaned(z_owned_sample_t *dst, z_loaned_sample_t *src)
Timestamp
Expand Down Expand Up @@ -1166,6 +1174,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_take_from_loaned(z_owned_query_t *dst, z_loaned_query_t *src)
Query
=====
Expand Down Expand Up @@ -1212,6 +1222,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_take_from_loaned(z_owned_reply_t *dst, z_loaned_reply_t *src)
Querier
=======
Expand Down Expand Up @@ -1293,6 +1305,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_take_from_loaned(z_owned_hello_t *dst, z_loaned_hello_t *src)
Serialization
Expand Down Expand Up @@ -1376,6 +1390,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_take_from_loaned(ze_owned_serializer_t *dst, ze_loaned_serializer_t *src)
Liveliness
========================
Expand Down
52 changes: 26 additions & 26 deletions include/zenoh-pico/api/handlers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) { \
Expand Down Expand Up @@ -145,30 +145,30 @@ extern "C" {
/* elem_drop_f */ z_##item_name##_drop, \
/* elem_null_f */ 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) \
Expand Down
Loading

0 comments on commit 0d10b49

Please sign in to comment.