Skip to content

Commit

Permalink
Merge pull request #23 from jean-roland/fix_initializers
Browse files Browse the repository at this point in the history
fix: remove dedicated initializers
  • Loading branch information
jean-roland authored Dec 5, 2024
2 parents 5381f9b + 50ceb6b commit d651684
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 8 deletions.
10 changes: 8 additions & 2 deletions include/zenoh-pico/collections/refcount.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(); \
} \
Expand Down Expand Up @@ -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(); \
} \
Expand Down
11 changes: 9 additions & 2 deletions include/zenoh-pico/collections/slice.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion include/zenoh-pico/collections/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 12 additions & 2 deletions include/zenoh-pico/collections/vec.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion include/zenoh-pico/protocol/definitions/network.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d651684

Please sign in to comment.