From 50ceb6b6c484ed7c0014612694557e66fcb0895f Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Thu, 5 Dec 2024 10:43:36 +0100 Subject: [PATCH] fix: remove dedicated initializers --- include/zenoh-pico/collections/refcount.h | 10 ++++++++-- include/zenoh-pico/collections/slice.h | 11 +++++++++-- include/zenoh-pico/collections/string.h | 4 +++- include/zenoh-pico/collections/vec.h | 14 ++++++++++++-- include/zenoh-pico/protocol/definitions/network.h | 2 +- 5 files changed, 33 insertions(+), 8 deletions(-) diff --git a/include/zenoh-pico/collections/refcount.h b/include/zenoh-pico/collections/refcount.h index f1ad023f0..86775c68f 100644 --- a/include/zenoh-pico/collections/refcount.h +++ b/include/zenoh-pico/collections/refcount.h @@ -93,7 +93,10 @@ size_t _z_simple_rc_strong_count(void *cnt); } \ static inline name##_weak_t name##_rc_clone_as_weak(const name##_rc_t *p) { \ if (_z_rc_increase_weak(p->_cnt) == _Z_RES_OK) { \ - return (name##_weak_t){._val = p->_val, ._cnt = p->_cnt}; \ + name##_weak_t ret; \ + ret._val = p->_val; \ + ret._cnt = p->_cnt; \ + return ret; \ } \ return name##_weak_null(); \ } \ @@ -142,7 +145,10 @@ size_t _z_simple_rc_strong_count(void *cnt); static inline void name##_weak_copy(name##_weak_t *dst, const name##_weak_t *p) { *dst = name##_weak_clone(p); } \ static inline name##_rc_t name##_weak_upgrade(const name##_weak_t *p) { \ if (_z_rc_weak_upgrade(p->_cnt) == _Z_RES_OK) { \ - return (name##_rc_t){._val = p->_val, ._cnt = p->_cnt}; \ + name##_rc_t ret; \ + ret._val = p->_val; \ + ret._cnt = p->_cnt; \ + return ret; \ } \ return name##_rc_null(); \ } \ diff --git a/include/zenoh-pico/collections/slice.h b/include/zenoh-pico/collections/slice.h index de0c5987a..278048a82 100644 --- a/include/zenoh-pico/collections/slice.h +++ b/include/zenoh-pico/collections/slice.h @@ -34,7 +34,10 @@ typedef struct { static inline _z_delete_context_t _z_delete_context_null(void) { return (_z_delete_context_t){0}; } static inline _z_delete_context_t _z_delete_context_create(void (*deleter)(void *context, void *data), void *context) { - return (_z_delete_context_t){.deleter = deleter, .context = context}; + _z_delete_context_t ret; + ret.deleter = deleter; + ret.context = context; + return ret; } static inline bool _z_delete_context_is_null(const _z_delete_context_t *c) { return c->deleter == NULL; } _z_delete_context_t _z_delete_context_default(void); @@ -60,7 +63,11 @@ static inline void _z_slice_reset(_z_slice_t *bs) { *bs = _z_slice_null(); } static inline bool _z_slice_is_empty(const _z_slice_t *bs) { return bs->len == 0; } static inline bool _z_slice_check(const _z_slice_t *slice) { return slice->start != NULL; } static inline _z_slice_t _z_slice_alias(const _z_slice_t bs) { - return (_z_slice_t){.len = bs.len, .start = bs.start, ._delete_context = _z_delete_context_null()}; + _z_slice_t ret; + ret.len = bs.len; + ret.start = bs.start; + ret._delete_context = _z_delete_context_null(); + return ret; } z_result_t _z_slice_init(_z_slice_t *bs, size_t capacity); _z_slice_t _z_slice_make(size_t capacity); diff --git a/include/zenoh-pico/collections/string.h b/include/zenoh-pico/collections/string.h index 78fc0e5e5..9e094b795 100644 --- a/include/zenoh-pico/collections/string.h +++ b/include/zenoh-pico/collections/string.h @@ -74,7 +74,9 @@ typedef struct { static inline _z_string_t _z_string_null(void) { return (_z_string_t){0}; } static inline bool _z_string_check(const _z_string_t *value) { return !_z_slice_is_empty(&value->_slice); } static inline _z_string_t _z_string_alias(const _z_string_t str) { - return (_z_string_t){._slice = _z_slice_alias(str._slice)}; + _z_string_t ret; + ret._slice = _z_slice_alias(str._slice); + return ret; } _z_string_t _z_string_copy_from_str(const char *value); diff --git a/include/zenoh-pico/collections/vec.h b/include/zenoh-pico/collections/vec.h index 9596379c9..a9277d423 100644 --- a/include/zenoh-pico/collections/vec.h +++ b/include/zenoh-pico/collections/vec.h @@ -86,10 +86,20 @@ typedef struct { static inline _z_svec_t _z_svec_null(void) { return (_z_svec_t){0}; } static inline _z_svec_t _z_svec_alias(const _z_svec_t *src) { - return (_z_svec_t){._capacity = src->_capacity, ._len = src->_len, ._val = src->_val, ._aliased = true}; + _z_svec_t ret; + ret._capacity = src->_capacity; + ret._len = src->_len; + ret._val = src->_val; + ret._aliased = true; + return ret; } static inline _z_svec_t _z_svec_alias_element(void *element) { - return (_z_svec_t){._capacity = 1, ._len = 1, ._val = element, ._aliased = true}; + _z_svec_t ret; + ret._capacity = 1; + ret._len = 1; + ret._val = element; + ret._aliased = true; + return ret; } void _z_svec_init(_z_svec_t *v, size_t offset, size_t element_size); _z_svec_t _z_svec_make(size_t capacity, size_t element_size); diff --git a/include/zenoh-pico/protocol/definitions/network.h b/include/zenoh-pico/protocol/definitions/network.h index f828d48f1..122f09aba 100644 --- a/include/zenoh-pico/protocol/definitions/network.h +++ b/include/zenoh-pico/protocol/definitions/network.h @@ -96,7 +96,7 @@ static inline bool _z_n_qos_get_express(_z_n_qos_t n_qos) { return (bool)(n_qos. #define _z_n_qos_make(express, nodrop, priority) \ _z_n_qos_create((bool)express, nodrop ? Z_CONGESTION_CONTROL_BLOCK : Z_CONGESTION_CONTROL_DROP, \ (z_priority_t)priority) -#define _Z_N_QOS_DEFAULT ((_z_qos_t){._val = 5}) +static const _z_qos_t _Z_N_QOS_DEFAULT = {._val = 5}; // RESPONSE FINAL message flags: // Z Extensions if Z==1 then Zenoh extensions are present