Skip to content

Commit

Permalink
add empty gravestone values for bytes_writer and serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisBiryukov91 committed Oct 30, 2024
1 parent 6cd1de4 commit 0b2dac9
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 73 deletions.
11 changes: 11 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------
Expand Down Expand Up @@ -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
======
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 */ 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
8 changes: 8 additions & 0 deletions include/zenoh-pico/api/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)

/**
Expand Down Expand Up @@ -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 <class T>
struct z_loaned_to_owned_type_t {};
Expand Down
88 changes: 53 additions & 35 deletions include/zenoh-pico/api/olv_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -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); \
Expand All @@ -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)

Expand Down Expand Up @@ -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) \
Expand Down
Loading

0 comments on commit 0b2dac9

Please sign in to comment.