From 51c04914d7c3d215646ece38faf89346a9cd24be Mon Sep 17 00:00:00 2001 From: Michael Ilyin Date: Tue, 20 Aug 2024 14:12:57 +0200 Subject: [PATCH 1/2] switch to ptr to z_xxx_moved_t (#597) * switch to ptr to z_xxx_moved_t * clang format * clang format * restored default values --- include/zenoh-pico/api/macros.h | 60 +++--- include/zenoh-pico/api/olv_macros.h | 92 ++++----- include/zenoh-pico/api/primitives.h | 42 ++-- include/zenoh-pico/api/types.h | 47 +++-- include/zenoh-pico/config.h | 6 +- include/zenoh-pico/system/platform-common.h | 4 +- src/api/api.c | 207 ++++++++++---------- src/system/platform-common.c | 4 +- zenohpico.pc | 2 +- 9 files changed, 230 insertions(+), 234 deletions(-) diff --git a/include/zenoh-pico/api/macros.h b/include/zenoh-pico/api/macros.h index 57a2cfd6b..a7aa01f75 100644 --- a/include/zenoh-pico/api/macros.h +++ b/include/zenoh-pico/api/macros.h @@ -96,36 +96,36 @@ * x: The instance to drop. */ #define z_drop(x) _Generic((x), \ - z_moved_keyexpr_t : z_keyexpr_drop, \ - z_moved_config_t : z_config_drop, \ - z_moved_session_t : z_session_drop, \ - z_moved_subscriber_t : z_subscriber_drop, \ - z_moved_publisher_t : z_publisher_drop, \ - z_moved_queryable_t : z_queryable_drop, \ - z_moved_reply_t : z_reply_drop, \ - z_moved_hello_t : z_hello_drop, \ - z_moved_string_t : z_string_drop, \ - z_moved_string_array_t : z_string_array_drop, \ - z_moved_sample_t : z_sample_drop, \ - z_moved_query_t : z_query_drop, \ - z_moved_encoding_t : z_encoding_drop, \ - z_moved_slice_t : z_slice_drop, \ - z_moved_bytes_t : z_bytes_drop, \ - z_moved_closure_sample_t : z_closure_sample_drop, \ - z_moved_closure_query_t : z_closure_query_drop, \ - z_moved_closure_reply_t : z_closure_reply_drop, \ - z_moved_closure_hello_t : z_closure_hello_drop, \ - z_moved_closure_zid_t : z_closure_zid_drop, \ - z_moved_task_t : z_task_join, \ - z_moved_mutex_t : z_mutex_drop, \ - z_moved_condvar_t : z_condvar_drop, \ - z_moved_fifo_handler_query_t : z_fifo_handler_query_drop, \ - z_moved_fifo_handler_reply_t : z_fifo_handler_reply_drop, \ - z_moved_fifo_handler_sample_t : z_fifo_handler_sample_drop, \ - z_moved_ring_handler_query_t : z_ring_handler_query_drop, \ - z_moved_ring_handler_reply_t : z_ring_handler_reply_drop, \ - z_moved_ring_handler_sample_t : z_ring_handler_sample_drop, \ - z_moved_reply_err_t : z_reply_err_drop \ + z_moved_keyexpr_t* : z_keyexpr_drop, \ + z_moved_config_t* : z_config_drop, \ + z_moved_session_t* : z_session_drop, \ + z_moved_subscriber_t* : z_subscriber_drop, \ + z_moved_publisher_t* : z_publisher_drop, \ + z_moved_queryable_t* : z_queryable_drop, \ + z_moved_reply_t* : z_reply_drop, \ + z_moved_hello_t* : z_hello_drop, \ + z_moved_string_t* : z_string_drop, \ + z_moved_string_array_t* : z_string_array_drop, \ + z_moved_sample_t* : z_sample_drop, \ + z_moved_query_t* : z_query_drop, \ + z_moved_encoding_t* : z_encoding_drop, \ + z_moved_slice_t* : z_slice_drop, \ + z_moved_bytes_t* : z_bytes_drop, \ + z_moved_closure_sample_t* : z_closure_sample_drop, \ + z_moved_closure_query_t* : z_closure_query_drop, \ + z_moved_closure_reply_t* : z_closure_reply_drop, \ + z_moved_closure_hello_t* : z_closure_hello_drop, \ + z_moved_closure_zid_t* : z_closure_zid_drop, \ + z_moved_task_t* : z_task_join, \ + z_moved_mutex_t* : z_mutex_drop, \ + z_moved_condvar_t* : z_condvar_drop, \ + z_moved_fifo_handler_query_t* : z_fifo_handler_query_drop, \ + z_moved_fifo_handler_reply_t* : z_fifo_handler_reply_drop, \ + z_moved_fifo_handler_sample_t* : z_fifo_handler_sample_drop, \ + z_moved_ring_handler_query_t* : z_ring_handler_query_drop, \ + z_moved_ring_handler_reply_t* : z_ring_handler_reply_drop, \ + z_moved_ring_handler_sample_t* : z_ring_handler_sample_drop, \ + z_moved_reply_err_t* : z_reply_err_drop \ )(x) /** diff --git a/include/zenoh-pico/api/olv_macros.h b/include/zenoh-pico/api/olv_macros.h index ce54828f4..5a399db17 100644 --- a/include/zenoh-pico/api/olv_macros.h +++ b/include/zenoh-pico/api/olv_macros.h @@ -29,7 +29,7 @@ #define _Z_MOVED_TYPE(name) \ typedef struct { \ - z_owned_##name##_t *_ptr; \ + z_owned_##name##_t _this; \ } z_moved_##name##_t; #define _Z_LOANED_TYPE(type, name) typedef type z_loaned_##name##_t; @@ -60,26 +60,26 @@ _Bool _z_owned_##name##_check(const z_owned_##name##_t *obj); \ const z_loaned_##name##_t *z_##name##_loan(const z_owned_##name##_t *obj); \ z_loaned_##name##_t *z_##name##_loan_mut(z_owned_##name##_t *obj); \ - z_moved_##name##_t z_##name##_move(z_owned_##name##_t *obj); \ - void z_##name##_take(z_owned_##name##_t *obj, z_moved_##name##_t src); \ + z_moved_##name##_t *z_##name##_move(z_owned_##name##_t *obj); \ + void z_##name##_take(z_owned_##name##_t *obj, z_moved_##name##_t *src); \ int8_t z_##name##_clone(z_owned_##name##_t *obj, const z_loaned_##name##_t *src); \ - void z_##name##_drop(z_moved_##name##_t obj); + void z_##name##_drop(z_moved_##name##_t *obj); #define _Z_OWNED_FUNCTIONS_NO_COPY_DEF(name) \ void _z_owned_##name##_null(z_owned_##name##_t *obj); \ _Bool _z_owned_##name##_check(const z_owned_##name##_t *obj); \ const z_loaned_##name##_t *z_##name##_loan(const z_owned_##name##_t *obj); \ z_loaned_##name##_t *z_##name##_loan_mut(z_owned_##name##_t *obj); \ - z_moved_##name##_t z_##name##_move(z_owned_##name##_t *obj); \ - void z_##name##_take(z_owned_##name##_t *obj, z_moved_##name##_t src); \ - void z_##name##_drop(z_moved_##name##_t obj); + z_moved_##name##_t *z_##name##_move(z_owned_##name##_t *obj); \ + void z_##name##_take(z_owned_##name##_t *obj, z_moved_##name##_t *src); \ + void z_##name##_drop(z_moved_##name##_t *obj); #define _Z_OWNED_FUNCTIONS_SYSTEM_DEF(name) \ void _z_owned_##name##_null(z_owned_##name##_t *obj); \ - void z_##name##_take(z_owned_##name##_t *obj, z_moved_##name##_t src); \ + void z_##name##_take(z_owned_##name##_t *obj, z_moved_##name##_t *src); \ const z_loaned_##name##_t *z_##name##_loan(const z_owned_##name##_t *obj); \ z_loaned_##name##_t *z_##name##_loan_mut(z_owned_##name##_t *obj); \ - z_moved_##name##_t z_##name##_move(z_owned_##name##_t *obj); + z_moved_##name##_t *z_##name##_move(z_owned_##name##_t *obj); #define _Z_VIEW_FUNCTIONS_DEF(name) \ _Bool z_view_##name##_is_empty(const z_view_##name##_t *obj); \ @@ -87,11 +87,11 @@ z_loaned_##name##_t *z_view_##name##_loan_mut(z_view_##name##_t *name); \ void _z_view_##name##_empty(z_view_##name##_t *name); -#define _Z_OWNED_FUNCTIONS_IMPL_MOVE_TAKE(name) \ - z_moved_##name##_t z_##name##_move(z_owned_##name##_t *obj) { return (z_moved_##name##_t){obj}; } \ - void z_##name##_take(z_owned_##name##_t *obj, z_moved_##name##_t src) { \ - *obj = *src._ptr; \ - _z_owned_##name##_null(src._ptr); \ +#define _Z_OWNED_FUNCTIONS_IMPL_MOVE_TAKE(name) \ + z_moved_##name##_t *z_##name##_move(z_owned_##name##_t *obj) { return (z_moved_##name##_t *)(obj); } \ + void z_##name##_take(z_owned_##name##_t *obj, z_moved_##name##_t *src) { \ + *obj = src->_this; \ + _z_owned_##name##_null(&src->_this); \ } #define _Z_OWNED_FUNCTIONS_PTR_IMPL(type, name, f_copy, f_free) \ @@ -110,9 +110,9 @@ } \ return ret; \ } \ - void z_##name##_drop(z_moved_##name##_t obj) { \ - if ((obj._ptr != NULL) && (obj._ptr->_val != NULL)) { \ - f_free(&obj._ptr->_val); \ + void z_##name##_drop(z_moved_##name##_t *obj) { \ + if ((obj != NULL) && (obj->_this._val != NULL)) { \ + f_free(obj->_this._val); \ } \ } @@ -125,22 +125,22 @@ int8_t z_##name##_clone(z_owned_##name##_t *obj, const z_loaned_##name##_t *src) { \ return f_copy((&obj->_val), src); \ } \ - void z_##name##_drop(z_moved_##name##_t obj) { \ - if (obj._ptr != NULL) f_drop((&obj._ptr->_val)); \ + void z_##name##_drop(z_moved_##name##_t *obj) { \ + if (obj != NULL) f_drop((&obj->_this._val)); \ } -#define _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_IMPL_INNER(type, name, f_check, f_null, f_drop, attribute) \ - attribute void _z_owned_##name##_null(z_owned_##name##_t *obj) { obj->_val = f_null(); } \ - attribute _Bool _z_owned_##name##_check(const z_owned_##name##_t *obj) { return f_check((&obj->_val)); } \ - attribute const z_loaned_##name##_t *z_##name##_loan(const z_owned_##name##_t *obj) { return &obj->_val; } \ - attribute z_loaned_##name##_t *z_##name##_loan_mut(z_owned_##name##_t *obj) { return &obj->_val; } \ - attribute z_moved_##name##_t z_##name##_move(z_owned_##name##_t *obj) { return (z_moved_##name##_t){obj}; } \ - attribute void z_##name##_take(z_owned_##name##_t *obj, z_moved_##name##_t src) { \ - *obj = *src._ptr; \ - _z_owned_##name##_null(src._ptr); \ - } \ - attribute void z_##name##_drop(z_moved_##name##_t obj) { \ - if (obj._ptr != NULL) f_drop((&obj._ptr->_val)); \ +#define _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_IMPL_INNER(type, name, f_check, f_null, f_drop, attribute) \ + attribute void _z_owned_##name##_null(z_owned_##name##_t *obj) { obj->_val = f_null(); } \ + attribute _Bool _z_owned_##name##_check(const z_owned_##name##_t *obj) { return f_check((&obj->_val)); } \ + attribute const z_loaned_##name##_t *z_##name##_loan(const z_owned_##name##_t *obj) { return &obj->_val; } \ + attribute z_loaned_##name##_t *z_##name##_loan_mut(z_owned_##name##_t *obj) { return &obj->_val; } \ + attribute z_moved_##name##_t *z_##name##_move(z_owned_##name##_t *obj) { return (z_moved_##name##_t *)(obj); } \ + attribute void z_##name##_take(z_owned_##name##_t *obj, z_moved_##name##_t *src) { \ + *obj = src->_this; \ + _z_owned_##name##_null(&src->_this); \ + } \ + attribute void z_##name##_drop(z_moved_##name##_t *obj) { \ + if (obj != NULL) f_drop((&obj->_this._val)); \ } #define _ZP_NOTHING @@ -165,9 +165,9 @@ } \ return ret; \ } \ - void z_##name##_drop(z_moved_##name##_t val) { \ - if (!_Z_RC_IS_NULL(&val._ptr->_rc)) { \ - _z_##name##_rc_drop(&val._ptr->_rc); \ + void z_##name##_drop(z_moved_##name##_t *obj) { \ + if (!_Z_RC_IS_NULL(&obj->_this._rc)) { \ + _z_##name##_rc_drop(&obj->_this._rc); \ } \ } @@ -183,12 +183,12 @@ z_loaned_##name##_t *z_view_##name##_loan_mut(z_view_##name##_t *obj) { return &obj->_val; } \ void z_view_##name##_empty(z_view_##name##_t *obj) { obj->_val = f_null(); } -#define _Z_OWNED_FUNCTIONS_CLOSURE_DEF(name) \ - void _z_owned_##name##_null(z_owned_##name##_t *name); \ - _Bool _z_owned_##name##_check(const z_owned_##name##_t *val); \ - z_moved_##name##_t z_##name##_move(z_owned_##name##_t *val); \ - void z_##name##_take(z_owned_##name##_t *obj, z_moved_##name##_t src); \ - void z_##name##_drop(z_moved_##name##_t val); \ +#define _Z_OWNED_FUNCTIONS_CLOSURE_DEF(name) \ + void _z_owned_##name##_null(z_owned_##name##_t *name); \ + _Bool _z_owned_##name##_check(const z_owned_##name##_t *val); \ + z_moved_##name##_t *z_##name##_move(z_owned_##name##_t *val); \ + void z_##name##_take(z_owned_##name##_t *obj, z_moved_##name##_t *src); \ + void z_##name##_drop(z_moved_##name##_t *obj); \ const z_loaned_##name##_t *z_##name##_loan(const z_owned_##name##_t *val); #define _Z_OWNED_FUNCTIONS_CLOSURE_IMPL(name, f_call, f_drop) \ @@ -199,13 +199,13 @@ val->_val.context = NULL; \ } \ _Bool _z_owned_##name##_check(const z_owned_##name##_t *val) { return val->_val.call != NULL; } \ - void z_##name##_drop(z_moved_##name##_t val) { \ - if (val._ptr->_val.drop != NULL) { \ - (val._ptr->_val.drop)(val._ptr->_val.context); \ - val._ptr->_val.drop = NULL; \ + void z_##name##_drop(z_moved_##name##_t *obj) { \ + if (obj->_this._val.drop != NULL) { \ + (obj->_this._val.drop)(obj->_this._val.context); \ + obj->_this._val.drop = NULL; \ } \ - val._ptr->_val.call = NULL; \ - val._ptr->_val.context = NULL; \ + obj->_this._val.call = NULL; \ + obj->_this._val.context = NULL; \ } \ const z_loaned_##name##_t *z_##name##_loan(const z_owned_##name##_t *val) { return &val->_val; } \ int8_t z_##name(z_owned_##name##_t *closure, f_call call, f_drop drop, void *context) { \ diff --git a/include/zenoh-pico/api/primitives.h b/include/zenoh-pico/api/primitives.h index de060781f..fa63295e5 100644 --- a/include/zenoh-pico/api/primitives.h +++ b/include/zenoh-pico/api/primitives.h @@ -805,7 +805,7 @@ int8_t z_bytes_serialize_from_slice(z_owned_bytes_t *bytes, const z_loaned_slice * Return: * ``0`` if encode successful, ``negative value`` otherwise. */ -int8_t z_bytes_from_slice(z_owned_bytes_t *bytes, z_moved_slice_t slice); +int8_t z_bytes_from_slice(z_owned_bytes_t *bytes, z_moved_slice_t *slice); /** * Encodes data into a :c:type:`z_owned_bytes_t`. @@ -872,7 +872,7 @@ int8_t z_bytes_serialize_from_string(z_owned_bytes_t *bytes, const z_loaned_stri * Return: * ``0`` if encode successful, ``negative value`` otherwise. */ -int8_t z_bytes_from_string(z_owned_bytes_t *bytes, z_moved_string_t s); +int8_t z_bytes_from_string(z_owned_bytes_t *bytes, z_moved_string_t *s); /** * Encodes a null-terminated string into a :c:type:`z_owned_bytes_t`. @@ -936,7 +936,7 @@ int8_t z_bytes_from_iter(z_owned_bytes_t *bytes, _Bool (*iterator_body)(z_owned_ * Return: * ``0`` if encode successful, ``negative value`` otherwise. */ -int8_t z_bytes_from_pair(z_owned_bytes_t *bytes, z_moved_bytes_t first, z_moved_bytes_t second); +int8_t z_bytes_from_pair(z_owned_bytes_t *bytes, z_moved_bytes_t *first, z_moved_bytes_t *second); /** * Parameters: @@ -1087,7 +1087,7 @@ int8_t z_bytes_writer_write_all(z_bytes_writer_t *writer, const uint8_t *src, si * Return: * 0 in case of success, negative error code otherwise */ -int8_t z_bytes_writer_append(z_bytes_writer_t *writer, z_moved_bytes_t bytes); +int8_t z_bytes_writer_append(z_bytes_writer_t *writer, z_moved_bytes_t *bytes); /** * Appends bytes, with boundaries information. It would allow to read the same piece of data using @@ -1100,7 +1100,7 @@ int8_t z_bytes_writer_append(z_bytes_writer_t *writer, z_moved_bytes_t bytes); * Return: * 0 in case of success, negative error code otherwise */ -int8_t z_bytes_writer_append_bounded(z_bytes_writer_t *writer, z_moved_bytes_t bytes); +int8_t z_bytes_writer_append_bounded(z_bytes_writer_t *writer, z_moved_bytes_t *bytes); /** * Create timestamp. @@ -1495,7 +1495,7 @@ int8_t z_whatami_to_view_string(z_whatami_t whatami, z_view_string_t *str_out); * Return: * ``0`` if scouting successfully triggered, ``negative value`` otherwise. */ -int8_t z_scout(z_moved_config_t config, z_moved_closure_hello_t callback, const z_scout_options_t *options); +int8_t z_scout(z_moved_config_t *config, z_moved_closure_hello_t *callback, const z_scout_options_t *options); /** * Opens a Zenoh session. @@ -1507,7 +1507,7 @@ int8_t z_scout(z_moved_config_t config, z_moved_closure_hello_t callback, const * Return: * ``0`` if open successful, ``negative value`` otherwise. */ -int8_t z_open(z_owned_session_t *zs, z_moved_config_t config); +int8_t z_open(z_owned_session_t *zs, z_moved_config_t *config); /** * Closes a Zenoh session. @@ -1518,7 +1518,7 @@ int8_t z_open(z_owned_session_t *zs, z_moved_config_t config); * Return: * ``0`` if close successful, ``negative value`` otherwise. */ -int8_t z_close(z_moved_session_t zs); +int8_t z_close(z_moved_session_t *zs); /** * Fetches Zenoh IDs of all connected peers. @@ -1533,7 +1533,7 @@ int8_t z_close(z_moved_session_t zs); * Return: * ``0`` if operation successfully triggered, ``negative value`` otherwise. */ -int8_t z_info_peers_zid(const z_loaned_session_t *zs, z_moved_closure_zid_t callback); +int8_t z_info_peers_zid(const z_loaned_session_t *zs, z_moved_closure_zid_t *callback); /** * Fetches Zenoh IDs of all connected routers. @@ -1548,7 +1548,7 @@ int8_t z_info_peers_zid(const z_loaned_session_t *zs, z_moved_closure_zid_t call * Return: * ``0`` if operation successfully triggered, ``negative value`` otherwise. */ -int8_t z_info_routers_zid(const z_loaned_session_t *zs, z_moved_closure_zid_t callback); +int8_t z_info_routers_zid(const z_loaned_session_t *zs, z_moved_closure_zid_t *callback); /** * Gets the local Zenoh ID associated to a given Zenoh session. @@ -1692,7 +1692,7 @@ void z_delete_options_default(z_delete_options_t *options); * Return: * ``0`` if put operation successful, ``negative value`` otherwise. */ -int8_t z_put(const z_loaned_session_t *zs, const z_loaned_keyexpr_t *keyexpr, z_moved_bytes_t payload, +int8_t z_put(const z_loaned_session_t *zs, const z_loaned_keyexpr_t *keyexpr, z_moved_bytes_t *payload, const z_put_options_t *options); /** @@ -1742,7 +1742,7 @@ int8_t z_declare_publisher(z_owned_publisher_t *pub, const z_loaned_session_t *z * Return: * ``0`` if undeclare successful, ``negative value`` otherwise. */ -int8_t z_undeclare_publisher(z_moved_publisher_t pub); +int8_t z_undeclare_publisher(z_moved_publisher_t *pub); /** * Builds a :c:type:`z_publisher_put_options_t` with default values. @@ -1771,7 +1771,7 @@ void z_publisher_delete_options_default(z_publisher_delete_options_t *options); * Return: * ``0`` if put operation successful, ``negative value`` otherwise. */ -int8_t z_publisher_put(const z_loaned_publisher_t *pub, z_moved_bytes_t payload, +int8_t z_publisher_put(const z_loaned_publisher_t *pub, z_moved_bytes_t *payload, const z_publisher_put_options_t *options); /** @@ -1821,7 +1821,7 @@ void z_get_options_default(z_get_options_t *options); * ``0`` if put operation successful, ``negative value`` otherwise. */ int8_t z_get(const z_loaned_session_t *zs, const z_loaned_keyexpr_t *keyexpr, const char *parameters, - z_moved_closure_reply_t callback, z_get_options_t *options); + z_moved_closure_reply_t *callback, z_get_options_t *options); /** * Checks if queryable answered with an OK, which allows this value to be treated as a sample. * @@ -1894,7 +1894,7 @@ void z_queryable_options_default(z_queryable_options_t *options); * ``0`` if declare operation successful, ``negative value`` otherwise. */ int8_t z_declare_queryable(z_owned_queryable_t *queryable, const z_loaned_session_t *zs, - const z_loaned_keyexpr_t *keyexpr, z_moved_closure_query_t callback, + const z_loaned_keyexpr_t *keyexpr, z_moved_closure_query_t *callback, const z_queryable_options_t *options); /** @@ -1906,7 +1906,7 @@ int8_t z_declare_queryable(z_owned_queryable_t *queryable, const z_loaned_sessio * Return: * ``0`` if undeclare operation successful, ``negative value`` otherwise. */ -int8_t z_undeclare_queryable(z_moved_queryable_t queryable); +int8_t z_undeclare_queryable(z_moved_queryable_t *queryable); /** * Builds a :c:type:`z_query_reply_options_t` with default values. @@ -1933,7 +1933,7 @@ void z_query_reply_options_default(z_query_reply_options_t *options); * Return: * ``0`` if reply operation successful, ``negative value`` otherwise. */ -int8_t z_query_reply(const z_loaned_query_t *query, const z_loaned_keyexpr_t *keyexpr, z_moved_bytes_t payload, +int8_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); /** @@ -1987,7 +1987,7 @@ void z_query_reply_err_options_default(z_query_reply_err_options_t *options); * Return: * ``0`` if reply operation successful, ``negative value`` otherwise. */ -int8_t z_query_reply_err(const z_loaned_query_t *query, z_moved_bytes_t payload, +int8_t z_query_reply_err(const z_loaned_query_t *query, z_moved_bytes_t *payload, const z_query_reply_err_options_t *options); #endif @@ -2070,7 +2070,7 @@ int8_t z_declare_keyexpr(z_owned_keyexpr_t *declared_keyexpr, const z_loaned_ses * Return: * ``0`` if undeclare successful, ``negative value`` otherwise. */ -int8_t z_undeclare_keyexpr(z_moved_keyexpr_t keyexpr, const z_loaned_session_t *zs); +int8_t z_undeclare_keyexpr(z_moved_keyexpr_t *keyexpr, const z_loaned_session_t *zs); #if Z_FEATURE_SUBSCRIPTION == 1 /** @@ -2095,7 +2095,7 @@ void z_subscriber_options_default(z_subscriber_options_t *options); * ``0`` if declare successful, ``negative value`` otherwise. */ int8_t z_declare_subscriber(z_owned_subscriber_t *sub, const z_loaned_session_t *zs, const z_loaned_keyexpr_t *keyexpr, - z_moved_closure_sample_t callback, const z_subscriber_options_t *options); + z_moved_closure_sample_t *callback, const z_subscriber_options_t *options); /** * Undeclares the subscriber. @@ -2106,7 +2106,7 @@ int8_t z_declare_subscriber(z_owned_subscriber_t *sub, const z_loaned_session_t * Return: * ``0`` if undeclare successful, ``negative value`` otherwise. */ -int8_t z_undeclare_subscriber(z_moved_subscriber_t sub); +int8_t z_undeclare_subscriber(z_moved_subscriber_t *sub); /** * Gets the keyexpr from a subscriber. diff --git a/include/zenoh-pico/api/types.h b/include/zenoh-pico/api/types.h index b5f417e04..39dea8a86 100644 --- a/include/zenoh-pico/api/types.h +++ b/include/zenoh-pico/api/types.h @@ -210,7 +210,7 @@ typedef struct { * _Bool is_express: If true, Zenoh will not wait to batch this operation with others to reduce the bandwidth. */ typedef struct { - z_moved_encoding_t encoding; + z_moved_encoding_t *encoding; z_congestion_control_t congestion_control; z_priority_t priority; _Bool is_express; @@ -230,20 +230,20 @@ typedef struct { * Represents the configuration used to configure a query reply sent via :c:func:`z_query_reply. * * Members: - * z_moved_encoding_t encoding: The encoding of the payload. + * z_moved_encoding_t* encoding: The encoding of the payload. * z_congestion_control_t congestion_control: The congestion control to apply when routing this message. * z_priority_t priority: The priority of this message when routed. * z_timestamp_t *timestamp: The API level timestamp (e.g. of the data when it was created). * _Bool is_express: If true, Zenoh will not wait to batch this operation with others to reduce the bandwidth. - * z_moved_bytes_t attachment: An optional attachment to the response. + * z_moved_bytes_t* attachment: An optional attachment to the response. */ typedef struct { - z_moved_encoding_t encoding; + z_moved_encoding_t *encoding; z_congestion_control_t congestion_control; z_priority_t priority; z_timestamp_t *timestamp; _Bool is_express; - z_moved_bytes_t attachment; + z_moved_bytes_t *attachment; } z_query_reply_options_t; /** @@ -254,45 +254,44 @@ typedef struct { * z_priority_t priority: The priority of this message when routed. * z_timestamp_t *timestamp: The API level timestamp (e.g. of the data when it was created). * _Bool is_express: If true, Zenoh will not wait to batch this operation with others to reduce the bandwidth. - * z_moved_bytes_t attachment: An optional attachment to the response. + * z_moved_bytes_t* attachment: An optional attachment to the response. */ typedef struct { z_congestion_control_t congestion_control; z_priority_t priority; z_timestamp_t *timestamp; _Bool is_express; - z_moved_bytes_t attachment; + z_moved_bytes_t *attachment; } z_query_reply_del_options_t; /** * Represents the configuration used to configure a query reply error sent via :c:func:`z_query_reply_err. * * Members: - * z_moved_encoding_t encoding: The encoding of the payload. + * z_moved_encoding_t* encoding: The encoding of the payload. */ typedef struct { - z_moved_encoding_t encoding; + z_moved_encoding_t *encoding; } z_query_reply_err_options_t; /** * Represents the configuration used to configure a put operation sent via via :c:func:`z_put`. * * Members: - * z_moved_encoding_t encoding: The encoding of the payload. + * z_moved_encoding_t* encoding: The encoding of the payload. * z_congestion_control_t congestion_control: The congestion control to apply when routing this message. * z_priority_t priority: The priority of this message when routed. * z_timestamp_t *timestamp: The API level timestamp (e.g. of the data when it was created). * _Bool is_express: If true, Zenoh will not wait to batch this operation with others to reduce the bandwidth. - * z_moved_bytes_t attachment: An optional attachment to the publication. + * z_moved_bytes_t* attachment: An optional attachment to the publication. */ typedef struct { - z_moved_encoding_t encoding; + z_moved_encoding_t *encoding; z_congestion_control_t congestion_control; z_priority_t priority; z_timestamp_t *timestamp; _Bool is_express; - z_moved_bytes_t attachment; - + z_moved_bytes_t *attachment; } z_put_options_t; /** @@ -316,14 +315,14 @@ typedef struct { * sent via :c:func:`z_publisher_put`. * * Members: - * z_moved_encoding_t encoding: The encoding of the payload. + * z_moved_encoding_t* encoding: The encoding of the payload. * z_timestamp_t *timestamp: The API level timestamp (e.g. of the data when it was created). - * z_moved_bytes_t attachment: An optional attachment to the publication. + * z_moved_bytes_t* attachment: An optional attachment to the publication. */ typedef struct { - z_moved_encoding_t encoding; + z_moved_encoding_t *encoding; z_timestamp_t *timestamp; - z_moved_bytes_t attachment; + z_moved_bytes_t *attachment; } z_publisher_put_options_t; /** @@ -341,25 +340,25 @@ typedef struct { * Represents the configuration used to configure a get operation sent via :c:func:`z_get`. * * Members: - * z_moved_bytes_t payload: The payload to include in the query. - * z_moved_encoding_t encoding: Payload encoding. + * z_moved_bytes_t* payload: The payload to include in the query. + * z_moved_encoding_t* encoding: Payload encoding. * z_query_consolidation_t consolidation: The replies consolidation strategy to apply on replies. * z_congestion_control_t congestion_control: The congestion control to apply when routing the query. * z_priority_t priority: The priority of the query. * _Bool is_express: If true, Zenoh will not wait to batch this operation with others to reduce the bandwidth. * z_query_target_t target: The queryables that should be targeted by this get. - * z_moved_bytes_t attachment: An optional attachment to the query. + * z_moved_bytes_t* attachment: An optional attachment to the query. */ typedef struct { - z_moved_bytes_t payload; - z_moved_encoding_t encoding; + z_moved_bytes_t *payload; + z_moved_encoding_t *encoding; z_query_consolidation_t consolidation; z_congestion_control_t congestion_control; z_priority_t priority; _Bool is_express; z_query_target_t target; uint32_t timeout_ms; - z_moved_bytes_t attachment; + z_moved_bytes_t *attachment; } z_get_options_t; /** diff --git a/include/zenoh-pico/config.h b/include/zenoh-pico/config.h index de3cb138e..3148545db 100644 --- a/include/zenoh-pico/config.h +++ b/include/zenoh-pico/config.h @@ -16,9 +16,9 @@ #define INCLUDE_ZENOH_PICO_CONFIG_H /*--- CMake generated config; pass values to CMake to change the following tokens ---*/ -#define Z_FRAG_MAX_SIZE 300000 -#define Z_BATCH_UNICAST_SIZE 65535 -#define Z_BATCH_MULTICAST_SIZE 8096 +#define Z_FRAG_MAX_SIZE 4096 +#define Z_BATCH_UNICAST_SIZE 2048 +#define Z_BATCH_MULTICAST_SIZE 2048 #define Z_CONFIG_SOCKET_TIMEOUT 100 #define Z_FEATURE_MULTI_THREAD 1 diff --git a/include/zenoh-pico/system/platform-common.h b/include/zenoh-pico/system/platform-common.h index a96600bb4..15f2440aa 100644 --- a/include/zenoh-pico/system/platform-common.h +++ b/include/zenoh-pico/system/platform-common.h @@ -107,7 +107,7 @@ _Z_OWNED_TYPE_VALUE(_z_mutex_t, mutex) _Z_OWNED_FUNCTIONS_SYSTEM_DEF(mutex) int8_t z_mutex_init(z_owned_mutex_t *m); -int8_t z_mutex_drop(z_moved_mutex_t m); +int8_t z_mutex_drop(z_moved_mutex_t *m); int8_t z_mutex_lock(z_loaned_mutex_t *m); int8_t z_mutex_try_lock(z_loaned_mutex_t *m); @@ -125,7 +125,7 @@ _Z_OWNED_TYPE_VALUE(_z_condvar_t, condvar) _Z_OWNED_FUNCTIONS_SYSTEM_DEF(condvar) int8_t z_condvar_init(z_owned_condvar_t *cv); -int8_t z_condvar_drop(z_moved_condvar_t cv); +int8_t z_condvar_drop(z_moved_condvar_t *cv); int8_t z_condvar_signal(z_loaned_condvar_t *cv); int8_t z_condvar_wait(z_loaned_condvar_t *cv, z_loaned_mutex_t *m); diff --git a/src/api/api.c b/src/api/api.c index 2911fb847..9c8f41380 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -549,9 +549,9 @@ int8_t z_bytes_serialize_from_double(z_owned_bytes_t *bytes, double val) { return _z_bytes_from_double(&bytes->_val, val); } -int8_t z_bytes_from_slice(z_owned_bytes_t *bytes, z_moved_slice_t slice) { +int8_t z_bytes_from_slice(z_owned_bytes_t *bytes, z_moved_slice_t *slice) { z_bytes_empty(bytes); - _z_slice_t s = _z_slice_steal(&slice._ptr->_val); + _z_slice_t s = _z_slice_steal(&slice->_this._val); _Z_CLEAN_RETURN_IF_ERR(_z_bytes_from_slice(&bytes->_val, s), _z_slice_clear(&s)); return _Z_RES_OK; } @@ -581,11 +581,11 @@ int8_t z_bytes_serialize_from_buf(z_owned_bytes_t *bytes, const uint8_t *data, s return z_bytes_from_slice(bytes, z_slice_move(&s)); } -int8_t z_bytes_from_string(z_owned_bytes_t *bytes, z_moved_string_t s) { +int8_t z_bytes_from_string(z_owned_bytes_t *bytes, z_moved_string_t *s) { // TODO, verify that string is a valid UTF-8 ? z_owned_slice_t slice; - size_t str_len = _z_string_len(&s._ptr->_val); - slice._val = _z_slice_steal(&s._ptr->_val._slice); + size_t str_len = _z_string_len(&s->_this._val); + slice._val = _z_slice_steal(&s->_this._val._slice); slice._val.len = str_len; return z_bytes_from_slice(bytes, z_slice_move(&slice)); } @@ -627,9 +627,9 @@ int8_t z_bytes_from_iter(z_owned_bytes_t *bytes, _Bool (*iterator_body)(z_owned_ return _Z_RES_OK; } -int8_t z_bytes_from_pair(z_owned_bytes_t *bytes, z_moved_bytes_t first, z_moved_bytes_t second) { +int8_t z_bytes_from_pair(z_owned_bytes_t *bytes, z_moved_bytes_t *first, z_moved_bytes_t *second) { z_bytes_empty(bytes); - return _z_bytes_from_pair(&bytes->_val, &first._ptr->_val, &second._ptr->_val); + return _z_bytes_from_pair(&bytes->_val, &first->_this._val, &second->_this._val); } void z_bytes_empty(z_owned_bytes_t *bytes) { bytes->_val = _z_bytes_null(); } @@ -673,12 +673,12 @@ int8_t z_bytes_writer_write_all(z_bytes_writer_t *writer, const uint8_t *src, si return _z_bytes_writer_write_all(&writer->writer, src, len); } -int8_t z_bytes_writer_append(z_bytes_writer_t *writer, z_moved_bytes_t bytes) { - return _z_bytes_writer_append(&writer->writer, &bytes._ptr->_val); +int8_t z_bytes_writer_append(z_bytes_writer_t *writer, z_moved_bytes_t *bytes) { + return _z_bytes_writer_append(&writer->writer, &bytes->_this._val); } -int8_t z_bytes_writer_append_bounded(z_bytes_writer_t *writer, z_moved_bytes_t bytes) { - return _z_bytes_iterator_writer_write(writer, &bytes._ptr->_val); +int8_t z_bytes_writer_append_bounded(z_bytes_writer_t *writer, z_moved_bytes_t *bytes) { + return _z_bytes_iterator_writer_write(writer, &bytes->_this._val); } int8_t z_timestamp_new(z_timestamp_t *ts, const z_loaned_session_t *zs) { @@ -857,32 +857,32 @@ void __z_hello_handler(_z_hello_t *hello, __z_hello_handler_wrapper_t *wrapped_c wrapped_ctx->user_call(hello, wrapped_ctx->ctx); } -int8_t z_scout(z_moved_config_t config, z_moved_closure_hello_t callback, const z_scout_options_t *options) { +int8_t z_scout(z_moved_config_t *config, z_moved_closure_hello_t *callback, const z_scout_options_t *options) { int8_t ret = _Z_RES_OK; - void *ctx = callback._ptr->_val.context; - callback._ptr->_val.context = NULL; + void *ctx = callback->_this._val.context; + callback->_this._val.context = NULL; // TODO[API-NET]: When API and NET are a single layer, there is no wrap the user callback and args // to enclose the z_reply_t into a z_owned_reply_t. __z_hello_handler_wrapper_t *wrapped_ctx = (__z_hello_handler_wrapper_t *)z_malloc(sizeof(__z_hello_handler_wrapper_t)); if (wrapped_ctx != NULL) { - wrapped_ctx->user_call = callback._ptr->_val.call; + wrapped_ctx->user_call = callback->_this._val.call; wrapped_ctx->ctx = ctx; z_what_t what; if (options != NULL) { what = options->what; } else { - char *opt_as_str = _z_config_get(&config._ptr->_val, Z_CONFIG_SCOUTING_WHAT_KEY); + char *opt_as_str = _z_config_get(&config->_this._val, Z_CONFIG_SCOUTING_WHAT_KEY); if (opt_as_str == NULL) { opt_as_str = (char *)Z_CONFIG_SCOUTING_WHAT_DEFAULT; } what = strtol(opt_as_str, NULL, 10); } - char *opt_as_str = _z_config_get(&config._ptr->_val, Z_CONFIG_MULTICAST_LOCATOR_KEY); + char *opt_as_str = _z_config_get(&config->_this._val, Z_CONFIG_MULTICAST_LOCATOR_KEY); if (opt_as_str == NULL) { opt_as_str = (char *)Z_CONFIG_MULTICAST_LOCATOR_DEFAULT; } @@ -892,7 +892,7 @@ int8_t z_scout(z_moved_config_t config, z_moved_closure_hello_t callback, const if (options != NULL) { timeout = options->timeout_ms; } else { - opt_as_str = _z_config_get(&config._ptr->_val, Z_CONFIG_SCOUTING_TIMEOUT_KEY); + opt_as_str = _z_config_get(&config->_this._val, Z_CONFIG_SCOUTING_TIMEOUT_KEY); if (opt_as_str == NULL) { opt_as_str = (char *)Z_CONFIG_SCOUTING_TIMEOUT_DEFAULT; } @@ -900,24 +900,24 @@ int8_t z_scout(z_moved_config_t config, z_moved_closure_hello_t callback, const } _z_id_t zid = _z_id_empty(); - char *zid_str = _z_config_get(&config._ptr->_val, Z_CONFIG_SESSION_ZID_KEY); + char *zid_str = _z_config_get(&config->_this._val, Z_CONFIG_SESSION_ZID_KEY); if (zid_str != NULL) { _z_uuid_to_bytes(zid.id, zid_str); } - _z_scout(what, zid, mcast_locator, timeout, __z_hello_handler, wrapped_ctx, callback._ptr->_val.drop, ctx); + _z_scout(what, zid, mcast_locator, timeout, __z_hello_handler, wrapped_ctx, callback->_this._val.drop, ctx); z_free(wrapped_ctx); z_config_drop(config); } else { ret = _Z_ERR_SYSTEM_OUT_OF_MEMORY; } - _z_owned_closure_hello_null(callback._ptr); + _z_owned_closure_hello_null(&callback->_this); return ret; } -int8_t z_open(z_owned_session_t *zs, z_moved_config_t config) { +int8_t z_open(z_owned_session_t *zs, z_moved_config_t *config) { _z_owned_session_null(zs); _z_session_t *s = z_malloc(sizeof(_z_session_t)); if (s == NULL) { @@ -934,7 +934,7 @@ int8_t z_open(z_owned_session_t *zs, z_moved_config_t config) { } zs->_rc = zsrc; // Open session - int8_t ret = _z_open(&zs->_rc, &config._ptr->_val); + int8_t ret = _z_open(&zs->_rc, &config->_this._val); if (ret != _Z_RES_OK) { _z_session_rc_decr(&zs->_rc); _z_owned_session_null(zs); @@ -946,52 +946,52 @@ int8_t z_open(z_owned_session_t *zs, z_moved_config_t config) { return _Z_RES_OK; } -int8_t z_close(z_moved_session_t zs) { - if (zs._ptr == NULL || !_z_owned_session_check(zs._ptr)) { +int8_t z_close(z_moved_session_t *zs) { + if (zs == NULL || !_z_owned_session_check(&zs->_this)) { return _Z_RES_OK; } z_session_drop(zs); return _Z_RES_OK; } -int8_t z_info_peers_zid(const z_loaned_session_t *zs, z_moved_closure_zid_t callback) { +int8_t z_info_peers_zid(const z_loaned_session_t *zs, z_moved_closure_zid_t *callback) { // Call transport function switch (_Z_RC_IN_VAL(zs)->_tp._type) { case _Z_TRANSPORT_MULTICAST_TYPE: case _Z_TRANSPORT_RAWETH_TYPE: - _zp_multicast_fetch_zid(&(_Z_RC_IN_VAL(zs)->_tp), &callback._ptr->_val); + _zp_multicast_fetch_zid(&(_Z_RC_IN_VAL(zs)->_tp), &callback->_this._val); break; default: break; } // Note and clear context - void *ctx = callback._ptr->_val.context; - callback._ptr->_val.context = NULL; + void *ctx = callback->_this._val.context; + callback->_this._val.context = NULL; // Drop if needed - if (callback._ptr->_val.drop != NULL) { - callback._ptr->_val.drop(ctx); + if (callback->_this._val.drop != NULL) { + callback->_this._val.drop(ctx); } - _z_owned_closure_zid_null(callback._ptr); + _z_owned_closure_zid_null(&callback->_this); return 0; } -int8_t z_info_routers_zid(const z_loaned_session_t *zs, z_moved_closure_zid_t callback) { +int8_t z_info_routers_zid(const z_loaned_session_t *zs, z_moved_closure_zid_t *callback) { // Call transport function switch (_Z_RC_IN_VAL(zs)->_tp._type) { case _Z_TRANSPORT_UNICAST_TYPE: - _zp_unicast_fetch_zid(&(_Z_RC_IN_VAL(zs)->_tp), &callback._ptr->_val); + _zp_unicast_fetch_zid(&(_Z_RC_IN_VAL(zs)->_tp), &callback->_this._val); break; default: break; } // Note and clear context - void *ctx = callback._ptr->_val.context; - callback._ptr->_val.context = NULL; + void *ctx = callback->_this._val.context; + callback->_this._val.context = NULL; // Drop if needed - if (callback._ptr->_val.drop != NULL) { - callback._ptr->_val.drop(ctx); + if (callback->_this._val.drop != NULL) { + callback->_this._val.drop(ctx); } - _z_owned_closure_zid_null(callback._ptr); + _z_owned_closure_zid_null(&callback->_this); return 0; } @@ -1060,10 +1060,10 @@ _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_IMPL(_z_publisher_t, publisher, _z_publisher_ch void z_put_options_default(z_put_options_t *options) { options->congestion_control = Z_CONGESTION_CONTROL_DEFAULT; options->priority = Z_PRIORITY_DEFAULT; - options->encoding = (z_moved_encoding_t){NULL}; + options->encoding = NULL; options->is_express = false; options->timestamp = NULL; - options->attachment = (z_moved_bytes_t){NULL}; + options->attachment = NULL; } void z_delete_options_default(z_delete_options_t *options) { @@ -1073,7 +1073,7 @@ void z_delete_options_default(z_delete_options_t *options) { options->priority = Z_PRIORITY_DEFAULT; } -int8_t z_put(const z_loaned_session_t *zs, const z_loaned_keyexpr_t *keyexpr, z_moved_bytes_t payload, +int8_t z_put(const z_loaned_session_t *zs, const z_loaned_keyexpr_t *keyexpr, z_moved_bytes_t *payload, const z_put_options_t *options) { int8_t ret = 0; @@ -1089,17 +1089,16 @@ int8_t z_put(const z_loaned_session_t *zs, const z_loaned_keyexpr_t *keyexpr, z_ } _z_keyexpr_t keyexpr_aliased = _z_keyexpr_alias_from_user_defined(*keyexpr, true); - ret = - _z_write(_Z_RC_IN_VAL(zs), keyexpr_aliased, _z_bytes_from_owned_bytes(payload._ptr), - opt.encoding._ptr == NULL ? NULL : &opt.encoding._ptr->_val, Z_SAMPLE_KIND_PUT, opt.congestion_control, - opt.priority, opt.is_express, opt.timestamp, _z_bytes_from_owned_bytes(opt.attachment._ptr)); + ret = _z_write(_Z_RC_IN_VAL(zs), keyexpr_aliased, _z_bytes_from_owned_bytes(&payload->_this), + opt.encoding == NULL ? NULL : &opt.encoding->_this._val, Z_SAMPLE_KIND_PUT, opt.congestion_control, + opt.priority, opt.is_express, opt.timestamp, _z_bytes_from_owned_bytes(&opt.attachment->_this)); // Trigger local subscriptions _z_trigger_local_subscriptions( - _Z_RC_IN_VAL(zs), keyexpr_aliased, _z_bytes_from_owned_bytes(payload._ptr), - opt.encoding._ptr == NULL ? NULL : &opt.encoding._ptr->_val, + _Z_RC_IN_VAL(zs), keyexpr_aliased, _z_bytes_from_owned_bytes(&payload->_this), + opt.encoding == NULL ? NULL : &opt.encoding->_this._val, _z_n_qos_make(opt.is_express, opt.congestion_control == Z_CONGESTION_CONTROL_BLOCK, opt.priority), - opt.timestamp, _z_bytes_from_owned_bytes(opt.attachment._ptr)); + opt.timestamp, _z_bytes_from_owned_bytes(&opt.attachment->_this)); // Clean-up z_encoding_drop(opt.encoding); z_bytes_drop(opt.attachment); @@ -1125,7 +1124,7 @@ int8_t z_delete(const z_loaned_session_t *zs, const z_loaned_keyexpr_t *keyexpr, } void z_publisher_options_default(z_publisher_options_t *options) { - options->encoding = (z_moved_encoding_t){NULL}; + options->encoding = NULL; options->congestion_control = Z_CONGESTION_CONTROL_DEFAULT; options->priority = Z_PRIORITY_DEFAULT; options->is_express = false; @@ -1154,7 +1153,7 @@ int8_t z_declare_publisher(z_owned_publisher_t *pub, const z_loaned_session_t *z opt = *options; } // Set publisher - _z_publisher_t int_pub = _z_declare_publisher(zs, key, opt.encoding._ptr == NULL ? NULL : &opt.encoding._ptr->_val, + _z_publisher_t int_pub = _z_declare_publisher(zs, key, opt.encoding == NULL ? NULL : &opt.encoding->_this._val, opt.congestion_control, opt.priority, opt.is_express); // Create write filter int8_t res = _z_write_filter_create(&int_pub); @@ -1168,17 +1167,17 @@ int8_t z_declare_publisher(z_owned_publisher_t *pub, const z_loaned_session_t *z return _Z_RES_OK; } -int8_t z_undeclare_publisher(z_moved_publisher_t pub) { return _z_undeclare_and_clear_publisher(&pub._ptr->_val); } +int8_t z_undeclare_publisher(z_moved_publisher_t *pub) { return _z_undeclare_and_clear_publisher(&pub->_this._val); } void z_publisher_put_options_default(z_publisher_put_options_t *options) { - options->encoding = (z_moved_encoding_t){NULL}; - options->attachment = (z_moved_bytes_t){NULL}; + options->encoding = NULL; + options->attachment = NULL; options->timestamp = NULL; } void z_publisher_delete_options_default(z_publisher_delete_options_t *options) { options->timestamp = NULL; } -int8_t z_publisher_put(const z_loaned_publisher_t *pub, z_moved_bytes_t payload, +int8_t z_publisher_put(const z_loaned_publisher_t *pub, z_moved_bytes_t *payload, const z_publisher_put_options_t *options) { int8_t ret = 0; // Build options @@ -1190,10 +1189,10 @@ int8_t z_publisher_put(const z_loaned_publisher_t *pub, z_moved_bytes_t payload, opt.attachment = options->attachment; } _z_encoding_t encoding; - if (opt.encoding._ptr == NULL) { + if (opt.encoding == NULL) { _Z_RETURN_IF_ERR(_z_encoding_copy(&encoding, &pub->_encoding)); } else { - encoding = _z_encoding_steal(&opt.encoding._ptr->_val); + encoding = _z_encoding_steal(&opt.encoding->_this._val); } // Remove potentially redundant ke suffix _z_keyexpr_t pub_keyexpr = _z_keyexpr_alias(pub->_key); @@ -1204,15 +1203,15 @@ int8_t z_publisher_put(const z_loaned_publisher_t *pub, z_moved_bytes_t payload, // Check if write filter is active before writing if (!_z_write_filter_active(pub)) { // Write value - ret = _z_write(_Z_RC_IN_VAL(&pub->_zn), pub_keyexpr, _z_bytes_from_owned_bytes(payload._ptr), &encoding, + ret = _z_write(_Z_RC_IN_VAL(&pub->_zn), pub_keyexpr, _z_bytes_from_owned_bytes(&payload->_this), &encoding, Z_SAMPLE_KIND_PUT, pub->_congestion_control, pub->_priority, pub->_is_express, opt.timestamp, - _z_bytes_from_owned_bytes(opt.attachment._ptr)); + _z_bytes_from_owned_bytes(&opt.attachment->_this)); } // Trigger local subscriptions _z_trigger_local_subscriptions( - _Z_RC_IN_VAL(&pub->_zn), pub_keyexpr, _z_bytes_from_owned_bytes(payload._ptr), &encoding, + _Z_RC_IN_VAL(&pub->_zn), pub_keyexpr, _z_bytes_from_owned_bytes(&payload->_this), &encoding, _z_n_qos_make(pub->_is_express, pub->_congestion_control == Z_CONGESTION_CONTROL_BLOCK, pub->_priority), - opt.timestamp, _z_bytes_from_owned_bytes(opt.attachment._ptr)); + opt.timestamp, _z_bytes_from_owned_bytes(&opt.attachment->_this)); // Clean-up _z_encoding_clear(&encoding); z_bytes_drop(opt.attachment); @@ -1259,18 +1258,18 @@ void z_get_options_default(z_get_options_t *options) { options->congestion_control = Z_CONGESTION_CONTROL_DEFAULT; options->priority = Z_PRIORITY_DEFAULT; options->is_express = false; - options->encoding = (z_moved_encoding_t){NULL}; - options->payload = (z_moved_bytes_t){NULL}; - options->attachment = (z_moved_bytes_t){NULL}; + options->encoding = NULL; + options->payload = NULL; + options->attachment = NULL; options->timeout_ms = Z_GET_TIMEOUT_DEFAULT; } int8_t z_get(const z_loaned_session_t *zs, const z_loaned_keyexpr_t *keyexpr, const char *parameters, - z_moved_closure_reply_t callback, z_get_options_t *options) { + z_moved_closure_reply_t *callback, z_get_options_t *options) { int8_t ret = _Z_RES_OK; - void *ctx = callback._ptr->_val.context; - callback._ptr->_val.context = NULL; + void *ctx = callback->_this._val.context; + callback->_this._val.context = NULL; _z_keyexpr_t keyexpr_aliased = _z_keyexpr_alias_from_user_defined(*keyexpr, true); @@ -1296,18 +1295,18 @@ int8_t z_get(const z_loaned_session_t *zs, const z_loaned_keyexpr_t *keyexpr, co } } // Set value - _z_value_t value = {.payload = _z_bytes_from_owned_bytes(opt.payload._ptr), - .encoding = _z_encoding_from_owned(opt.encoding._ptr)}; + _z_value_t value = {.payload = _z_bytes_from_owned_bytes(&opt.payload->_this), + .encoding = _z_encoding_from_owned(&opt.encoding->_this)}; - ret = - _z_query(_Z_RC_IN_VAL(zs), keyexpr_aliased, parameters, opt.target, opt.consolidation.mode, value, - callback._ptr->_val.call, callback._ptr->_val.drop, ctx, opt.timeout_ms, - _z_bytes_from_owned_bytes(opt.attachment._ptr), opt.congestion_control, opt.priority, opt.is_express); + ret = _z_query(_Z_RC_IN_VAL(zs), keyexpr_aliased, parameters, opt.target, opt.consolidation.mode, value, + callback->_this._val.call, callback->_this._val.drop, ctx, opt.timeout_ms, + _z_bytes_from_owned_bytes(&opt.attachment->_this), opt.congestion_control, opt.priority, + opt.is_express); // Clean-up z_bytes_drop(opt.payload); z_encoding_drop(opt.encoding); z_bytes_drop(opt.attachment); - _z_owned_closure_reply_null(callback._ptr); // call and drop passed to _z_query, so we nullify the closure here + _z_owned_closure_reply_null(&callback->_this); // call and drop passed to _z_query, so we nullify the closure here return ret; } @@ -1345,10 +1344,10 @@ _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_IMPL(_z_queryable_t, queryable, _z_queryable_ch void z_queryable_options_default(z_queryable_options_t *options) { options->complete = _Z_QUERYABLE_COMPLETE_DEFAULT; } int8_t z_declare_queryable(z_owned_queryable_t *queryable, const z_loaned_session_t *zs, - const z_loaned_keyexpr_t *keyexpr, z_moved_closure_query_t callback, + const z_loaned_keyexpr_t *keyexpr, z_moved_closure_query_t *callback, const z_queryable_options_t *options) { - void *ctx = callback._ptr->_val.context; - callback._ptr->_val.context = NULL; + void *ctx = callback->_this._val.context; + callback->_this._val.context = NULL; _z_keyexpr_t keyexpr_aliased = _z_keyexpr_alias_from_user_defined(*keyexpr, true); _z_keyexpr_t key = keyexpr_aliased; @@ -1371,26 +1370,26 @@ int8_t z_declare_queryable(z_owned_queryable_t *queryable, const z_loaned_sessio } queryable->_val = - _z_declare_queryable(zs, key, opt.complete, callback._ptr->_val.call, callback._ptr->_val.drop, ctx); + _z_declare_queryable(zs, key, opt.complete, callback->_this._val.call, callback->_this._val.drop, ctx); - _z_owned_closure_query_null(callback._ptr); + _z_owned_closure_query_null(&callback->_this); return _Z_RES_OK; } -int8_t z_undeclare_queryable(z_moved_queryable_t queryable) { - return _z_undeclare_and_clear_queryable(&queryable._ptr->_val); +int8_t z_undeclare_queryable(z_moved_queryable_t *queryable) { + return _z_undeclare_and_clear_queryable(&queryable->_this._val); } void z_query_reply_options_default(z_query_reply_options_t *options) { - options->encoding = (z_moved_encoding_t){NULL}; + options->encoding = NULL; options->congestion_control = Z_CONGESTION_CONTROL_DEFAULT; options->priority = Z_PRIORITY_DEFAULT; options->timestamp = NULL; options->is_express = false; - options->attachment = (z_moved_bytes_t){NULL}; + options->attachment = NULL; } -int8_t z_query_reply(const z_loaned_query_t *query, const z_loaned_keyexpr_t *keyexpr, z_moved_bytes_t payload, +int8_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) { // Try upgrading session weak to rc _z_session_rc_t sess_rc = _z_session_weak_upgrade(&_Z_RC_IN_VAL(query)->_zn); @@ -1406,12 +1405,12 @@ int8_t z_query_reply(const z_loaned_query_t *query, const z_loaned_keyexpr_t *ke opts = *options; } // Set value - _z_value_t value = {.payload = _z_bytes_from_owned_bytes(payload._ptr), - .encoding = _z_encoding_from_owned(opts.encoding._ptr)}; + _z_value_t value = {.payload = _z_bytes_from_owned_bytes(&payload->_this), + .encoding = _z_encoding_from_owned(&opts.encoding->_this)}; - int8_t ret = - _z_send_reply(_Z_RC_IN_VAL(query), &sess_rc, keyexpr_aliased, value, Z_SAMPLE_KIND_PUT, opts.congestion_control, - opts.priority, opts.is_express, opts.timestamp, _z_bytes_from_owned_bytes(opts.attachment._ptr)); + int8_t ret = _z_send_reply(_Z_RC_IN_VAL(query), &sess_rc, keyexpr_aliased, value, Z_SAMPLE_KIND_PUT, + opts.congestion_control, opts.priority, opts.is_express, opts.timestamp, + _z_bytes_from_owned_bytes(&opts.attachment->_this)); z_bytes_drop(payload); // Clean-up _z_session_rc_drop(&sess_rc); @@ -1425,7 +1424,7 @@ void z_query_reply_del_options_default(z_query_reply_del_options_t *options) { options->priority = Z_PRIORITY_DEFAULT; options->timestamp = NULL; options->is_express = false; - options->attachment = (z_moved_bytes_t){NULL}; + options->attachment = NULL; } int8_t z_query_reply_del(const z_loaned_query_t *query, const z_loaned_keyexpr_t *keyexpr, @@ -1447,18 +1446,16 @@ int8_t z_query_reply_del(const z_loaned_query_t *query, const z_loaned_keyexpr_t int8_t ret = _z_send_reply(_Z_RC_IN_VAL(query), &sess_rc, keyexpr_aliased, value, Z_SAMPLE_KIND_DELETE, opts.congestion_control, opts.priority, opts.is_express, opts.timestamp, - _z_bytes_from_owned_bytes(opts.attachment._ptr)); + _z_bytes_from_owned_bytes(&opts.attachment->_this)); // Clean-up _z_session_rc_drop(&sess_rc); z_bytes_drop(opts.attachment); return ret; } -void z_query_reply_err_options_default(z_query_reply_err_options_t *options) { - options->encoding = (z_moved_encoding_t){NULL}; -} +void z_query_reply_err_options_default(z_query_reply_err_options_t *options) { options->encoding = NULL; } -int8_t z_query_reply_err(const z_loaned_query_t *query, z_moved_bytes_t payload, +int8_t z_query_reply_err(const z_loaned_query_t *query, z_moved_bytes_t *payload, const z_query_reply_err_options_t *options) { // Try upgrading session weak to rc _z_session_rc_t sess_rc = _z_session_weak_upgrade(&_Z_RC_IN_VAL(query)->_zn); @@ -1472,8 +1469,8 @@ int8_t z_query_reply_err(const z_loaned_query_t *query, z_moved_bytes_t payload, opts = *options; } // Set value - _z_value_t value = {.payload = _z_bytes_from_owned_bytes(payload._ptr), - .encoding = _z_encoding_from_owned(opts.encoding._ptr)}; + _z_value_t value = {.payload = _z_bytes_from_owned_bytes(&payload->_this), + .encoding = _z_encoding_from_owned(&opts.encoding->_this)}; int8_t ret = _z_send_reply_err(_Z_RC_IN_VAL(query), &sess_rc, value); z_bytes_drop(payload); @@ -1536,10 +1533,10 @@ int8_t z_declare_keyexpr(z_owned_keyexpr_t *key, const z_loaned_session_t *zs, c return _Z_RES_OK; } -int8_t z_undeclare_keyexpr(z_moved_keyexpr_t keyexpr, const z_loaned_session_t *zs) { +int8_t z_undeclare_keyexpr(z_moved_keyexpr_t *keyexpr, const z_loaned_session_t *zs) { int8_t ret = _Z_RES_OK; - ret = _z_undeclare_resource(_Z_RC_IN_VAL(zs), keyexpr._ptr->_val._id); + ret = _z_undeclare_resource(_Z_RC_IN_VAL(zs), keyexpr->_this._val._id); z_keyexpr_drop(keyexpr); return ret; @@ -1561,9 +1558,9 @@ _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_IMPL(_z_subscriber_t, subscriber, _z_subscriber void z_subscriber_options_default(z_subscriber_options_t *options) { options->reliability = Z_RELIABILITY_DEFAULT; } int8_t z_declare_subscriber(z_owned_subscriber_t *sub, const z_loaned_session_t *zs, const z_loaned_keyexpr_t *keyexpr, - z_moved_closure_sample_t callback, const z_subscriber_options_t *options) { - void *ctx = callback._ptr->_val.context; - callback._ptr->_val.context = NULL; + z_moved_closure_sample_t *callback, const z_subscriber_options_t *options) { + void *ctx = callback->_this._val.context; + callback->_this._val.context = NULL; char *suffix = NULL; _z_keyexpr_t keyexpr_aliased = _z_keyexpr_alias_from_user_defined(*keyexpr, true); @@ -1604,11 +1601,11 @@ int8_t z_declare_subscriber(z_owned_subscriber_t *sub, const z_loaned_session_t subinfo.reliability = options->reliability; } _z_subscriber_t int_sub = - _z_declare_subscriber(zs, key, subinfo, callback._ptr->_val.call, callback._ptr->_val.drop, ctx); + _z_declare_subscriber(zs, key, subinfo, callback->_this._val.call, callback->_this._val.drop, ctx); if (suffix != NULL) { z_free(suffix); } - _z_owned_closure_sample_null(callback._ptr); + _z_owned_closure_sample_null(&callback->_this); sub->_val = int_sub; if (!_z_subscriber_check(&sub->_val)) { @@ -1618,7 +1615,7 @@ int8_t z_declare_subscriber(z_owned_subscriber_t *sub, const z_loaned_session_t } } -int8_t z_undeclare_subscriber(z_moved_subscriber_t sub) { return _z_undeclare_and_clear_subscriber(&sub._ptr->_val); } +int8_t z_undeclare_subscriber(z_moved_subscriber_t *sub) { return _z_undeclare_and_clear_subscriber(&sub->_this._val); } const z_loaned_keyexpr_t *z_subscriber_keyexpr(const z_loaned_subscriber_t *sub) { // Retrieve keyexpr from session diff --git a/src/system/platform-common.c b/src/system/platform-common.c index 259a19284..ab1a9d2e4 100644 --- a/src/system/platform-common.c +++ b/src/system/platform-common.c @@ -38,7 +38,7 @@ int8_t z_task_join(z_owned_task_t *task) { _Z_OWNED_FUNCTIONS_SYSTEM_IMPL(_z_mutex_t, mutex) int8_t z_mutex_init(z_owned_mutex_t *m) { return _z_mutex_init(&m->_val); } -int8_t z_mutex_drop(z_moved_mutex_t m) { return _z_mutex_drop(&m._ptr->_val); } +int8_t z_mutex_drop(z_moved_mutex_t *m) { return _z_mutex_drop(&m->_this._val); } int8_t z_mutex_lock(z_loaned_mutex_t *m) { return _z_mutex_lock(m); } int8_t z_mutex_try_lock(z_loaned_mutex_t *m) { return _z_mutex_try_lock(m); } @@ -48,7 +48,7 @@ int8_t z_mutex_unlock(z_loaned_mutex_t *m) { return _z_mutex_unlock(m); } _Z_OWNED_FUNCTIONS_SYSTEM_IMPL(_z_condvar_t, condvar) int8_t z_condvar_init(z_owned_condvar_t *cv) { return _z_condvar_init(&cv->_val); } -int8_t z_condvar_drop(z_moved_condvar_t cv) { return _z_condvar_drop(&cv._ptr->_val); } +int8_t z_condvar_drop(z_moved_condvar_t *cv) { return _z_condvar_drop(&cv->_this._val); } int8_t z_condvar_signal(z_loaned_condvar_t *cv) { return _z_condvar_signal(cv); } int8_t z_condvar_wait(z_loaned_condvar_t *cv, z_loaned_mutex_t *m) { return _z_condvar_wait(cv, m); } diff --git a/zenohpico.pc b/zenohpico.pc index fd68ae549..9d0772da5 100644 --- a/zenohpico.pc +++ b/zenohpico.pc @@ -3,6 +3,6 @@ prefix=/usr/local Name: zenohpico Description: URL: -Version: 1.0.20240812dev +Version: 1.0.20240819dev Cflags: -I${prefix}/include Libs: -L${prefix}/lib -lzenohpico From cf6292601ea6bc595d47d1fb75dc11de0ba79fa4 Mon Sep 17 00:00:00 2001 From: Michael Ilyin Date: Tue, 20 Aug 2024 16:00:33 +0200 Subject: [PATCH 2/2] _z_check/null renamed to z_internal (#599) * _z_check/null renamed to z_internal * macro fix * test fix * macros corrected * test fix * tests fix * clang format --- include/zenoh-pico/api/handlers.h | 2 +- include/zenoh-pico/api/macros.h | 184 ++++++++++++++-------------- include/zenoh-pico/api/olv_macros.h | 114 ++++++++--------- src/api/api.c | 35 +++--- tests/z_api_alignment_test.c | 22 ++-- tests/z_api_bytes_test.c | 4 +- tests/z_api_config_test.c | 6 +- tests/z_api_double_drop_test.c | 12 +- tests/z_api_encoding_test.c | 18 +-- tests/z_api_null_drop_test.c | 26 ++-- tests/z_client_test.c | 2 +- tests/z_keyexpr_test.c | 2 +- 12 files changed, 214 insertions(+), 213 deletions(-) diff --git a/include/zenoh-pico/api/handlers.h b/include/zenoh-pico/api/handlers.h index b3d48012d..25b4444df 100644 --- a/include/zenoh-pico/api/handlers.h +++ b/include/zenoh-pico/api/handlers.h @@ -141,7 +141,7 @@ extern "C" { /* elem_clone_f */ z_##item_name##_clone, \ /* elem_move_f */ z_##item_name##_move, \ /* elem_drop_f */ z_##item_name##_drop, \ - /* elem_null */ _z_owned_##item_name##_null) + /* elem_null */ z_internal_##item_name##_null) #define _Z_CHANNEL_DEFINE_DUMMY(item_name, kind_name) \ typedef struct { \ diff --git a/include/zenoh-pico/api/macros.h b/include/zenoh-pico/api/macros.h index a7aa01f75..de4be79bf 100644 --- a/include/zenoh-pico/api/macros.h +++ b/include/zenoh-pico/api/macros.h @@ -138,28 +138,28 @@ * Returns ``true`` if valid, or ``false`` otherwise. */ -#define _z_check(x) _Generic((x), \ - z_owned_keyexpr_t : _z_owned_keyexpr_check, \ - z_owned_reply_err_t : _z_owned_reply_err_check, \ - z_owned_config_t : _z_owned_config_check, \ - z_owned_session_t : _z_owned_session_check, \ - z_owned_subscriber_t : _z_owned_subscriber_check, \ - z_owned_publisher_t : _z_owned_publisher_check, \ - z_owned_queryable_t : _z_owned_queryable_check, \ - z_owned_reply_t : _z_owned_reply_check, \ - z_owned_hello_t : _z_owned_hello_check, \ - z_owned_string_t : _z_owned_string_check, \ - z_owned_string_array_t : _z_owned_string_array_check, \ - z_owned_closure_sample_t : _z_owned_closure_sample_check, \ - z_owned_closure_query_t : _z_owned_closure_query_check, \ - z_owned_closure_reply_t : _z_owned_closure_reply_check, \ - z_owned_closure_hello_t : _z_owned_closure_hello_check, \ - z_owned_closure_zid_t : _z_owned_closure_zid_check, \ - z_owned_slice_t : _z_owned_slice_check, \ - z_owned_bytes_t : _z_owned_bytes_check, \ - z_owned_sample_t : _z_owned_sample_check, \ - z_owned_query_t : _z_owned_query_check, \ - z_owned_encoding_t : _z_owned_encoding_check \ +#define z_internal_check(x) _Generic((x), \ + z_owned_keyexpr_t : z_internal_keyexpr_check, \ + z_owned_reply_err_t : z_internal_reply_err_check, \ + z_owned_config_t : z_internal_config_check, \ + z_owned_session_t : z_internal_session_check, \ + z_owned_subscriber_t : z_internal_subscriber_check, \ + z_owned_publisher_t : z_internal_publisher_check, \ + z_owned_queryable_t : z_internal_queryable_check, \ + z_owned_reply_t : z_internal_reply_check, \ + z_owned_hello_t : z_internal_hello_check, \ + z_owned_string_t : z_internal_string_check, \ + z_owned_string_array_t : z_internal_string_array_check, \ + z_owned_closure_sample_t : z_internal_closure_sample_check, \ + z_owned_closure_query_t : z_internal_closure_query_check, \ + z_owned_closure_reply_t : z_internal_closure_reply_check, \ + z_owned_closure_hello_t : z_internal_closure_hello_check, \ + z_owned_closure_zid_t : z_internal_closure_zid_check, \ + z_owned_slice_t : z_internal_slice_check, \ + z_owned_bytes_t : z_internal_bytes_check, \ + z_owned_sample_t : z_internal_sample_check, \ + z_owned_query_t : z_internal_query_check, \ + z_owned_encoding_t : z_internal_encoding_check \ )(&x) /** @@ -314,28 +314,28 @@ * Parameters: * x: The instance to nullify. */ -#define _z_null(x) _Generic((x), \ - z_owned_session_t * : _z_owned_session_null, \ - z_owned_publisher_t * : _z_owned_publisher_null, \ - z_owned_keyexpr_t * : _z_owned_keyexpr_null, \ - z_owned_config_t * : _z_owned_config_null, \ - z_owned_subscriber_t * : _z_owned_subscriber_null, \ - z_owned_queryable_t * : _z_owned_queryable_null, \ - z_owned_query_t * : _z_owned_query_null, \ - z_owned_reply_t * : _z_owned_reply_null, \ - z_owned_hello_t * : _z_owned_hello_null, \ - z_owned_string_t * : _z_owned_string_null, \ - z_owned_string_array_t * : _z_owned_string_array_null, \ - z_owned_slice_t *: _z_owned_slice_null, \ - z_owned_bytes_t *: _z_owned_bytes_null, \ - z_owned_closure_sample_t * : _z_owned_closure_sample_null, \ - z_owned_closure_query_t * : _z_owned_closure_query_null, \ - z_owned_closure_reply_t * : _z_owned_closure_reply_null, \ - z_owned_closure_hello_t * : _z_owned_closure_hello_null, \ - z_owned_closure_zid_t * : _z_owned_closure_zid_null, \ - z_owned_sample_t * : _z_owned_sample_null, \ - z_owned_encoding_t * : _z_owned_encoding_null, \ - z_owned_reply_err_t * : _z_owned_reply_err_null \ +#define z_internal_null(x) _Generic((x), \ + z_owned_session_t * : z_internal_session_null, \ + z_owned_publisher_t * : z_internal_publisher_null, \ + z_owned_keyexpr_t * : z_internal_keyexpr_null, \ + z_owned_config_t * : z_internal_config_null, \ + z_owned_subscriber_t * : z_internal_subscriber_null, \ + z_owned_queryable_t * : z_internal_queryable_null, \ + z_owned_query_t * : z_internal_query_null, \ + z_owned_reply_t * : z_internal_reply_null, \ + z_owned_hello_t * : z_internal_hello_null, \ + z_owned_string_t * : z_internal_string_null, \ + z_owned_string_array_t * : z_internal_string_array_null, \ + z_owned_slice_t *: z_internal_slice_null, \ + z_owned_bytes_t *: z_internal_bytes_null, \ + z_owned_closure_sample_t * : z_internal_closure_sample_null, \ + z_owned_closure_query_t * : z_internal_closure_query_null, \ + z_owned_closure_reply_t * : z_internal_closure_reply_null, \ + z_owned_closure_hello_t * : z_internal_closure_hello_null, \ + z_owned_closure_zid_t * : z_internal_closure_zid_null, \ + z_owned_sample_t * : z_internal_sample_null, \ + z_owned_encoding_t * : z_internal_encoding_null, \ + z_owned_reply_err_t * : z_internal_reply_err_null \ )(x) // clang-format on @@ -451,54 +451,54 @@ inline void z_drop(z_owned_fifo_handler_query_t* v) { z_fifo_handler_query_drop( inline void z_drop(z_owned_ring_handler_reply_t* v) { z_ring_handler_reply_drop(v); } inline void z_drop(z_owned_fifo_handler_reply_t* v) { z_fifo_handler_reply_drop(v); } -// _z_null definition -inline void _z_null(z_owned_session_t* v) { _z_owned_session_null(v); } -inline void _z_null(z_owned_publisher_t* v) { _z_owned_publisher_null(v); } -inline void _z_null(z_owned_keyexpr_t* v) { _z_owned_keyexpr_null(v); } -inline void _z_null(z_owned_config_t* v) { _z_owned_config_null(v); } -inline void _z_null(z_owned_subscriber_t* v) { _z_owned_subscriber_null(v); } -inline void _z_null(z_owned_queryable_t* v) { _z_owned_queryable_null(v); } -inline void _z_null(z_owned_query_t* v) { _z_owned_query_null(v); } -inline void _z_null(z_owned_sample_t* v) { _z_owned_sample_null(v); } -inline void _z_null(z_owned_reply_t* v) { _z_owned_reply_null(v); } -inline void _z_null(z_owned_hello_t* v) { _z_owned_hello_null(v); } -inline void _z_null(z_owned_string_t* v) { _z_owned_string_null(v); } -inline void _z_null(z_owned_bytes_t* v) { _z_owned_bytes_null(v); } -inline void _z_null(z_owned_encoding_t* v) { _z_owned_encoding_null(v); } -inline void _z_null(z_owned_reply_err_t* v) { _z_owned_reply_err_null(v); } -inline void _z_null(z_owned_closure_sample_t* v) { _z_owned_closure_sample_null(v); } -inline void _z_null(z_owned_closure_query_t* v) { _z_owned_closure_query_null(v); } -inline void _z_null(z_owned_closure_reply_t* v) { _z_owned_closure_reply_null(v); } -inline void _z_null(z_owned_closure_hello_t* v) { _z_owned_closure_hello_null(v); } -inline void _z_null(z_owned_closure_zid_t* v) { _z_owned_closure_zid_null(v); } -inline void _z_null(z_owned_ring_handler_query_t* v) { return _z_owned_ring_handler_query_null(v); }; -inline void _z_null(z_owned_ring_handler_reply_t* v) { return _z_owned_ring_handler_reply_null(v); }; -inline void _z_null(z_owned_ring_handler_sample_t* v) { return _z_owned_ring_handler_sample_null(v); }; -inline void _z_null(z_owned_fifo_handler_query_t* v) { return _z_owned_fifo_handler_query_null(v); }; -inline void _z_null(z_owned_fifo_handler_reply_t* v) { return _z_owned_fifo_handler_reply_null(v); }; -inline void _z_null(z_owned_fifo_handler_sample_t* v) { return _z_owned_fifo_handler_sample_null(v); }; - -// _z_check definition -inline bool _z_check(const z_owned_session_t& v) { return _z_owned_session_check(&v); } -inline bool _z_check(const z_owned_publisher_t& v) { return _z_owned_publisher_check(&v); } -inline bool _z_check(const z_owned_keyexpr_t& v) { return _z_owned_keyexpr_check(&v); } -inline bool _z_check(const z_owned_config_t& v) { return _z_owned_config_check(&v); } -inline bool _z_check(const z_owned_subscriber_t& v) { return _z_owned_subscriber_check(&v); } -inline bool _z_check(const z_owned_queryable_t& v) { return _z_owned_queryable_check(&v); } -inline bool _z_check(const z_owned_reply_t& v) { return _z_owned_reply_check(&v); } -inline bool _z_check(const z_owned_query_t& v) { return _z_owned_query_check(&v); } -inline bool _z_check(const z_owned_hello_t& v) { return _z_owned_hello_check(&v); } -inline bool _z_check(const z_owned_string_t& v) { return _z_owned_string_check(&v); } -inline bool _z_check(const z_owned_sample_t& v) { return _z_owned_sample_check(&v); } -inline bool _z_check(const z_owned_bytes_t& v) { return _z_owned_bytes_check(&v); } -inline bool _z_check(const z_owned_encoding_t& v) { return _z_owned_encoding_check(&v); } -inline bool _z_check(const z_owned_reply_err_t& v) { return _z_owned_reply_err_check(&v); } -inline bool _z_check(const z_owned_fifo_handler_query_t& v) { return _z_owned_fifo_handler_query_check(&v); }; -inline bool _z_check(const z_owned_fifo_handler_reply_t& v) { return _z_owned_fifo_handler_reply_check(&v); }; -inline bool _z_check(const z_owned_fifo_handler_sample_t& v) { return _z_owned_fifo_handler_sample_check(&v); }; -inline bool _z_check(const z_owned_ring_handler_query_t& v) { return _z_owned_ring_handler_query_check(&v); }; -inline bool _z_check(const z_owned_ring_handler_reply_t& v) { return _z_owned_ring_handler_reply_check(&v); }; -inline bool _z_check(const z_owned_ring_handler_sample_t& v) { return _z_owned_ring_handler_sample_check(&v); }; +// z_internal_null definition +inline void z_internal_null(z_owned_session_t* v) { z_internal_session_null(v); } +inline void z_internal_null(z_owned_publisher_t* v) { z_internal_publisher_null(v); } +inline void z_internal_null(z_owned_keyexpr_t* v) { z_internal_keyexpr_null(v); } +inline void z_internal_null(z_owned_config_t* v) { z_internal_config_null(v); } +inline void z_internal_null(z_owned_subscriber_t* v) { z_internal_subscriber_null(v); } +inline void z_internal_null(z_owned_queryable_t* v) { z_internal_queryable_null(v); } +inline void z_internal_null(z_owned_query_t* v) { z_internal_query_null(v); } +inline void z_internal_null(z_owned_sample_t* v) { z_internal_sample_null(v); } +inline void z_internal_null(z_owned_reply_t* v) { z_internal_reply_null(v); } +inline void z_internal_null(z_owned_hello_t* v) { z_internal_hello_null(v); } +inline void z_internal_null(z_owned_string_t* v) { z_internal_string_null(v); } +inline void z_internal_null(z_owned_bytes_t* v) { z_internal_bytes_null(v); } +inline void z_internal_null(z_owned_encoding_t* v) { z_internal_encoding_null(v); } +inline void z_internal_null(z_owned_reply_err_t* v) { z_internal_reply_err_null(v); } +inline void z_internal_null(z_owned_closure_sample_t* v) { z_internal_closure_sample_null(v); } +inline void z_internal_null(z_owned_closure_query_t* v) { z_internal_closure_query_null(v); } +inline void z_internal_null(z_owned_closure_reply_t* v) { z_internal_closure_reply_null(v); } +inline void z_internal_null(z_owned_closure_hello_t* v) { z_internal_closure_hello_null(v); } +inline void z_internal_null(z_owned_closure_zid_t* v) { z_internal_closure_zid_null(v); } +inline void z_internal_null(z_owned_ring_handler_query_t* v) { return z_internal_ring_handler_query_null(v); }; +inline void z_internal_null(z_owned_ring_handler_reply_t* v) { return z_internal_ring_handler_reply_null(v); }; +inline void z_internal_null(z_owned_ring_handler_sample_t* v) { return z_internal_ring_handler_sample_null(v); }; +inline void z_internal_null(z_owned_fifo_handler_query_t* v) { return z_internal_fifo_handler_query_null(v); }; +inline void z_internal_null(z_owned_fifo_handler_reply_t* v) { return z_internal_fifo_handler_reply_null(v); }; +inline void z_internal_null(z_owned_fifo_handler_sample_t* v) { return z_internal_fifo_handler_sample_null(v); }; + +// z_internal_check definition +inline bool z_internal_check(const z_owned_session_t& v) { return z_internal_session_check(&v); } +inline bool z_internal_check(const z_owned_publisher_t& v) { return z_internal_publisher_check(&v); } +inline bool z_internal_check(const z_owned_keyexpr_t& v) { return z_internal_keyexpr_check(&v); } +inline bool z_internal_check(const z_owned_config_t& v) { return z_internal_config_check(&v); } +inline bool z_internal_check(const z_owned_subscriber_t& v) { return z_internal_subscriber_check(&v); } +inline bool z_internal_check(const z_owned_queryable_t& v) { return z_internal_queryable_check(&v); } +inline bool z_internal_check(const z_owned_reply_t& v) { return z_internal_reply_check(&v); } +inline bool z_internal_check(const z_owned_query_t& v) { return z_internal_query_check(&v); } +inline bool z_internal_check(const z_owned_hello_t& v) { return z_internal_hello_check(&v); } +inline bool z_internal_check(const z_owned_string_t& v) { return z_internal_string_check(&v); } +inline bool z_internal_check(const z_owned_sample_t& v) { return z_internal_sample_check(&v); } +inline bool z_internal_check(const z_owned_bytes_t& v) { return z_internal_bytes_check(&v); } +inline bool z_internal_check(const z_owned_encoding_t& v) { return z_internal_encoding_check(&v); } +inline bool z_internal_check(const z_owned_reply_err_t& v) { return z_internal_reply_err_check(&v); } +inline bool z_internal_check(const z_owned_fifo_handler_query_t& v) { return z_internal_fifo_handler_query_check(&v); }; +inline bool z_internal_check(const z_owned_fifo_handler_reply_t& v) { return z_internal_fifo_handler_reply_check(&v); }; +inline bool z_internal_check(const z_owned_fifo_handler_sample_t& v) { return z_internal_fifo_handler_sample_check(&v); }; +inline bool z_internal_check(const z_owned_ring_handler_query_t& v) { return z_internal_ring_handler_query_check(&v); }; +inline bool z_internal_check(const z_owned_ring_handler_reply_t& v) { return z_internal_ring_handler_reply_check(&v); }; +inline bool z_internal_check(const z_owned_ring_handler_sample_t& v) { return z_internal_ring_handler_sample_check(&v); }; // z_call definition inline void z_call(const z_loaned_closure_sample_t &closure, const z_loaned_sample_t *sample) diff --git a/include/zenoh-pico/api/olv_macros.h b/include/zenoh-pico/api/olv_macros.h index 5a399db17..9f535b304 100644 --- a/include/zenoh-pico/api/olv_macros.h +++ b/include/zenoh-pico/api/olv_macros.h @@ -56,8 +56,8 @@ } z_view_##name##_t; #define _Z_OWNED_FUNCTIONS_DEF(name) \ - void _z_owned_##name##_null(z_owned_##name##_t *obj); \ - _Bool _z_owned_##name##_check(const z_owned_##name##_t *obj); \ + void z_internal_##name##_null(z_owned_##name##_t *obj); \ + _Bool z_internal_##name##_check(const z_owned_##name##_t *obj); \ const z_loaned_##name##_t *z_##name##_loan(const z_owned_##name##_t *obj); \ z_loaned_##name##_t *z_##name##_loan_mut(z_owned_##name##_t *obj); \ z_moved_##name##_t *z_##name##_move(z_owned_##name##_t *obj); \ @@ -66,8 +66,8 @@ void z_##name##_drop(z_moved_##name##_t *obj); #define _Z_OWNED_FUNCTIONS_NO_COPY_DEF(name) \ - void _z_owned_##name##_null(z_owned_##name##_t *obj); \ - _Bool _z_owned_##name##_check(const z_owned_##name##_t *obj); \ + void z_internal_##name##_null(z_owned_##name##_t *obj); \ + _Bool z_internal_##name##_check(const z_owned_##name##_t *obj); \ const z_loaned_##name##_t *z_##name##_loan(const z_owned_##name##_t *obj); \ z_loaned_##name##_t *z_##name##_loan_mut(z_owned_##name##_t *obj); \ z_moved_##name##_t *z_##name##_move(z_owned_##name##_t *obj); \ @@ -75,7 +75,7 @@ void z_##name##_drop(z_moved_##name##_t *obj); #define _Z_OWNED_FUNCTIONS_SYSTEM_DEF(name) \ - void _z_owned_##name##_null(z_owned_##name##_t *obj); \ + void z_internal_##name##_null(z_owned_##name##_t *obj); \ void z_##name##_take(z_owned_##name##_t *obj, z_moved_##name##_t *src); \ const z_loaned_##name##_t *z_##name##_loan(const z_owned_##name##_t *obj); \ z_loaned_##name##_t *z_##name##_loan_mut(z_owned_##name##_t *obj); \ @@ -91,13 +91,13 @@ z_moved_##name##_t *z_##name##_move(z_owned_##name##_t *obj) { return (z_moved_##name##_t *)(obj); } \ void z_##name##_take(z_owned_##name##_t *obj, z_moved_##name##_t *src) { \ *obj = src->_this; \ - _z_owned_##name##_null(&src->_this); \ + z_internal_##name##_null(&src->_this); \ } #define _Z_OWNED_FUNCTIONS_PTR_IMPL(type, name, f_copy, f_free) \ _Z_OWNED_FUNCTIONS_IMPL_MOVE_TAKE(name) \ - void _z_owned_##name##_null(z_owned_##name##_t *obj) { obj->_val = NULL; } \ - _Bool _z_owned_##name##_check(const z_owned_##name##_t *obj) { return obj->_val != NULL; } \ + void z_internal_##name##_null(z_owned_##name##_t *obj) { obj->_val = NULL; } \ + _Bool z_internal_##name##_check(const z_owned_##name##_t *obj) { return obj->_val != NULL; } \ const z_loaned_##name##_t *z_##name##_loan(const z_owned_##name##_t *obj) { return obj->_val; } \ z_loaned_##name##_t *z_##name##_loan_mut(z_owned_##name##_t *obj) { return obj->_val; } \ int8_t z_##name##_clone(z_owned_##name##_t *obj, const z_loaned_##name##_t *src) { \ @@ -118,8 +118,8 @@ #define _Z_OWNED_FUNCTIONS_VALUE_IMPL(type, name, f_check, f_null, f_copy, f_drop) \ _Z_OWNED_FUNCTIONS_IMPL_MOVE_TAKE(name) \ - void _z_owned_##name##_null(z_owned_##name##_t *obj) { obj->_val = f_null(); } \ - _Bool _z_owned_##name##_check(const z_owned_##name##_t *obj) { return f_check((&obj->_val)); } \ + void z_internal_##name##_null(z_owned_##name##_t *obj) { obj->_val = f_null(); } \ + _Bool z_internal_##name##_check(const z_owned_##name##_t *obj) { return f_check((&obj->_val)); } \ const z_loaned_##name##_t *z_##name##_loan(const z_owned_##name##_t *obj) { return &obj->_val; } \ z_loaned_##name##_t *z_##name##_loan_mut(z_owned_##name##_t *obj) { return &obj->_val; } \ int8_t z_##name##_clone(z_owned_##name##_t *obj, const z_loaned_##name##_t *src) { \ @@ -130,14 +130,14 @@ } #define _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_IMPL_INNER(type, name, f_check, f_null, f_drop, attribute) \ - attribute void _z_owned_##name##_null(z_owned_##name##_t *obj) { obj->_val = f_null(); } \ - attribute _Bool _z_owned_##name##_check(const z_owned_##name##_t *obj) { return f_check((&obj->_val)); } \ + attribute void z_internal_##name##_null(z_owned_##name##_t *obj) { obj->_val = f_null(); } \ + attribute _Bool z_internal_##name##_check(const z_owned_##name##_t *obj) { return f_check((&obj->_val)); } \ attribute const z_loaned_##name##_t *z_##name##_loan(const z_owned_##name##_t *obj) { return &obj->_val; } \ attribute z_loaned_##name##_t *z_##name##_loan_mut(z_owned_##name##_t *obj) { return &obj->_val; } \ attribute z_moved_##name##_t *z_##name##_move(z_owned_##name##_t *obj) { return (z_moved_##name##_t *)(obj); } \ attribute void z_##name##_take(z_owned_##name##_t *obj, z_moved_##name##_t *src) { \ *obj = src->_this; \ - _z_owned_##name##_null(&src->_this); \ + z_internal_##name##_null(&src->_this); \ } \ attribute void z_##name##_drop(z_moved_##name##_t *obj) { \ if (obj != NULL) f_drop((&obj->_this._val)); \ @@ -151,29 +151,29 @@ #define _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_INLINE_IMPL(type, name, f_check, f_null, f_drop) \ _Z_OWNED_FUNCTIONS_VALUE_NO_COPY_IMPL_INNER(type, name, f_check, f_null, f_drop, static inline) -#define _Z_OWNED_FUNCTIONS_RC_IMPL(name) \ - _Z_OWNED_FUNCTIONS_IMPL_MOVE_TAKE(name) \ - void _z_owned_##name##_null(z_owned_##name##_t *val) { val->_rc = _z_##name##_rc_null(); } \ - _Bool _z_owned_##name##_check(const z_owned_##name##_t *val) { return !_Z_RC_IS_NULL(&val->_rc); } \ - const z_loaned_##name##_t *z_##name##_loan(const z_owned_##name##_t *val) { return &val->_rc; } \ - z_loaned_##name##_t *z_##name##_loan_mut(z_owned_##name##_t *val) { return &val->_rc; } \ - int8_t z_##name##_clone(z_owned_##name##_t *obj, const z_loaned_##name##_t *src) { \ - int8_t ret = _Z_RES_OK; \ - obj->_rc = _z_##name##_rc_clone((z_loaned_##name##_t *)src); \ - if (_Z_RC_IS_NULL(&obj->_rc)) { \ - ret = _Z_ERR_SYSTEM_OUT_OF_MEMORY; \ - } \ - return ret; \ - } \ - void z_##name##_drop(z_moved_##name##_t *obj) { \ - if (!_Z_RC_IS_NULL(&obj->_this._rc)) { \ - _z_##name##_rc_drop(&obj->_this._rc); \ - } \ +#define _Z_OWNED_FUNCTIONS_RC_IMPL(name) \ + _Z_OWNED_FUNCTIONS_IMPL_MOVE_TAKE(name) \ + void z_internal_##name##_null(z_owned_##name##_t *val) { val->_rc = _z_##name##_rc_null(); } \ + _Bool z_internal_##name##_check(const z_owned_##name##_t *val) { return !_Z_RC_IS_NULL(&val->_rc); } \ + const z_loaned_##name##_t *z_##name##_loan(const z_owned_##name##_t *val) { return &val->_rc; } \ + z_loaned_##name##_t *z_##name##_loan_mut(z_owned_##name##_t *val) { return &val->_rc; } \ + int8_t z_##name##_clone(z_owned_##name##_t *obj, const z_loaned_##name##_t *src) { \ + int8_t ret = _Z_RES_OK; \ + obj->_rc = _z_##name##_rc_clone((z_loaned_##name##_t *)src); \ + if (_Z_RC_IS_NULL(&obj->_rc)) { \ + ret = _Z_ERR_SYSTEM_OUT_OF_MEMORY; \ + } \ + return ret; \ + } \ + void z_##name##_drop(z_moved_##name##_t *obj) { \ + if (!_Z_RC_IS_NULL(&obj->_this._rc)) { \ + _z_##name##_rc_drop(&obj->_this._rc); \ + } \ } #define _Z_OWNED_FUNCTIONS_SYSTEM_IMPL(type, name) \ _Z_OWNED_FUNCTIONS_IMPL_MOVE_TAKE(name) \ - void _z_owned_##name##_null(z_owned_##name##_t *obj) { (void)obj; } \ + void z_internal_##name##_null(z_owned_##name##_t *obj) { (void)obj; } \ const z_loaned_##name##_t *z_##name##_loan(const z_owned_##name##_t *obj) { return &obj->_val; } \ z_loaned_##name##_t *z_##name##_loan_mut(z_owned_##name##_t *obj) { return &obj->_val; } @@ -184,36 +184,36 @@ void z_view_##name##_empty(z_view_##name##_t *obj) { obj->_val = f_null(); } #define _Z_OWNED_FUNCTIONS_CLOSURE_DEF(name) \ - void _z_owned_##name##_null(z_owned_##name##_t *name); \ - _Bool _z_owned_##name##_check(const z_owned_##name##_t *val); \ + void z_internal_##name##_null(z_owned_##name##_t *name); \ + _Bool z_internal_##name##_check(const z_owned_##name##_t *val); \ z_moved_##name##_t *z_##name##_move(z_owned_##name##_t *val); \ void z_##name##_take(z_owned_##name##_t *obj, z_moved_##name##_t *src); \ void z_##name##_drop(z_moved_##name##_t *obj); \ const z_loaned_##name##_t *z_##name##_loan(const z_owned_##name##_t *val); -#define _Z_OWNED_FUNCTIONS_CLOSURE_IMPL(name, f_call, f_drop) \ - _Z_OWNED_FUNCTIONS_IMPL_MOVE_TAKE(name) \ - void _z_owned_##name##_null(z_owned_##name##_t *val) { \ - val->_val.call = NULL; \ - val->_val.drop = NULL; \ - val->_val.context = NULL; \ - } \ - _Bool _z_owned_##name##_check(const z_owned_##name##_t *val) { return val->_val.call != NULL; } \ - void z_##name##_drop(z_moved_##name##_t *obj) { \ - if (obj->_this._val.drop != NULL) { \ - (obj->_this._val.drop)(obj->_this._val.context); \ - obj->_this._val.drop = NULL; \ - } \ - obj->_this._val.call = NULL; \ - obj->_this._val.context = NULL; \ - } \ - const z_loaned_##name##_t *z_##name##_loan(const z_owned_##name##_t *val) { return &val->_val; } \ - int8_t z_##name(z_owned_##name##_t *closure, f_call call, f_drop drop, void *context) { \ - closure->_val.call = call; \ - closure->_val.drop = drop; \ - closure->_val.context = context; \ - \ - return _Z_RES_OK; \ +#define _Z_OWNED_FUNCTIONS_CLOSURE_IMPL(name, f_call, f_drop) \ + _Z_OWNED_FUNCTIONS_IMPL_MOVE_TAKE(name) \ + void z_internal_##name##_null(z_owned_##name##_t *val) { \ + val->_val.call = NULL; \ + val->_val.drop = NULL; \ + val->_val.context = NULL; \ + } \ + _Bool z_internal_##name##_check(const z_owned_##name##_t *val) { return val->_val.call != NULL; } \ + void z_##name##_drop(z_moved_##name##_t *obj) { \ + if (obj->_this._val.drop != NULL) { \ + (obj->_this._val.drop)(obj->_this._val.context); \ + obj->_this._val.drop = NULL; \ + } \ + obj->_this._val.call = NULL; \ + obj->_this._val.context = NULL; \ + } \ + const z_loaned_##name##_t *z_##name##_loan(const z_owned_##name##_t *val) { return &val->_val; } \ + int8_t z_##name(z_owned_##name##_t *closure, f_call call, f_drop drop, void *context) { \ + closure->_val.call = call; \ + closure->_val.drop = drop; \ + closure->_val.context = context; \ + \ + return _Z_RES_OK; \ } #endif /* INCLUDE_ZENOH_PICO_API_OLV_MACROS_H */ diff --git a/src/api/api.c b/src/api/api.c index 9c8f41380..768efd4ba 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -95,7 +95,7 @@ int8_t z_keyexpr_as_view_string(const z_loaned_keyexpr_t *keyexpr, z_view_string } int8_t z_keyexpr_concat(z_owned_keyexpr_t *key, const z_loaned_keyexpr_t *left, const char *right, size_t len) { - _z_owned_keyexpr_null(key); + z_internal_keyexpr_null(key); if (len == 0) { return z_keyexpr_clone(key, left); } else if (right == NULL) { @@ -124,7 +124,7 @@ int8_t z_keyexpr_concat(z_owned_keyexpr_t *key, const z_loaned_keyexpr_t *left, } int8_t z_keyexpr_join(z_owned_keyexpr_t *key, const z_loaned_keyexpr_t *left, const z_loaned_keyexpr_t *right) { - _z_owned_keyexpr_null(key); + z_internal_keyexpr_null(key); size_t left_len = strlen(left->_suffix); size_t right_len = strlen(right->_suffix); @@ -376,7 +376,7 @@ _Z_OWNED_FUNCTIONS_VALUE_IMPL(_z_encoding_t, encoding, _z_encoding_check, _z_enc int8_t z_encoding_from_str(z_owned_encoding_t *encoding, const char *s) { // Init owned encoding - _z_owned_encoding_null(encoding); + z_internal_encoding_null(encoding); // Convert string to encoding if (s != NULL) { return _z_encoding_convert_from_substr(encoding, s, strlen(s)); @@ -386,7 +386,7 @@ int8_t z_encoding_from_str(z_owned_encoding_t *encoding, const char *s) { int8_t z_encoding_from_substr(z_owned_encoding_t *encoding, const char *s, size_t len) { // Init owned encoding - _z_owned_encoding_null(encoding); + z_internal_encoding_null(encoding); // Convert string to encoding if (s != NULL) { return _z_encoding_convert_from_substr(encoding, s, len); @@ -411,7 +411,7 @@ int8_t z_encoding_set_schema_from_substr(z_loaned_encoding_t *encoding, const ch int8_t z_encoding_to_string(const z_loaned_encoding_t *encoding, z_owned_string_t *s) { // Init owned string - _z_owned_string_null(s); + z_internal_string_null(s); // Convert encoding to string _z_encoding_convert_into_string(encoding, s); return _Z_RES_OK; @@ -487,7 +487,7 @@ int8_t z_bytes_deserialize_into_slice(const z_loaned_bytes_t *bytes, z_owned_sli int8_t z_bytes_deserialize_into_string(const z_loaned_bytes_t *bytes, z_owned_string_t *s) { // Init owned string - _z_owned_string_null(s); + z_internal_string_null(s); // Convert bytes to string size_t len = _z_bytes_len(bytes); s->_val = _z_string_preallocate(len); @@ -912,13 +912,13 @@ int8_t z_scout(z_moved_config_t *config, z_moved_closure_hello_t *callback, cons } else { ret = _Z_ERR_SYSTEM_OUT_OF_MEMORY; } - _z_owned_closure_hello_null(&callback->_this); + z_internal_closure_hello_null(&callback->_this); return ret; } int8_t z_open(z_owned_session_t *zs, z_moved_config_t *config) { - _z_owned_session_null(zs); + z_internal_session_null(zs); _z_session_t *s = z_malloc(sizeof(_z_session_t)); if (s == NULL) { z_config_drop(config); @@ -937,7 +937,7 @@ int8_t z_open(z_owned_session_t *zs, z_moved_config_t *config) { int8_t ret = _z_open(&zs->_rc, &config->_this._val); if (ret != _Z_RES_OK) { _z_session_rc_decr(&zs->_rc); - _z_owned_session_null(zs); + z_internal_session_null(zs); z_config_drop(config); return ret; } @@ -947,7 +947,7 @@ int8_t z_open(z_owned_session_t *zs, z_moved_config_t *config) { } int8_t z_close(z_moved_session_t *zs) { - if (zs == NULL || !_z_owned_session_check(&zs->_this)) { + if (zs == NULL || !z_internal_session_check(&zs->_this)) { return _Z_RES_OK; } z_session_drop(zs); @@ -971,7 +971,7 @@ int8_t z_info_peers_zid(const z_loaned_session_t *zs, z_moved_closure_zid_t *cal if (callback->_this._val.drop != NULL) { callback->_this._val.drop(ctx); } - _z_owned_closure_zid_null(&callback->_this); + z_internal_closure_zid_null(&callback->_this); return 0; } @@ -991,7 +991,7 @@ int8_t z_info_routers_zid(const z_loaned_session_t *zs, z_moved_closure_zid_t *c if (callback->_this._val.drop != NULL) { callback->_this._val.drop(ctx); } - _z_owned_closure_zid_null(&callback->_this); + z_internal_closure_zid_null(&callback->_this); return 0; } @@ -1306,7 +1306,8 @@ int8_t z_get(const z_loaned_session_t *zs, const z_loaned_keyexpr_t *keyexpr, co z_bytes_drop(opt.payload); z_encoding_drop(opt.encoding); z_bytes_drop(opt.attachment); - _z_owned_closure_reply_null(&callback->_this); // call and drop passed to _z_query, so we nullify the closure here + z_internal_closure_reply_null( + &callback->_this); // call and drop passed to _z_query, so we nullify the closure here return ret; } @@ -1372,7 +1373,7 @@ int8_t z_declare_queryable(z_owned_queryable_t *queryable, const z_loaned_sessio queryable->_val = _z_declare_queryable(zs, key, opt.complete, callback->_this._val.call, callback->_this._val.drop, ctx); - _z_owned_closure_query_null(&callback->_this); + z_internal_closure_query_null(&callback->_this); return _Z_RES_OK; } @@ -1486,7 +1487,7 @@ int8_t z_keyexpr_from_str_autocanonize(z_owned_keyexpr_t *key, const char *name) } int8_t z_keyexpr_from_substr_autocanonize(z_owned_keyexpr_t *key, const char *name, size_t *len) { - _z_owned_keyexpr_null(key); + z_internal_keyexpr_null(key); char *name_copy = _z_str_n_clone(name, *len); if (name_copy == NULL) { return _Z_ERR_SYSTEM_OUT_OF_MEMORY; @@ -1504,7 +1505,7 @@ int8_t z_keyexpr_from_str(z_owned_keyexpr_t *key, const char *name) { } int8_t z_keyexpr_from_substr(z_owned_keyexpr_t *key, const char *name, size_t len) { - _z_owned_keyexpr_null(key); + z_internal_keyexpr_null(key); char *name_copy = _z_str_n_clone(name, len); if (name_copy == NULL) { return _Z_ERR_SYSTEM_OUT_OF_MEMORY; @@ -1605,7 +1606,7 @@ int8_t z_declare_subscriber(z_owned_subscriber_t *sub, const z_loaned_session_t if (suffix != NULL) { z_free(suffix); } - _z_owned_closure_sample_null(&callback->_this); + z_internal_closure_sample_null(&callback->_this); sub->_val = int_sub; if (!_z_subscriber_check(&sub->_val)) { diff --git a/tests/z_api_alignment_test.c b/tests/z_api_alignment_test.c index 29999db2a..e98de29da 100644 --- a/tests/z_api_alignment_test.c +++ b/tests/z_api_alignment_test.c @@ -186,10 +186,10 @@ int main(int argc, char **argv) { printf("Testing Configs..."); z_owned_config_t _ret_config; z_config_new(&_ret_config); - assert(!_z_check(_ret_config)); // null config corresponds to empty one + assert(!z_internal_check(_ret_config)); // null config corresponds to empty one z_drop(z_move(_ret_config)); z_config_default(&_ret_config); - assert(_z_check(_ret_config)); + assert(z_internal_check(_ret_config)); #ifdef ZENOH_PICO _ret_int8 = zp_config_insert(z_loan_mut(_ret_config), Z_CONFIG_CONNECT_KEY, argv[1]); assert_eq(_ret_int8, 0); @@ -200,7 +200,7 @@ int main(int argc, char **argv) { z_owned_config_t _ret_sconfig; z_config_default(&_ret_sconfig); - assert(_z_check(_ret_sconfig)); + assert(z_internal_check(_ret_sconfig)); printf("Ok\n"); z_sleep_s(SLEEP); @@ -219,7 +219,7 @@ int main(int argc, char **argv) { z_owned_session_t s1; z_open(&s1, z_move(_ret_config)); - assert(_z_check(s1)); + assert(z_internal_check(s1)); z_id_t _ret_zid = z_info_zid(z_loan(s1)); printf("Session 1 with PID: 0x"); for (unsigned long i = 0; i < sizeof(_ret_zid); i++) { @@ -263,7 +263,7 @@ int main(int argc, char **argv) { z_owned_session_t s2; z_open(&s2, z_move(_ret_config)); - assert(_z_check(s2)); + assert(z_internal_check(s2)); _ret_zid = z_info_zid(z_loan(s2)); printf("Session 2 with PID: 0x"); for (unsigned long i = 0; i < sizeof(_ret_zid); i++) { @@ -300,7 +300,7 @@ int main(int argc, char **argv) { z_view_keyexpr_from_str(&s1_key, s1_res); z_owned_keyexpr_t _ret_expr; z_declare_keyexpr(&_ret_expr, z_loan(s1), z_loan(s1_key)); - assert(_z_check(_ret_expr)); + assert(z_internal_check(_ret_expr)); printf("Ok\n"); printf("Session Put..."); @@ -317,7 +317,7 @@ int main(int argc, char **argv) { _ret_int8 = z_put(z_loan(s1), z_loan(_ret_expr), z_move(payload), &_ret_put_opt); assert_eq(_ret_int8, 0); - assert(!_z_check(encoding)); + assert(!z_internal_check(encoding)); printf("Ok\n"); z_sleep_s(SLEEP); @@ -338,7 +338,7 @@ int main(int argc, char **argv) { _ret_int8 = z_undeclare_keyexpr(z_move(_ret_expr), z_loan(s1)); printf(" %02x\n", _ret_int8); assert_eq(_ret_int8, 0); - assert(!_z_check(_ret_expr)); + assert(!z_internal_check(_ret_expr)); printf("Ok\n"); printf("Declaring Publisher..."); @@ -350,7 +350,7 @@ int main(int argc, char **argv) { z_owned_publisher_t _ret_pub; _ret_int8 = z_declare_publisher(&_ret_pub, z_loan(s1), z_loan(s1_key), &_ret_pub_opt); assert(_ret_int8 == _Z_RES_OK); - assert(!_z_check(encoding)); + assert(!z_internal_check(encoding)); printf("Ok\n"); z_sleep_s(SLEEP); @@ -381,7 +381,7 @@ int main(int argc, char **argv) { printf("Undeclaring Publisher..."); _ret_int8 = z_undeclare_publisher(z_move(_ret_pub)); assert_eq(_ret_int8, 0); - assert(!_z_check(_ret_pub)); + assert(!z_internal_check(_ret_pub)); printf("Ok\n"); z_sleep_s(SLEEP); @@ -389,7 +389,7 @@ int main(int argc, char **argv) { printf("Undeclaring Subscriber..."); _ret_int8 = z_undeclare_subscriber(z_move(_ret_sub)); assert_eq(_ret_int8, 0); - assert(!_z_check(_ret_sub)); + assert(!z_internal_check(_ret_sub)); printf("Ok\n"); z_sleep_s(SLEEP); diff --git a/tests/z_api_bytes_test.c b/tests/z_api_bytes_test.c index e3ab9b51c..cbf0c9610 100644 --- a/tests/z_api_bytes_test.c +++ b/tests/z_api_bytes_test.c @@ -205,14 +205,14 @@ void test_slice(void) { z_owned_slice_t s; z_slice_copy_from_buf(&s, data, 10); z_bytes_serialize_from_slice(&payload2, z_slice_loan(&s)); - assert(_z_owned_slice_check(&s)); + assert(z_internal_slice_check(&s)); z_slice_drop(z_slice_move(&s)); assert(z_check_and_drop_payload(&payload2, data, 10)); z_owned_bytes_t payload3; z_slice_copy_from_buf(&s, data, 10); z_bytes_from_slice(&payload3, z_slice_move(&s)); - assert(!_z_owned_slice_check(&s)); + assert(!z_internal_slice_check(&s)); assert(z_check_and_drop_payload(&payload3, data, 10)); z_owned_bytes_t payload4; diff --git a/tests/z_api_config_test.c b/tests/z_api_config_test.c index ca6dc6a71..534edd317 100644 --- a/tests/z_api_config_test.c +++ b/tests/z_api_config_test.c @@ -25,7 +25,7 @@ void config_client(void) { const char *locator = "tcp/127.0.0.1"; z_owned_config_t config; assert(0 == z_config_client(&config, locator)); - assert(_z_owned_config_check(&config)); + assert(z_internal_config_check(&config)); assert(strcmp(zp_config_get(z_config_loan(&config), Z_CONFIG_MODE_KEY), Z_CONFIG_MODE_CLIENT) == 0); assert(strcmp(zp_config_get(z_config_loan(&config), Z_CONFIG_CONNECT_KEY), locator) == 0); z_config_drop(z_config_move(&config)); @@ -35,12 +35,12 @@ void config_peer(void) { const char *locator = "udp/228.0.0.4:7447#iface=en0"; z_owned_config_t config; assert(0 == z_config_peer(&config, locator)); - assert(_z_owned_config_check(&config)); + assert(z_internal_config_check(&config)); assert(strcmp(zp_config_get(z_config_loan(&config), Z_CONFIG_MODE_KEY), Z_CONFIG_MODE_PEER) == 0); assert(strcmp(zp_config_get(z_config_loan(&config), Z_CONFIG_CONNECT_KEY), locator) == 0); z_config_drop(z_config_move(&config)); assert(0 != z_config_peer(&config, NULL)); - assert(!_z_owned_config_check(&config)); + assert(!z_internal_config_check(&config)); } int main(void) { diff --git a/tests/z_api_double_drop_test.c b/tests/z_api_double_drop_test.c index e04babcd0..7de607c24 100644 --- a/tests/z_api_double_drop_test.c +++ b/tests/z_api_double_drop_test.c @@ -25,21 +25,21 @@ void test_keyexpr(void) { z_owned_keyexpr_t keyexpr; z_keyexpr_from_str(&keyexpr, URL); - assert(_z_check(keyexpr)); + assert(z_internal_check(keyexpr)); z_drop(z_move(keyexpr)); - assert(!_z_check(keyexpr)); + assert(!z_internal_check(keyexpr)); z_drop(z_move(keyexpr)); - assert(!_z_check(keyexpr)); + assert(!z_internal_check(keyexpr)); } void test_config(void) { z_owned_config_t config; z_config_default(&config); - assert(_z_check(config)); + assert(z_internal_check(config)); z_drop(z_move(config)); - assert(!_z_check(config)); + assert(!z_internal_check(config)); z_drop(z_move(config)); - assert(!_z_check(config)); + assert(!z_internal_check(config)); } int main(void) { diff --git a/tests/z_api_encoding_test.c b/tests/z_api_encoding_test.c index bbcb6bc9b..8f3577085 100644 --- a/tests/z_api_encoding_test.c +++ b/tests/z_api_encoding_test.c @@ -10,15 +10,15 @@ void test_null_encoding(void) { z_owned_encoding_t e; - _z_owned_encoding_null(&e); - assert(!_z_owned_encoding_check(&e)); + z_internal_encoding_null(&e); + assert(!z_internal_encoding_check(&e)); z_encoding_drop(z_encoding_move(&e)); } void test_encoding_without_id(void) { z_owned_encoding_t e1; z_encoding_from_str(&e1, "my_encoding"); - assert(_z_owned_encoding_check(&e1)); + assert(z_internal_encoding_check(&e1)); z_owned_string_t s; z_encoding_to_string(z_encoding_loan(&e1), &s); assert(strncmp("zenoh/bytes;my_encoding", z_string_data(z_string_loan(&s)), z_string_len(z_string_loan(&s))) == 0); @@ -27,7 +27,7 @@ void test_encoding_without_id(void) { z_owned_encoding_t e2; z_encoding_from_substr(&e2, "my_encoding", 4); - assert(_z_owned_encoding_check(&e2)); + assert(z_internal_encoding_check(&e2)); z_encoding_to_string(z_encoding_loan(&e2), &s); assert(strncmp("zenoh/bytes;my_e", z_string_data(z_string_loan(&s)), z_string_len(z_string_loan(&s))) == 0); @@ -38,7 +38,7 @@ void test_encoding_without_id(void) { void test_encoding_with_id(void) { z_owned_encoding_t e1; z_encoding_from_str(&e1, "zenoh/string;utf8"); - assert(_z_owned_encoding_check(&e1)); + assert(z_internal_encoding_check(&e1)); z_owned_string_t s; z_encoding_to_string(z_encoding_loan(&e1), &s); assert(strncmp("zenoh/string;utf8", z_string_data(z_string_loan(&s)), z_string_len(z_string_loan(&s))) == 0); @@ -47,7 +47,7 @@ void test_encoding_with_id(void) { z_owned_encoding_t e2; z_encoding_from_substr(&e2, "zenoh/string;utf8", 15); - assert(_z_owned_encoding_check(&e2)); + assert(z_internal_encoding_check(&e2)); z_encoding_to_string(z_encoding_loan(&e2), &s); assert(strncmp("zenoh/string;utf8", z_string_data(z_string_loan(&s)), z_string_len(z_string_loan(&s))) == 0); @@ -56,7 +56,7 @@ void test_encoding_with_id(void) { z_owned_encoding_t e3; z_encoding_from_str(&e3, "custom_id;custom_schema"); - assert(_z_owned_encoding_check(&e3)); + assert(z_internal_encoding_check(&e3)); z_encoding_to_string(z_encoding_loan(&e3), &s); assert(strncmp("zenoh/bytes;custom_id;custom_schema", z_string_data(z_string_loan(&s)), @@ -66,7 +66,7 @@ void test_encoding_with_id(void) { z_owned_encoding_t e4; z_encoding_from_substr(&e4, "custom_id;custom_schema", 16); - assert(_z_owned_encoding_check(&e2)); + assert(z_internal_encoding_check(&e2)); z_encoding_to_string(z_encoding_loan(&e4), &s); assert(strncmp("zenoh/bytes;custom_id;custom", z_string_data(z_string_loan(&s)), z_string_len(z_string_loan(&s))) == @@ -77,7 +77,7 @@ void test_encoding_with_id(void) { void test_with_schema(void) { z_owned_encoding_t e; - _z_owned_encoding_null(&e); + z_internal_encoding_null(&e); z_encoding_set_schema_from_str(z_encoding_loan_mut(&e), "my_schema"); z_owned_string_t s; diff --git a/tests/z_api_null_drop_test.c b/tests/z_api_null_drop_test.c index bdb74d176..8168af075 100644 --- a/tests/z_api_null_drop_test.c +++ b/tests/z_api_null_drop_test.c @@ -30,19 +30,19 @@ // set v1 to null // move v to v1 // make sure that v is null now -#define TEST(name) \ - { \ - z_owned_##name##_t v; \ - memset(&v, -1, sizeof(v)); \ - _z_null(&v); \ - assert(!_z_check(v)); \ - z_drop(z_move(v)); \ - z_drop(z_move(v)); \ - z_owned_##name##_t v1; \ - _z_null(&v1); \ - memset(&v, -1, sizeof(v)); \ - z_take(&v1, z_move(v)); \ - assert(!_z_check(v)); \ +#define TEST(name) \ + { \ + z_owned_##name##_t v; \ + memset(&v, -1, sizeof(v)); \ + z_internal_null(&v); \ + assert(!z_internal_check(v)); \ + z_drop(z_move(v)); \ + z_drop(z_move(v)); \ + z_owned_##name##_t v1; \ + z_internal_null(&v1); \ + memset(&v, -1, sizeof(v)); \ + z_take(&v1, z_move(v)); \ + assert(!z_internal_check(v)); \ } int main(void) { diff --git a/tests/z_client_test.c b/tests/z_client_test.c index c08992e29..ba8afdb3d 100644 --- a/tests/z_client_test.c +++ b/tests/z_client_test.c @@ -148,7 +148,7 @@ int main(int argc, char **argv) { z_owned_session_t s2; assert(z_open(&s2, z_move(config)) == Z_OK); - assert(_z_check(s2)); + assert(z_internal_check(s2)); _z_string_t zid2 = format_id(&(_Z_RC_IN_VAL(z_loan(s2))->_local_zid)); printf("Session 2 with PID: %s\n", _z_string_data(&zid2)); _z_string_clear(&zid2); diff --git a/tests/z_keyexpr_test.c b/tests/z_keyexpr_test.c index 3cac6b17b..3c3c34ce2 100644 --- a/tests/z_keyexpr_test.c +++ b/tests/z_keyexpr_test.c @@ -469,7 +469,7 @@ void test_concat(void) { z_keyexpr_drop(z_keyexpr_move(&ke2)); assert(0 != z_keyexpr_concat(&ke2, z_keyexpr_loan(&ke1), "*/e/*", 3)); - assert(!_z_owned_keyexpr_check(&ke2)); + assert(!z_internal_keyexpr_check(&ke2)); z_keyexpr_drop(z_keyexpr_move(&ke1)); }